diff options
| author | Kai Stevenson <kai@kaistevenson.com> | 2023-02-16 21:58:47 -0800 |
|---|---|---|
| committer | Kai Stevenson <kai@kaistevenson.com> | 2023-02-16 21:58:47 -0800 |
| commit | e34f5492b0df9ae22de0aaa537018efa2a191d2d (patch) | |
| tree | 637348c444c2773bc4db2aba47fa791ba6906002 /src/eval.c | |
| parent | cd4a69bf4b219e2f96de2d86d8ea41ab01d0f5e3 (diff) | |
changed some stuff to get recursion working, made some more memory leaks
Diffstat (limited to 'src/eval.c')
| -rw-r--r-- | src/eval.c | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -19,7 +19,7 @@ sym_t* eval(sym_t* symbol, hashtable_t* parentScope) { else if (symbol->province == KEY_REF) { sym_t* returnV = NULL; /* entering new scope, so create a new table */ - hashtable_t* newScope = init_hashtable(500, parentScope); + hashtable_t* newScope = init_hashtable(50, parentScope); sym_t* ir = try_eval_internal(symbol, newScope); if (ir != NULL) { returnV = ir; @@ -48,7 +48,7 @@ sym_t* eval(sym_t* symbol, hashtable_t* parentScope) { } } /* clear new scope, then return */ - destroy_hashtable(newScope); + /* destroy_hashtable(newScope); */ return returnV; } else { @@ -59,7 +59,7 @@ sym_t* eval(sym_t* symbol, hashtable_t* parentScope) { void exec_all(sym_t** symbols, int count, hashtable_t* symbolScope) { for (int i = 0; i < count; i++) { eval(symbols[i], symbolScope); - destroy_sym(symbols[i]); + /* destroy_sym(symbols[i]); */ } } /* internal functions? @@ -123,6 +123,14 @@ sym_t* try_eval_internal(sym_t* symbol, hashtable_t* symbolScope) { int b = symtoi(v); return b ? &falseSym : &trueSym; } + else if (hash == get_hash("sum")) { + int* sum = calloc(1, sizeof(int)); + for (int i = 0; i < symbol->argCount; i++) { + sym_t* v = eval(symbol->args[i], symbolScope); + *sum += symtoi(v); + } + return init_sym(LITERAL, INT, sum); + } else if (hash == get_hash("print")) { sym_t* v = eval(symbol->args[0], symbolScope); switch (v->litType) { |
