: \ IMMEDIATE
- KEY
- 10 = 0BRANCH [ -5 , ]
+ #TIB @ >IN !
; \ We can now comment!
\ BASIC DEFINITIONS ----------------------------------------------------------------------
: LITERAL IMMEDIATE ['] LIT , , ;
-: CHAR
- WORD
- DROP @
-;
+: ' BL WORD FIND >CFA ;
+: CHAR BL WORD 1+ @ ;
: [CHAR] IMMEDIATE
CHAR
['] LIT , ,
: SPACE BL emit ;
: [COMPILE] IMMEDIATE
- WORD \ get the next word
+ BL WORD \ get the next word
FIND \ find it in the dictionary
>CFA \ get its codeword
, \ and compile that
, \ 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
- KEY \ read next character
+ >IN @ #TIB @ >= IF \ End of TIB?
+ QUERY \ Get next line
+ THEN
+
+ TIB >IN @ + @ 1 >IN +!
DUP [CHAR] ( = IF \ open paren?
DROP \ drop the open paren
1+ \ depth increases
( CONSTANTS AND VARIABLES ------------------------------------------------------ )
: CONSTANT
- WORD HEADER ( make dictionary entry (the name follows CONSTANT) )
+ BL WORD HEADER ( make dictionary entry (the name follows CONSTANT) )
DOCOL , ( append DOCOL (the codeword field of this word) )
['] LIT , ( append the codeword LIT )
, ( append the value on the top of the stack )
: VALUE ( n -- )
- WORD HEADER ( make the dictionary entry (the name follows VALUE) )
+ BL WORD HEADER ( make the dictionary entry (the name follows VALUE) )
DOCOL , ( append DOCOL )
['] LIT , ( append the codeword LIT )
, ( append the initial value )
;
: TO IMMEDIATE ( n -- )
- WORD ( get the name of the value )
+ BL WORD ( get the name of the value )
FIND ( look it up in the dictionary )
- >DFA ( get a pointer to the first data field (the 'LIT') )
+ >PFA ( get a pointer to the first data field (the 'LIT') )
1+ ( increment to point at the value )
STATE @ IF ( compiling? )
['] LIT , ( compile LIT )
( x +TO VAL adds x to VAL )
: +TO IMMEDIATE
- WORD ( get the name of the value )
+ BL WORD ( get the name of the value )
FIND ( look it up in the dictionary )
- >DFA ( get a pointer to the first data field (the 'LIT') )
+ >PFA ( get a pointer to the first data field (the 'LIT') )
1+ ( increment to point at the value )
STATE @ IF ( compiling? )
['] LIT , ( compile LIT )
( FORGET ---------------------------------------------------------------------- )
: FORGET
- WORD FIND ( find the word, gets the dictionary entry address )
+ BL WORD FIND ( find the word, gets the dictionary entry address )
DUP @ LATEST ! ( set LATEST to point to the previous word )
HERE ! ( and store HERE with the dictionary address )
;
;
: SEE
- WORD 2DUP FIND ( find the dictionary entry to decompile )
+ BL WORD 2DUP FIND ( find the dictionary entry to decompile )
?DUP 0= IF
." Word '" TYPE ." ' not found in dictionary."
4 SPACES
- >DFA ( get the data address, ie. points after DOCOL | end-of-word start-of-data )
+ >PFA ( get the data address, ie. points after DOCOL | end-of-word start-of-data )
( now we start decompiling until we hit the end of the word )
BEGIN ( end start )