From 4501313410e4fd23da55ca841291077f89966938 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Tue, 28 Apr 2020 08:28:59 -0400 Subject: [PATCH] Add [IF] .. [THEN] Will be useful as kinds of "#ifdef"s during xcomp. --- blk/042 | 8 ++++---- blk/043 | 11 +++++------ blk/044 | 5 +++++ blk/426 | 4 ++++ emul/stage0.bin | Bin 7335 -> 7441 bytes 5 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 blk/044 diff --git a/blk/042 b/blk/042 index 862ebf3..45b0351 100644 --- a/blk/042 +++ b/blk/042 @@ -7,10 +7,10 @@ context, branching doesn't work. f IF A ELSE B THEN: if f is true, execute A, if false, execute B. ELSE is optional. +[IF] .. [THEN]: Meta-IF. Works outside definitions. No [ELSE]. BEGIN .. f UNTIL: if f is false, branch to BEGIN. BEGIN .. AGAIN: Always branch to BEGIN. x y DO .. LOOP: LOOP increments y. if y != x, branch to DO. -x CASE y OF A ENDOF z OF B ENDOF C ENDCASE: If x == y, execute -A, if x == z, execute B. Otherwise, execute C. x is dropped -in case of an OF match, *but it is kept if it reaches C*. You -have to consume it to avoid PSP leak. (cont.) + + + (cont.) diff --git a/blk/043 b/blk/043 index 14cecc7..e4c6099 100644 --- a/blk/043 +++ b/blk/043 @@ -1,4 +1,8 @@ -(cont.) +x CASE y OF A ENDOF z OF B ENDOF C ENDCASE: If x == y, execute +A, if x == z, execute B. Otherwise, execute C. x is dropped +in case of an OF match, *but it is kept if it reaches C*. You +have to consume it to avoid PSP leak. + (br) -- Branches by the number specified in the 2 following bytes. Can be negative. (?br) f -- Branch if f is false. @@ -9,8 +13,3 @@ ABORT -- Resets PS and RS and returns to interpreter. ABORT" x" -- *I* Compiles a ." followed by a ABORT. EXECUTE a -- Execute wordref at addr a -INTERPRET -- Get a line from stdin, compile it in tmp memory, - then execute the compiled contents. -LEAVE -- In a DO..LOOP, exit at the next LOOP call. -QUIT -- Return to interpreter prompt immediately -EXIT! -- Exit current INTERPRET loop. diff --git a/blk/044 b/blk/044 new file mode 100644 index 0000000..1ff3ef1 --- /dev/null +++ b/blk/044 @@ -0,0 +1,5 @@ +INTERPRET -- Get a line from stdin, compile it in tmp memory, + then execute the compiled contents. +LEAVE -- In a DO..LOOP, exit at the next LOOP call. +QUIT -- Return to interpreter prompt immediately +EXIT! -- Exit current INTERPRET loop. diff --git a/blk/426 b/blk/426 index 5d02510..c80b968 100644 --- a/blk/426 +++ b/blk/426 @@ -6,3 +6,7 @@ H@ 2- ( push a. -2 for allot offset ) ; IMMEDIATE +: [IF] + IF EXIT THEN + LIT< [THEN] BEGIN DUP WORD S= UNTIL DROP ; +: [THEN] ; diff --git a/emul/stage0.bin b/emul/stage0.bin index 25a33ae5475a366a0a5c9b06f003f20c7ef8c1cd..c2c3b5d11448fce6d9cc10f672c24a428e6d01d2 100644 GIT binary patch delta 133 zcmXxaF%E(-7(n3zuy};mNfQ?!E*2dmwD^Zw8Z1FWIFuJKadI{BbZ*Mv_VV&Qw>SNI zB=snELM-MYk$5y7CvnF(=R|30@l<_aXuFE@p58}sR9zb=(0^CF@5yJ8Y6c00(lslx YG~bY7#kqMX_47*_b0y2^4yQGWFUxZxqyPW_ delta 29 lcmbPewcK*ULhjA4xxWbrs4IB8Mk*K@DFiwCYAYxz005+02?hWF