shithub: rgbds

Download patch

ref: 14e6a79adce5216144e638f7f3c9ca66e79aa08e
parent: 7a2ee26792b35a714002574bfdbe3ec70b0fe7b9
author: Rangi <35663410+Rangi42@users.noreply.github.com>
date: Sun Aug 28 11:22:21 EDT 2022

Deprecate the old macro syntax (#1025)

Fixes #1011

--- a/man/rgbasm.5
+++ b/man/rgbasm.5
@@ -1214,14 +1214,16 @@
 .Ql MyMacro
 as a new 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
 instead of
 .Ql MACRO MyMacro ,
 with a single colon
 .Ql \&:
-following the macro's name.
-With the older syntax, string constants may be expanded for the name.
+following the macro's name, string constants may be expanded for the name.)
 .Pp
 Macros can't be exported or imported.
 .Pp
--- a/src/asm/parser.y
+++ b/src/asm/parser.y
@@ -1100,6 +1100,7 @@
 					     captureBody.size);
 		}
 		| 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);
 		} endofline {
 			if ($<captureTerminated>5)
--- a/test/asm/arg-shift.asm
+++ b/test/asm/arg-shift.asm
@@ -1,4 +1,4 @@
-print_all: MACRO
+MACRO print_all
 	REPT _NARG
 		PRINT " \1"
 		SHIFT
@@ -6,7 +6,7 @@
 	PRINTLN
 ENDM
 
-print_some: MACRO
+MACRO print_some
 	PRINT "\1"
 	SHIFT 5
 	PRINT "\2\6\9"
@@ -15,12 +15,12 @@
 	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
--- a/test/asm/bank.asm
+++ b/test/asm/bank.asm
@@ -1,4 +1,4 @@
-def_sect: macro
+macro def_sect
 	IF _NARG == 2
 		SECTION "\1", \2
 	ELSE
--- a/test/asm/break.asm
+++ b/test/asm/break.asm
@@ -11,7 +11,7 @@
   break
   ; skips invalid code
   !@#$%
-elif: macro
+macro elif
   invalid
 endr
 warn "OK"
--- a/test/asm/code-after-endm-endr-endc.asm
+++ b/test/asm/code-after-endm-endr-endc.asm
@@ -1,7 +1,7 @@
 println "start"
 
 ; will not define 'mac'
-mac: MACRO
+MACRO mac
 	println \1
 ENDM println "<_<"
 	mac "argument"
--- a/test/asm/div-mod.asm
+++ b/test/asm/div-mod.asm
@@ -1,6 +1,6 @@
 def _ASM equ 0
 
-test: MACRO
+MACRO test
 	; Test RGBASM
 	redef V equs "_ASM +"
 	static_assert \#
@@ -9,7 +9,7 @@
 	assert \#
 ENDM
 
-test_mod: MACRO
+MACRO test_mod
 	def x = \1 ; dividend
 	def y = \2 ; divisor
 	shift 2
@@ -21,7 +21,7 @@
 	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)
@@ -28,7 +28,7 @@
 	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 (V r) == (V m)
 ENDM
 
-test_each_pow: MACRO
+MACRO test_each_pow
 	test_pow (\1), (\2)
 	test_pow -(\1), (\2)
 ENDM
--- a/test/asm/equs-macrodef.asm
+++ b/test/asm/equs-macrodef.asm
@@ -1,3 +1,3 @@
-DEFINE equs "mac: MACRO\nPRINTLN \"Hello :D\"\nENDM"
+DEFINE equs "MACRO mac\nPRINTLN \"Hello :D\"\nENDM"
 DEFINE
 	mac
--- a/test/asm/expand-empty-string.asm
+++ b/test/asm/expand-empty-string.asm
@@ -1,4 +1,4 @@
-test: MACRO
+MACRO test
 v equs "X"
 X equs "" ; should not be expanded
 \1
--- a/test/asm/if-macro.asm
+++ b/test/asm/if-macro.asm
@@ -1,4 +1,4 @@
-m: macro
+macro m
 	if 0
 		WARN "3"
 	else
