+\ Compiler Words
+\ -----------------------------------------------------------------------------
: immediate
latest @ \ Get the latest word
CELLSZ + \ Add offset to get to the flags field
dup @ \ Fetch the current value
F_IMMEDIATE | ! \ Set the immediate bit
-; immediate
+; \ immediate
-: [compile] immediate
- word find ,
-;
+\ : [compile] immediate
+\ word find ,
+\ ;
-: # [compile] \ ;
-: #! [compile] \ ;
+\ : recurse immediate
+\ latest @ ,
+\ ;
-: recurse immediate
- latest @ ,
-;
+\ Conditional Words: if, then, else
+\ -----------------------------------------------------------------------------
+\ : if immediate
+\ ' 0br , \ compile 0branch
+\ here @ \ save location of the offset on the stack
+\ 0 , \ compile a dummy offset
+\ ;
-: if immediate
- ' 0br , \ compile 0branch
- here @ \ save location of the offset on the stack
- 0 , \ compile a dummy offset
-;
+\ : then immediate
+\ dup
+\ here @ swap - \ calculate the offset from the address saved on the stack
+\ !
+\ ;
-: then immediate
- dup
- here @ swap - \ calculate the offset from the address saved on the stack
- !
-;
+\ : else immediate
+\ ' br , \ definite branch to just over the false-part
+\ here @ \ save location of the offset on the stack
+\ 0 , \ compile a dummy offset
+\ swap \ now back-fill the original (if) offset
+\ dup \ same as for then word above
+\ here @ swap - \ calculate the offset from the address saved on the stack
+\ !
+\ ;
-: else immediate
- ' br , \ definite branch to just over the false-part
- here @ \ save location of the offset on the stack
- 0 , \ compile a dummy offset
- swap \ now back-fill the original (if) offset
- dup \ same as for then word above
- here @ swap - \ calculate the offset from the address saved on the stack
- !
-;
+\ Looping Words
+\ -----------------------------------------------------------------------------
+\ : begin immediate here @ ;
-: begin immediate here @ ;
+\ : until immediate
+\ ' 0br , \ compile 0BRANCH
+\ here @ - \ calculate the offset from the address saved on the stack
+\ , \ compile the offset here
+\ ;
-: until immediate
- ' 0br , \ compile 0BRANCH
- here @ - \ calculate the offset from the address saved on the stack
- , \ compile the offset here
-;
+\ : again immediate
+\ ' br , \ compile branch
+\ here @ - \ calculate the offset back
+\ , \ compile the offset here
+\ ;
-: again immediate
- ' br , \ compile branch
- here @ - \ calculate the offset back
- , \ compile the offset here
-;
+\ : while immediate
+\ ' 0br , \ compile 0branch
+\ here @ \ save location of the offset2 on the stack
+\ 0 , \ compile a dummy offset2
+\ ;
-: while immediate
- ' 0br , \ compile 0branch
- here @ \ save location of the offset2 on the stack
- 0 , \ compile a dummy offset2
-;
+\ : repeat immediate
+\ ' br , \ compile branch
+\ swap \ get the original offset (from begin)
+\ here @ - , \ and compile it after branch
+\ dup
+\ here @ swap - \ calculate the offset2
+\ ! \ and back-fill it in the original location
+\ ;
-: repeat immediate
- ' br , \ compile branch
- swap \ get the original offset (from begin)
- here @ - , \ and compile it after branch
- dup
- here @ swap - \ calculate the offset2
- ! \ and back-fill it in the original location
-;
+\ : unless immediate
+\ ' not , \ compile not (to reverse the test)
+\ [compile] if \ continue by calling the normal if
+\ ;
+
+\ Comment Words
+\ -----------------------------------------------------------------------------
+\ : # [compile] \ ;
+\ : #! [compile] \ ;
+
+\ : ( immediate
+\ 1 \ allowed nested parens by keeping track of depth
+\ begin
+\ key \ read next character
+\ dup 0x28 = if \ open paren?
+\ drop \ drop the open paren
+\ 1 + \ depth increases
+\ else
+\ 0x29 = if \ close paren?
+\ 1 - \ depth decreases
+\ then
+\ then
+\ dup 0 = until \ continue until we reach matching close paren, depth 0
+\ drop \ drop the depth counter
+\ ;
-: unless immediate
- ' not , \ compile not (to reverse the test)
- [compile] if \ continue by calling the normal if
-;