#lang planet zwizwa/staapl/pic18 \ -*- forth -*-
\ Stand-alone standard Forth compiler.
\ SEE vm-dtc.ss
\ The compiler is written in low-level 8-bit Forth instead of as a
\ self-hosted standard Forth application. This makes bootstrapping
\ more straightforward, as only the dictionary needs to be created.
\ The Forth is subroutine-threaded, to make interoperation with the
\ 8-bit Forth more straightforward.
\ Words are compiled first to RAM. For this a fixed size circular
\ buffer is reserved which uses the bottom bits of the "here" pointer,
\ which contains the FLASH address.
\ Code is subroutine threaded. As a first approximation, only
\ relative addressing is used. This allows for +- 2K byte jumps.
\ Later this should compile indirection jumps or 2-word instructions.
: _compile \ xt_lo xt_hi --
_here _@ _- _>> _1- \ relative word address
#x07 and \ clear opcode bits
#xD8 or \ add opcode bits
\ Literals use a dolit primitive to not make them too big.
xl @ fl !
xh @ fh !
fl @ xl !
fh @ xh !
' dolit address 1 <<< ,,