mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
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.
This commit is contained in:
@@ -949,10 +949,14 @@ rept : T_POP_REPT uconst T_NEWLINE {
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
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);
|
lexer_CaptureRept(&captureBody);
|
||||||
} T_NEWLINE {
|
} 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);
|
captureBody.body, captureBody.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -979,10 +983,14 @@ break : T_POP_BREAK T_NEWLINE {
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
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);
|
lexer_CaptureMacroBody(&captureBody);
|
||||||
} T_NEWLINE {
|
} 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 {
|
| T_LABEL T_COLON T_POP_MACRO T_NEWLINE {
|
||||||
lexer_CaptureMacroBody(&captureBody);
|
lexer_CaptureMacroBody(&captureBody);
|
||||||
|
|||||||
@@ -1094,7 +1094,7 @@ will treat it as a macro invocation.
|
|||||||
Furthermore, without the
|
Furthermore, without the
|
||||||
.Ql DEF
|
.Ql DEF
|
||||||
keyword,
|
keyword,
|
||||||
string equates may expanded for the name.
|
string symbols may be expanded for the name.
|
||||||
This can lead to surprising results:
|
This can lead to surprising results:
|
||||||
.Bd -literal -offset indent
|
.Bd -literal -offset indent
|
||||||
X EQUS "Y"
|
X EQUS "Y"
|
||||||
@@ -1118,6 +1118,7 @@ ENDM
|
|||||||
The example above defines
|
The example above defines
|
||||||
.Ql MyMacro
|
.Ql MyMacro
|
||||||
as a new macro.
|
as a new macro.
|
||||||
|
String symbols are not expanded within the name of the macro.
|
||||||
You may use the older syntax
|
You may use the older syntax
|
||||||
.Ql MyMacro: MACRO
|
.Ql MyMacro: MACRO
|
||||||
instead of
|
instead of
|
||||||
@@ -1125,6 +1126,7 @@ instead of
|
|||||||
with a single colon
|
with a single colon
|
||||||
.Ql \&:
|
.Ql \&:
|
||||||
following the macro's name.
|
following the macro's name.
|
||||||
|
With the older syntax, string symbols may be expanded for the name.
|
||||||
.Pp
|
.Pp
|
||||||
Macros can't be exported or imported.
|
Macros can't be exported or imported.
|
||||||
.Pp
|
.Pp
|
||||||
@@ -1632,6 +1634,7 @@ Everything between
|
|||||||
and the matching
|
and the matching
|
||||||
.Ic ENDR
|
.Ic ENDR
|
||||||
will be repeated for each value of a given symbol.
|
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:
|
For example, this code will produce a table of squared values from 0 to 255:
|
||||||
.Bd -literal -offset indent
|
.Bd -literal -offset indent
|
||||||
FOR N, 256
|
FOR N, 256
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ endr
|
|||||||
println "-> {d:q}"
|
println "-> {d:q}"
|
||||||
|
|
||||||
s EQUS "x"
|
s EQUS "x"
|
||||||
for s, 3, 30, 3
|
for {s}, 3, 30, 3
|
||||||
print "{d:x} "
|
print "{d:x} "
|
||||||
endr
|
endr
|
||||||
println "-> {d:x}"
|
println "-> {d:x}"
|
||||||
|
|||||||
Reference in New Issue
Block a user