aboutsummaryrefslogtreecommitdiff
path: root/src/term.c
diff options
context:
space:
mode:
authorMarvin Borner2023-05-17 00:19:14 +0200
committerMarvin Borner2023-05-17 00:24:37 +0200
commitf640ceee89836b56ac95c4eb1b0a43d1171c3354 (patch)
tree9deab5538634c983794a78e04b8e2cd5255711ab /src/term.c
parentae597603952e3e329eecc25512606a7fa85ea0ec (diff)
General improvements
(nothing special, mainly cleanup and docs)
Diffstat (limited to 'src/term.c')
-rw-r--r--src/term.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/term.c b/src/term.c
index 50333c7..63bbb05 100644
--- a/src/term.c
+++ b/src/term.c
@@ -12,7 +12,30 @@ struct term *new_term(term_type type)
{
struct term *term = malloc(sizeof(*term));
if (!term)
- fatal("Out of memory!\n");
+ fatal("out of memory!\n");
term->type = type;
return term;
}
+
+void free_term(struct term *term)
+{
+ switch (term->type) {
+ case ABS:
+ free_term(term->u.abs.term);
+ free(term);
+ break;
+ case APP:
+ free_term(term->u.app.lhs);
+ free_term(term->u.app.rhs);
+ free(term);
+ break;
+ case VAR:
+ free(term);
+ break;
+ case REF:
+ free(term);
+ break;
+ default:
+ fatal("invalid type %d\n", term->type);
+ }
+}