aboutsummaryrefslogtreecommitdiff
path: root/fptr_ast/struct.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2025-08-31 14:45:52 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2025-08-31 14:45:52 +0300
commit752675bc0c9ba6082038bc25cefe838c1f58b5de (patch)
tree358c76ccf2a6195d7f6ab1e4d72b40d32bbb75af /fptr_ast/struct.c
parenta0c6ff2c222beb72493f2e40ed27492061dfdf22 (diff)
downloadplayground-752675bc0c9ba6082038bc25cefe838c1f58b5de.tar.gz
playground-752675bc0c9ba6082038bc25cefe838c1f58b5de.zip
free resources
Diffstat (limited to 'fptr_ast/struct.c')
-rw-r--r--fptr_ast/struct.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/fptr_ast/struct.c b/fptr_ast/struct.c
index f22fae4..f33044a 100644
--- a/fptr_ast/struct.c
+++ b/fptr_ast/struct.c
@@ -51,6 +51,12 @@ static proc *gen_proc(int header, ...)
#define gen_proc(...) gen_proc(0, __VA_ARGS__, NULL)
+static void destroy_proc(proc *proc)
+{
+ vars_destroy(&proc->vars);
+ free(proc);
+}
+
static void proc_set(proc *proc, char *name, intptr_t v)
{
foreach(vars, var, &proc->vars) {
@@ -328,3 +334,24 @@ static intptr_t run(node *n)
return 0;
}
+
+/* destruction is easy as hell */
+static void destroy(node *n)
+{
+ if (!n)
+ return;
+
+ destroy(n->n0);
+ destroy(n->n1);
+ destroy(n->n2);
+ destroy(n->n3);
+
+ foreach(nodes, node, &n->nodes) {
+ destroy(*node);
+ }
+
+ nodes_destroy(&n->nodes);
+ free(n);
+
+ /* strings are not owned, nor are references to variables */
+}