\ Stand-alone self-hosted compiler for a subroutine threaded Forth \ that can operate well with the 8-bit PIC18 Forth. This is written \ in a subset of standard Forth so it works on a 16-bit VM. variable here variable last 16 base ! \ Words used for compilation: \ variable base ! : ; @ dup >r r> 2/ - and or postpone \ \ Machine code kernel primitives: \ dolit : cell 4 ; : , here @ dup >r ! r> 1 cell + ; \ PIC18 specific compile and literal. : compile \ XT -- here @ - 2/ 1 - \ relative word offset 07FF and D800 or , ; \ relative branch instruction. : literal \ n -- postpone dolit , ; : postpone \ -- parse find compile ; \ For the subroutine threaded forth, execution tokens (XT) point to \ executable machine code. The compilation semantics points to the XT \ of the word's compiler. A dictionary entry looks like this: \ LINK pointer to next record \ XT pointer to executable code of interpret semantics \ CT compile \ NAME padded pascal string \ The dictionary does not contain in-line machine code - only a \ reference. This allows the entire dictionary to be wiped or \ implemented off-target without disturbing machine code. : rec>link @ ; : rec>xt 1 cell + @ ; : rec>ct 2 cell + @ ; : rec>name 3 cell + ; \ Compare two strings. : string= \ s \ Lookup in the dictionary to find the execution token. : find \ string -- xt ; : xt>ct \ xt -- ct