2020-04-09 22:23:53 +10:00
|
|
|
( Do dictionary cross compilation.
|
|
|
|
Include this file right before your cross compilation, then
|
|
|
|
set XCURRENT to CURRENT and XOFF to H@ - your target hook.
|
|
|
|
Example: H@ ' _bend - XOFF !
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
New defining words establish a new XCURRENT, a copy of
|
|
|
|
CURRENT. From now on, CURRENT doesn't move. This means that
|
|
|
|
"'" and friends will *not* find words you're about to
|
|
|
|
define. Only (xfind) will.
|
|
|
|
|
2020-04-10 21:53:41 +10:00
|
|
|
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.
|
2020-04-09 23:43:48 +10:00
|
|
|
|
2020-04-09 22:23:53 +10:00
|
|
|
See example in /emul/forth/xcomp.fs
|
2020-04-10 21:53:41 +10:00
|
|
|
|
|
|
|
Note that this cross compilation unit is far from foolproof
|
|
|
|
and cannot cross compile any kind of code. Cross compliation
|
|
|
|
of Forth dicts is *tricky*. This unit is designed to cross
|
|
|
|
compile the core full interpreter, that is, the contents
|
|
|
|
of the "/forth" folder of the project.
|
|
|
|
|
|
|
|
Cross compiling anything else might work, but as soon as
|
|
|
|
you start defining immediates and using them on-the-fly,
|
|
|
|
things get icky.
|
2020-04-09 22:23:53 +10:00
|
|
|
)
|
|
|
|
|
|
|
|
VARIABLE XCURRENT
|
|
|
|
VARIABLE XOFF
|
|
|
|
|
2020-04-10 02:01:08 +10:00
|
|
|
: XCON XCURRENT CURRENT* ! ;
|
2020-04-10 21:53:41 +10:00
|
|
|
: XCOFF 0x02 RAM+ CURRENT* ! ;
|
2020-04-10 02:01:08 +10:00
|
|
|
|
|
|
|
: (xentry) XCON (entry) XCOFF ;
|
2020-04-09 22:23:53 +10:00
|
|
|
|
2020-04-10 02:01:08 +10:00
|
|
|
: XCODE XCON CODE XCOFF ;
|
2020-04-09 22:23:53 +10:00
|
|
|
|
2020-04-10 02:01:08 +10:00
|
|
|
: XIMM XCON IMMEDIATE XCOFF ;
|
2020-04-09 22:23:53 +10:00
|
|
|
|
2020-04-10 21:53:41 +10:00
|
|
|
: XAPPLY
|
|
|
|
DUP XOFF @ > IF XOFF @ - THEN
|
|
|
|
;
|
|
|
|
|
|
|
|
( Run find in XCURRENT and apply XOFF )
|
|
|
|
: (xfind)
|
|
|
|
XCURRENT @ SWAP ( xcur w )
|
|
|
|
_find ( a f )
|
|
|
|
IF ( a )
|
|
|
|
( apply XOFF )
|
|
|
|
XAPPLY 1
|
|
|
|
ELSE
|
|
|
|
0
|
|
|
|
THEN
|
|
|
|
;
|
|
|
|
|
|
|
|
: X' XCON ' XCOFF XAPPLY ;
|
|
|
|
: X['] X' LITN ;
|
|
|
|
( TODO: am I making the word "," stable here? )
|
|
|
|
: XCOMPILE X' LITN ['] , , ;
|
|
|
|
|
2020-04-09 23:43:48 +10:00
|
|
|
: X:
|
2020-04-10 21:53:41 +10:00
|
|
|
(xentry)
|
2020-04-09 22:23:53 +10:00
|
|
|
( 0e == compiledWord )
|
|
|
|
[ 0x0e LITN ] ,
|
|
|
|
BEGIN
|
2020-04-10 02:02:56 +10:00
|
|
|
( DUP is because we need a copy in case it's IMMED )
|
|
|
|
WORD DUP
|
2020-04-10 21:53:41 +10:00
|
|
|
( cross compile CURRENT )
|
|
|
|
XCURRENT @ SWAP ( w xcur w )
|
|
|
|
_find ( w a f )
|
2020-04-10 02:02:56 +10:00
|
|
|
IF
|
2020-04-09 22:23:53 +10:00
|
|
|
( is word )
|
|
|
|
DUP IMMED?
|
2020-04-10 02:02:56 +10:00
|
|
|
IF ( w a )
|
2020-04-09 22:23:53 +10:00
|
|
|
( When encountering IMMEDIATE, we exec the *host*
|
|
|
|
word. )
|
2020-04-10 02:02:56 +10:00
|
|
|
DROP ( w )
|
2020-04-10 21:53:41 +10:00
|
|
|
( system CURRENT )
|
2020-04-10 02:02:56 +10:00
|
|
|
0x02 RAM+ @ SWAP ( cur w )
|
|
|
|
_find ( a f )
|
2020-04-09 22:23:53 +10:00
|
|
|
NOT IF ABORT THEN ( a )
|
2020-04-10 21:53:41 +10:00
|
|
|
XCON EXECUTE XCOFF
|
2020-04-09 22:23:53 +10:00
|
|
|
ELSE
|
2020-04-10 02:02:56 +10:00
|
|
|
( not an immed. drop backup w and write, with
|
|
|
|
offset. )
|
|
|
|
SWAP DROP ( a )
|
2020-04-10 21:53:41 +10:00
|
|
|
XAPPLY
|
2020-04-10 02:02:56 +10:00
|
|
|
,
|
2020-04-09 22:23:53 +10:00
|
|
|
THEN
|
2020-04-10 02:02:56 +10:00
|
|
|
ELSE ( w a )
|
2020-04-10 23:55:58 +10:00
|
|
|
( 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. )
|
|
|
|
DROP ( w )
|
|
|
|
( 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
|
2020-04-09 22:23:53 +10:00
|
|
|
THEN
|
|
|
|
AGAIN
|
2020-04-09 23:27:51 +10:00
|
|
|
;
|