X-Git-Url: https://jxself.org/git/?p=inform.git;a=blobdiff_plain;f=src%2Fsymbols.c;fp=src%2Fsymbols.c;h=6d736e940832cf1893b288d8417811a57e61fd24;hp=90ec3bfe427cdc85fa9e2586bbbc68d8ad144fbd;hb=d8d68d0bd4c45af6f0dc69b4fc33d37d961aca85;hpb=c881aa3386c00d7021ffabf2f66275d6c110c1c1 diff --git a/src/symbols.c b/src/symbols.c index 90ec3bf..6d736e9 100644 --- a/src/symbols.c +++ b/src/symbols.c @@ -89,6 +89,8 @@ static char** symbol_name_space_chunks; /* For chunks of memory used to hold the name strings of symbols */ static int no_symbol_name_space_chunks; +/* Symbol replacements (used by the "Replace X Y" directive). */ + typedef struct value_pair_struct { int original_symbol; int renamed_symbol; @@ -97,6 +99,18 @@ static value_pair_t *symbol_replacements; static int symbol_replacements_count; static int symbol_replacements_size; /* calloced size */ +/* Symbol definitions requested at compile time. (There may not be any.) + These are set up at command-line parse time, not in init_symbols_vars(). + Similarly, they are not cleaned up by symbols_free_arrays(). */ + +typedef struct keyvalue_pair_struct { + char *symbol; + int32 value; +} keyvalue_pair_t; +static keyvalue_pair_t *symbol_definitions = NULL; +static int symbol_definitions_count = 0; +static int symbol_definitions_size = 0; /* calloced size */ + /* ------------------------------------------------------------------------- */ /* The symbols table is "hash-coded" into a disjoint union of linked */ /* lists, so that for any symbol i, next_entry[i] is either -1 (meaning */ @@ -170,6 +184,28 @@ extern int strcmpcis(char *p, char *q) return -qc; } +/* ------------------------------------------------------------------------- */ + +extern void add_config_symbol_definition(char *symbol, int32 value) +{ + if (symbol_definitions_count == symbol_definitions_size) { + int oldsize = symbol_definitions_size; + if (symbol_definitions_size == 0) + symbol_definitions_size = 4; + else + symbol_definitions_size *= 2; + my_recalloc(&symbol_definitions, sizeof(keyvalue_pair_t), oldsize, + symbol_definitions_size, "symbol definition table"); + } + + char *str = my_malloc(strlen(symbol)+1, "symbol name"); + strcpy(str, symbol); + + symbol_definitions[symbol_definitions_count].symbol = str; + symbol_definitions[symbol_definitions_count].value = value; + symbol_definitions_count++; +} + /* ------------------------------------------------------------------------- */ /* Symbol finding, creating, and removing. */ /* ------------------------------------------------------------------------- */ @@ -391,7 +427,7 @@ extern void write_the_identifier_names(void) veneer_mode = TRUE; - null_value = compile_string(unknown_attribute, FALSE, FALSE); + null_value = compile_string(unknown_attribute, STRCTX_SYMBOL); for (i=0; iaddress != DF_NOT_IN_FUNCTION) + if (!func || func->address != DF_NOT_IN_FUNCTION) { compiler_error("DF: Global namespace entry is not at the head of the chain."); + return; + } for (ent = func->refs; ent; ent=ent->refsnext) { uint32 addr;