From de32e245c973d23815c27e9fe3bb2c6a5d01140d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ni=C3=B1o=20D=C3=ADaz?= Date: Sun, 7 Jan 2018 23:05:04 +0000 Subject: [PATCH] PUSHS and POPS also affect the symbol scope MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now, when POPS is executed, it restores the symbol scope of the corresponding PUSHS. That way, the local symbols previously available can be used again after the POPS. This is useful in cases like this one: ``` SECTION "Section 1", ROMX BigFunction: ... .loop: ... PUSHS SECTION "Section 2", ROMX DataForBigFunction: DB 1, 2, 3, 4, 5 POPS ld a,BANK(DataForBigFunction) ld hl,DataForBigFunction ... jr .loop ``` Signed-off-by: Antonio Niño Díaz --- include/asm/symbol.h | 4 ++++ src/asm/output.c | 3 +++ src/asm/symbol.c | 12 +++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/include/asm/symbol.h b/include/asm/symbol.h index 606cb97a..e02220a0 100644 --- a/include/asm/symbol.h +++ b/include/asm/symbol.h @@ -80,4 +80,8 @@ void sym_Purge(char *tzName); uint32_t sym_isConstDefined(char *tzName); int32_t sym_IsRelocDiffDefined(char *tzSym1, char *tzSym2); +/* Functions to save and restore the current symbol scope. */ +struct sSymbol *sym_GetCurrentSymbolScope(void); +void sym_SetCurrentSymbolScope(struct sSymbol *pNewScope); + #endif /* RGBDS_SYMBOL_H */ diff --git a/src/asm/output.c b/src/asm/output.c index 917a3496..678b4a30 100644 --- a/src/asm/output.c +++ b/src/asm/output.c @@ -42,6 +42,7 @@ struct PatchSymbol { struct SectionStackEntry { struct Section *pSection; + struct sSymbol *pScope; /* Section's symbol scope */ struct SectionStackEntry *pNext; }; @@ -64,6 +65,7 @@ void out_PushSection(void) fatalerror("No memory for section stack"); pSect->pSection = pCurrentSection; + pSect->pScope = sym_GetCurrentSymbolScope(); pSect->pNext = pSectionStack; pSectionStack = pSect; } @@ -77,6 +79,7 @@ void out_PopSection(void) pSect = pSectionStack; out_SetCurrentSection(pSect->pSection); + sym_SetCurrentSymbolScope(pSect->pScope); pSectionStack = pSect->pNext; free(pSect); } diff --git a/src/asm/symbol.c b/src/asm/symbol.c index 948d691a..375269d3 100644 --- a/src/asm/symbol.c +++ b/src/asm/symbol.c @@ -19,7 +19,7 @@ #include "extern/version.h" struct sSymbol *tHashedSymbols[HASHSIZE]; -static struct sSymbol *pScope; +static struct sSymbol *pScope; /* Current section symbol scope */ struct sSymbol *pPCSymbol; static struct sSymbol *p_NARGSymbol; static struct sSymbol *p__LINE__Symbol; @@ -406,6 +406,16 @@ uint32_t sym_GetDefinedValue(char *s) return 0; } +struct sSymbol *sym_GetCurrentSymbolScope(void) +{ + return pScope; +} + +void sym_SetCurrentSymbolScope(struct sSymbol *pNewScope) +{ + pScope = pNewScope; +} + /* * Macro argument stuff */