Deprecate the old macro syntax (#1025)

Fixes #1011
This commit is contained in:
Rangi
2022-08-28 15:22:21 -04:00
committed by GitHub
parent 7a2ee26792
commit 14e6a79adc
55 changed files with 94 additions and 87 deletions

View File

@@ -1,4 +1,4 @@
print_all: MACRO
MACRO print_all
REPT _NARG
PRINT " \1"
SHIFT
@@ -6,7 +6,7 @@ print_all: MACRO
PRINTLN
ENDM
print_some: MACRO
MACRO print_some
PRINT "\1"
SHIFT 5
PRINT "\2\6\9"
@@ -15,12 +15,12 @@ print_some: MACRO
PRINT "\3\9"
ENDM
bad: MACRO
MACRO bad
shift _NARG - 1
PRINTLN \1
ENDM
bad_rept: MACRO
MACRO bad_rept
REPT _NARG - 2
REPT 1
shift

View File

@@ -1,4 +1,4 @@
def_sect: macro
macro def_sect
IF _NARG == 2
SECTION "\1", \2
ELSE

View File

@@ -11,7 +11,7 @@ rept 1
break
; skips invalid code
!@#$%
elif: macro
macro elif
invalid
endr
warn "OK"

View File

@@ -1,7 +1,7 @@
println "start"
; will not define 'mac'
mac: MACRO
MACRO mac
println \1
ENDM println "<_<"
mac "argument"

View File

@@ -1,6 +1,6 @@
def _ASM equ 0
test: MACRO
MACRO test
; Test RGBASM
redef V equs "_ASM +"
static_assert \#
@@ -9,7 +9,7 @@ test: MACRO
assert \#
ENDM
test_mod: MACRO
MACRO test_mod
def x = \1 ; dividend
def y = \2 ; divisor
shift 2
@@ -21,14 +21,14 @@ test_mod: MACRO
test (V (x - y) % y) == (V r)
ENDM
test_each_mod: MACRO
MACRO test_each_mod
test_mod (\1), (\2)
test_mod (\1), -(\2)
test_mod -(\1), (\2)
test_mod -(\1), -(\2)
ENDM
test_pow: MACRO
MACRO test_pow
def x = \1 ; dividend
def y = 2 ** \2 ; divisor
def r = x % y ; remainder
@@ -37,7 +37,7 @@ test_pow: MACRO
test (V r) == (V m)
ENDM
test_each_pow: MACRO
MACRO test_each_pow
test_pow (\1), (\2)
test_pow -(\1), (\2)
ENDM

View File

@@ -1,3 +1,3 @@
DEFINE equs "mac: MACRO\nPRINTLN \"Hello :D\"\nENDM"
DEFINE equs "MACRO mac\nPRINTLN \"Hello :D\"\nENDM"
DEFINE
mac

View File

@@ -1,4 +1,4 @@
test: MACRO
MACRO test
v equs "X"
X equs "" ; should not be expanded
\1

View File

@@ -1,4 +1,4 @@
m: macro
macro m
if 0
WARN "3"
else

View File

@@ -1,6 +1,6 @@
; This test tries to pass invalid UTF-8 through a macro argument
; to exercise the lexer's unknown character reporting
m:MACRO
MACRO m
\1
ENDM
m <EFBFBD><EFBFBD>

View File

@@ -1,7 +1,7 @@
TEST_NUM = 0
test_expr: MACRO
MACRO test_expr
TEST_NUM = TEST_NUM + 1
IS_CONST = ISCONST(\1)

View File

@@ -16,7 +16,7 @@ SECTION "fixed 2", ROM0[69]
Constant2: ; Same as above
print_diff: MACRO
MACRO print_diff
PRINTLN (\1) - (\2)
PRINTLN (\2) - (\1)
ENDM

View File

@@ -0,0 +1,2 @@
warning: label-indent.asm(10): [-Wobsolete]
`mac: MACRO` is deprecated; use `MACRO mac`

View File

@@ -1,11 +1,11 @@
m1: MACRO
MACRO m1
x\1
ENDM
S EQUS "y"
S2 EQUS "yy"
m2: MACRO
MACRO m2
S\1
ENDM
@@ -20,7 +20,7 @@ ENDM
println yy
test_char: MACRO
MACRO test_char
VAR_DEF equs "sizeof_\1something = 0"
VAR_DEF
sizeof_\1something = 1

View File

@@ -1,6 +1,6 @@
SECTION "sec", ROM0
dw Sym
m: MACRO
MACRO m
Sym::
ENDM
m

View File

@@ -1,7 +1,7 @@
m: MACRO
MACRO m
ENDM
m2: MACRO
MACRO m2
m \
ENDM

View File

@@ -1,4 +1,4 @@
m: MACRO
MACRO m
ENDM
REPT 1

View File

@@ -1,7 +1,7 @@
; Test that \ followed by whitespace after a macro invocation at the end of the
; file doesn't cause a segfault.
bar: MACRO
MACRO bar
ENDM
foo: bar baz\

View File

@@ -1,7 +1,7 @@
; Test that \ after a macro invocation at the end of the file doesn't
; cause a segfault.
bar: MACRO
MACRO bar
ENDM
foo: bar baz\

View File

@@ -2,7 +2,7 @@ SECTION "sec", ROM0
X0 EQUS "0"
m: MACRO
MACRO m
\1 EQUS STRCAT("{X\2}", "+1")
ENDM

View File

@@ -4,7 +4,7 @@ fifty-seven--characters altogether. That's just enough for its last
two characters to be truncated by rgbasm's lexer, since it can't
handle more than 255-character strings. The final two won't print: !?"""
mac: MACRO
MACRO mac
println "\1" ; x1
println "\1\1\1\1\1\1" ; x6
ENDM

View File

@@ -1,6 +1,6 @@
SECTION "Test", ROM0
list: MACRO
MACRO list
db _NARG
if _NARG > 0
db \#
@@ -12,11 +12,11 @@ ENDM
list 42
list $aa, $bb, $cc, $dd, $ee
person: MACRO
MACRO person
db \1, \2, \3, \4, \5
ENDM
object: MACRO
MACRO object
x = \1
y = \2
shift 2
@@ -26,7 +26,7 @@ ENDM
person 5, 10, $33, $44, $55
object 12, 6, $66, $77, $88
echo: MACRO
MACRO echo
println "\#"
ENDM
@@ -36,7 +36,7 @@ R EQUS "S"
echo Q,R, {R}, T
echo 42,$2a
printall: MACRO
MACRO printall
println \#
ENDM

View File

@@ -1,4 +1,4 @@
print1: MACRO
MACRO print1
if _NARG == 2
assert !STRCMP("\1", \2)
endc
@@ -12,14 +12,14 @@ D
print1 E\!F ; illegal character escape
iprint: MACRO
MACRO iprint
PRINTLN "{\1}"
ENDM
s EQUS "hello"
iprint s
symprint: MACRO
MACRO symprint
PRINTLN {\1}
ENDM

View File

@@ -1,4 +1,4 @@
addargs: MACRO
MACRO addargs
sum = 0
rept _NARG
sum = sum + \1

View File

@@ -1,4 +1,4 @@
mac: MACRO
MACRO mac
println "'mac \#':"
for i, _NARG
println strfmt("\\%d: <\1>", i+1)

View File

@@ -1,6 +1,6 @@
; Macro invocations not followed by a newline may scan an EOF;
; If this is the case, it shouldn't cause the parse to end before the macro is expanded
mac: macro
macro mac
PRINTLN "Hi beautiful"
endm
mac

View File

@@ -1,6 +1,6 @@
WARN "Line 2"
m: macro
macro m
WARN "Line 4"
endm
WARN "Line 6"

View File

@@ -1,5 +1,5 @@
; Check deleting a macro then using its file stack info
m: MACRO
MACRO m
PURGE m
WARN "Where am I?"
ENDM

View File

@@ -1,4 +1,4 @@
recurse: MACRO
MACRO recurse
recurse
ENDM
recurse

View File

@@ -1,3 +1,5 @@
warning: macro-syntax.asm(2): [-Wobsolete]
`old: MACRO` is deprecated; use `MACRO old`
error: macro-syntax.asm(13):
syntax error, unexpected identifier, expecting newline
error: macro-syntax.asm(15):

View File

@@ -1,6 +1,6 @@
X equ 0
test: MACRO
MACRO test
; Test RGBASM
v equs "X +"
static_assert \#

View File

@@ -15,7 +15,7 @@ can contain:
PRINT """\n"""
printarg: MACRO
MACRO printarg
PRINTLN "arg <\1>"
PRINTLN """arg (\1)"""
ENDM

View File

@@ -1,6 +1,6 @@
opt Wno-unmapped-char
new_: MACRO
MACRO new_
IF _NARG > 1
println "newcharmap \1, \2"
newcharmap \1, \2
@@ -10,22 +10,22 @@ new_: MACRO
ENDC
ENDM
set_: MACRO
MACRO set_
println "setcharmap \1"
setcharmap \1
ENDM
push_: MACRO
MACRO push_
println "pushc"
pushc
ENDM
pop_: MACRO
MACRO pop_
println "popc"
popc
ENDM
print_mapped: MACRO
MACRO print_mapped
x = \1
println "{x}"
ENDM

View File

@@ -1,4 +1,4 @@
testing: MACRO
MACRO testing
db _NARG
shift
db _NARG

View File

@@ -1,5 +1,5 @@
outer_ok: MACRO
definition equs "inner_ok: MACRO\nPRINTLN \"Hello!\"\nENDM"
MACRO outer_ok
definition equs "MACRO inner_ok\nPRINTLN \"Hello!\"\nENDM"
definition
PURGE definition
ENDM
@@ -8,8 +8,8 @@ ENDM
inner_ok
outer_arg: MACRO
definition equs "inner_arg: MACRO\nPRINTLN \"outer: \1\\ninner: \\1\"\nENDM"
MACRO outer_arg
definition equs "MACRO inner_arg\nPRINTLN \"outer: \1\\ninner: \\1\"\nENDM"
definition
PURGE definition
ENDM
@@ -18,9 +18,9 @@ ENDM
inner_arg inside
outer: MACRO
MACRO outer
WARN "Nested macros shouldn't work, whose argument would be \\1?"
inner: MACRO
MACRO inner
ENDM
outer

Binary file not shown.

View File

@@ -1,6 +1,6 @@
SECTION "sec", ROM0
print_x: MACRO
MACRO print_x
println x
ENDM

View File

@@ -1,11 +1,11 @@
printargs: MACRO
MACRO printargs
rept _NARG
println \1
shift
endr
ENDM
printlit: MACRO
MACRO printlit
rept _NARG
println "\1"
shift

View File

@@ -3,12 +3,12 @@ REDEF n EQU 1
; prints "$1"
PRINTLN n
list: MACRO
MACRO list
LIST_NAME EQUS "\1"
DEF LENGTH_{LIST_NAME} EQU 0
ENDM
item: MACRO
MACRO item
REDEF LENGTH_{LIST_NAME} EQU LENGTH_{LIST_NAME} + 1
DEF {LIST_NAME}_{d:LENGTH_{LIST_NAME}} EQU \1
ENDM

View File

@@ -3,7 +3,7 @@ REDEF s EQUS "{s}world!"
; prints "Hello, world!"
PRINTLN "{s}"
list: MACRO
MACRO list
LIST_NAME EQUS "\1"
REDEF {LIST_NAME} EQUS "["
REPT _NARG - 1

View File

@@ -8,6 +8,6 @@ W equ 0 ; OK
X equs "0" ; Not OK
db Y
Y: macro ; Not ok
macro Y ; Not ok
db 0
endm

View File

@@ -1,4 +1,4 @@
m: macro
macro m
PRINT "\1 "
REPT 4
SHIFT

View File

@@ -15,7 +15,7 @@ SECTION "calls", ROM0[0]
rst rst2A
defRST: MACRO
MACRO defRST
SECTION "rst\1", ROM0[$\1]
rst\1:
ENDM

View File

@@ -16,7 +16,7 @@ End:
SECTION UNION "test", WRAM0,ALIGN[9]
check_label: MACRO
MACRO check_label
EXPECTED equ \2
IF \1 == EXPECTED
RESULT equs "OK!"

View File

@@ -1,4 +1,4 @@
reverse: MACRO
MACRO reverse
for i, _NARG
i = _NARG - i - 1
shift i
@@ -9,7 +9,7 @@ ENDM
reverse $1, $2, $3
m: MACRO
MACRO m
shift 2
shift -3
shift 1

View File

@@ -1,4 +1,4 @@
mac: MACRO
MACRO mac
if (\1) < 10
println "small \1"
elif (\1) > 100

View File

@@ -9,7 +9,7 @@ s equs "hello"
println "<{f:pi}> <{06.f:f}> <{.10f:f}>"
println "<{#-10s:s}> <{10s:s}>"
foo: macro
macro foo
println "<{\1}>"
endm

View File

@@ -1,6 +1,6 @@
SECTION "sec", ROM0
xstrlen: MACRO
MACRO xstrlen
PRINTLN STRLEN(\1)
ENDM

View File

@@ -1,6 +1,6 @@
SECTION "sec", ROM0
xstrsub: MACRO
MACRO xstrsub
PRINTLN STRSUB(\#)
ENDM

View File

@@ -1,6 +1,6 @@
SECTION "test", ROM0
mac: MACRO
MACRO mac
println "\#"
ENDM

View File

@@ -1,6 +1,6 @@
warn_unique EQUS "WARN \"\\@!\""
m: macro
macro m
warn_unique
REPT 2
warn_unique

View File

@@ -2,7 +2,7 @@ SECTION "All instructions", ROM0[0]
; 8-bit Arithmetic and Logic Instructions
alu_instruction_list: MACRO
MACRO alu_instruction_list
\1 a,a
\1 a,b
\1 a,c
@@ -23,7 +23,7 @@ ENDM
alu_instruction_list sub
alu_instruction_list xor
incdec_8bit_instruction_list: MACRO
MACRO incdec_8bit_instruction_list
\1 a
\1 b
\1 c
@@ -56,7 +56,7 @@ ENDM
; Bit Operations Instructions
bitop_u3_instruction_list: MACRO
MACRO bitop_u3_instruction_list
NBIT = 0
REPT 8
\1 NBIT,a
@@ -75,7 +75,7 @@ ENDM
bitop_u3_instruction_list res
bitop_u3_instruction_list set
bitop_noarg_instruction_list: MACRO
MACRO bitop_noarg_instruction_list
\1 a
\1 b
\1 c
@@ -105,7 +105,7 @@ ENDM
; Load Instructions
ld_r8_x_instruction_list: MACRO
MACRO ld_r8_x_instruction_list
ld \1,a
ld \1,b
ld \1,c
@@ -125,7 +125,7 @@ ENDM
ld_r8_x_instruction_list [hl]
ld_r8_x_instruction_list l
ld_x_r8_instruction_list: MACRO
MACRO ld_x_r8_instruction_list
ld a,\1
ld b,\1
ld c,\1

View File

@@ -1,5 +1,5 @@
ldhilo : MACRO
ld HIGH(\1),LOW(\2)
MACRO ldhilo
ld HIGH(\1),LOW(\2)
ENDM
SECTION "r0", ROM0[$0]

View File

@@ -13,7 +13,7 @@ SECTION "calls", ROM0[0]
rst rst38
defRST: MACRO
MACRO defRST
SECTION "rst\1", ROM0[$\1]
rst\1:
ENDM