X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?p=forth.jl.git;a=blobdiff_plain;f=src%2Flib_2_control.4th;h=beb232d837a859e4f6f2a0542785ade97941ae26;hp=464a9a4a6588886befd043477fd508be6826d7c6;hb=90a9b8ad41a542c3ca7d150d4d1168cb8ec97b81;hpb=56f581c25775f4244cd60d5943a5beb46a9ccafb diff --git a/src/lib_2_control.4th b/src/lib_2_control.4th index 464a9a4..beb232d 100644 --- a/src/lib_2_control.4th +++ b/src/lib_2_control.4th @@ -1,11 +1,18 @@ \ 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 @@ -22,6 +29,9 @@ SWAP ! ; + +\ begin ... while ... repeat, begin ... until, begin ... repeat + : BEGIN IMMEDIATE HERE \ save location on the stack ; @@ -53,10 +63,8 @@ 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 @@ -76,6 +84,8 @@ : J RSP@ 6 - @ ; +: K RSP@ 9 - @ ; + : ?LEAVE IMMEDIATE ['] 0BRANCH , 13 , ['] R> , ['] RDROP , ['] RDROP , @@ -123,7 +133,7 @@ ; -\ CASE ------------------------------------------------------------------------ +\ case [of ... endof]+ ... endcase : CASE IMMEDIATE 0 \ push 0 to mark the bottom of the stack