diff --git a/src/asm/fstack.c b/src/asm/fstack.c index 970c405f..4f12fc49 100644 --- a/src/asm/fstack.c +++ b/src/asm/fstack.c @@ -351,8 +351,10 @@ void fstk_RunInclude(char const *path) 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 diff --git a/test/asm/include-unique-id.asm b/test/asm/include-unique-id.asm new file mode 100644 index 00000000..0762d042 --- /dev/null +++ b/test/asm/include-unique-id.asm @@ -0,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 diff --git a/test/asm/include-unique-id.err b/test/asm/include-unique-id.err new file mode 100644 index 00000000..e69de29b diff --git a/test/asm/include-unique-id.inc b/test/asm/include-unique-id.inc new file mode 100644 index 00000000..4e256dcf --- /dev/null +++ b/test/asm/include-unique-id.inc @@ -0,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 diff --git a/test/asm/include-unique-id.out b/test/asm/include-unique-id.out new file mode 100644 index 00000000..0205d942 --- /dev/null +++ b/test/asm/include-unique-id.out @@ -0,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