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