compact local array
This commit is contained in:
parent
70a78b282a
commit
61b41ee713
13
boot.c
13
boot.c
@ -484,6 +484,8 @@ void next_token() {
|
||||
fprintf(stderr, "unexpected character: %c(%d)\n", ch, ch);
|
||||
exit(1);
|
||||
}
|
||||
// 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];
|
||||
@ -492,6 +494,7 @@ void next_token() {
|
||||
fprintf(stderr, " number: %d\n", token_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void expect_token(int expected_type) {
|
||||
next_token();
|
||||
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user