diff options
Diffstat (limited to 'src/eval.c')
| -rw-r--r-- | src/eval.c | 42 |
1 files changed, 29 insertions, 13 deletions
@@ -107,23 +107,26 @@ sym_t* try_eval_internal(sym_t* symbol, hashtable_t* symbolScope) { } else if (hash == get_hash("store")) { /* first arg is value, second arg is key */ - sym_t* v = eval(symbol->args[1], symbolScope); - char* k = symtos(v); - destroy_sym(v); - sym_t* value = eval(symbol->args[0], symbolScope); - pair_t p = init_pair(k, (void*)value); - free(k); - hashtable_add_pair(symbolScope->parent, p); + sym_t* k = eval(symbol->args[1], symbolScope); + char* key = symtos(k); + destroy_sym(k); + sym_t* v = eval(symbol->args[0], symbolScope); + pair_t p = init_pair(key, (void*)v); + int result = hashtable_add_pair(symbolScope->parent, p); + if (result == 0) { + printf("Hashtable full when attempting to store pair with key %s\n", key); + } + free(key); return init_sym_int(1); } else if (hash == get_hash("update")) { /* first arg is value, second arg is key */ - 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); + sym_t* k = eval(symbol->args[1], symbolScope); + char* key = symtos(k); + destroy_sym(k); + sym_t* v = eval(symbol->args[0], symbolScope); + pair_t p = init_pair(key, (void*)v); + free(key); hashtable_update_pair_recurse(symbolScope->parent, p); return init_sym_int(1); } @@ -196,6 +199,19 @@ sym_t* try_eval_internal(sym_t* symbol, hashtable_t* symbolScope) { } return init_sym_int(0); } + else if (hash == get_hash("while")) { + while (1) { + sym_t* c = eval(symbol->args[0], symbolScope); + if (symtoi(c) != 0) { + destroy_sym(c); + exec_all(symbol->args + 1, symbol->argCount - 1, symbolScope); + } + else { + destroy_sym(c); + return init_sym_int(1); + } + } + } else if (hash == get_hash("not")) { sym_t* v = eval(symbol->args[0], symbolScope); int b = symtoi(v); |
