ref: 7e127a4e52118fe469e70b6f1980ca18c42822d4
parent: b8093847dcbb4815d832ef741da58f6302ee735c
author: Rangi <[email protected]>
date: Wed Mar 17 17:23:17 EDT 2021
Don't expand string symbols in MACRO and FOR symbol names Explicit {interpolation} can still achieve this, but to match DEF, REDEF, and PURGE, these new directives that define symbols do not expand string EQUS.
--- a/src/asm/parser.y
+++ b/src/asm/parser.y
@@ -949,10 +949,14 @@
}
;
-for : T_POP_FOR T_ID T_COMMA for_args T_NEWLINE {
+for : T_POP_FOR {
+ lexer_ToggleStringExpansion(false);
+ } T_ID {
+ lexer_ToggleStringExpansion(true);
+ } T_COMMA for_args T_NEWLINE {
lexer_CaptureRept(&captureBody);
} T_NEWLINE {
- fstk_RunFor($2, $4.start, $4.stop, $4.step, captureBody.lineNo,
+ fstk_RunFor($3, $6.start, $6.stop, $6.step, captureBody.lineNo,
captureBody.body, captureBody.size);
}
@@ -979,10 +983,14 @@
}
;
-macrodef : T_POP_MACRO T_ID T_NEWLINE {
+macrodef : T_POP_MACRO {
+ lexer_ToggleStringExpansion(false);
+ } T_ID {
+ lexer_ToggleStringExpansion(true);
+ } T_NEWLINE {
lexer_CaptureMacroBody(&captureBody);
} T_NEWLINE {
- sym_AddMacro($2, captureBody.lineNo, captureBody.body, captureBody.size);
+ sym_AddMacro($3, captureBody.lineNo, captureBody.body, captureBody.size);
}
| T_LABEL T_COLON T_POP_MACRO T_NEWLINE {
lexer_CaptureMacroBody(&captureBody);
--- a/src/asm/rgbasm.5
+++ b/src/asm/rgbasm.5
@@ -1094,7 +1094,7 @@
Furthermore, without the
.Ql DEF
keyword,
-string equates may expanded for the name.
+string symbols may be expanded for the name.
This can lead to surprising results:
.Bd -literal -offset indent
X EQUS "Y"
@@ -1118,6 +1118,7 @@
The example above defines
.Ql MyMacro
as a new macro.
+String symbols are not expanded within the name of the macro.
You may use the older syntax
.Ql MyMacro: MACRO
instead of
@@ -1125,6 +1126,7 @@
with a single colon
.Ql \&:
following the macro's name.
+With the older syntax, string symbols may be expanded for the name.
.Pp
Macros can't be exported or imported.
.Pp
@@ -1632,6 +1634,7 @@
and the matching
.Ic ENDR
will be repeated for each value of a given symbol.
+String symbols are not expanded within the symbol name.
For example, this code will produce a table of squared values from 0 to 255:
.Bd -literal -offset indent
FOR N, 256
--- a/test/asm/for.asm
+++ b/test/asm/for.asm
@@ -33,7 +33,7 @@
println "-> {d:q}"
s EQUS "x"
-for s, 3, 30, 3
+for {s}, 3, 30, 3
print "{d:x} "
endr
println "-> {d:x}"