From b1fa3024fd2fae76e6e0345861f3fa17b4a082ef Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sat, 15 Apr 2017 22:33:15 +0200 Subject: Hide module implementation details --- source/primitives/conditional.d | 62 ++++++++++++++++++++++------------------- source/primitives/core.d | 8 ++++-- 2 files changed, 39 insertions(+), 31 deletions(-) (limited to 'source/primitives') 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)); } + +} -- cgit v1.2.3