mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-24 03:52:08 +00:00
Create specialized symbol finder functions
The old "find symbol with auto scope" function is now three: - One finds the exact name passed to it, skipping any checks This is useful e.g. if such checks were already performed. - One checks that the name is not scoped, and calls the first. This is useful for names that cannot be scoped, such as checking for EQUS. Doing this instead of the third should improve performance somehwat, since this specific case is hit by the lexer each time an identifier is read. - The last one checks if the name should be expanded (`.loc` → `Glob.loc`), and that the local part is not scoped. This is essentially the old function.
This commit is contained in:
@@ -296,6 +296,11 @@ static void writerpn(uint8_t *rpnexpr, uint32_t *rpnptr, uint8_t *rpn,
|
||||
uint8_t rpndata = popbyte();
|
||||
|
||||
switch (rpndata) {
|
||||
struct Symbol *sym;
|
||||
uint32_t value;
|
||||
uint8_t b;
|
||||
size_t i;
|
||||
|
||||
case RPN_CONST:
|
||||
writebyte(RPN_CONST);
|
||||
writebyte(popbyte());
|
||||
@@ -303,13 +308,15 @@ static void writerpn(uint8_t *rpnexpr, uint32_t *rpnptr, uint8_t *rpn,
|
||||
writebyte(popbyte());
|
||||
writebyte(popbyte());
|
||||
break;
|
||||
case RPN_SYM:
|
||||
{
|
||||
for (unsigned int i = -1; (tzSym[++i] = popbyte()); )
|
||||
;
|
||||
struct Symbol *sym = sym_FindSymbol(tzSym);
|
||||
uint32_t value;
|
||||
|
||||
case RPN_SYM:
|
||||
i = 0;
|
||||
do {
|
||||
tzSym[i] = popbyte();
|
||||
} while (tzSym[i++]);
|
||||
|
||||
// The symbol name is always written expanded
|
||||
sym = sym_FindExactSymbol(tzSym);
|
||||
if (sym_IsConstant(sym)) {
|
||||
writebyte(RPN_CONST);
|
||||
value = sym_GetConstantValue(tzSym);
|
||||
@@ -317,18 +324,22 @@ static void writerpn(uint8_t *rpnexpr, uint32_t *rpnptr, uint8_t *rpn,
|
||||
writebyte(RPN_SYM);
|
||||
value = getSymbolID(sym);
|
||||
}
|
||||
|
||||
writebyte(value & 0xFF);
|
||||
writebyte(value >> 8);
|
||||
writebyte(value >> 16);
|
||||
writebyte(value >> 24);
|
||||
break;
|
||||
}
|
||||
|
||||
case RPN_BANK_SYM:
|
||||
{
|
||||
for (unsigned int i = -1; (tzSym[++i] = popbyte()); )
|
||||
;
|
||||
struct Symbol *sym = sym_FindSymbol(tzSym);
|
||||
uint32_t value = getSymbolID(sym);
|
||||
i = 0;
|
||||
do {
|
||||
tzSym[i] = popbyte();
|
||||
} while (tzSym[i++]);
|
||||
|
||||
// The symbol name is always written expanded
|
||||
sym = sym_FindExactSymbol(tzSym);
|
||||
value = getSymbolID(sym);
|
||||
|
||||
writebyte(RPN_BANK_SYM);
|
||||
writebyte(value & 0xFF);
|
||||
@@ -336,18 +347,15 @@ static void writerpn(uint8_t *rpnexpr, uint32_t *rpnptr, uint8_t *rpn,
|
||||
writebyte(value >> 16);
|
||||
writebyte(value >> 24);
|
||||
break;
|
||||
}
|
||||
case RPN_BANK_SECT:
|
||||
{
|
||||
uint8_t b;
|
||||
|
||||
case RPN_BANK_SECT:
|
||||
writebyte(RPN_BANK_SECT);
|
||||
do {
|
||||
b = popbyte();
|
||||
writebyte(b);
|
||||
} while (b != 0);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
writebyte(rpndata);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user