Consistently handle negative shifted macro args (#2014)

Negative macro arguments count from the end, i.e. `\<-1>`
is equivalent to `\<_NARG>`, even after `shift`ing them.

Negative arguments cannot be used to access shifted values.
This commit is contained in:
Rangi
2026-07-07 02:19:37 -04:00
committed by GitHub
parent f82b0838a1
commit 21682e8814
5 changed files with 72 additions and 10 deletions
+22
View File
@@ -0,0 +1,22 @@
MACRO test
static_assert _NARG == 10
println _NARG
println \1, \<10>, \<-1>, \<-10>
println \<999>
println \<-999>
shift 3
println _NARG
println \1, \7, \<-1>, \<-7>
println \<8>
println \<-8>
println \<-999>
shift 7
println _NARG
println \1
println \<-1>
shift -10
println _NARG
println \<-2_147_483_648>
ENDM
test "a", "b", "c", "d", "e", "f", "g", "h", "i", "j"
+19
View File
@@ -0,0 +1,19 @@
error: Macro argument `\<999>` not defined
at negative-shifted-macro-args.asm::test(5) <- negative-shifted-macro-args.asm(22)
error: Macro argument `\<-999>` not defined
at negative-shifted-macro-args.asm::test(6) <- negative-shifted-macro-args.asm(22)
error: Macro argument `\<8>` not defined
at negative-shifted-macro-args.asm::test(10) <- negative-shifted-macro-args.asm(22)
error: Macro argument `\<-8>` not defined
at negative-shifted-macro-args.asm::test(11) <- negative-shifted-macro-args.asm(22)
error: Macro argument `\<-999>` not defined
at negative-shifted-macro-args.asm::test(12) <- negative-shifted-macro-args.asm(22)
error: Macro argument `\1` not defined
at negative-shifted-macro-args.asm::test(15) <- negative-shifted-macro-args.asm(22)
error: Macro argument `\<-1>` not defined
at negative-shifted-macro-args.asm::test(16) <- negative-shifted-macro-args.asm(22)
error: Number in bracketed macro argument is too large
at negative-shifted-macro-args.asm::test(19) <- negative-shifted-macro-args.asm(22)
error: syntax error, unexpected >
at negative-shifted-macro-args.asm::test(19) <- negative-shifted-macro-args.asm(22)
Assembly aborted with 9 errors
+13
View File
@@ -0,0 +1,13 @@
$A
ajja
$7
djjd
$0
$A