Adequate handling of EOF restored.
[forth.jl.git] / src / lib.4th
index c9df3d9..4e73206 100644 (file)
@@ -1,6 +1,5 @@
 : \ IMMEDIATE
-        KEY
-        10 = 0BRANCH [ -5 , ]
+        #TIB @ >IN !
 ; \ We can now comment!
 
 \ BASIC DEFINITIONS  ----------------------------------------------------------------------
 
 : 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
 ;
 
 : +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<= ,
             ['] 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 !
 
         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