# Outer interpreter
TRACE = defPrimWord("TRACE", () -> begin
+ println("Val: $(popPS())")
print("RS: "); printRS()
print("PS: "); printPS()
print("[paused]")
DUP, FETCH, ZE, ZBRANCH, 3,
DROP, EXIT, # Exit if TIB is exhausted
- STATE_CFA, FETCH, ZBRANCH, 32,
+ STATE_CFA, FETCH, ZBRANCH, 31,
# Compiling
DUP, FIND, QDUP, ZBRANCH, 19,
COMMA, BRANCH, -36,
# No word found, parse number
- NUMBER, BTICK, LIT, COMMA, COMMA, TRACE, BRANCH, -44,
+ NUMBER, BTICK, LIT, COMMA, COMMA, BRANCH, -43,
# Interpreting
DUP, FIND, QDUP, ZBRANCH, 7,
# Found word. Execute!
- SWAP, DROP, TOCFA, EXECUTE, BRANCH, -55,
+ SWAP, DROP, TOCFA, EXECUTE, BRANCH, -54,
# No word found, parse number and leave on stack
- NUMBER, BRANCH, -58,
+ NUMBER, BRANCH, -57,
EXIT]
)
: \ IMMEDIATE
- KEY
- 10 = 0BRANCH [ -5 , ]
+ #TIB @ >IN !
; \ We can now comment!
\ BASIC DEFINITIONS ----------------------------------------------------------------------
: LITERAL IMMEDIATE ['] LIT , , ;
-: CHAR
- BL WORD
- DROP @
-;
+: CHAR BL WORD 1+ @ ;
: [CHAR] IMMEDIATE
CHAR
, \ compile it
;
-: DEBUGON TRUE DEBUG ! ;
-: DEBUGOFF FALSE DEBUG ! ;
-
\ CONTROL STRUCTURES ----------------------------------------------------------------------
: IF IMMEDIATE
: ( 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