diff options
author | Adrian Kummerlaender | 2017-04-15 18:56:35 +0200 |
---|---|---|
committer | Adrian Kummerlaender | 2017-04-15 18:56:35 +0200 |
commit | a654500cd3084cff93e4cf866a15e7977ff0cc94 (patch) | |
tree | 49042f24a7fbe4ac291360876286b251a8558588 /source/primitives | |
parent | 568e457d5f879633adc8a33d8c2979d563556868 (diff) | |
download | slang-a654500cd3084cff93e4cf866a15e7977ff0cc94.tar slang-a654500cd3084cff93e4cf866a15e7977ff0cc94.tar.gz slang-a654500cd3084cff93e4cf866a15e7977ff0cc94.tar.bz2 slang-a654500cd3084cff93e4cf866a15e7977ff0cc94.tar.lz slang-a654500cd3084cff93e4cf866a15e7977ff0cc94.tar.xz slang-a654500cd3084cff93e4cf866a15e7977ff0cc94.tar.zst slang-a654500cd3084cff93e4cf866a15e7977ff0cc94.zip |
Clearly separate handling of core, conditional and definition primitives
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) ); } |