#lang planet zwizwa/staapl/pic18 \ -*- forth -*-
provide-all
\ Macros implementing the control words. For a self-hosted
\ interpreter these need to be replaced by immediate words.
staapl pic18/double-math
staapl pic18/double-pred
staapl pic18/execute
staapl pic18/vm-core
macro
\ note: XT need to be word addresses, since i have only 14 bit
\ literals. return stack still contains byte addresses though, so for
\ now it's kept abstract.
\ create a jump label symbol and duplicate it (for to and from)
: 2sym>m sym >m m-dup
\ jumps are implemented as literal + primitive (instead of reading
\ from instruction stream)
: m>jmp m> literal ' _run compile _exit : m>0=jmp m> literal ' _0=run
: _begin 2sym>m m> label: : _again m>jmp : _until m>0=jmp _space
: _if 2sym>m m>0=jmp : _else 2sym>m m>jmp m-swap m> label: : _then m> label: _space
: _space ' _nop compile
\ : _for _2sym>m m> label ' do-for compile \ : _next _m>literal ' do-next compile _space
: _for
' _>r compile
_begin : _next
' do-next compile m>0=jmp
' _rdrop compile
_space