summaryrefslogtreecommitdiff
path: root/src/eval.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/eval.c')
-rw-r--r--src/eval.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/eval.c b/src/eval.c
index c658502..f34a0f1 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -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) {