mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Separate union members for EQUS and MACROs
This commit is contained in:
@@ -37,12 +37,16 @@ struct Symbol {
|
||||
// If sym_IsNumeric
|
||||
int32_t value;
|
||||
int32_t (*numCallback)(void);
|
||||
// For SYM_MACRO and SYM_EQUS; TODO: have separate fields
|
||||
// For SYM_MACRO
|
||||
struct {
|
||||
size_t size;
|
||||
char *value;
|
||||
} macro;
|
||||
// For SYM_EQUS
|
||||
struct {
|
||||
size_t size;
|
||||
char *value;
|
||||
} equs;
|
||||
char const *(*strCallback)(void);
|
||||
};
|
||||
|
||||
@@ -97,7 +101,7 @@ static inline char const *sym_GetStringValue(struct Symbol const *sym)
|
||||
{
|
||||
if (sym->hasCallback)
|
||||
return sym->strCallback();
|
||||
return sym->macro.value;
|
||||
return sym->equs.value;
|
||||
}
|
||||
|
||||
void sym_ForEach(void (*func)(struct Symbol *, void *), void *arg);
|
||||
|
||||
@@ -164,8 +164,8 @@ static void assignStringSymbol(struct Symbol *sym, char const *value)
|
||||
fatalerror("No memory for string equate: %s\n", strerror(errno));
|
||||
|
||||
sym->type = SYM_EQUS;
|
||||
sym->macro.value = string;
|
||||
sym->macro.size = strlen(string);
|
||||
sym->equs.value = string;
|
||||
sym->equs.size = strlen(string);
|
||||
}
|
||||
|
||||
struct Symbol *sym_FindExactSymbol(char const *symName)
|
||||
@@ -233,8 +233,8 @@ void sym_Purge(char const *symName)
|
||||
if (sym->name == labelScope)
|
||||
sym_SetCurrentSymbolScope(NULL);
|
||||
|
||||
// FIXME: this leaks sym->macro.value for SYM_EQUS and SYM_MACRO, but this can't
|
||||
// free(sym->macro.value) because the expansion may be purging itself.
|
||||
// FIXME: this leaks sym->equs.value for SYM_EQUS and sym->macro.value for SYM_MACRO,
|
||||
// but this can't free either of them because the expansion may be purging itself.
|
||||
hash_RemoveElement(symbols, sym->name);
|
||||
// TODO: ideally, also unref the file stack nodes
|
||||
free(sym);
|
||||
@@ -401,8 +401,8 @@ struct Symbol *sym_RedefString(char const *symName, char const *value)
|
||||
}
|
||||
|
||||
updateSymbolFilename(sym);
|
||||
// FIXME: this leaks the previous sym->macro.value value, but this can't
|
||||
// free(sym->macro.value) because the expansion may be redefining itself.
|
||||
// FIXME: this leaks the previous sym->equs.value, but this can't free(sym->equs.value)
|
||||
// because the expansion may be redefining itself.
|
||||
assignStringSymbol(sym, value);
|
||||
|
||||
return sym;
|
||||
|
||||
Reference in New Issue
Block a user