2020-03-27 08:23:45 -04:00
|
|
|
( Inner core. This unit represents core definitions that
|
|
|
|
happen right after native definitions. Before core.fs.
|
|
|
|
|
|
|
|
Unlike core.fs and its followers, this unit isn't self-
|
|
|
|
sustained. Like native defs it uses the machinery of a
|
|
|
|
full Forth interpreter, notably for flow structures.
|
|
|
|
|
|
|
|
Because of that, it has to obey specific rules:
|
|
|
|
|
|
|
|
1. It cannot compile a word from higher layers. Using
|
|
|
|
immediates is fine though.
|
|
|
|
2. If it references a word from this unit or from native
|
|
|
|
definitions, these need to be properly offsetted
|
|
|
|
because their offset at compile time are not the same
|
|
|
|
as their runtime offsets.
|
|
|
|
3. Anything they refer to in the boot binary has to be
|
|
|
|
properly stabilized.
|
|
|
|
4. Make sure that the words you compile are not overridden
|
|
|
|
by the full interpreter.
|
|
|
|
)
|
|
|
|
|
2020-03-27 09:32:03 -04:00
|
|
|
( When referencing words from native defs or this very unit,
|
|
|
|
use this compiling word, which subtract the proper offset
|
|
|
|
from the compiled word. That proper offset is:
|
|
|
|
1. Take ROT-header addr, the first native def.
|
|
|
|
2. Subtract _bend, boot's last word.
|
|
|
|
3. That will give us the offset to subtract to get the addr
|
|
|
|
of our word at runtime.
|
|
|
|
|
|
|
|
This means, of course, that any word compiling a _c word
|
|
|
|
can't be executed immediately.
|
2020-03-27 15:33:04 -04:00
|
|
|
|
|
|
|
Also note that because of that "_c" mechanism, it might
|
|
|
|
take two rounds of bootstrapping before the compiled
|
|
|
|
z80c.bin file is "stabilized". That's because the 2nd time
|
|
|
|
around, the recorded offset will have changed.
|
2020-03-27 09:32:03 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
: _c
|
2020-03-27 15:33:04 -04:00
|
|
|
[
|
|
|
|
' ROT
|
2020-03-27 09:32:03 -04:00
|
|
|
6 - ( header )
|
2020-03-27 15:33:04 -04:00
|
|
|
' _bend
|
2020-03-27 09:32:03 -04:00
|
|
|
- ( our offset )
|
2020-03-27 15:33:04 -04:00
|
|
|
LITN
|
|
|
|
]
|
2020-03-27 09:32:03 -04:00
|
|
|
' ( get word )
|
|
|
|
-^ ( apply offset )
|
|
|
|
, ( write! )
|
|
|
|
; IMMEDIATE
|
|
|
|
|
2020-03-28 10:11:52 -04:00
|
|
|
: ABORT _c (resSP) QUIT ;
|
|
|
|
|
2020-03-27 08:23:45 -04:00
|
|
|
: INTERPRET
|
|
|
|
BEGIN
|
|
|
|
WORD
|
|
|
|
(find)
|
|
|
|
IF
|
|
|
|
1 FLAGS !
|
|
|
|
EXECUTE
|
|
|
|
0 FLAGS !
|
|
|
|
ELSE
|
|
|
|
(parse*) @ EXECUTE
|
|
|
|
THEN
|
|
|
|
AGAIN
|
|
|
|
;
|
2020-03-27 11:27:40 -04:00
|
|
|
|
2020-03-28 09:08:46 -04:00
|
|
|
: BOOT
|
|
|
|
LIT< (c<$) (find) IF EXECUTE ELSE DROP THEN
|
|
|
|
_c INTERPRET
|
|
|
|
;
|
|
|
|
|
2020-03-27 11:49:50 -04:00
|
|
|
( This is only the "early parser" in earlier stages. No need
|
|
|
|
for an abort message )
|
|
|
|
: (parse)
|
2020-03-28 10:11:52 -04:00
|
|
|
(parsed) SKIP? _c ABORT
|
2020-03-27 11:49:50 -04:00
|
|
|
;
|
|
|
|
|
2020-03-27 12:36:10 -04:00
|
|
|
( a -- )
|
|
|
|
: (print)
|
|
|
|
BEGIN
|
|
|
|
DUP ( a a )
|
|
|
|
_c C@ ( a c )
|
|
|
|
( exit if null )
|
|
|
|
DUP NOT IF DROP DROP EXIT THEN
|
2020-03-28 10:25:02 -04:00
|
|
|
_c EMIT ( a )
|
2020-03-27 12:36:10 -04:00
|
|
|
1 + ( a+1 )
|
|
|
|
AGAIN
|
|
|
|
;
|
|
|
|
|
2020-03-28 09:19:40 -04:00
|
|
|
: (uflw)
|
2020-03-28 10:11:52 -04:00
|
|
|
LIT< stack-underflow _c (print) _c ABORT
|
2020-03-28 09:19:40 -04:00
|
|
|
;
|
|
|
|
|
2020-03-27 19:12:46 -04:00
|
|
|
: C,
|
|
|
|
HERE @ _c C!
|
|
|
|
HERE @ 1 + HERE !
|
|
|
|
;
|
|
|
|
|
2020-03-27 16:52:42 -04:00
|
|
|
: (entry)
|
|
|
|
HERE @ ( h )
|
|
|
|
WORD ( h s )
|
|
|
|
SCPY ( h )
|
|
|
|
( Adjust HERE -1 because SCPY copies the null )
|
|
|
|
HERE @ 1 _c - ( h h' )
|
|
|
|
DUP HERE ! ( h h' )
|
|
|
|
SWAP _c - ( sz )
|
|
|
|
( write prev value )
|
|
|
|
HERE @ CURRENT @ _c - ,
|
|
|
|
( write size )
|
2020-03-27 19:12:46 -04:00
|
|
|
_c C,
|
2020-03-27 16:52:42 -04:00
|
|
|
HERE @ CURRENT !
|
|
|
|
;
|
|
|
|
|
2020-03-27 16:16:57 -04:00
|
|
|
( : and ; have to be defined last because it can't be
|
|
|
|
executed now also, they can't have their real name
|
|
|
|
right away )
|
|
|
|
|
|
|
|
: X
|
2020-03-27 16:52:42 -04:00
|
|
|
_c (entry)
|
2020-03-27 19:52:45 -04:00
|
|
|
( JTBL+6 == compiledWord )
|
|
|
|
[ JTBL 6 + LITN ] ,
|
2020-03-27 16:16:57 -04:00
|
|
|
BEGIN
|
|
|
|
WORD
|
|
|
|
(find)
|
|
|
|
( is word )
|
2020-03-27 21:58:24 -04:00
|
|
|
IF DUP _c IMMED? IF EXECUTE ELSE , THEN
|
2020-03-27 16:16:57 -04:00
|
|
|
( maybe number )
|
|
|
|
ELSE (parse*) @ EXECUTE LITN THEN
|
|
|
|
AGAIN
|
|
|
|
; IMMEDIATE
|
|
|
|
|
|
|
|
: Y
|
2020-03-27 11:27:40 -04:00
|
|
|
['] EXIT ,
|
|
|
|
_c R> DROP ( exit : )
|
|
|
|
; IMMEDIATE
|
|
|
|
|
2020-03-27 16:16:57 -04:00
|
|
|
( Give ":" and ";" their real name )
|
|
|
|
':' ' X 4 - C!
|
|
|
|
';' ' Y 4 - C!
|
2020-03-27 11:27:40 -04:00
|
|
|
|