Allow negative values to count macro arguments from the end (#1670)

This commit is contained in:
Rangi
2025-04-20 00:37:50 -04:00
committed by GitHub
parent df83bc31d2
commit 0b7cda9e0c
7 changed files with 91 additions and 11 deletions

View File

@@ -0,0 +1,21 @@
MACRO mac
for i, -1, -_NARG - 1, -1
println "{d:i}: \<i> == \<{d:i}>"
endr
; error cases
def i = 0
println "{d:i}: \<i> == \<{d:i}>"
def i = -_NARG - 1
println "{d:i}: \<i> == \<{d:i}>"
def i = $7fff_ffff
println "{d:i}: \<i> == \<{d:i}>"
; signed/unsigned difference error cases
def i = $8000_0000
println "{d:i}: \<i> == \<{d:i}>"
println "{u:i}: \<i> == \<{u:i}>"
def i = $ffff_ffff
println "{d:i}: \<i> == \<{d:i}>"
println "{u:i}: \<i> == \<{u:i}>"
ENDM
mac A, B, C, D, E, F, G

View File

@@ -0,0 +1,26 @@
error: negative-macro-args.asm(21) -> negative-macro-args.asm::mac(7):
Invalid bracketed macro argument '\<0>'
error: negative-macro-args.asm(21) -> negative-macro-args.asm::mac(7):
Invalid bracketed macro argument '\<0>'
error: negative-macro-args.asm(21) -> negative-macro-args.asm::mac(9):
Macro argument '\<-8>' not defined
error: negative-macro-args.asm(21) -> negative-macro-args.asm::mac(9):
Macro argument '\<-8>' not defined
error: negative-macro-args.asm(21) -> negative-macro-args.asm::mac(11):
Macro argument '\<2147483647>' not defined
error: negative-macro-args.asm(21) -> negative-macro-args.asm::mac(11):
Macro argument '\<2147483647>' not defined
error: negative-macro-args.asm(21) -> negative-macro-args.asm::mac(14):
Macro argument '\<-2147483648>' not defined
error: negative-macro-args.asm(21) -> negative-macro-args.asm::mac(14):
Number in bracketed macro argument is too large
while expanding symbol "-2147483648"
error: negative-macro-args.asm(21) -> negative-macro-args.asm::mac(15):
Macro argument '\<-2147483648>' not defined
error: negative-macro-args.asm(21) -> negative-macro-args.asm::mac(15):
Number in bracketed macro argument is too large
while expanding symbol "2147483648"
error: negative-macro-args.asm(21) -> negative-macro-args.asm::mac(18):
Number in bracketed macro argument is too large
while expanding symbol "4294967295"
error: Assembly aborted (11 errors)!

View File

@@ -0,0 +1,14 @@
-1: G == G
-2: F == F
-3: E == E
-4: D == D
-5: C == C
-6: B == B
-7: A == A
0: ==
-8: ==
2147483647: ==
-2147483648: == >
2147483648: == >
-1: G == G
4294967295: G == >