diff options
-rw-r--r-- | src/primitives/eval.d | 17 | ||||
-rw-r--r-- | src/primitives/impl.d | 9 |
2 files changed, 18 insertions, 8 deletions
diff --git a/src/primitives/eval.d b/src/primitives/eval.d index 3f52e6d..533f491 100644 --- a/src/primitives/eval.d +++ b/src/primitives/eval.d @@ -8,10 +8,13 @@ bool evaluate(int value) { bool evaluate(string word) { if ( drop_mode ) { - if ( word == "then" ) { - return conditional_end; - } else { - return true; + switch ( word ) { + case "then": + return conditional_then; + case "else": + return conditional_else; + default: + return true; } } @@ -23,9 +26,11 @@ bool evaluate(string word) { case "@": return unary_op_variable_resolve; case "if": - return conditional_start; + return conditional_if; case "then": - return conditional_end; + return conditional_then; + case "else": + return conditional_else; case "+": return binary_op_add; case "*": diff --git a/src/primitives/impl.d b/src/primitives/impl.d index 56ea4ce..cac3e64 100644 --- a/src/primitives/impl.d +++ b/src/primitives/impl.d @@ -31,7 +31,7 @@ bool unary_op_variable_resolve() { return true; } -bool conditional_start() { +bool conditional_if() { switch ( stack.pop.get!int ) { case 0: drop_mode = true; @@ -44,7 +44,12 @@ bool conditional_start() { } } -bool conditional_end() { +bool conditional_then() { + drop_mode = !drop_mode; + return true; +} + +bool conditional_else() { drop_mode = false; return true; } |