diff options
Diffstat (limited to 'src/eval.c')
| -rw-r--r-- | src/eval.c | 24 |
1 files changed, 23 insertions, 1 deletions
@@ -86,7 +86,6 @@ sym_t* try_eval_internal(sym_t* symbol, hashtable_t* symbolScope) { exec_all(symbol->args, symbol->argCount - 1, symbolScope); return eval(symbol->args[symbol->argCount - 1], symbolScope); } - /* TODO: rename storel */ else if (hash == get_hash("store")) { /* first arg is value, remaining args are names */ /* TODO: recursion for multiple pairs */ @@ -99,6 +98,18 @@ sym_t* try_eval_internal(sym_t* symbol, hashtable_t* symbolScope) { hashtable_add_pair(symbolScope->parent, p); return init_sym_int(1); } + else if (hash == get_hash("update")) { + /* first arg is value, remaining args are names */ + /* TODO: recursion for multiple pairs */ + sym_t* v = eval(symbol->args[1], symbolScope); + char* k = symtos(v); + destroy_sym(v); + sym_t* value = symbol->args[0]; + pair_t p = init_pair(k, (void*)value); + free(k); + hashtable_update_pair_recurse(symbolScope->parent, p); + return init_sym_int(1); + } /* TODO: release()/free() method? */ else if (hash == get_hash("eq")) { litType_t type = NO_TYPE; @@ -175,6 +186,17 @@ sym_t* try_eval_internal(sym_t* symbol, hashtable_t* symbolScope) { } return init_sym_int(sum); } + else if (hash == get_hash("sub")) { + sym_t* v1 = eval(symbol->args[0], symbolScope); + int sum = symtoi(v1); + destroy_sym(v1); + for (int i = 1; i < symbol->argCount; i++) { + sym_t* v = eval(symbol->args[i], symbolScope); + sum -= symtoi(v); + destroy_sym(v); + } + return init_sym_int(sum); + } else if (hash == get_hash("print")) { sym_t* v = eval(symbol->args[0], symbolScope); if (v->litType == INT) { |
