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

@@ -1214,14 +1214,16 @@ The example above defines
.Ql MyMacro .Ql MyMacro
as a new macro. as a new macro.
String constants are not expanded within the name of the macro. String constants are not expanded within the name of the macro.
You may use the older syntax .Pp
(Using the
.Em deprecated
older syntax
.Ql MyMacro: MACRO .Ql MyMacro: MACRO
instead of instead of
.Ql MACRO MyMacro , .Ql MACRO MyMacro ,
with a single colon with a single colon
.Ql \&: .Ql \&:
following the macro's name. following the macro's name, string constants may be expanded for the name.)
With the older syntax, string constants may be expanded for the name.
.Pp .Pp
Macros can't be exported or imported. Macros can't be exported or imported.
.Pp .Pp

View File

@@ -1100,6 +1100,7 @@ macrodef : T_POP_MACRO {
captureBody.size); captureBody.size);
} }
| T_LABEL T_COLON T_POP_MACRO T_NEWLINE { | T_LABEL T_COLON T_POP_MACRO T_NEWLINE {
warning(WARNING_OBSOLETE, "`%s: MACRO` is deprecated; use `MACRO %s`\n", $1, $1);
$<captureTerminated>$ = lexer_CaptureMacroBody(&captureBody); $<captureTerminated>$ = lexer_CaptureMacroBody(&captureBody);
} endofline { } endofline {
if ($<captureTerminated>5) if ($<captureTerminated>5)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -16,7 +16,7 @@ SECTION "fixed 2", ROM0[69]
Constant2: ; Same as above Constant2: ; Same as above
print_diff: MACRO MACRO print_diff
PRINTLN (\1) - (\2) PRINTLN (\1) - (\2)
PRINTLN (\2) - (\1) PRINTLN (\2) - (\1)
ENDM 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 x\1
ENDM ENDM
S EQUS "y" S EQUS "y"
S2 EQUS "yy" S2 EQUS "yy"
m2: MACRO MACRO m2
S\1 S\1
ENDM ENDM
@@ -20,7 +20,7 @@ ENDM
println yy println yy
test_char: MACRO MACRO test_char
VAR_DEF equs "sizeof_\1something = 0" VAR_DEF equs "sizeof_\1something = 0"
VAR_DEF VAR_DEF
sizeof_\1something = 1 sizeof_\1something = 1

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -2,7 +2,7 @@ SECTION "sec", ROM0
X0 EQUS "0" X0 EQUS "0"
m: MACRO MACRO m
\1 EQUS STRCAT("{X\2}", "+1") \1 EQUS STRCAT("{X\2}", "+1")
ENDM 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 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: !?""" handle more than 255-character strings. The final two won't print: !?"""
mac: MACRO MACRO mac
println "\1" ; x1 println "\1" ; x1
println "\1\1\1\1\1\1" ; x6 println "\1\1\1\1\1\1" ; x6
ENDM ENDM

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,6 +1,6 @@
; Macro invocations not followed by a newline may scan an EOF; ; 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 ; 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" PRINTLN "Hi beautiful"
endm endm
mac mac

View File

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

View File

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

View File

@@ -1,4 +1,4 @@
recurse: MACRO MACRO recurse
recurse recurse
ENDM ENDM
recurse 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): error: macro-syntax.asm(13):
syntax error, unexpected identifier, expecting newline syntax error, unexpected identifier, expecting newline
error: macro-syntax.asm(15): error: macro-syntax.asm(15):

View File

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

View File

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

View File

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

View File

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

View File

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

Binary file not shown.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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