diff --git a/boot.c b/boot.c index 4a7b5b0..eb71c13 100644 --- a/boot.c +++ b/boot.c @@ -484,12 +484,15 @@ void next_token() { fprintf(stderr, "unexpected character: %c(%d)\n", ch, ch); exit(1); } - fprintf(stderr, "token: %d\n", token_type); - if (token_type == TOKEN_ID) { - const char* name = id_table + id_lut[token_data]; - fprintf(stderr, " id: %s\n", name); - } else if (token_type == TOKEN_NUMBER) { - fprintf(stderr, " number: %d\n", token_data); + // debug info + if (0) { + fprintf(stderr, "token: %d\n", token_type); + if (token_type == TOKEN_ID) { + const char* name = id_table + id_lut[token_data]; + fprintf(stderr, " id: %s\n", name); + } else if (token_type == TOKEN_NUMBER) { + fprintf(stderr, " number: %d\n", token_data); + } } } @@ -670,11 +673,17 @@ int declare_local(int id, int type) { return local_table[id] = slot; } +int array_size_of(int type, int size) { + return type == TYPE_CHAR ? size : 4 * size; +} + int declare_local_array(int id, int type, int size) { if (local_table[id] != 0) return local_table[id]; int slot = next_local_slot(type); + int array_size = array_size_of(type, size); + int slot_size = (array_size + 7) / 8; local_marker[slot] = MARKER_ARRAY; - for (int i = 1; i < size; ++i) local_marker[next_local_slot(type)] = MARKER_ARRAY; + for (int i = 1; i < slot_size; ++i) local_marker[next_local_slot(type)] = MARKER_ARRAY; return local_table[id] = slot; } @@ -1841,7 +1850,7 @@ void parse_global_variable(int id, const char* name, int type) { expect_token(TOKEN_NUMBER); int size = token_data; expect_token(TOKEN_BRACKET_RIGHT); - int array_size = type == TYPE_CHAR ? size : 4 * size; + int array_size = array_size_of(type, size); printf(" .zero %d\n", array_size); declare_global(id, MARKER_ARRAY, type); } else {