aboutsummaryrefslogtreecommitdiff
path: root/source/primitives
diff options
context:
space:
mode:
authorAdrian Kummerlaender2017-04-17 14:44:26 +0200
committerAdrian Kummerlaender2017-04-17 14:44:26 +0200
commit6e115f5229dc2323804b8250138339a7f62bd852 (patch)
tree0ad6ebf50e6b1f5b0c2b57524a12476978b093d4 /source/primitives
parentf321905b1436e888c99b4863e3943f090cbadce1 (diff)
downloadslang-6e115f5229dc2323804b8250138339a7f62bd852.tar
slang-6e115f5229dc2323804b8250138339a7f62bd852.tar.gz
slang-6e115f5229dc2323804b8250138339a7f62bd852.tar.bz2
slang-6e115f5229dc2323804b8250138339a7f62bd852.tar.lz
slang-6e115f5229dc2323804b8250138339a7f62bd852.tar.xz
slang-6e115f5229dc2323804b8250138339a7f62bd852.tar.zst
slang-6e115f5229dc2323804b8250138339a7f62bd852.zip
Add logic negation operation; and, or conditions
Diffstat (limited to 'source/primitives')
-rw-r--r--source/primitives/core.d23
1 files changed, 23 insertions, 0 deletions
diff --git a/source/primitives/core.d b/source/primitives/core.d
index 971f495..a3a24f0 100644
--- a/source/primitives/core.d
+++ b/source/primitives/core.d
@@ -29,8 +29,11 @@ bool handle(string word) {
case "rot" : ternary_op_stack_rot; break;
case "true" : nullary_op_value_bool(true); break;
case "false" : nullary_op_value_bool(false); break;
+ case "!" : unary_op_negate; break;
case "<" : binary_cond_lt; break;
case "=" : binary_cond_eq; break;
+ case "&" : binary_cond_and; break;
+ case "or" : binary_cond_or; break;
case "#" : debug_print_stack; break;
default : return false;
}
@@ -117,6 +120,12 @@ void nullary_op_value_bool(bool value) {
stack.push(Token(value));
}
+void unary_op_negate() {
+ bool a = stack.pop.get!bool;
+
+ stack.push(Token(!a));
+}
+
void binary_cond_lt() {
int b = stack.pop.get!int;
int a = stack.pop.get!int;
@@ -131,6 +140,20 @@ void binary_cond_eq() {
stack.push(a == b);
}
+void binary_cond_and() {
+ bool b = stack.pop.get!bool;
+ bool a = stack.pop.get!bool;
+
+ stack.push(Token(a && b));
+}
+
+void binary_cond_or() {
+ bool b = stack.pop.get!bool;
+ bool a = stack.pop.get!bool;
+
+ stack.push(Token(a || b));
+}
+
void debug_print_stack() {
writeln(stack[]);
}