\ Flow control
+\ ... if/unless ... [else ...] then
+
: IF IMMEDIATE
['] 0BRANCH , \ compile 0BRANCH
HERE \ save location of the offset on the stack
0 , \ compile a dummy offset
;
+: UNLESS IMMEDIATE
+ ['] NOT , \ compile NOT (to reverse the test)
+ [COMPILE] IF \ continue by calling the normal IF
+;
+
: THEN IMMEDIATE
DUP
HERE SWAP - \ calculate the offset from the address saved on the stack
SWAP !
;
+
+\ begin ... while ... repeat, begin ... until, begin ... repeat
+
: BEGIN IMMEDIATE
HERE \ save location on the stack
;
SWAP ! \ and back-fill it in the original location
;
-: UNLESS IMMEDIATE
- ['] NOT , \ compile NOT (to reverse the test)
- [COMPILE] IF \ continue by calling the normal IF
-;
+
+\ [?]do ... [+]loop
: DO IMMEDIATE
['] LIT , -1 , [COMPILE] IF
: J RSP@ 6 - @ ;
+: K RSP@ 9 - @ ;
+
: ?LEAVE IMMEDIATE
['] 0BRANCH , 13 ,
['] R> , ['] RDROP , ['] RDROP ,
[COMPILE] ?LEAVE
;
+\ Clean up return stack
+: UNLOOP IMMEDIATE
+ ['] RDROP , ['] RDROP , ['] RDROP ,
+;
+
: +LOOP IMMEDIATE
['] DUP , \ Store copy of increment
;
-\ CASE ------------------------------------------------------------------------
+\ case [of ... endof]+ ... endcase
: CASE IMMEDIATE
0 \ push 0 to mark the bottom of the stack