ref: 01f1703dfb64b6a859e04e077249881c3857dd06
parent: 69a573923f208d625df589c7a54a18738b07969c
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Sun Dec 11 06:57:45 EST 2022
Preserve `\@` through `INCLUDE` Fixes #1112
--- a/src/asm/fstack.c
+++ b/src/asm/fstack.c
@@ -351,8 +351,10 @@
if (!contextStack->lexerState)
fatalerror("Failed to set up lexer for file include\n");
lexer_SetStateAtEOL(contextStack->lexerState);
- // We're back at top-level, so most things are reset
- contextStack->uniqueID = macro_UndefUniqueID();
+ // We're back at top-level, so most things are reset,
+ // but not the unique ID, since INCLUDE may be inside a
+ // MACRO or REPT/FOR loop
+ contextStack->uniqueID = contextStack->parent->uniqueID;
}
// Similar to `fstk_RunInclude`, but not subject to `-MG`, and
--- /dev/null
+++ b/test/asm/include-unique-id.asm
@@ -1,0 +1,24 @@
+MACRO mac
+ println "outer mac: \@ (\#)"
+ INCLUDE "include-unique-id.inc"
+ENDM
+
+ DEF state = 1
+ mac hello, world
+ mac goodbye, world
+
+REPT 2
+ DEF state = 2
+ println "outer rept before: \@"
+ INCLUDE "include-unique-id.inc"
+
+ FOR n, 3
+ DEF state = 3
+ println "outer for: \@ ({n})"
+ INCLUDE "include-unique-id.inc"
+ ENDR
+
+ DEF state = 4
+ println "outer rept after: \@"
+ INCLUDE "include-unique-id.inc"
+ENDR
\ No newline at end of file
--- /dev/null
+++ b/test/asm/include-unique-id.inc
@@ -1,0 +1,9 @@
+IF state == 1
+ println "inner mac: \@ (\#)"
+ELIF state == 2
+ println "inner rept before: \@"
+ELIF state == 3
+ println "inner for: \@ ({n})"
+ELIF state == 4
+ println "inner rept after: \@"
+ENDC
--- /dev/null
+++ b/test/asm/include-unique-id.out
@@ -1,0 +1,24 @@
+outer mac: _u1 (hello,world)
+inner mac: _u1 (hello,world)
+outer mac: _u2 (goodbye,world)
+inner mac: _u2 (goodbye,world)
+outer rept before: _u3
+inner rept before: _u3
+outer for: _u4 ($0)
+inner for: _u4 ($0)
+outer for: _u5 ($1)
+inner for: _u5 ($1)
+outer for: _u6 ($2)
+inner for: _u6 ($2)
+outer rept after: _u3
+inner rept after: _u3
+outer rept before: _u7
+inner rept before: _u7
+outer for: _u8 ($0)
+inner for: _u8 ($0)
+outer for: _u9 ($1)
+inner for: _u9 ($1)
+outer for: _u10 ($2)
+inner for: _u10 ($2)
+outer rept after: _u7
+inner rept after: _u7