diff options
Diffstat (limited to 'source/primitives')
-rw-r--r-- | source/primitives/core.d | 24 | ||||
-rw-r--r-- | source/primitives/eval.d | 26 |
2 files changed, 25 insertions, 25 deletions
diff --git a/source/primitives/core.d b/source/primitives/core.d index 07ed0c7..f2766d2 100644 --- a/source/primitives/core.d +++ b/source/primitives/core.d @@ -6,6 +6,28 @@ import base.stack; Token[string] variables; +bool handle(string word) { + switch ( word ) { + case "$" : binary_op_variable_bind; break; + case "@" : unary_op_variable_resolve; break; + case "+" : binary_op_add; break; + case "*" : binary_op_multiply; break; + case "/" : binary_op_divide; break; + case "%" : binary_op_modulo; break; + case "." : unary_op_io_print; break; + case "pop" : unary_op_stack_pop; break; + case "dup" : unary_op_stack_dup; break; + case "swp" : binary_op_stack_swp; break; + case "true" : nullary_op_value_bool(true); break; + case "false" : nullary_op_value_bool(false); break; + case "<" : binary_cond_lt; break; + case "=" : binary_cond_eq; break; + default : return false; + } + + return true; +} + void binary_op_variable_bind() { string name = stack.pop.get!string; Token value = stack.pop; @@ -91,6 +113,6 @@ void binary_cond_eq() { stack.push(a == b); } -void integral_value_bool(bool value) { +void nullary_op_value_bool(bool value) { stack.push(Token(value)); } diff --git a/source/primitives/eval.d b/source/primitives/eval.d index 2ae5373..fc5938e 100644 --- a/source/primitives/eval.d +++ b/source/primitives/eval.d @@ -3,33 +3,11 @@ module primitives.eval; import std.variant; import base.stack; -import primitives.core; +import core = primitives.core; import definition = base.definition; import conditional = primitives.conditional; -bool evaluate_primitive(string word) { - switch ( word ) { - case "$" : binary_op_variable_bind; break; - case "@" : unary_op_variable_resolve; break; - case "+" : binary_op_add; break; - case "*" : binary_op_multiply; break; - case "/" : binary_op_divide; break; - case "%" : binary_op_modulo; break; - case "." : unary_op_io_print; break; - case "pop" : unary_op_stack_pop; break; - case "dup" : unary_op_stack_dup; break; - case "swp" : binary_op_stack_swp; break; - case "true" : integral_value_bool(true); break; - case "false" : integral_value_bool(false); break; - case "<" : binary_cond_lt; break; - case "=" : binary_cond_eq; break; - default : return false; - } - - return true; -} - bool evaluate(Token token) { if ( definition.handle(token) ) { return true; @@ -42,7 +20,7 @@ bool evaluate(Token token) { return token.visit!( (int value) => false, (bool value) => false, - (string word ) => evaluate_primitive(word) + (string word ) => core.handle(word) ); } |