X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=blobdiff_plain;f=src%2Flib.4th;h=4e732068323e3ab7c710e42c69b722be08101072;hb=366db53c2e77d243c744c11f68b8bdeb575c86e6;hp=c9df3d96729631cd2abf60ce1594e518f810c449;hpb=6162399a858a397add5ed60ba33f31a4d6dba4c2;p=forth.jl.git diff --git a/src/lib.4th b/src/lib.4th index c9df3d9..4e73206 100644 --- a/src/lib.4th +++ b/src/lib.4th @@ -1,6 +1,5 @@ : \ IMMEDIATE - KEY - 10 = 0BRANCH [ -5 , ] + #TIB @ >IN ! ; \ We can now comment! \ BASIC DEFINITIONS ---------------------------------------------------------------------- @@ -33,11 +32,9 @@ : LITERAL IMMEDIATE ['] LIT , , ; -: CHAR - BL WORD - DROP @ -; +: ' BL WORD FIND >CFA ; +: CHAR BL WORD 1+ @ ; : [CHAR] IMMEDIATE CHAR ['] LIT , , @@ -59,9 +56,6 @@ , \ compile it ; -: DEBUGON TRUE DEBUG ! ; -: DEBUGOFF FALSE DEBUG ! ; - \ CONTROL STRUCTURES ---------------------------------------------------------------------- : IF IMMEDIATE @@ -154,11 +148,16 @@ ; : +LOOP IMMEDIATE + + trace + ['] DUP , \ Store copy of increment ['] R> , ['] SWAP , ['] R> , ['] SWAP , ['] R> , ['] SWAP , ['] + , ['] 2DUP , ['] - , ['] SWAP , ['] >R , ['] SWAP , ['] >R , ['] SWAP , ['] >R , + trace + \ Condition differently depending on sign of increment ['] SWAP , ['] 0>= , [COMPILE] IF ['] 0<= , @@ -166,12 +165,16 @@ ['] 0> , [COMPILE] THEN + trace + \ Branch back to begining of loop kernel ['] 0BRANCH , HERE @ - , \ Clean up ['] RDROP , ['] RDROP , ['] RDROP , + trace + \ Record address of loop end for any LEAVEs to use HERE @ SWAP ! @@ -214,17 +217,18 @@ REPEAT ; +xx \ COMMENTS ---------------------------------------------------------------------- : ( IMMEDIATE 1 \ allowed nested parens by keeping track of depth BEGIN - >IN #TIB >= IF \ End of TIB? + >IN @ #TIB @ >= IF \ End of TIB? QUERY \ Get next line THEN - >IN @ 1 >IN +! + TIB >IN @ + @ 1 >IN +! DUP [CHAR] ( = IF \ open paren? DROP \ drop the open paren 1+ \ depth increases