Started with actually freeing terms that are not used anymore
[lambda.git] / lambda.y
index eda3c59..cb8259a 100644 (file)
--- a/lambda.y
+++ b/lambda.y
@@ -38,6 +38,7 @@ struct lambda *make_abstraction(char *i, struct lambda *t)
        struct lambda *r = make_lambda();
        r->which = lambda_abs;
        r->data.abstraction.ident = strdup(i);
+       r->data.abstraction.revision = 0;
        r->data.abstraction.expr = t;
        return r;
 }
@@ -55,7 +56,7 @@ void decls_prepend(char *ident, struct lambda *value)
 {
        struct decllist *head = malloc(sizeof (struct decllist));
        head->next = decls;
-       head->ident = ident;
+       head->ident = strdup(ident);
        head->value = value;
        printf("Declared %s as ", ident);
        lambda_print(value, NULL);
@@ -73,6 +74,18 @@ struct lambda *decls_lookup(char *ident)
        return make_ident(ident);
 }
 
+void decls_free()
+{
+       struct decllist *t;
+       while(decls != NULL){
+               free(decls->ident);
+               lambda_free(decls->value);
+               t = decls->next;
+               free(decls);
+               decls = t;
+       }
+}
+
 %}
 
 %token LAMBDA DOT OBRACE CBRACE IDENT FUNC SEMICOLON ASSIGN
@@ -85,7 +98,10 @@ lambda
                { result = $$; }
 decl
        : FUNC ASSIGN term SEMICOLON
-               { decls_prepend($1->data.identifier.ident, $3); }
+               {
+                       decls_prepend($1->data.identifier.ident, $3);
+                       lambda_free($1);
+               }
 term
        : term appterm
                { $$ = make_application($1, $2); }