diff options
Diffstat (limited to 'eval.c')
| -rw-r--r-- | eval.c | 24 |
1 files changed, 17 insertions, 7 deletions
@@ -17,10 +17,10 @@ void init_eval() { } /* TODO: read base hashtable from file to allow modularity pair value value? */ -void exec_all(symset_t symset) { - for (int i = 0; i < symset.count; i++) { +void exec_all(sym_t** symbols, int count) { + for (int i = 0; i < count; i++) { /* dispose of result */ - eval(symset.symbols[i]); + eval(symbols[i]); } } sym_t* eval(sym_t* symbol) { @@ -58,10 +58,7 @@ sym_t* try_eval_internal(sym_t* symbol) { /* TODO: return last arg. that's the function return line */ if (hash == get_hash("root")) { /* execute all args as roots */ - symset_t symset; - symset.symbols = symbol->args; - symset.count = symbol->argCount; - exec_all(symset); + exec_all(symbol->args, symbol->argCount); return &trueSym; } else if (hash == get_hash("store")) { @@ -101,6 +98,19 @@ sym_t* try_eval_internal(sym_t* symbol) { } return &trueSym; } + else if (hash == get_hash("if")) { + sym_t* v = eval(symbol->args[0]); + if (symtoi(v) != 0) { + exec_all(symbol->args + 1, symbol->argCount - 1); + return &trueSym; + } + return &falseSym; + } + else if (hash == get_hash("not")) { + sym_t* v = eval(symbol->args[0]); + int b = symtoi(v); + return b ? &falseSym : &trueSym; + } else if (hash == get_hash("print")) { sym_t* v = eval(symbol->args[0]); switch (v->litType) { |
