mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Only restore parent context's \@ value if it had one defined (#1366)
This way, if a child context initializes `\@`, the parent won't reset it. And if the child context did not initialize `\@`, then resetting it would be redundant.
This commit is contained in:
@@ -14,8 +14,6 @@
|
||||
|
||||
#include "linkdefs.hpp"
|
||||
|
||||
#include "asm/lexer.hpp"
|
||||
|
||||
struct FileStackNode {
|
||||
FileStackNodeType type;
|
||||
std::variant<
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <inttypes.h>
|
||||
#include <new>
|
||||
#include <stack>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string_view>
|
||||
|
||||
@@ -207,20 +208,23 @@ bool yywrap() {
|
||||
return true;
|
||||
}
|
||||
|
||||
Context oldContext = contextStack.top();
|
||||
|
||||
Context oldContext = std::move(contextStack.top());
|
||||
contextStack.pop();
|
||||
|
||||
lexer_CleanupState(oldContext.lexerState);
|
||||
// Restore args if a macro (not REPT) saved them
|
||||
if (oldContext.fileInfo->type == NODE_MACRO)
|
||||
macro_UseNewArgs(contextStack.top().macroArgs);
|
||||
// Restore the `\@` value if the old context was supposed to define one
|
||||
// (i.e. it either is a macro or REPT, or it initialized `\@` for its parent)
|
||||
if (oldContext.fileInfo->type == NODE_REPT || oldContext.fileInfo->type == NODE_MACRO
|
||||
|| contextStack.top().uniqueID > 0)
|
||||
macro_SetUniqueID(contextStack.top().uniqueID);
|
||||
// Free the file stack node
|
||||
if (!oldContext.fileInfo->referenced)
|
||||
delete oldContext.fileInfo;
|
||||
|
||||
lexer_SetState(&contextStack.top().lexerState);
|
||||
macro_SetUniqueID(contextStack.top().uniqueID);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
27
test/asm/unique-id-include.asm
Normal file
27
test/asm/unique-id-include.asm
Normal file
@@ -0,0 +1,27 @@
|
||||
REPT 2
|
||||
println "Within REPT"
|
||||
INCLUDE "unique-id-include.inc"
|
||||
println "Outside INCLUDE: \@"
|
||||
ENDR
|
||||
|
||||
MACRO m1
|
||||
println "Within MACRO"
|
||||
INCLUDE "unique-id-include.inc"
|
||||
println "Outside INCLUDE: \@"
|
||||
ENDM
|
||||
m1
|
||||
|
||||
println
|
||||
|
||||
REPT 2
|
||||
println "Within REPT: \@"
|
||||
INCLUDE "unique-id-include.inc"
|
||||
println "Outside INCLUDE: \@"
|
||||
ENDR
|
||||
|
||||
MACRO m2
|
||||
println "Within MACRO: \@"
|
||||
INCLUDE "unique-id-include.inc"
|
||||
println "Outside INCLUDE: \@"
|
||||
ENDM
|
||||
m2
|
||||
1
test/asm/unique-id-include.inc
Normal file
1
test/asm/unique-id-include.inc
Normal file
@@ -0,0 +1 @@
|
||||
println "Within INCLUDE: \@"
|
||||
19
test/asm/unique-id-include.out
Normal file
19
test/asm/unique-id-include.out
Normal file
@@ -0,0 +1,19 @@
|
||||
Within REPT
|
||||
Within INCLUDE: _u1
|
||||
Outside INCLUDE: _u1
|
||||
Within REPT
|
||||
Within INCLUDE: _u2
|
||||
Outside INCLUDE: _u2
|
||||
Within MACRO
|
||||
Within INCLUDE: _u3
|
||||
Outside INCLUDE: _u3
|
||||
|
||||
Within REPT: _u4
|
||||
Within INCLUDE: _u4
|
||||
Outside INCLUDE: _u4
|
||||
Within REPT: _u5
|
||||
Within INCLUDE: _u5
|
||||
Outside INCLUDE: _u5
|
||||
Within MACRO: _u6
|
||||
Within INCLUDE: _u6
|
||||
Outside INCLUDE: _u6
|
||||
33
test/asm/unique-id-nested.asm
Normal file
33
test/asm/unique-id-nested.asm
Normal file
@@ -0,0 +1,33 @@
|
||||
MACRO m1
|
||||
PRINTLN "Begin MACRO"
|
||||
DEF nested EQUS """MACRO mm
|
||||
PRINTLN "Within nested MACRO: \\@"
|
||||
\n ENDM
|
||||
mm"""
|
||||
nested
|
||||
PURGE nested, mm
|
||||
PRINTLN "Within MACRO: \@"
|
||||
ENDM
|
||||
REPT 2
|
||||
PRINTLN "Begin REPT"
|
||||
m1
|
||||
PRINTLN "Within REPT: \@"
|
||||
ENDR
|
||||
|
||||
PRINTLN
|
||||
|
||||
MACRO m2
|
||||
PRINTLN "Begin MACRO: \@"
|
||||
DEF nested EQUS """MACRO mm
|
||||
PRINTLN "Within nested MACRO: \\@"
|
||||
\n ENDM
|
||||
mm"""
|
||||
nested
|
||||
PURGE nested, mm
|
||||
PRINTLN "Within MACRO: \@"
|
||||
ENDM
|
||||
REPT 2
|
||||
PRINTLN "Begin REPT: \@"
|
||||
m2
|
||||
PRINTLN "Within REPT: \@"
|
||||
ENDR
|
||||
21
test/asm/unique-id-nested.out
Normal file
21
test/asm/unique-id-nested.out
Normal file
@@ -0,0 +1,21 @@
|
||||
Begin REPT
|
||||
Begin MACRO
|
||||
Within nested MACRO: _u1
|
||||
Within MACRO: _u2
|
||||
Within REPT: _u3
|
||||
Begin REPT
|
||||
Begin MACRO
|
||||
Within nested MACRO: _u4
|
||||
Within MACRO: _u5
|
||||
Within REPT: _u6
|
||||
|
||||
Begin REPT: _u7
|
||||
Begin MACRO: _u8
|
||||
Within nested MACRO: _u9
|
||||
Within MACRO: _u8
|
||||
Within REPT: _u7
|
||||
Begin REPT: _u10
|
||||
Begin MACRO: _u11
|
||||
Within nested MACRO: _u12
|
||||
Within MACRO: _u11
|
||||
Within REPT: _u10
|
||||
Reference in New Issue
Block a user