CORE words: Dictionary, Compiling and Defining


Dictionary

Name Stack Effect Summary Token
HERE  ( -- addr ) address of next free char in the dictionary xt = 0xB2
PALIGN  ( -- ) align dp with word boundary xt = 0x1A3
ALIGN  ( -- ) align dp with word boundary xt = 0xB4
PALIGNED  ( addr -- addr ) align tos with word boundary xt = 0x1A2
ALIGNED  ( addr -- addr ) align tos with word boundary xt = 0xB3
ALLOT  ( n -- ) allot n chars in dictionary xt = 0xB1
W,  ( x -- ) append 16-bit to dictionary xt = 0x45
( x -- ) append cell to dictionary xt = 0x46
C,  ( x -- ) append char to dictionary xt = 0x44
ORG  ( addr -- ) change dictionary pointer xt = 0x1AC
EMPTY  ( -- ) empty the user dictionary xt = 0x1DA
UNUSED  ( -- n ) number of unused data bytes xt = 0x1B0
ROM  ( -- ) set to compile to code space xt = 0x1AE
RAM  ( -- ) set to compile to data space xt = 0x1AD

Compiling

Name Stack Effect Summary Token
STATE  ( -- a ) T if compile, F if interpret xt = 0x1BA
[cell]
>BODY  ( xt -- pfa ) address of data field of an xt xt = 0xBF
Assumes that xt is a CREATEd item that starts with code for a literal, extracts the literal from the machine code. See ,LIT
EXIT  ( -- ) compile an exit xt = 0xFD
IMMEDIATE
(COMPILE)  ( xt -- ) compile call to xt's address xt = 0x1B1
LOOP  ( addr1 addr2 -- ) compile code for xt = 0xF1
IMMEDIATE
+LOOP  ( addr1 addr2 -- ) compile code for +LOOP xt = 0xF2
IMMEDIATE
?DO  ( -- addr1 addr2 ) compile code for ?DO xt = 0xF0
IMMEDIATE
AGAIN  ( addr -- ) compile code for AGAIN xt = 0xEC
IMMEDIATE
AHEAD  ( -- addr ) compile code for AHEAD xt = 0xE5
IMMEDIATE
BEGIN  ( -- addr ) compile code for BEGIN xt = 0xEA
IMMEDIATE
CASE  ( -- 0 ) compile code for CASE xt = 0xF3
IMMEDIATE
DO  ( -- addr1 addr2 ) compile code for DO xt = 0xEF
IMMEDIATE
ELSE  ( addr -- addr' ) compile code for ELSE xt = 0xE9
IMMEDIATE
ENDCASE  ( ... -- ) compile code for ENDCASE xt = 0xF6
IMMEDIATE
ENDIF  ( addr -- ) compile code for ENDIF xt = 0xE8
IMMEDIATE
ENDOF  ( a -- a' ) compile code for ENDOF xt = 0xF5
IMMEDIATE
IF  ( -- addr ) compile code for IF xt = 0xE6
IMMEDIATE
MULTI  ( -- addr1 addr2 ) compile code for MULTI xt = 0xBC
IMMEDIATE MULTI ... REPEAT is equivalent to BEGIN R@ 0< 0= WHILE R> 1- >R ... REPEAT
OF  ( ... -- ... a ) compile code for OF xt = 0xF4
IMMEDIATE
REPEAT  ( addr addr -- ) compile code for REPEAT xt = 0xEE
IMMEDIATE
THEN  ( addr -- ) compile code for THEN xt = 0xE7
IMMEDIATE
UNTIL  ( addr -- ) compile code for UNTIL xt = 0xEB
IMMEDIATE
WHILE  ( addr -- addr' ) compile code for WHILE xt = 0xED
IMMEDIATE
LITERAL  ( n -- ) compile code for a literal xt = 0xD7
IMMEDIATE
,LIT  ( n -- ) compile code for a literal xt = 0x1B2
POSTPONE  ( <xt> -- ) compile next token in stream xt = 0x1D4
IMMEDIATE
RECURSE  ( -- ) compile static call to this word xt = 0xE4
IMMEDIATE
RETRY  ( -- ) compile static jump to this word xt = 0x1C3
IMMEDIATE Wil Baden invented RETRY, which jumps back to the beginning of a word.
COMPILE,  ( xt -- ) compile xt into the definition xt = 0x1D3
Compiles a call into the binding table except when: 1. The word is inlineable (it's macro bit is set) 2. The XT is the same as that of the definition being built. To avoid accidental recursion, we bypass the binding table with a direct call.
[COMPILE]  ( <xt> -- ) compiles code to compile a word xt = 0x1D2
IMMEDIATE The created code compiles a call to xt at run time.
UNLOOP  ( -- ) discard loop parameters xt = 0x81
loop-sys: ... leave-addr limit I RA --> ...
LEAVE  ( -- ) discard loop parameters, leave xt = 0x82
loop-sys: ... leave-addr limit I RA --> ...
( -- ) enter compiling state xt = 0xD9
( -- ) enter interpretive state xt = 0xD8
IMMEDIATE
?EXIT  ( f -- ) exit definition if true xt = 0x83
( -- n|u ) innermost loop index xt = 0x84
( -- n|u ) next innermost loop index xt = 0x85
DOES>  ( -- ) patch last create, point to code xt = 0xBE
Also stop defining the definition
TO  ( n <xt> -- ) prefix store to a VALUE xt = 0x1CE
IMMEDIATE compile: ( <xt> -- ) *** STATE SMART ***
CALL-ONLY  ( -- ) set CALL-ONLY bit of header xt = 0x1CB
IMMEDIATE  ( -- ) set IMMEDIATE bit of header xt = 0x1CA
MACRO  ( -- ) set MACRO bit of header xt = 0x1CC

Defining

Name Stack Effect Summary Token
CONSTANT  ( x <xt> -- ) compile code for a constant xt = 0xDA
<xt> returns ( -- x )
VALUE  ( x <xt> -- ) compile code for a value xt = 0xE0
<xt> returns ( -- x )
STRING  ( x <xt> -- ) compile code for array of bytes xt = 0xDD
<xt> returns ( -- addr len )
ARRAY  ( x <xt> -- ) compile code for array of bytes xt = 0xDC
<xt> returns ( -- addr )
VARIABLE  ( <xt> -- ) compile code for cell variable xt = 0xDE
<xt> returns ( -- addr )
CREATE  ( <xt> -- ) compile code for data structure xt = 0xBD
Sets up to place (comma) data into data space
2CONSTANT  ( d <xt> -- ) compile code for double constant xt = 0xDB
<xt> returns ( -- d )
2VARIABLE  ( <xt> -- ) compile code for double variable xt = 0xDF
<xt> returns ( -- addr )
USER  ( n <xt> -- ) compile code for user variable xt = 0x1ED
run-time: ( -- addr )
[']  ( n -- ) compiles XT as a literal xt = 0xFB
IMMEDIATE
CODE  ( <c><xt><length16><data> -- ) create a header for raw code xt = 0xFE
creates a header with no code attached to it, if the CPU type matches
MARKER  ( <xt> -- ) create a marker that resets HERE xt = 0x1D1
Compile code to reset 'here to previous value
( -- ) end a colon definition xt = 0xE2
IMMEDIATE Also link this definition into the binding table.
( <xt> -- ) gets xt from the input stream xt = 0xFA
( <xt> -- ) start a colon definition xt = 0xE1
Object code for the definition is compiled into the dictionary. Semicolon binds this definition to the XT's table entry.
:NONAME  ( -- cfa ) start a headerless definition xt = 0xE3
** Warning **: This returns a static address, not an xt. Not ANS compilant: you must use EXECUTECFA to execute the cfa.