summaryrefslogtreecommitdiff
path: root/interpreter.c
diff options
context:
space:
mode:
Diffstat (limited to 'interpreter.c')
-rw-r--r--interpreter.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/interpreter.c b/interpreter.c
index 05e5d2c..fec9087 100644
--- a/interpreter.c
+++ b/interpreter.c
@@ -172,7 +172,9 @@ static InterRet interpret(InterState *is,const AST *ast){
#define NOT_IMPLEMENTED false
if(nodes[0]->la.body)assert(NOT_IMPLEMENTED);
- return nodes[0]->la.cfunc(is,ast->li.len-1,nodes+1);
+ InterRet ir=nodes[0]->la.cfunc(is,ast->li.len-1,nodes+1);
+ for(int i=0;i<ast->li.len;i++)ast_free(nodes[i]);
+ return ir;
}
case AST_SYMBOL:
@@ -201,16 +203,20 @@ static InterRet interpret(InterState *is,const AST *ast){
}
}
-void inter_register(InterState *is,const char *name,lambdafunc_t cfunc){
+void inter_assign(InterState *is,const char *name,AST *ast){
assert(is->scope);
int h=namehash(name,VMAP_HASHSZ);
Vllist *ll=malloc(1,Vllist);
ll->name=copystring(name);
- ll->value=ast_lambda(cfunc,NULL);
+ ll->value=ast;
ll->next=is->scope->vmap[h];
is->scope->vmap[h]=ll;
}
+void inter_register(InterState *is,const char *name,lambdafunc_t cfunc){
+ inter_assign(is,name,ast_lambda(cfunc,NULL));
+}
+
void inter_register_prelude(InterState *is){
inter_register(is,"do",builtin_do);
inter_register(is,"print",builtin_print);
@@ -224,10 +230,10 @@ void inter_register_prelude(InterState *is){
inter_register(is,"product",builtin_product);
inter_register(is,"quotient",builtin_quotient);
inter_register(is,"remainder",builtin_remainder);
+ inter_register(is,"define",builtin_define);
}
InterRet inter_runcode(InterState *is,AST *ast){
intern_symbols(is,ast);
-
return interpret(is,ast);
}