From 4804893a6616a312ac8028e42d2aa990018ffbe6 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Wed, 12 Apr 2017 16:58:18 +0200 Subject: Modularize primitives implementation, add stack manipulators --- src/primitives/eval.d | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/primitives/eval.d (limited to 'src/primitives/eval.d') diff --git a/src/primitives/eval.d b/src/primitives/eval.d new file mode 100644 index 0000000..3f91e80 --- /dev/null +++ b/src/primitives/eval.d @@ -0,0 +1,48 @@ +module src.primitives.eval; + +import src.primitives.impl; + +bool evaluate(int value) { + return drop_mode; +} + +bool evaluate(string word) { + if ( drop_mode ) { + if ( word == "then" ) { + return conditional_end; + } else { + return true; + } + } + + switch ( word ) { + case "ยง": + return definition_start; + case "$": + return binary_op_variable_bind; + case "@": + return unary_op_variable_resolve; + case "if": + return conditional_start; + case "then": + return conditional_end; + case "+": + return binary_op_add; + case "*": + return binary_op_multiply; + case "/": + return binary_op_divide; + case "%": + return binary_op_modulo; + case ".": + return unary_op_io_print; + case "pop": + return unary_op_stack_pop; + case "dup": + return unary_op_stack_dup; + case "swp": + return binary_op_stack_swp; + default: + return false; + } +} -- cgit v1.2.3