xcomp: widen scope

We can now cross-compile core.fs.
This commit is contained in:
Virgil Dupras 2020-04-10 07:53:41 -04:00
parent 54929c2aa0
commit c8c337fd58
2 changed files with 54 additions and 13 deletions

View File

@ -1,11 +1,20 @@
: _
['] EXIT ,
R> DROP ( exit : )
XCOFF
; IMMEDIATE
';' CURRENT @ 4 - C!
: (find) (xfind) ;
: ['] X['] ; IMMEDIATE
: COMPILE XCOMPILE ; IMMEDIATE
: CODE XCODE ;
: IMMEDIATE XIMM ;
: : [ ' X: , ] ;
CURRENT @ XCURRENT !
H@ ' _bend - 4 + XOFF !
( dummy entry for dict hook )
(xentry) _
H@ 256 /MOD 2 PC! 2 PC!
H@ ' _bend - XOFF !

View File

@ -14,18 +14,29 @@
"'" and friends will *not* find words you're about to
define. Only (xfind) will.
Words ":", "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.
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
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.
)
VARIABLE XCURRENT
VARIABLE XOFF
: XCON XCURRENT CURRENT* ! ;
: XCOFF CURRENT CURRENT* ! ;
: XCOFF 0x02 RAM+ CURRENT* ! ;
: (xentry) XCON (entry) XCOFF ;
@ -33,15 +44,37 @@ VARIABLE XOFF
: XIMM XCON IMMEDIATE XCOFF ;
: 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 ['] , , ;
: X:
XCON
(entry)
(xentry)
( 0e == compiledWord )
[ 0x0e LITN ] ,
BEGIN
( DUP is because we need a copy in case it's IMMED )
WORD DUP
(find) ( w a f )
( cross compile CURRENT )
XCURRENT @ SWAP ( w xcur w )
_find ( w a f )
IF
( is word )
DUP IMMED?
@ -49,16 +82,16 @@ VARIABLE XOFF
( When encountering IMMEDIATE, we exec the *host*
word. )
DROP ( w )
( hardcoded system CURRENT )
( system CURRENT )
0x02 RAM+ @ SWAP ( cur w )
_find ( a f )
NOT IF ABORT THEN ( a )
EXECUTE
XCON EXECUTE XCOFF
ELSE
( not an immed. drop backup w and write, with
offset. )
SWAP DROP ( a )
DUP 0x100 > IF XOFF @ - THEN
XAPPLY
,
THEN
ELSE ( w a )
@ -67,5 +100,4 @@ VARIABLE XOFF
(parse*) @ EXECUTE LITN
THEN
AGAIN
XCOFF
;