X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=src%2Farrays.c;h=82caa7cb11ba187142d4ebf87ad480b57603dbc1;hb=HEAD;hp=c1f410ce34b9d47f1513c957c6ac5af927aaf18d;hpb=8760c1ba6442153afe76bcac742e086f90c59fe8;p=inform.git diff --git a/src/arrays.c b/src/arrays.c index c1f410c..82caa7c 100644 --- a/src/arrays.c +++ b/src/arrays.c @@ -3,8 +3,8 @@ /* likewise global variables, which are in some ways a */ /* simpler form of the same thing. */ /* */ -/* Part of Inform 6.35 */ -/* copyright (c) Graham Nelson 1993 - 2020 */ +/* Part of Inform 6.42 */ +/* copyright (c) Graham Nelson 1993 - 2024 */ /* */ /* Inform is free software: you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ @@ -26,29 +26,30 @@ /* ------------------------------------------------------------------------- */ /* Arrays defined below: */ /* */ -/* int dynamic_array_area[] Initial values for the bytes of */ +/* uchar dynamic_array_area[] Initial values for the bytes of */ /* the dynamic array area */ -/* int static_array_area[] Initial values for the bytes of */ +/* uchar static_array_area[] Initial values for the bytes of */ /* the static array area */ /* int32 global_initial_value[n] The initialised value of the nth */ -/* global variable (counting 0 - 239) */ +/* global variable (counting 0 - 239, */ +/* or higher for Glulx) */ /* */ /* The "dynamic array area" is the Z-machine area holding the current */ /* values of the global variables (in 240x2 = 480 bytes) followed by any */ -/* (dynamic) arrays which may be defined. Owing to a poor choice of name */ -/* some years ago, this is also called the "static data area", which is */ -/* why the memory setting for its maximum extent is "MAX_STATIC_DATA". */ +/* (dynamic) arrays which may be defined. */ /* */ -/* In Glulx, that 240 is changed to MAX_GLOBAL_VAR_NUMBER, and we take */ -/* correspondingly more space for the globals. This *really* ought to be */ -/* split into two segments. */ +/* In Glulx, we don't keep the global variables in dynamic_array_area. */ +/* Array data starts at the start. */ /* */ /* We can also store arrays (but not globals) into static memory (ROM). */ -/* The storage for these goes, unsurprisingly, into static_array_area -- */ -/* a separate allocation of MAX_STATIC_DATA bytes. */ +/* The storage for these goes, unsurprisingly, into static_array_area. */ /* ------------------------------------------------------------------------- */ -int *dynamic_array_area; /* See above */ -int32 *global_initial_value; +uchar *dynamic_array_area; /* See above */ +memory_list dynamic_array_area_memlist; +int dynamic_array_area_size; /* Size in bytes */ + +int32 *global_initial_value; /* Allocated to no_globals */ +static memory_list global_initial_value_memlist; int no_globals; /* Number of global variables used by the programmer (Inform itself @@ -57,17 +58,13 @@ int no_globals; /* Number of global variables used /* In Glulx, Inform uses the bottom ten. */ -int dynamic_array_area_size; /* Size in bytes */ - -int *static_array_area; +uchar *static_array_area; +memory_list static_array_area_memlist; int static_array_area_size; int no_arrays; -int32 *array_symbols; -int *array_sizes, *array_types, *array_locs; -/* array_sizes[N] gives the length of array N; array_types[N] is one of - the constants BYTE_ARRAY, WORD_ARRAY, etc; array_locs[N] is true for - static arrays, false for dynamic arrays. */ +arrayinfo *arrays; +static memory_list arrays_memlist; static int array_entry_size, /* 1 for byte array, 2 for word array */ array_base; /* Offset in dynamic array area of the @@ -81,16 +78,24 @@ static int array_entry_size, /* 1 for byte array, 2 for word array */ /* In Glulx, of course, that will be 4 instead of 2. */ +static memory_list current_array_name; /* The name of the global or array + currently being compiled. */ + +/* Complete the array. Fill in the size field (if it has one) and + advance foo_array_area_size. +*/ extern void finish_array(int32 i, int is_static) { - int *area; + uchar *area; int area_size; if (!is_static) { + ensure_memory_list_available(&dynamic_array_area_memlist, dynamic_array_area_size+array_base+1*array_entry_size); area = dynamic_array_area; area_size = dynamic_array_area_size; } else { + ensure_memory_list_available(&static_array_area_memlist, static_array_area_size+array_base+1*array_entry_size); area = static_array_area; area_size = static_array_area_size; } @@ -146,16 +151,22 @@ extern void finish_array(int32 i, int is_static) } +/* Fill in array entry i (in either the static or dynamic area). + When this is called, foo_array_area_size is the end of the previous + array; we're writing after that. +*/ extern void array_entry(int32 i, int is_static, assembly_operand VAL) { - int *area; + uchar *area; int area_size; if (!is_static) { + ensure_memory_list_available(&dynamic_array_area_memlist, dynamic_array_area_size+(i+1)*array_entry_size); area = dynamic_array_area; area_size = dynamic_array_area_size; } else { + ensure_memory_list_available(&static_array_area_memlist, static_array_area_size+(i+1)*array_entry_size); area = static_array_area; area_size = static_array_area_size; } @@ -163,9 +174,6 @@ extern void array_entry(int32 i, int is_static, assembly_operand VAL) if (!glulx_mode) { /* Array entry i (initial entry has i=0) is set to Z-machine value j */ - if (area_size+(i+1)*array_entry_size > MAX_STATIC_DATA) - memoryerror("MAX_STATIC_DATA", MAX_STATIC_DATA); - if (array_entry_size==1) { area[area_size+i] = (VAL.value)%256; @@ -198,9 +206,6 @@ extern void array_entry(int32 i, int is_static, assembly_operand VAL) else { /* Array entry i (initial entry has i=0) is set to value j */ - if (area_size+(i+1)*array_entry_size > MAX_STATIC_DATA) - memoryerror("MAX_STATIC_DATA", MAX_STATIC_DATA); - if (array_entry_size==1) { area[area_size+i] = (VAL.value) & 0xFF; @@ -223,22 +228,19 @@ extern void array_entry(int32 i, int is_static, assembly_operand VAL) if (VAL.marker != 0) { if (!is_static) { backpatch_zmachine(VAL.marker, DYNAMIC_ARRAY_ZA, - addr - 4*MAX_GLOBAL_VARIABLES); + addr); } else { /* We can't use backpatch_zmachine() because that only applies to RAM. Instead we add an entry to staticarray_backpatch_table. A backpatch entry is five bytes: *_MV followed by the array offset (in static array area). */ - write_byte_to_memory_block(&staticarray_backpatch_table, - staticarray_backpatch_size++, - VAL.marker); - write_byte_to_memory_block(&staticarray_backpatch_table, - staticarray_backpatch_size++, ((addr >> 24) & 0xFF)); - write_byte_to_memory_block(&staticarray_backpatch_table, - staticarray_backpatch_size++, ((addr >> 16) & 0xFF)); - write_byte_to_memory_block(&staticarray_backpatch_table, - staticarray_backpatch_size++, ((addr >> 8) & 0xFF)); - write_byte_to_memory_block(&staticarray_backpatch_table, - staticarray_backpatch_size++, (addr & 0xFF)); + if (bpatch_trace_setting >= 2) + printf("BP added: MV %d staticarray %04x\n", VAL.marker, addr); + ensure_memory_list_available(&staticarray_backpatch_table_memlist, staticarray_backpatch_size+5); + staticarray_backpatch_table[staticarray_backpatch_size++] = VAL.marker; + staticarray_backpatch_table[staticarray_backpatch_size++] = ((addr >> 24) & 0xFF); + staticarray_backpatch_table[staticarray_backpatch_size++] = ((addr >> 16) & 0xFF); + staticarray_backpatch_table[staticarray_backpatch_size++] = ((addr >> 8) & 0xFF); + staticarray_backpatch_table[staticarray_backpatch_size++] = (addr & 0xFF); } } } @@ -252,9 +254,7 @@ extern void array_entry(int32 i, int is_static, assembly_operand VAL) /* ------------------------------------------------------------------------- */ /* Global and Array directives. */ /* */ -/* Global | */ -/* | = */ -/* | */ +/* Global [ [=] ] */ /* */ /* Array [static] */ /* */ @@ -271,7 +271,11 @@ extern void array_entry(int32 i, int is_static, assembly_operand VAL) /* ------------------------------------------------------------------------- */ extern void set_variable_value(int i, int32 v) -{ global_initial_value[i]=v; +{ + /* This isn't currently called to create a new global, but it has + been used that way within living memory. So we call ensure. */ + ensure_memory_list_available(&global_initial_value_memlist, i+1); + global_initial_value[i]=v; } /* There are four ways to initialise arrays: */ @@ -282,19 +286,14 @@ extern void set_variable_value(int i, int32 v) #define ASCII_AI 2 #define BRACKET_AI 3 -extern void make_global(int array_flag, int name_only) +extern void make_global() { - /* array_flag is TRUE for an Array directive, FALSE for a Global; - name_only is only TRUE for parsing an imported variable name, so - array_flag is always FALSE in that case. */ - int32 i; - int array_type, data_type; - int is_static = FALSE; + int name_length; assembly_operand AO; + uint32 globalnum; int32 global_symbol; - const char *global_name; debug_location_beginning beginning_debug_location = get_token_location_beginning(); @@ -302,111 +301,84 @@ extern void make_global(int array_flag, int name_only) get_next_token(); i = token_value; global_symbol = i; - global_name = token_text; + + name_length = strlen(token_text) + 1; + ensure_memory_list_available(¤t_array_name, name_length); + strncpy(current_array_name.data, token_text, name_length); if (!glulx_mode) { - if ((token_type==SYMBOL_TT) && (stypes[i]==GLOBAL_VARIABLE_T) - && (svals[i] >= LOWEST_SYSTEM_VAR_NUMBER)) + if ((token_type==SYMBOL_TT) && (symbols[i].type==GLOBAL_VARIABLE_T) + && (symbols[i].value >= LOWEST_SYSTEM_VAR_NUMBER)) { + globalnum = symbols[i].value - MAX_LOCAL_VARIABLES; goto RedefinitionOfSystemVar; + } } else { - if ((token_type==SYMBOL_TT) && (stypes[i]==GLOBAL_VARIABLE_T)) + if ((token_type==SYMBOL_TT) && (symbols[i].type==GLOBAL_VARIABLE_T)) { + globalnum = symbols[i].value - MAX_LOCAL_VARIABLES; goto RedefinitionOfSystemVar; + } } if (token_type != SYMBOL_TT) { discard_token_location(beginning_debug_location); - if (array_flag) - ebf_error("new array name", token_text); - else ebf_error("new global variable name", token_text); + ebf_curtoken_error("new global variable name"); panic_mode_error_recovery(); return; } - if (!(sflags[i] & UNKNOWN_SFLAG)) + if (!(symbols[i].flags & UNKNOWN_SFLAG)) { discard_token_location(beginning_debug_location); - if (array_flag) - ebf_symbol_error("new array name", token_text, typename(stypes[i]), slines[i]); - else ebf_symbol_error("new global variable name", token_text, typename(stypes[i]), slines[i]); + ebf_symbol_error("new global variable name", token_text, typename(symbols[i].type), symbols[i].line); panic_mode_error_recovery(); return; } - if ((!array_flag) && (sflags[i] & USED_SFLAG)) + if (symbols[i].flags & USED_SFLAG) error_named("Variable must be defined before use:", token_text); directive_keywords.enabled = TRUE; get_next_token(); directive_keywords.enabled = FALSE; if ((token_type==DIR_KEYWORD_TT)&&(token_value==STATIC_DK)) { - if (array_flag) { - is_static = TRUE; - } - else { - error("Global variables cannot be static"); - } + error("Global variables cannot be static"); } else { put_token_back(); } - if (array_flag) - { if (!is_static) { - if (!glulx_mode) - assign_symbol(i, dynamic_array_area_size, ARRAY_T); - else - assign_symbol(i, - dynamic_array_area_size - 4*MAX_GLOBAL_VARIABLES, ARRAY_T); - } - else { - assign_symbol(i, static_array_area_size, STATIC_ARRAY_T); - } - if (no_arrays == MAX_ARRAYS) - memoryerror("MAX_ARRAYS", MAX_ARRAYS); - array_symbols[no_arrays] = i; + if (!glulx_mode && no_globals==233) + { discard_token_location(beginning_debug_location); + error("All 233 global variables already declared"); + panic_mode_error_recovery(); + return; } - else - { if (!glulx_mode && no_globals==233) - { discard_token_location(beginning_debug_location); - error("All 233 global variables already declared"); - panic_mode_error_recovery(); - return; - } - if (glulx_mode && no_globals==MAX_GLOBAL_VARIABLES) - { discard_token_location(beginning_debug_location); - memoryerror("MAX_GLOBAL_VARIABLES", MAX_GLOBAL_VARIABLES); - panic_mode_error_recovery(); - return; - } - variable_tokens[MAX_LOCAL_VARIABLES+no_globals] = i; - assign_symbol(i, MAX_LOCAL_VARIABLES+no_globals, GLOBAL_VARIABLE_T); - variable_tokens[svals[i]] = i; + globalnum = no_globals; + + ensure_memory_list_available(&variables_memlist, MAX_LOCAL_VARIABLES+no_globals+1); + variables[MAX_LOCAL_VARIABLES+no_globals].token = i; + variables[MAX_LOCAL_VARIABLES+no_globals].usage = FALSE; + assign_symbol(i, MAX_LOCAL_VARIABLES+no_globals, GLOBAL_VARIABLE_T); - if (name_only) import_symbol(i); - else global_initial_value[no_globals++]=0; - } + ensure_memory_list_available(&global_initial_value_memlist, no_globals+1); + global_initial_value[no_globals++]=0; directive_keywords.enabled = TRUE; RedefinitionOfSystemVar: - if (name_only) - { discard_token_location(beginning_debug_location); - return; - } - get_next_token(); if ((token_type == SEP_TT) && (token_value == SEMICOLON_SEP)) - { if (array_flag) - { discard_token_location(beginning_debug_location); - ebf_error("array definition", token_text); - } + { + /* No initial value. */ put_token_back(); - if (debugfile_switch && !array_flag) - { debug_file_printf(""); + if (debugfile_switch) + { + char *global_name = current_array_name.data; + debug_file_printf(""); debug_file_printf("%s", global_name); debug_file_printf("
"); - write_debug_global_backpatch(svals[global_symbol]); + write_debug_global_backpatch(symbols[global_symbol].value); debug_file_printf("
"); write_debug_locations (get_token_location_end(beginning_debug_location)); @@ -415,62 +387,124 @@ extern void make_global(int array_flag, int name_only) return; } - if (!array_flag) + if (((token_type==SEP_TT)&&(token_value==ARROW_SEP)) + || ((token_type==SEP_TT)&&(token_value==DARROW_SEP)) + || ((token_type==DIR_KEYWORD_TT)&&(token_value==STRING_DK)) + || ((token_type==DIR_KEYWORD_TT)&&(token_value==TABLE_DK)) + || ((token_type==DIR_KEYWORD_TT)&&(token_value==BUFFER_DK))) { - /* is_static is always false in this case */ - if ((token_type == SEP_TT) && (token_value == SETEQUALS_SEP)) - { AO = parse_expression(CONSTANT_CONTEXT); - if (!glulx_mode) { - if (AO.marker != 0) - backpatch_zmachine(AO.marker, DYNAMIC_ARRAY_ZA, - 2*(no_globals-1)); - } - else { - if (AO.marker != 0) - backpatch_zmachine(AO.marker, GLOBALVAR_ZA, - 4*(no_globals-1)); - } - global_initial_value[no_globals-1] = AO.value; - if (debugfile_switch) - { debug_file_printf(""); - debug_file_printf("%s", global_name); - debug_file_printf("
"); - write_debug_global_backpatch(svals[global_symbol]); - debug_file_printf("
"); - write_debug_locations - (get_token_location_end(beginning_debug_location)); - debug_file_printf("
"); - } - return; - } + error("use 'Array' to define arrays, not 'Global'"); + return; + } - obsolete_warning("more modern to use 'Array', not 'Global'"); + /* Skip "=" if present. */ + if (!((token_type == SEP_TT) && (token_value == SETEQUALS_SEP))) + put_token_back(); - if (!glulx_mode) { - backpatch_zmachine(ARRAY_MV, DYNAMIC_ARRAY_ZA, 2*(no_globals-1)); - global_initial_value[no_globals-1] - = dynamic_array_area_size+variables_offset; - } - else { - backpatch_zmachine(ARRAY_MV, GLOBALVAR_ZA, 4*(no_globals-1)); - global_initial_value[no_globals-1] - = dynamic_array_area_size - 4*MAX_GLOBAL_VARIABLES; - } + AO = parse_expression(CONSTANT_CONTEXT); + if (!glulx_mode) { + if (AO.marker != 0) + backpatch_zmachine(AO.marker, DYNAMIC_ARRAY_ZA, + 2*globalnum); + } + else { + if (AO.marker != 0) + backpatch_zmachine(AO.marker, GLOBALVAR_ZA, + 4*globalnum); + } + + if (globalnum >= global_initial_value_memlist.count) + compiler_error("Globalnum out of range"); + global_initial_value[globalnum] = AO.value; + + if (debugfile_switch) + { + char *global_name = current_array_name.data; + debug_file_printf(""); + debug_file_printf("%s", global_name); + debug_file_printf("
"); + write_debug_global_backpatch(symbols[global_symbol].value); + debug_file_printf("
"); + write_debug_locations + (get_token_location_end(beginning_debug_location)); + debug_file_printf("
"); + } +} + +extern void make_array() +{ + int32 i; + int name_length; + int array_type, data_type; + int is_static = FALSE; + assembly_operand AO; + + int extraspace; + + int32 global_symbol; + debug_location_beginning beginning_debug_location = + get_token_location_beginning(); + + directive_keywords.enabled = FALSE; + get_next_token(); + i = token_value; + global_symbol = i; + + name_length = strlen(token_text) + 1; + ensure_memory_list_available(¤t_array_name, name_length); + strncpy(current_array_name.data, token_text, name_length); + + if (token_type != SYMBOL_TT) + { discard_token_location(beginning_debug_location); + ebf_curtoken_error("new array name"); + panic_mode_error_recovery(); return; + } + + if (!(symbols[i].flags & UNKNOWN_SFLAG)) + { discard_token_location(beginning_debug_location); + ebf_symbol_error("new array name", token_text, typename(symbols[i].type), symbols[i].line); + panic_mode_error_recovery(); return; + } + + directive_keywords.enabled = TRUE; + get_next_token(); + directive_keywords.enabled = FALSE; + if ((token_type==DIR_KEYWORD_TT)&&(token_value==STATIC_DK)) { + is_static = TRUE; + } + else { + put_token_back(); + } + + if (!is_static) { + assign_symbol(i, dynamic_array_area_size, ARRAY_T); + } + else { + assign_symbol(i, static_array_area_size, STATIC_ARRAY_T); + } + ensure_memory_list_available(&arrays_memlist, no_arrays+1); + arrays[no_arrays].symbol = i; + + directive_keywords.enabled = TRUE; + + get_next_token(); + + if ((token_type == SEP_TT) && (token_value == SEMICOLON_SEP)) + { + discard_token_location(beginning_debug_location); + ebf_curtoken_error("array definition"); + put_token_back(); + return; } array_type = BYTE_ARRAY; data_type = UNSPECIFIED_AI; - if ((!array_flag) && - ((token_type==DIR_KEYWORD_TT)&&(token_value==DATA_DK))) - data_type=NULLS_AI; - else if ((!array_flag) && - ((token_type==DIR_KEYWORD_TT)&&(token_value==INITIAL_DK))) - data_type=DATA_AI; - else if ((!array_flag) && - ((token_type==DIR_KEYWORD_TT)&&(token_value==INITSTR_DK))) - data_type=ASCII_AI; - - else if ((token_type==SEP_TT)&&(token_value==ARROW_SEP)) + /* The keywords "data", "initial", and "initstr" used to be accepted + here -- but only in a Global directive, not Array. The Global directive + no longer calls here, so those keywords are now (more) obsolete. + */ + + if ((token_type==SEP_TT)&&(token_value==ARROW_SEP)) array_type = BYTE_ARRAY; else if ((token_type==SEP_TT)&&(token_value==DARROW_SEP)) array_type = WORD_ARRAY; @@ -482,12 +516,7 @@ extern void make_global(int array_flag, int name_only) array_type = BUFFER_ARRAY; else { discard_token_location(beginning_debug_location); - if (array_flag) - ebf_error - ("'->', '-->', 'string', 'table' or 'buffer'", token_text); - else - ebf_error - ("'=', '->', '-->', 'string', 'table' or 'buffer'", token_text); + ebf_curtoken_error("'->', '-->', 'string', 'table' or 'buffer'"); panic_mode_error_recovery(); return; } @@ -525,28 +554,27 @@ extern void make_global(int array_flag, int name_only) /* Leave room to write the array size in later, if string/table array */ - int extraspace = 0; + extraspace = 0; if ((array_type==STRING_ARRAY) || (array_type==TABLE_ARRAY)) extraspace += array_entry_size; if (array_type==BUFFER_ARRAY) extraspace += WORDSIZE; - - int orig_area_size; if (!is_static) { - orig_area_size = dynamic_array_area_size; array_base = dynamic_array_area_size; dynamic_array_area_size += extraspace; } else { - orig_area_size = static_array_area_size; array_base = static_array_area_size; static_array_area_size += extraspace; } - array_types[no_arrays] = array_type; - array_locs[no_arrays] = is_static; + arrays[no_arrays].type = array_type; + arrays[no_arrays].loc = is_static; + /* Note that, from this point, we must continue through finish_array(). + Exiting this routine on error causes problems. */ + switch(data_type) { case NULLS_AI: @@ -584,7 +612,12 @@ extern void make_global(int array_flag, int name_only) i=0; do - { get_next_token(); + { + /* This isn't the start of a statement, but it's safe to + release token texts anyway. Expressions in an array + list are independent of each other. */ + release_token_texts(); + get_next_token(); if ((token_type == SEP_TT) && (token_value == SEMICOLON_SEP)) break; @@ -594,11 +627,12 @@ extern void make_global(int array_flag, int name_only) { discard_token_location(beginning_debug_location); error("Missing ';' to end the initial array values " "before \"[\" or \"]\""); - return; } put_token_back(); AO = parse_expression(ARRAY_CONTEXT); + if (AO.marker == ERROR_MV) + break; if (i == 0) { get_next_token(); @@ -623,7 +657,7 @@ extern void make_global(int array_flag, int name_only) get_next_token(); if (token_type != DQ_TT) - { ebf_error("literal text in double-quotes", token_text); + { ebf_curtoken_error("literal text in double-quotes"); token_text = "error"; } @@ -671,7 +705,13 @@ advance as part of 'Zcharacter table':", unicode); i = 0; while (TRUE) - { get_next_token(); + { + assembly_operand AO; + /* This isn't the start of a statement, but it's safe to + release token texts anyway. Expressions in an array + list are independent of each other. */ + release_token_texts(); + get_next_token(); if ((token_type == SEP_TT) && (token_value == SEMICOLON_SEP)) continue; if ((token_type == SEP_TT) && (token_value == CLOSE_SQUARE_SEP)) @@ -681,11 +721,14 @@ advance as part of 'Zcharacter table':", unicode); been missed, and the programmer is now starting a new routine */ - ebf_error("']'", token_text); + ebf_curtoken_error("']'"); put_token_back(); break; } put_token_back(); - array_entry(i, is_static, parse_expression(ARRAY_CONTEXT)); + AO = parse_expression(ARRAY_CONTEXT); + if (AO.marker == ERROR_MV) + break; + array_entry(i, is_static, AO); i++; } } @@ -693,12 +736,15 @@ advance as part of 'Zcharacter table':", unicode); finish_array(i, is_static); if (debugfile_switch) - { debug_file_printf(""); + { + int32 new_area_size; + char *global_name = current_array_name.data; + debug_file_printf(""); debug_file_printf("%s", global_name); debug_file_printf(""); - write_debug_array_backpatch(svals[global_symbol]); + write_debug_array_backpatch(symbols[global_symbol].value); debug_file_printf(""); - int32 new_area_size = (!is_static ? dynamic_array_area_size : static_array_area_size); + new_area_size = (!is_static ? dynamic_array_area_size : static_array_area_size); debug_file_printf ("%d", new_area_size - array_base); @@ -717,7 +763,7 @@ advance as part of 'Zcharacter table':", unicode); if ((array_type==BYTE_ARRAY) || (array_type==WORD_ARRAY)) i--; if (array_type==BUFFER_ARRAY) i+=WORDSIZE-1; - array_sizes[no_arrays++] = i; + arrays[no_arrays++].size = i; } extern int32 begin_table_array(void) @@ -733,10 +779,7 @@ extern int32 begin_table_array(void) dynamic_array_area_size += array_entry_size; - if (!glulx_mode) - return array_base; - else - return array_base - WORDSIZE * MAX_GLOBAL_VARIABLES; + return array_base; } extern int32 begin_word_array(void) @@ -748,10 +791,7 @@ extern int32 begin_word_array(void) array_base = dynamic_array_area_size; array_entry_size = WORDSIZE; - if (!glulx_mode) - return array_base; - else - return array_base - WORDSIZE * MAX_GLOBAL_VARIABLES; + return array_base; } /* ========================================================================= */ @@ -761,41 +801,85 @@ extern int32 begin_word_array(void) extern void init_arrays_vars(void) { dynamic_array_area = NULL; static_array_area = NULL; + arrays = NULL; global_initial_value = NULL; - array_sizes = NULL; array_symbols = NULL; array_types = NULL; + variables = NULL; } extern void arrays_begin_pass(void) -{ no_arrays = 0; - if (!glulx_mode) - no_globals=0; - else - no_globals=11; - dynamic_array_area_size = WORDSIZE * MAX_GLOBAL_VARIABLES; +{ + int ix, totalvar; + + no_arrays = 0; + if (!glulx_mode) { + no_globals = 0; + /* The compiler-defined globals start at 239 and go down, so + we need to initialize the entire list from the start. */ + totalvar = MAX_ZCODE_GLOBAL_VARS; + } + else { + /* The compiler-defined globals run from 0 to 10. */ + no_globals = 11; + totalvar = no_globals; + } + + ensure_memory_list_available(&global_initial_value_memlist, totalvar); + for (ix=0; ix