aboutsummaryrefslogtreecommitdiff
path: root/src/primitives
diff options
context:
space:
mode:
authorAdrian Kummerlaender2017-04-12 21:55:26 +0200
committerAdrian Kummerlaender2017-04-12 21:55:26 +0200
commitd5ea77e49e30ad751678f90123f891344642a36c (patch)
tree947e183a950e9291263ddc2a84ad25f2e11652be /src/primitives
parent061db1f3810efac768dc7a83a8fbfaecfc512577 (diff)
downloadslang-d5ea77e49e30ad751678f90123f891344642a36c.tar
slang-d5ea77e49e30ad751678f90123f891344642a36c.tar.gz
slang-d5ea77e49e30ad751678f90123f891344642a36c.tar.bz2
slang-d5ea77e49e30ad751678f90123f891344642a36c.tar.lz
slang-d5ea77e49e30ad751678f90123f891344642a36c.tar.xz
slang-d5ea77e49e30ad751678f90123f891344642a36c.tar.zst
slang-d5ea77e49e30ad751678f90123f891344642a36c.zip
Introduce native boolean type
Diffstat (limited to 'src/primitives')
-rw-r--r--src/primitives/eval.d8
-rw-r--r--src/primitives/impl.d27
2 files changed, 20 insertions, 15 deletions
diff --git a/src/primitives/eval.d b/src/primitives/eval.d
index 533f491..d62fdb8 100644
--- a/src/primitives/eval.d
+++ b/src/primitives/eval.d
@@ -6,6 +6,10 @@ bool evaluate(int value) {
return drop_mode;
}
+bool evaluate(bool value) {
+ return drop_mode;
+}
+
bool evaluate(string word) {
if ( drop_mode ) {
switch ( word ) {
@@ -47,6 +51,10 @@ bool evaluate(string word) {
return unary_op_stack_dup;
case "swp":
return binary_op_stack_swp;
+ case "true":
+ return integral_value_bool(true);
+ case "false":
+ return integral_value_bool(false);
case "<":
return binary_cond_lt;
case "=":
diff --git a/src/primitives/impl.d b/src/primitives/impl.d
index cac3e64..dd257cc 100644
--- a/src/primitives/impl.d
+++ b/src/primitives/impl.d
@@ -5,8 +5,8 @@ import std.stdio;
import src.stack;
import src.definition;
-int[string] variables;
-bool drop_mode;
+Token[string] variables;
+bool drop_mode;
bool definition_start() {
src.definition.start;
@@ -15,7 +15,7 @@ bool definition_start() {
bool binary_op_variable_bind() {
string name = stack.pop.get!string;
- int value = stack.pop.get!int;
+ Token value = stack.pop;
variables[name] = value;
return true;
@@ -32,16 +32,8 @@ bool unary_op_variable_resolve() {
}
bool conditional_if() {
- switch ( stack.pop.get!int ) {
- case 0:
- drop_mode = true;
- return true;
- case 1:
- drop_mode = false;
- return true;
- default:
- throw new Exception("invalid logic value");
- }
+ drop_mode = !stack.pop.get!bool;
+ return true;
}
bool conditional_then() {
@@ -132,9 +124,14 @@ bool binary_cond_lt() {
}
bool binary_cond_eq() {
- int b = stack.pop.get!int;
- int a = stack.pop.get!int;
+ auto b = stack.pop;
+ auto a = stack.pop;
stack.push(a == b);
return true;
}
+
+bool integral_value_bool(bool value) {
+ stack.push(Token(value));
+ return true;
+}