From d5ea77e49e30ad751678f90123f891344642a36c Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Wed, 12 Apr 2017 21:55:26 +0200 Subject: Introduce native boolean type --- repl.d | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'repl.d') diff --git a/repl.d b/repl.d index e3aef2b..b68b46a 100644 --- a/repl.d +++ b/repl.d @@ -11,14 +11,17 @@ import src.stack; static import definition = src.definition; static import primitives = src.primitives.eval; -void process(int x) { - try { - if ( !primitives.evaluate(x) ) { - stack.push(x); +template process(T) +if ( is(T == int) || is(T == bool) ) { + void process(T value) { + try { + if ( !primitives.evaluate(value) ) { + stack.push(value); + } + } + catch (Exception ex) { + writeln("Error: ", ex.msg); } - } - catch (Exception ex) { - writeln("Error: ", ex.msg); } } @@ -41,8 +44,9 @@ void process(string word) { void process(Token token) { token.visit!( - (int x ) => process(x), - (string word) => process(word) + (int value) => process(value), + (bool value) => process(value), + (string word ) => process(word) ); } @@ -50,7 +54,7 @@ void main() { while ( !stdin.eof ) { foreach ( token; stdin.readln.split ) { if ( token.isNumeric ) { - immutable int value = parse!int(token); + auto value = parse!int(token); if ( !definition.handle(value) ) { process(value); -- cgit v1.2.3