Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failing assertion with backslash at EOF in macro arguments #1634

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/asm/lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,9 @@ void BufferedContent::advance() {
if (offset == std::size(buf)) {
offset = 0; // Wrap around if necessary
}
assume(size > 0);
size--;
if (size > 0) {
size--;
}
}

void BufferedContent::refill() {
Expand Down
3 changes: 3 additions & 0 deletions test/asm/command-line-symbols.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
assert !strcmp("{FOO}", "hello")
assert !strcmp("{DEFINED}", "1")
def FOO equ 42
3 changes: 3 additions & 0 deletions test/asm/command-line-symbols.err
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
error: command-line-symbols.asm(3):
'FOO' already defined at <command-line>
error: Assembly aborted (1 error)!
1 change: 1 addition & 0 deletions test/asm/command-line-symbols.flags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Weverything -DFOO=hello -DDEFINED
3 changes: 3 additions & 0 deletions test/asm/for.asm
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ for {s}, 3, 30, 3
print "{d:x} "
endr
println "-> {d:x}"
for s, 10
println "{d:s}"
endr

for v, 10
println "{d:v}"
Expand Down
8 changes: 5 additions & 3 deletions test/asm/for.err
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ error: for.asm(16):
FOR cannot have a step value of 0
warning: for.asm(20): [-Wbackwards-for]
FOR goes backwards from 1 to 2 by -1
error: for.asm(45) -> for.asm::REPT~4(51):
'v' already defined as constant at for.asm(45) -> for.asm::REPT~4(49)
FATAL: for.asm(45) -> for.asm::REPT~4(51):
error: for.asm(46):
's' already defined as constant at for.asm(39)
error: for.asm(48) -> for.asm::REPT~4(54):
'v' already defined as constant at for.asm(48) -> for.asm::REPT~4(52)
FATAL: for.asm(48) -> for.asm::REPT~4(54):
Failed to update FOR symbol value
5 changes: 5 additions & 0 deletions test/asm/macro-arg-escape-chars.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
MACRO mac
DEF s EQUS "\#"
println "{#s:s}"
ENDM
mac \\\"\t\r\0\n\{\}\,\(\)\w\
5 changes: 5 additions & 0 deletions test/asm/macro-arg-escape-chars.err
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: macro-arg-escape-chars.asm(5):
Illegal character escape 'w'
error: macro-arg-escape-chars.asm(5):
Illegal character escape at end of input
error: Assembly aborted (2 errors)!
1 change: 1 addition & 0 deletions test/asm/macro-arg-escape-chars.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
\\\"\t\r\0\n\{},()w\\
11 changes: 11 additions & 0 deletions test/asm/string-literal-macro-arg.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
MACRO mac
println "\1"
println \1
ENDM
mac "hello \\\"\t\r\0\n\ ; comment
\wor\
ld"
mac """goodbye
cruel\ ; comment
\nworld"""
mac "\
9 changes: 9 additions & 0 deletions test/asm/string-literal-macro-arg.err
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error: string-literal-macro-arg.asm(6):
Illegal character escape 'w'
error: string-literal-macro-arg.asm(11):
Illegal character escape at end of input
error: string-literal-macro-arg.asm(11):
Unterminated string
error: string-literal-macro-arg.asm(11) -> string-literal-macro-arg.asm::mac(4):
Unterminated string
error: Assembly aborted (4 errors)!
Binary file added test/asm/string-literal-macro-arg.out
Binary file not shown.
Loading