X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=src%2Fsymbols.c;h=6d736e940832cf1893b288d8417811a57e61fd24;hb=d8d68d0bd4c45af6f0dc69b4fc33d37d961aca85;hp=d2f42dac576c4c2d7e01a8ca89b9fd074c9fc173;hpb=8760c1ba6442153afe76bcac742e086f90c59fe8;p=inform.git diff --git a/src/symbols.c b/src/symbols.c index d2f42da..6d736e9 100644 --- a/src/symbols.c +++ b/src/symbols.c @@ -2,7 +2,7 @@ /* "symbols" : The symbols table; creating stock of reserved words */ /* */ /* Part of Inform 6.35 */ -/* copyright (c) Graham Nelson 1993 - 2020 */ +/* copyright (c) Graham Nelson 1993 - 2021 */ /* */ /* Inform is free software: you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ @@ -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; @@ -1223,6 +1285,8 @@ uint32 df_stripped_offset_for_code_offset(uint32 offset, int *stripped) { df_function_t *func; int count; + int beg; + int end; if (!track_unused_routines) compiler_error("DF: df_stripped_offset_for_code_offset called, but function references have not been mapped"); @@ -1250,13 +1314,14 @@ uint32 df_stripped_offset_for_code_offset(uint32 offset, int *stripped) /* Do a binary search. Maintain beg <= res < end, where res is the function containing the desired address. */ - int beg = 0; - int end = df_functions_sorted_count; + beg = 0; + end = df_functions_sorted_count; /* Set stripped flag until we decide on a non-stripped function. */ *stripped = TRUE; while (1) { + int new; if (beg >= end) { error("DF: offset_for_code_offset: Could not locate address."); return 0; @@ -1268,7 +1333,7 @@ uint32 df_stripped_offset_for_code_offset(uint32 offset, int *stripped) *stripped = FALSE; return func->newaddress + (offset - func->address); } - int new = (beg + end) / 2; + new = (beg + end) / 2; if (new <= beg || new >= end) compiler_error("DF: binary search went off the rails");