diff options
| author | Mustafa Quraish <[email protected]> | 2022-02-02 02:34:19 -0500 |
|---|---|---|
| committer | Mustafa Quraish <[email protected]> | 2022-02-02 02:34:19 -0500 |
| commit | ae3638402a41f1c75f59aa1da923d6f7ffd058ac (patch) | |
| tree | d1f985eb73ce3def8aa3caa6220687af71a4d125 /src/parser.c | |
| parent | Modify how types are stored. (diff) | |
| download | cup-ae3638402a41f1c75f59aa1da923d6f7ffd058ac.tar.xz cup-ae3638402a41f1c75f59aa1da923d6f7ffd058ac.zip | |
Add `size_for_type()` helper instead of hard-coding variable sizes
Diffstat (limited to 'src/parser.c')
| -rw-r--r-- | src/parser.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/parser.c b/src/parser.c index 67cbfbc..a9a26e3 100644 --- a/src/parser.c +++ b/src/parser.c @@ -144,8 +144,7 @@ Node *find_function_definition(Token *token) void add_global_variable(Variable *var) { var->offset = global_vars_offset; - // TODO: Compute based on type - int var_size = 8; + int var_size = size_for_type(var->type); global_vars_offset += var_size; global_vars[global_vars_count++] = var; } @@ -157,7 +156,8 @@ void add_variable_to_current_block(Variable *var) Node *cur_block = block_stack[block_stack_count - 1]; int new_len = (cur_block->block.num_locals + 1); - int var_size = 8; // TODO: Compute sizes based on different types + // TODO: Align the stack to a certain size? + int var_size = size_for_type(var->type); // Add to the block // FIXME: Use a map here @@ -560,8 +560,8 @@ void parse_func_args(Lexer *lexer, Node *func) for (int i = 0; i < func->func.num_args; i++) { Variable *var = &func->func.args[i]; var->offset = offset; - // TODO: Compute this for different types - int var_size = 8; + // TODO: Do we need to align the stack here? + int var_size = size_for_type(var->type); offset -= var_size; } } |