--- a/test/asm/invalid-utf-8.asm
+++ b/test/asm/invalid-utf-8.asm
@@ -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 ��
--- a/test/asm/isconst.asm
+++ b/test/asm/isconst.asm
@@ -1,7 +1,7 @@
 
 TEST_NUM = 0
 
-test_expr: MACRO
+MACRO test_expr
 TEST_NUM = TEST_NUM + 1
 
 IS_CONST = ISCONST(\1)
--- a/test/asm/label-diff.asm
+++ b/test/asm/label-diff.asm
@@ -16,7 +16,7 @@
 Constant2: ; Same as above
 
 
-print_diff: MACRO
+MACRO print_diff
 	PRINTLN (\1) - (\2)
 	PRINTLN (\2) - (\1)
 ENDM
--- a/test/asm/label-indent.err
+++ b/test/asm/label-indent.err
@@ -1,0 +1,2 @@
+warning: label-indent.asm(10): [-Wobsolete]
+    `mac: MACRO` is deprecated; use `MACRO mac`
--- a/test/asm/label-macro-arg.asm
+++ b/test/asm/label-macro-arg.asm
@@ -1,4 +1,4 @@
-m1: MACRO
+MACRO m1
 x\1
 ENDM
 
@@ -5,7 +5,7 @@
 S EQUS "y"
 S2 EQUS "yy"
 
-m2: MACRO
+MACRO m2
 S\1
 ENDM
 
@@ -20,7 +20,7 @@
 	println yy
 
 
-test_char: MACRO
+MACRO test_char
 VAR_DEF equs "sizeof_\1something = 0"
 VAR_DEF
 sizeof_\1something = 1
--- a/test/asm/label-redefinition.asm
+++ b/test/asm/label-redefinition.asm
@@ -1,6 +1,6 @@
 SECTION "sec", ROM0
     dw Sym
-m: MACRO
+MACRO m
 Sym::
 ENDM
     m
--- a/test/asm/line-continuation-macro.asm
+++ b/test/asm/line-continuation-macro.asm
@@ -1,7 +1,7 @@
-m: MACRO
+MACRO m
 ENDM
 
-m2: MACRO
+MACRO m2
 	m \
 ENDM
 
--- a/test/asm/line-continuation-rept.asm
+++ b/test/asm/line-continuation-rept.asm
@@ -1,4 +1,4 @@
-m: MACRO
+MACRO m
 ENDM
 
 REPT 1
--- a/test/asm/line-continuation-whitespace.asm
+++ b/test/asm/line-continuation-whitespace.asm
@@ -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\
--- a/test/asm/line-continuation.asm
+++ b/test/asm/line-continuation.asm
@@ -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\
--- a/test/asm/long-rpn-expression.asm
+++ b/test/asm/long-rpn-expression.asm
@@ -2,7 +2,7 @@
 
 X0 EQUS "0"
 
-m: MACRO
+MACRO m
 \1 EQUS STRCAT("{X\2}", "+1")
 ENDM
 
--- a/test/asm/long-string-constant.asm
+++ b/test/asm/long-string-constant.asm
@@ -4,7 +4,7 @@
 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
--- a/test/asm/macro-#.asm
+++ b/test/asm/macro-#.asm
@@ -1,6 +1,6 @@
 SECTION "Test", ROM0
 
-list: MACRO
+MACRO list
 	db _NARG
 if _NARG > 0
 	db \#
@@ -12,11 +12,11 @@
 	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 @@
 	person  5, 10, $33, $44, $55
 	object 12,  6, $66, $77, $88
 
-echo: MACRO
+MACRO echo
 	println "\#"
 ENDM
 
@@ -36,7 +36,7 @@
 	echo Q,R, {R},  T
 	echo 42,$2a
 
-printall: MACRO
+MACRO printall
 	println \#
 ENDM
 
--- a/test/asm/macro-arg-in-string.asm
+++ b/test/asm/macro-arg-in-string.asm
@@ -1,4 +1,4 @@
-print1: MACRO
+MACRO print1
 	if _NARG == 2
 		assert !STRCMP("\1", \2)
 	endc
@@ -12,7 +12,7 @@
 	print1 E\!F ; illegal character escape
 
 
-iprint: MACRO
+MACRO iprint
 	PRINTLN "{\1}"
 ENDM
 
