aboutsummaryrefslogtreecommitdiff
path: root/src/parser/ast.c
blob: 979dff0f0fbeaf340f0f3935cd1bd82d2af4f92e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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;
}