diff --git a/emul/forth/xcomp.fs b/emul/forth/xcomp.fs index cb94468..aafd773 100644 --- a/emul/forth/xcomp.fs +++ b/emul/forth/xcomp.fs @@ -1,13 +1,3 @@ -: _ - ['] EXIT , - R> DROP ( exit : ) - XCOFF -; IMMEDIATE -';' CURRENT @ 4 - C! - -: (find) (xfind) ; -: ['] X['] ; IMMEDIATE -: COMPILE XCOMPILE ; IMMEDIATE : CODE XCODE ; : IMMEDIATE XIMM ; : : [ ' X: , ] ; diff --git a/forth/icore.fs b/forth/icore.fs index 7880a4d..efb1622 100644 --- a/forth/icore.fs +++ b/forth/icore.fs @@ -214,7 +214,7 @@ R> DROP ( exit : ) ; IMMEDIATE -';' XCURRENT @ 4 - C! +XCURRENT @ ( to PSP ) : : (entry) @@ -231,3 +231,5 @@ ELSE (parse*) @ EXECUTE LITN THEN AGAIN ; + +( from PSP ) ';' SWAP 4 - C! diff --git a/forth/xcomp.fs b/forth/xcomp.fs index 7b498b1..76cfc6f 100644 --- a/forth/xcomp.fs +++ b/forth/xcomp.fs @@ -1,7 +1,6 @@ -( Do dictionary cross compilation. +( Allow cross-compilation of z80c and icore. Include this file right before your cross compilation, then - set XCURRENT to CURRENT and XOFF to H@ - your target hook. - Example: H@ ' _bend - XOFF ! + set XCURRENT to CURRENT and XOFF to H@. This redefines defining words to achieve cross compilation. The goal is two-fold: @@ -9,11 +8,6 @@ 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. - 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 @@ -21,15 +15,8 @@ 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. + Why limit ourselves to icore? Oh, I've tried cross-compiling + the whole shebang. I tried. And failed. Too dynamic. ) VARIABLE XCURRENT @@ -44,60 +31,26 @@ 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: (xentry) ( 0e == compiledWord ) [ 0x0e LITN ] , BEGIN - ( DUP is because we need a copy in case it's IMMED ) - WORD DUP + WORD ( cross compile CURRENT ) XCURRENT @ SWAP ( w xcur w ) _find ( w a f ) IF ( is word ) - DUP IMMED? - IF ( w a ) - ( When encountering IMMEDIATE, we exec the *host* - word. ) - DROP ( w ) - ( system CURRENT ) - 0x02 RAM+ @ SWAP ( cur w ) - _find ( a f ) - NOT IF ABORT THEN ( a ) - XCON EXECUTE XCOFF - ELSE - ( not an immed. drop backup w and write, with - offset. ) - SWAP DROP ( a ) - XAPPLY - , - THEN - ELSE ( w a ) + ( 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. ) - DROP ( w ) ( system CURRENT ) 0x02 RAM+ @ SWAP ( cur w ) _find ( a f )