From 2127b746f0eecb657b31653ad5967623f994cbaf Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Sat, 4 Mar 2023 01:19:17 -0800 Subject: added any(), all(), one(). replaced not() with none() --- src/eval.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 6 deletions(-) (limited to 'src/eval.c') diff --git a/src/eval.c b/src/eval.c index b583fc6..8b41f38 100644 --- a/src/eval.c +++ b/src/eval.c @@ -189,6 +189,57 @@ sym_t* try_eval_internal(sym_t* symbol, hashtable_t* symbolScope) { } return init_sym_int(1); } + /* OR */ + else if (hash == get_hash("any")) { + for (int i = 0; i < symbol->argCount; i++) { + sym_t* v = eval(symbol->args[i], symbolScope); + if (symtoi(v) != 0) { + destroy_sym(v); + return init_sym_int(1); + } + destroy_sym(v); + } + return init_sym_int(0); + } + /* AND */ + else if (hash == get_hash("all")) { + for (int i = 0; i < symbol->argCount; i++) { + sym_t* v = eval(symbol->args[i], symbolScope); + if (symtoi(v) == 0) { + destroy_sym(v); + return init_sym_int(0); + } + destroy_sym(v); + } + return init_sym_int(1); + } + /* XOR */ + else if (hash == get_hash("one")) { + char b = 0; + for (int i = 0; i < symbol->argCount; i++) { + sym_t* v = eval(symbol->args[i], symbolScope); + if (symtoi(v) == 1) { + if (b == 1) { + destroy_sym(v); + return init_sym_int(0); + } + b = 1; + } + destroy_sym(v); + } + return init_sym_int(b); + } + else if (hash == get_hash("none")) { + for (int i = 0; i < symbol->argCount; i++) { + sym_t* v = eval(symbol->args[i], symbolScope); + if (symtoi(v) == 1) { + destroy_sym(v); + return init_sym_int(0); + } + destroy_sym(v); + } + return init_sym_int(1); + } else if (hash == get_hash("if")) { sym_t* v = eval(symbol->args[0], symbolScope); int si = symtoi(v); @@ -212,12 +263,6 @@ sym_t* try_eval_internal(sym_t* symbol, hashtable_t* symbolScope) { } } } - else if (hash == get_hash("not")) { - sym_t* v = eval(symbol->args[0], symbolScope); - int b = symtoi(v); - destroy_sym(v); - return init_sym_int(!b); - } else if (hash == get_hash("sum")) { int sum = 0; float fSum = 0; -- cgit v1.3.1