diff options
Diffstat (limited to 'src/parser/ast.c')
| -rw-r--r-- | src/parser/ast.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/parser/ast.c b/src/parser/ast.c new file mode 100644 index 0000000..979dff0 --- /dev/null +++ b/src/parser/ast.c @@ -0,0 +1,33 @@ +#include <stdlib.h> + +#include "parser/ast.h" + +struct Program create_program(void) +{ + struct Program program; + program.consts = NULL; + program.const_count = 0; + program.const_capacity = 0; + return program; +} + +void free_program(struct Program* program) +{ + free(program->consts); + program->consts = NULL; + program->const_count = 0; + program->const_capacity = 0; +} + +void add_const(struct Program* program, struct ConstDecl decl) +{ + if (program->const_count == program->const_capacity) + { + size_t capacity = program->const_capacity < 8 ? 8 : program->const_capacity * 2; + program->consts = realloc(program->consts, capacity * sizeof(struct ConstDecl)); + program->const_capacity = capacity; + } + + program->consts[program->const_count] = decl; + program->const_count += 1; +} |
