1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-27 14:08:05 +11:00

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 ; : CODE XCODE ;
: IMMEDIATE XIMM ; : IMMEDIATE XIMM ;
: : [ ' X: , ] ; : : [ ' X: , ] ;
CURRENT @ XCURRENT ! CURRENT @ XCURRENT !
H@ ' _bend - 4 + XOFF !
( dummy entry for dict hook ) ( dummy entry for dict hook )
(xentry) _ (xentry) _
H@ 256 /MOD 2 PC! 2 PC! 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 "'" and friends will *not* find words you're about to
define. Only (xfind) will. define. Only (xfind) will.
Words ":", "IMMEDIATE" and "CODE" are not automatically Words overrides like ":", "IMMEDIATE" and "CODE" are not
shadowed to allow the harmless inclusion of this unit. This automatically shadowed to allow the harmless inclusion of
shadowing has to take place in your xcomp configuration. this unit. This shadowing has to take place in your xcomp
configuration.
See example in /emul/forth/xcomp.fs 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 XCURRENT
VARIABLE XOFF VARIABLE XOFF
: XCON XCURRENT CURRENT* ! ; : XCON XCURRENT CURRENT* ! ;
: XCOFF CURRENT CURRENT* ! ; : XCOFF 0x02 RAM+ CURRENT* ! ;
: (xentry) XCON (entry) XCOFF ; : (xentry) XCON (entry) XCOFF ;
@ -33,15 +44,37 @@ VARIABLE XOFF
: XIMM XCON IMMEDIATE XCOFF ; : 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: : X:
XCON (xentry)
(entry)
( 0e == compiledWord ) ( 0e == compiledWord )
[ 0x0e LITN ] , [ 0x0e LITN ] ,
BEGIN BEGIN
( DUP is because we need a copy in case it's IMMED ) ( DUP is because we need a copy in case it's IMMED )
WORD DUP WORD DUP
(find) ( w a f ) ( cross compile CURRENT )
XCURRENT @ SWAP ( w xcur w )
_find ( w a f )
IF IF
( is word ) ( is word )
DUP IMMED? DUP IMMED?
@ -49,16 +82,16 @@ VARIABLE XOFF
( When encountering IMMEDIATE, we exec the *host* ( When encountering IMMEDIATE, we exec the *host*
word. ) word. )
DROP ( w ) DROP ( w )
( hardcoded system CURRENT ) ( system CURRENT )
0x02 RAM+ @ SWAP ( cur w ) 0x02 RAM+ @ SWAP ( cur w )
_find ( a f ) _find ( a f )
NOT IF ABORT THEN ( a ) NOT IF ABORT THEN ( a )
EXECUTE XCON EXECUTE XCOFF
ELSE ELSE
( not an immed. drop backup w and write, with ( not an immed. drop backup w and write, with
offset. ) offset. )
SWAP DROP ( a ) SWAP DROP ( a )
DUP 0x100 > IF XOFF @ - THEN XAPPLY
, ,
THEN THEN
ELSE ( w a ) ELSE ( w a )
@ -67,5 +100,4 @@ VARIABLE XOFF
(parse*) @ EXECUTE LITN (parse*) @ EXECUTE LITN
THEN THEN
AGAIN AGAIN
XCOFF
; ;