aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrian Kummerlaender2017-04-12 16:47:45 +0200
committerAdrian Kummerlaender2017-04-12 16:47:45 +0200
commit900c223ed40e36ffedce95e9a987d9a3c0309271 (patch)
tree36796ac25968a20a3d8b1d217392e59a25cc4f33 /src
parent45e4fe29a237ae5cda4147c803046ff5f6793770 (diff)
downloadslang-900c223ed40e36ffedce95e9a987d9a3c0309271.tar
slang-900c223ed40e36ffedce95e9a987d9a3c0309271.tar.gz
slang-900c223ed40e36ffedce95e9a987d9a3c0309271.tar.bz2
slang-900c223ed40e36ffedce95e9a987d9a3c0309271.tar.lz
slang-900c223ed40e36ffedce95e9a987d9a3c0309271.tar.xz
slang-900c223ed40e36ffedce95e9a987d9a3c0309271.tar.zst
slang-900c223ed40e36ffedce95e9a987d9a3c0309271.zip
Implementent conditional primitive
Diffstat (limited to 'src')
-rw-r--r--src/primitives.d27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/primitives.d b/src/primitives.d
index 0be6836..f577713 100644
--- a/src/primitives.d
+++ b/src/primitives.d
@@ -6,8 +6,21 @@ import src.stack;
import src.definition;
int[string] variables;
+bool drop_mode;
+
+bool evaluate(int value) {
+ return drop_mode;
+}
bool evaluate(string word) {
+ if ( drop_mode ) {
+ if ( word == "then" ) {
+ drop_mode = false;
+ }
+
+ return true;
+ }
+
switch ( word ) {
case "ยง":
src.definition.start;
@@ -25,6 +38,20 @@ bool evaluate(string word) {
stack.push(variables[name]);
}
return true;
+ case "if":
+ switch ( stack.pop.get!int ) {
+ case 0:
+ drop_mode = true;
+ return true;
+ case 1:
+ drop_mode = false;
+ return true;
+ default:
+ throw new Exception("invalid logic value");
+ }
+ case "then":
+ drop_mode = false;
+ return true;
case "+":
int b = stack.pop.get!int;
int a = stack.pop.get!int;