summaryrefslogtreecommitdiff
path: root/src/eval.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/eval.c')
-rw-r--r--src/eval.c57
1 files changed, 51 insertions, 6 deletions
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;