collapseos/forth/xcomp.fs

68 lines
1.8 KiB
Forth
Raw Normal View History

( Allow cross-compilation of z80c and icore.
Include this file right before your cross compilation, then
set XCURRENT to CURRENT and XOFF to H@.
This redefines defining words to achieve cross compilation.
The goal is two-fold:
1. Add an offset to all word references in definitions.
2. Don't shadow important words we need right now.
Words overrides like ":", "IMMEDIATE" and "CODE" are not
automatically shadowed to allow the harmless inclusion of
this unit. This shadowing has to take place in your xcomp
configuration.
See example in /emul/forth/xcomp.fs
Why limit ourselves to icore? Oh, I've tried cross-compiling
the whole shebang. I tried. And failed. Too dynamic.
)
VARIABLE XCURRENT
VARIABLE XOFF
2020-04-09 12:01:08 -04:00
: XCON XCURRENT CURRENT* ! ;
: XCOFF 0x02 RAM+ CURRENT* ! ;
2020-04-09 12:01:08 -04:00
: (xentry) XCON (entry) XCOFF ;
2020-04-09 12:01:08 -04:00
: XCODE XCON CODE XCOFF ;
2020-04-09 12:01:08 -04:00
: XIMM XCON IMMEDIATE XCOFF ;
: X:
(xentry)
( 0e == compiledWord )
[ 0x0e LITN ] C,
BEGIN
WORD
( cross compile CURRENT )
XCURRENT @ SWAP ( w xcur w )
_find ( w a f )
2020-04-09 12:02:56 -04:00
IF
( is word )
( never supposed to encounter an IMMEDIATE in xdict )
DUP IMMED? IF ABORT THEN
( not an immed. drop backup w and write, with
offset. )
DUP XOFF @ > IF XOFF @ - THEN
,
ELSE ( w )
( not found? it might be an immediate that isn't yet defined in our
cross-compiled dict. It's alright, we can find-and-execute it. )
( system CURRENT )
0x02 RAM+ @ SWAP ( cur w )
_find ( a f )
IF
( found. It *must* be an IMMED )
DUP IMMED? NOT IF ABORT THEN
EXECUTE
ELSE
( not found. maybe number )
(parse*) @ EXECUTE LITN
THEN
THEN
AGAIN
2020-04-09 09:27:51 -04:00
;