aboutsummaryrefslogtreecommitdiff
path: root/source/primitives
diff options
context:
space:
mode:
Diffstat (limited to 'source/primitives')
-rw-r--r--source/primitives/conditional.d62
-rw-r--r--source/primitives/core.d8
2 files changed, 39 insertions, 31 deletions
diff --git a/source/primitives/conditional.d b/source/primitives/conditional.d
index 38f0050..5dc0fa5 100644
--- a/source/primitives/conditional.d
+++ b/source/primitives/conditional.d
@@ -6,6 +6,39 @@ import std.container : DList;
import base.stack;
+bool handle(string word) {
+ switch ( word ) {
+ case "if" : unary_op_if; return true;
+ case "then" : n_ary_op_then; return true;
+ case "else" : n_ary_op_else; return true;
+ default : return capture(Token(word));
+ }
+}
+
+bool handle(Token token) {
+ return token.visit!(
+ (int ) => capture(token),
+ (bool ) => capture(token),
+ (string word) => handle(word)
+ );
+}
+
+bool dischargeable() {
+ return concluded && !buffer.isNull;
+}
+
+Stack!Token discharge() {
+ if ( concluded ) {
+ Stack!Token result = buffer[];
+ buffer.nullify;
+ return result;
+ } else {
+ throw new Exception("unconcluded conditional may not be discharged");
+ }
+}
+
+private {
+
Nullable!(DList!Token) buffer;
bool concluded = true;
bool drop_mode = false;
@@ -49,33 +82,4 @@ bool capture(Token token) {
}
}
-bool handle(string word) {
- switch ( word ) {
- case "if" : unary_op_if; return true;
- case "then" : n_ary_op_then; return true;
- case "else" : n_ary_op_else; return true;
- default : return capture(Token(word));
- }
-}
-
-bool handle(Token token) {
- return token.visit!(
- (int ) => capture(token),
- (bool ) => capture(token),
- (string word) => handle(word)
- );
-}
-
-bool dischargeable() {
- return concluded && !buffer.isNull;
-}
-
-Stack!Token discharge() {
- if ( concluded ) {
- Stack!Token result = buffer[];
- buffer.nullify;
- return result;
- } else {
- throw new Exception("unconcluded conditional may not be discharged");
- }
}
diff --git a/source/primitives/core.d b/source/primitives/core.d
index f2766d2..cae577b 100644
--- a/source/primitives/core.d
+++ b/source/primitives/core.d
@@ -4,8 +4,6 @@ import std.stdio;
import base.stack;
-Token[string] variables;
-
bool handle(string word) {
switch ( word ) {
case "$" : binary_op_variable_bind; break;
@@ -28,6 +26,10 @@ bool handle(string word) {
return true;
}
+private {
+
+Token[string] variables;
+
void binary_op_variable_bind() {
string name = stack.pop.get!string;
Token value = stack.pop;
@@ -116,3 +118,5 @@ void binary_cond_eq() {
void nullary_op_value_bool(bool value) {
stack.push(Token(value));
}
+
+}