From c926a70e7b692849e4904a8f99080c194029d471 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Tue, 22 Apr 2014 14:25:27 -0400 Subject: [PATCH] Working 'native' versions of if,else, and then --- source/slvm/main.c | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/source/slvm/main.c b/source/slvm/main.c index be2af88..a8ecb72 100644 --- a/source/slvm/main.c +++ b/source/slvm/main.c @@ -1,9 +1,6 @@ #include #include - #include -#include -#include #include #include #include @@ -219,16 +216,19 @@ defcode("lit", literal, 0, 0, &find_word){ } defcode("br", branch, 0, 0, &literal){ - CodePtr += *(CodePtr); - CodePtr++; + CodePtr = (long*)(((long)CodePtr) + *(CodePtr)); } defcode("0br", zbranch, 0, 0, &branch){ - if (!(*ArgStackPtr)) + if (*ArgStackPtr == 0) + { + CodePtr = (long*)(((long)CodePtr) + *(CodePtr)); + } + else { - CodePtr += *(CodePtr); CodePtr++; } + ArgStackPtr--; } /* Compiler Words @@ -598,22 +598,37 @@ defcode("then", _then, 0, 1, &_if){ EXEC(sub); // SWAP ! \ store the offset in the back-filled location EXEC(swap); - //EXEC(store); - printf("STACK: %ld %ld\n", *(ArgStackPtr-1), *(ArgStackPtr)); - //*((long*)*ArgStackPtr) = *(ArgStackPtr-1); - //ArgStackPtr -= 2; + *((long*)*ArgStackPtr) = *(ArgStackPtr-1); + ArgStackPtr -= 2; // ; } defcode("else", _else, 0, 1, &_then){ // : ELSE IMMEDIATE // ' BRANCH , \ definite branch to just over the false-part + ArgStackPtr++; + *(ArgStackPtr) = (long)&branch; + EXEC(comma); // HERE @ \ save location of the offset on the stack + ArgStackPtr++; + *(ArgStackPtr) = here_val; // 0 , \ compile a dummy offset + ArgStackPtr++; + *(ArgStackPtr) = 0; + EXEC(comma); // SWAP \ now back-fill the original (IF) offset + EXEC(swap); // DUP \ same as for THEN word above + EXEC(dup); // HERE @ SWAP - + ArgStackPtr++; + *(ArgStackPtr) = here_val; + EXEC(swap); + EXEC(sub); // SWAP ! + EXEC(swap); + *((long*)*ArgStackPtr) = *(ArgStackPtr-1); + ArgStackPtr -= 2; // ; } -- 2.55.0