X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=blobdiff_plain;f=src%2Flib.4th;h=ea4e7dea202350178b613bb5f70423de06fedf9f;hb=91c9ee133605d4d8871b897b109a60f401b3aa79;hp=1f97d20d7a2e415d6c559833d7e1398bbcad8739;hpb=efcae7affe8a5106424a7f0b67a1fd550e8cb320;p=forth.jl.git diff --git a/src/lib.4th b/src/lib.4th index 1f97d20..ea4e7de 100644 --- a/src/lib.4th +++ b/src/lib.4th @@ -1,6 +1,6 @@ : / /MOD SWAP DROP ; : MOD /MOD DROP ; -: */ * / ; +: */ -ROT * SWAP / ; : NEGATE 0 SWAP - ; @@ -116,7 +116,9 @@ : I RSP@ 3 - @ ; -: LEAVE? IMMEDIATE +: J RSP@ 6 - @ ; + +: ?LEAVE IMMEDIATE ' 0BRANCH , 13 , ' R> , ' RDROP , ' RDROP , ' LIT , HERE @ 7 + , ' DUP , ' -ROT , ' - , ' SWAP , ' ! , @@ -126,10 +128,10 @@ : LEAVE IMMEDIATE ' LIT , -1 , - [COMPILE] LEAVE? + [COMPILE] ?LEAVE ; -: LOOP+ IMMEDIATE +: +LOOP IMMEDIATE ' R> , ' SWAP , ' R> , ' SWAP , ' R> , ' SWAP , ' + , ' 2DUP , ' - , ' SWAP , ' >R , ' SWAP , ' >R , ' SWAP , ' >R , ' 0<= , ' 0BRANCH , @@ -140,7 +142,7 @@ : LOOP IMMEDIATE ' LIT , 1 , - [COMPILE] LOOP+ + [COMPILE] +LOOP ; \ COMMENTS ---------------------------------------------------------------------- @@ -170,10 +172,6 @@ @ ( and fetch ) ; -: ROLL ( x_u x_u-1... x_0 u -- x_u-1 ... x_0 x_u ) - 1+ DUP PICK SWAP ( x_u x_u-1 ... x_0 x_u u+1 ) -; - ( With the looping constructs, we can now write SPACES, which writes n spaces to stdout. ) : SPACES ( n -- ) 0 DO @@ -316,3 +314,13 @@ THEN ; +: ROLL ( x_u x_u-1... x_0 u -- x_u-1 ... x_0 x_u ) + 1+ DUP PICK SWAP ( x_u x_u-1 ... x_0 x_u u+1 ) + PSP@ 1- SWAP - PSP@ 2- SWAP + DO + i 1+ @ i ! + LOOP + SWAP DROP +; + +include ../examples/mandelbrot.4th