diff options
| author | hachem <im@hachem.wtf> | 2026-08-30 03:38:46 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-08-30 03:38:46 +0200 |
| commit | 2e7cab34d22a0174909030942671e95d5a3c769f (patch) | |
| tree | fe2d5a54f20b7908936c8dc9151023e440168d46 /src/parser/ast.c | |
| parent | 5767110816ca9452ef77d15245d1a747bfdd896b (diff) | |
add: top level data declarations
Diffstat (limited to 'src/parser/ast.c')
| -rw-r--r-- | src/parser/ast.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/parser/ast.c b/src/parser/ast.c index 979dff0..3f360cc 100644 --- a/src/parser/ast.c +++ b/src/parser/ast.c @@ -8,17 +8,25 @@ struct Program create_program(void) program.consts = NULL; program.const_count = 0; program.const_capacity = 0; + program.data_decls = NULL; + program.data_count = 0; + program.data_capacity = 0; return program; } void free_program(struct Program* program) { free(program->consts); + free(program->data_decls); program->consts = NULL; program->const_count = 0; program->const_capacity = 0; + program->data_decls = NULL; + program->data_count = 0; + program->data_capacity = 0; } +// TODO: generalize this growable-array boilerplate once a third list appears void add_const(struct Program* program, struct ConstDecl decl) { if (program->const_count == program->const_capacity) @@ -31,3 +39,16 @@ void add_const(struct Program* program, struct ConstDecl decl) program->consts[program->const_count] = decl; program->const_count += 1; } + +void add_data(struct Program* program, struct DataDecl decl) +{ + if (program->data_count == program->data_capacity) + { + size_t capacity = program->data_capacity < 8 ? 8 : program->data_capacity * 2; + program->data_decls = realloc(program->data_decls, capacity * sizeof(struct DataDecl)); + program->data_capacity = capacity; + } + + program->data_decls[program->data_count] = decl; + program->data_count += 1; +} |
