diff options
| author | Kai Stevenson <kai@kaistevenson.com> | 2023-03-04 01:19:17 -0800 |
|---|---|---|
| committer | Kai Stevenson <kai@kaistevenson.com> | 2023-03-04 01:21:14 -0800 |
| commit | 2127b746f0eecb657b31653ad5967623f994cbaf (patch) | |
| tree | 9df6e054410102ed620aae7b497f0dce66b6efc3 /src | |
| parent | f52050d53e698975d6598da86ddd99100ae70fdf (diff) | |
added any(), all(), one(). replaced not() with none()
Diffstat (limited to 'src')
| -rw-r--r-- | src/eval.c | 57 |
1 files changed, 51 insertions, 6 deletions
@@ -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; |
