aboutsummaryrefslogtreecommitdiff
path: root/source/primitives
diff options
context:
space:
mode:
authorAdrian Kummerlaender2017-04-15 22:33:15 +0200
committerAdrian Kummerlaender2017-04-15 22:34:47 +0200
commitb1fa3024fd2fae76e6e0345861f3fa17b4a082ef (patch)
tree876a34b82c291c9b3b10219198a3d7f26b2b6686 /source/primitives
parenta654500cd3084cff93e4cf866a15e7977ff0cc94 (diff)
downloadslang-b1fa3024fd2fae76e6e0345861f3fa17b4a082ef.tar
slang-b1fa3024fd2fae76e6e0345861f3fa17b4a082ef.tar.gz
slang-b1fa3024fd2fae76e6e0345861f3fa17b4a082ef.tar.bz2
slang-b1fa3024fd2fae76e6e0345861f3fa17b4a082ef.tar.lz
slang-b1fa3024fd2fae76e6e0345861f3fa17b4a082ef.tar.xz
slang-b1fa3024fd2fae76e6e0345861f3fa17b4a082ef.tar.zst
slang-b1fa3024fd2fae76e6e0345861f3fa17b4a082ef.zip
Hide module implementation details
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));
}
+
+}