-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathast.c
51 lines (45 loc) · 1.08 KB
/
ast.c
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdlib.h>
#include "ast.h"
void value_destroy(value *val) {
if(val->type == VALUE_STR_TYPE || val->type == VALUE_IDENT_TYPE) {
free(val->val.string);
} else if (val->type == VALUE_CALL_TYPE) {
fn_call_destroy(val->val.fn_call);
}
free(val);
}
void fn_arg_destroy(fn_arg *arg) {
value_destroy(arg->val);
free(arg);
}
void fn_args_destroy(fn_args *args) {
fn_arg *curr = args->first, *next;
while(curr != NULL) {
next = curr->next;
fn_arg_destroy(curr);
curr = next;
}
free(args);
}
void fn_call_destroy(fn_call *call) {
if(call->args != NULL) fn_args_destroy(call->args);
free(call);
}
void block_destroy(block *block) {
fn_call *curr = block->first, *next;
while(curr != NULL) {
next = curr->next;
fn_call_destroy(curr);
curr = next;
}
free(block);
}
void program_destroy(program *program) {
fn_call *curr = program->first, *next;
while(curr != NULL) {
next = curr->next;
fn_call_destroy(curr);
curr = next;
}
free(program);
}