mirror of
https://github.com/hsoft/collapseos.git
synced 2024-12-25 04:58:05 +11:00
Make word routines into word types
Instead of having wordref point to core word routines, I made them into word 4 word types. It liberates space into the stable ABI and should make porting to other arches easier. I'm also thinking of combining word type with the namelen field for precious bytes saving, but not now...
This commit is contained in:
parent
3383a00040
commit
3d2dc041fb
2
blk/070
2
blk/070
@ -2,7 +2,7 @@ Implementation notes
|
||||
|
||||
71 Execution model 73 Executing a word
|
||||
75 Stack management 77 Dictionary
|
||||
80 System variables 85 Word routines
|
||||
80 System variables 85 Word types
|
||||
89 Initialization sequence
|
||||
|
||||
|
||||
|
21
blk/085
21
blk/085
@ -1,16 +1,15 @@
|
||||
Word routines
|
||||
Word types
|
||||
|
||||
This is the description of all word routine you can encounter
|
||||
in this Forth implementation. That is, a wordref will always
|
||||
point to a memory offset containing one of these numbers.
|
||||
There are 4 word types in Collapse OS. Whenever you have a
|
||||
wordref, it's pointing to a byte with numbers 0 to 3. This
|
||||
number is the word type and the word's behavior depends on it.
|
||||
|
||||
0x17: nativeWord. This words PFA contains native binary code
|
||||
and is jumped to directly.
|
||||
0: native. This words PFA contains native binary code and is
|
||||
jumped to directly.
|
||||
|
||||
0x0e: compiledWord. This word's PFA contains an atom list and
|
||||
its execution is described in "EXECUTION MODEL" above.
|
||||
1: compiled. This word's PFA contains an atom list and its
|
||||
execution is described in "EXECUTION MODEL" above.
|
||||
|
||||
0x0b: cellWord. This word is usually followed by a 2-byte value
|
||||
in its PFA. Upon execution, the *address* of the PFA is pushed
|
||||
to PS.
|
||||
2: cell. This word is usually followed by a 2-byte value in its
|
||||
PFA. Upon execution, the address of the PFA is pushed to PS.
|
||||
(cont.)
|
||||
|
14
blk/086
14
blk/086
@ -1,13 +1,13 @@
|
||||
0x2b: doesWord. This word is created by "DOES>" and is followed
|
||||
3: DOES>. This word is created by "DOES>" and is followed
|
||||
by a 2-byte value as well as the address where "DOES>" was
|
||||
compiled. At that address is an atom list exactly like in a
|
||||
compiled word. Upon execution, after having pushed its cell
|
||||
addr to PSP, it execute its reference exactly like a
|
||||
compiledWord.
|
||||
|
||||
Also note that word routines references in wordrefs are 1b.
|
||||
This means that all word routine reference must live below
|
||||
0x100 in boot binary.
|
||||
addr to PSP, it executes its reference exactly like a
|
||||
compiled word.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
4
blk/243
4
blk/243
@ -8,9 +8,7 @@
|
||||
: chkPS, L4 @ CALLnn, ; ( chkPS, B305 )
|
||||
|
||||
: CODE ( same as CREATE, but with native word )
|
||||
(entry)
|
||||
23 C, ( 23 == nativeWord )
|
||||
;
|
||||
(entry) 0 C, ( 0 == native ) ;
|
||||
: ;CODE JPNEXT, ;
|
||||
|
||||
|
||||
|
2
blk/263
2
blk/263
@ -2,7 +2,7 @@ VARIABLE XCURRENT
|
||||
: XCON XCURRENT CURRENT* ! ;
|
||||
: XCOFF 0x02 RAM+ CURRENT* ! ;
|
||||
: (xentry) XCON (entry) XCOFF ;
|
||||
: XCREATE (xentry) 11 C, ;
|
||||
: XCREATE (xentry) 2 C, ;
|
||||
: XCODE XCON CODE XCOFF ;
|
||||
: XIMM XCON IMMEDIATE XCOFF ;
|
||||
: _xapply ( a -- a-off )
|
||||
|
2
blk/265
2
blk/265
@ -1,5 +1,5 @@
|
||||
: X:
|
||||
(xentry) [ 0x0e LITN ] C,
|
||||
(xentry) 1 ( compiled ) C,
|
||||
BEGIN WORD
|
||||
XCURRENT @ SWAP ( xcur w ) _find ( a f )
|
||||
IF ( a )
|
||||
|
10
blk/283
10
blk/283
@ -1,16 +1,14 @@
|
||||
H@ ORG !
|
||||
0 JPnn, ( 00, main ) 0 JPnn, ( 03, find )
|
||||
NOP, NOP, ( 06, unused ) NOP, NOP, ( 08, LATEST )
|
||||
NOP, ( 0a, unused )
|
||||
( 0b cellWord, push PFA ) DE PUSHqq, JR, 0x0c A, ( next )
|
||||
0 JPnn, ( 0e, compiledWord ) 0 JPnn, ( 11, pushRS )
|
||||
0 JPnn, ( 14, popRS )
|
||||
EXDEHL, JP(HL), NOP, ( 17, nativeWord )
|
||||
NOP, NOP, NOP, NOP, NOP, NOP, NOP, ( 0a, unused )
|
||||
0 JPnn, ( 11, pushRS ) 0 JPnn, ( 14, popRS )
|
||||
NOP, NOP, NOP, ( 17, unused )
|
||||
0 JPnn, ( 1a, next ) 0 JPnn, ( unused )
|
||||
NOP, NOP, NOP, NOP, ( 20, unused )
|
||||
NOP, NOP, NOP, NOP, ( 24, unused )
|
||||
0 JPnn, ( RST 28 )
|
||||
0 JPnn, ( 2b, doesWord ) NOP, NOP, ( 2e, unused )
|
||||
NOP, NOP, NOP, NOP, NOP, ( 2b, unused )
|
||||
0 JPnn, ( RST 30 )
|
||||
0 JPnn, ( 33, execute ) NOP, NOP, ( unused )
|
||||
0 JPnn, ( RST 38 )
|
||||
|
2
blk/284
2
blk/284
@ -5,7 +5,7 @@
|
||||
0 A,, ( prev )
|
||||
4 A,
|
||||
H@ XCURRENT ! ( set current tip of dict, 0x42 )
|
||||
0x17 A, ( nativeWord )
|
||||
0 A, ( native )
|
||||
0x14 BCALL, ( popRS )
|
||||
HL PUSHqq, IY POPqq, ( --> IP )
|
||||
JPNEXT,
|
||||
|
2
blk/285
2
blk/285
@ -6,7 +6,7 @@ CODE (?br) ( 0x67 )
|
||||
( True, skip next 2 bytes and don't branch )
|
||||
IY INCss, IY INCss,
|
||||
JPNEXT, NOP, NOP, NOP,
|
||||
CODE (loop) ( 0x77 )
|
||||
CODE (loop) ( 0x80 )
|
||||
0 IX+ INC(IXY+), IFZ, 1 IX+ INC(IXY+), THEN, ( I++ )
|
||||
( Jump if I <> I' )
|
||||
A 0 IX+ LDrIXY, 2 IX- CP(IXY+), JRNZ, L2 BWR ( branch )
|
||||
|
14
blk/301
14
blk/301
@ -4,11 +4,9 @@ L3 BSET PC ORG @ 0x34 + ! ( execute. DE -> wordref )
|
||||
BIN( @ [IF]
|
||||
A XORr, D ORr, IFZ, D BIN( @ 256 / LDrn, THEN,
|
||||
[THEN]
|
||||
LDA(DE),
|
||||
L A LDrr,
|
||||
H BIN( @ 256 / LDrn,
|
||||
DE INCss,
|
||||
( DE points to PFA )
|
||||
JP(HL),
|
||||
|
||||
|
||||
LDA(DE), DE INCss,
|
||||
A ORr, IFZ, EXDEHL, JP(HL), THEN,
|
||||
A DECr, JRZ, L1 FWR ( compiled B303 )
|
||||
( cell or does. push PFA ) DE PUSHqq,
|
||||
A DECr, IFZ, JPNEXT, THEN, ( cell )
|
||||
( continue to does, B302 )
|
||||
|
4
blk/302
4
blk/302
@ -1,11 +1,9 @@
|
||||
PC ORG @ 0x2c + ! ( doesWord )
|
||||
( The word was spawned from a definition word that has a
|
||||
( does. The word was spawned from a definition word that has a
|
||||
DOES>. PFA+2 (right after the actual cell) is a link to the
|
||||
slot right after that DOES>. Therefore, what we need to do
|
||||
push the cell addr like a regular cell, then follow the
|
||||
linkfrom the PFA, and then continue as a regular
|
||||
compiledWord. )
|
||||
DE PUSHqq, ( like a regular cell )
|
||||
EXDEHL,
|
||||
HL INCss,
|
||||
HL INCss,
|
||||
|
3
blk/303
3
blk/303
@ -1,4 +1,4 @@
|
||||
PC ORG @ 0x0f + ! ( compiledWord )
|
||||
( compiled word ) L1 FSET ( execute B301 )
|
||||
( 1. Push current IP to RS
|
||||
2. Set new IP to the second atom of the list
|
||||
3. Execute the first atom of the list. )
|
||||
@ -13,4 +13,3 @@ PC ORG @ 0x0f + ! ( compiledWord )
|
||||
|
||||
|
||||
|
||||
|
||||
|
2
blk/371
2
blk/371
@ -6,7 +6,7 @@
|
||||
H@ CURRENT !
|
||||
;
|
||||
: (entry) WORD [entry] ;
|
||||
: CREATE (entry) 11 ( 11 == cellWord ) C, ;
|
||||
: CREATE (entry) 2 ( cellWord ) C, ;
|
||||
: VARIABLE CREATE 2 ALLOT ;
|
||||
|
||||
|
||||
|
3
blk/373
3
blk/373
@ -1,7 +1,6 @@
|
||||
: DOES>
|
||||
( Overwrite cellWord in CURRENT )
|
||||
( 43 == doesWord )
|
||||
43 CURRENT @ C!
|
||||
3 ( does ) CURRENT @ C!
|
||||
( When we have a DOES>, we forcefully place HERE to 4
|
||||
bytes after CURRENT. This allows a DOES word to use ","
|
||||
and "C," without messing everything up. )
|
||||
|
3
blk/397
3
blk/397
@ -7,8 +7,7 @@
|
||||
( gets its name at the very end. can't comment afterwards )
|
||||
: _ BEGIN LIT< ) WORD S= UNTIL ; IMMEDIATE
|
||||
: _ ( : will get its name almost at the very end )
|
||||
(entry)
|
||||
[ 14 ( == compiledWord ) LITN ] C,
|
||||
(entry) 1 ( compiled ) C,
|
||||
BEGIN
|
||||
WORD FIND
|
||||
IF ( is word ) DUP IMMED? IF EXECUTE ELSE , THEN
|
||||
|
BIN
emul/forth.bin
BIN
emul/forth.bin
Binary file not shown.
Loading…
Reference in New Issue
Block a user