From fe08adffcf1446dce2a7d366f7f12c90fdce7e58 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sun, 16 Apr 2017 13:29:23 +0200 Subject: Clean up state, primitives, processing distinction --- source/primitives/core.d | 13 +++++++++++-- source/primitives/eval.d | 39 --------------------------------------- 2 files changed, 11 insertions(+), 41 deletions(-) delete mode 100644 source/primitives/eval.d (limited to 'source/primitives') diff --git a/source/primitives/core.d b/source/primitives/core.d index 75783ed..ab0b85c 100644 --- a/source/primitives/core.d +++ b/source/primitives/core.d @@ -1,9 +1,20 @@ module primitives.core; import std.stdio; +import std.variant; import state.stack; +bool handle(Token token) { + return token.visit!( + (int ) => false, + (bool ) => false, + (string word) => handle(word) + ); +} + +private { + bool handle(string word) { switch ( word ) { case "+" : binary_op_add; break; @@ -24,8 +35,6 @@ bool handle(string word) { return true; } -private { - void binary_op_add() { int b = stack.pop.get!int; int a = stack.pop.get!int; diff --git a/source/primitives/eval.d b/source/primitives/eval.d deleted file mode 100644 index a18e897..0000000 --- a/source/primitives/eval.d +++ /dev/null @@ -1,39 +0,0 @@ -module primitives.eval; - -import std.variant; - -import state.stack; - -import definition = state.definition; -import variable = state.variable; - -import core = primitives.core; -import conditional = primitives.conditional; - -bool evaluate(Token token) { - if ( definition.handle(token) ) { - return true; - } - - if ( conditional.handle(token) ) { - return true; - } - - if ( variable.handle(token) ) { - return true; - } - - return token.visit!( - (int value) => false, - (bool value) => false, - (string word ) => core.handle(word) - ); -} - -Stack!Token result() { - if ( conditional.dischargeable ) { - return conditional.discharge; - } else { - return Stack!Token(); - } -} -- cgit v1.2.3