@@ -19,7 +19,7 @@
 s EQUS "hello"
 	iprint s
 
-symprint: MACRO
+MACRO symprint
 	PRINTLN {\1}
 ENDM
 
--- a/test/asm/macro-argument-limit.asm
+++ b/test/asm/macro-argument-limit.asm
@@ -1,4 +1,4 @@
-addargs: MACRO
+MACRO addargs
 sum = 0
 	rept _NARG
 sum = sum + \1
--- a/test/asm/macro-arguments.asm
+++ b/test/asm/macro-arguments.asm
@@ -1,4 +1,4 @@
-mac: MACRO
+MACRO mac
 	println "'mac \#':"
 	for i, _NARG
 		println strfmt("\\%d: <\1>", i+1)
--- a/test/asm/macro-eof.asm
+++ b/test/asm/macro-eof.asm
@@ -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
\ No newline at end of file
--- a/test/asm/macro-line-no.asm
+++ b/test/asm/macro-line-no.asm
@@ -1,6 +1,6 @@
 
 WARN "Line 2"
-m: macro
+macro m
 	WARN "Line 4"
 endm
 WARN "Line 6"
--- a/test/asm/macro-purge.asm
+++ b/test/asm/macro-purge.asm
@@ -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
--- a/test/asm/macro-recursion.asm
+++ b/test/asm/macro-recursion.asm
@@ -1,4 +1,4 @@
-recurse: MACRO
+MACRO recurse
 	recurse
 ENDM
 	recurse
--- a/test/asm/macro-syntax.err
+++ b/test/asm/macro-syntax.err
@@ -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):
--- a/test/asm/math.asm
+++ b/test/asm/math.asm
@@ -1,6 +1,6 @@
 X equ 0
 
-test: MACRO
+MACRO test
 ; Test RGBASM
 v equs "X +"
 	static_assert \#
--- a/test/asm/multi-line-strings.asm
+++ b/test/asm/multi-line-strings.asm
@@ -15,7 +15,7 @@
 
 PRINT """\n"""
 
-printarg: MACRO
+MACRO printarg
 	PRINTLN "arg <\1>"
 	PRINTLN """arg (\1)"""
 ENDM
--- a/test/asm/multiple-charmaps.asm
+++ b/test/asm/multiple-charmaps.asm
@@ -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 @@
 	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
--- a/test/asm/narg-decreases-after-shift.asm
+++ b/test/asm/narg-decreases-after-shift.asm
@@ -1,4 +1,4 @@
-testing: MACRO
+MACRO testing
 	db _NARG
 	shift
 	db _NARG
--- a/test/asm/nested-macrodef.asm
+++ b/test/asm/nested-macrodef.asm
@@ -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 @@
 	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 @@
 	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 files a/test/asm/null-in-macro.asm b/test/asm/null-in-macro.asm differ
--- a/test/asm/overflow.asm
+++ b/test/asm/overflow.asm
@@ -1,6 +1,6 @@
 SECTION "sec", ROM0
 
-print_x: MACRO
+MACRO print_x
 	println x
 ENDM
 
--- a/test/asm/raw-macro-args.asm
+++ b/test/asm/raw-macro-args.asm
@@ -1,4 +1,4 @@
-printargs: MACRO
+MACRO printargs
 	rept _NARG
 		println \1
 		shift
@@ -5,7 +5,7 @@
 	endr
 ENDM
 
-printlit: MACRO
+MACRO printlit
 	rept _NARG
 		println "\1"
 		shift
--- a/test/asm/redef-equ.asm
+++ b/test/asm/redef-equ.asm
@@ -3,12 +3,12 @@
 ; 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
--- a/test/asm/redef-equs.asm
+++ b/test/asm/redef-equs.asm
@@ -3,7 +3,7 @@
 ; prints "Hello, world!"
 PRINTLN "{s}"
 
-list: MACRO
+MACRO list
 LIST_NAME EQUS "\1"
 REDEF {LIST_NAME} EQUS "["
 REPT _NARG - 1
--- a/test/asm/ref-override-bad.asm
+++ b/test/asm/ref-override-bad.asm
@@ -8,6 +8,6 @@
 X equs "0" ; Not OK
 
 	db Y
-Y: macro ; Not ok
+macro Y ; Not ok
 	db 0
 endm
--- a/test/asm/rept-shift.asm
+++ b/test/asm/rept-shift.asm
@@ -1,4 +1,4 @@
-m: macro
+macro m
 	PRINT "\1 "
 	REPT 4
 		SHIFT
--- a/test/asm/rst.asm
+++ b/test/asm/rst.asm
@@ -15,7 +15,7 @@
 	rst rst2A
 
 
-defRST: MACRO
+MACRO defRST
 	SECTION "rst\1", ROM0[$\1]
 	rst\1:
 ENDM
--- a/test/asm/section-union.asm
+++ b/test/asm/section-union.asm
@@ -16,7 +16,7 @@
 SECTION UNION "test", WRAM0,ALIGN[9]
 
 
-check_label: MACRO
+MACRO check_label
 EXPECTED equ \2
 	IF \1 == EXPECTED
 RESULT equs "OK!"
--- a/test/asm/shift-negative.asm
+++ b/test/asm/shift-negative.asm
@@ -1,4 +1,4 @@
-reverse: MACRO
+MACRO reverse
 	for i, _NARG
 i = _NARG - i - 1
 		shift i
@@ -9,7 +9,7 @@
 
 	reverse $1, $2, $3
 
-m: MACRO
+MACRO m
 	shift 2
 	shift -3
 	shift 1
--- a/test/asm/skip-elif-condition.asm
+++ b/test/asm/skip-elif-condition.asm
@@ -1,4 +1,4 @@
-mac: MACRO
+MACRO mac
 	if (\1) < 10
 		println "small \1"
 	elif (\1) > 100
--- a/test/asm/string-formatting.asm
+++ b/test/asm/string-formatting.asm
@@ -9,7 +9,7 @@
 	println "<{f:pi}> <{06.f:f}> <{.10f:f}>"
 	println "<{#-10s:s}> <{10s:s}>"
 
-foo: macro
+macro foo
 	println "<{\1}>"
 endm
 
--- a/test/asm/strlen.asm
+++ b/test/asm/strlen.asm
@@ -1,6 +1,6 @@
 SECTION "sec", ROM0
 
-xstrlen: MACRO
+MACRO xstrlen
 	PRINTLN STRLEN(\1)
 ENDM
 
--- a/test/asm/strsub.asm
+++ b/test/asm/strsub.asm
@@ -1,6 +1,6 @@
 SECTION "sec", ROM0
 
-xstrsub: MACRO
+MACRO xstrsub
 	PRINTLN STRSUB(\#)
 ENDM
 
--- a/test/asm/trailing-commas.asm
+++ b/test/asm/trailing-commas.asm
@@ -1,6 +1,6 @@
 SECTION "test", ROM0
 
-mac: MACRO
+MACRO mac
 	println "\#"
 ENDM
 
--- a/test/asm/unique-id.asm
+++ b/test/asm/unique-id.asm
@@ -1,6 +1,6 @@
 warn_unique EQUS "WARN \"\\@!\""
 
-m: macro
+macro m
     warn_unique
     REPT 2
     	warn_unique
--- a/test/link/all-instructions.asm
+++ b/test/link/all-instructions.asm
@@ -2,7 +2,7 @@
 
     ; 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 @@
     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 @@
 
     ; Bit Operations Instructions
 
-bitop_u3_instruction_list: MACRO
+MACRO bitop_u3_instruction_list
 NBIT = 0
     REPT 8
         \1 NBIT,a
@@ -75,7 +75,7 @@
     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 @@
 
     ; 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 @@
     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
--- a/test/link/high-low/a.asm
+++ b/test/link/high-low/a.asm
@@ -1,5 +1,5 @@
-ldhilo : MACRO
-    ld  HIGH(\1),LOW(\2)
+MACRO ldhilo
+    ld HIGH(\1),LOW(\2)
 ENDM
 
 SECTION "r0", ROM0[$0]
--- a/test/link/rst.asm
+++ b/test/link/rst.asm
@@ -13,7 +13,7 @@
 	rst rst38
 
 
-defRST: MACRO
+MACRO defRST
 	SECTION "rst\1", ROM0[$\1]
 	rst\1:
 ENDM