瀏覽代碼

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...
pull/124/head
Virgil Dupras 4 年之前
父節點
當前提交
3d2dc041fb
共有 16 個文件被更改,包括 37 次插入49 次删除
  1. +1
    -1
      blk/070
  2. +10
    -11
      blk/085
  3. +6
    -6
      blk/086
  4. +1
    -3
      blk/243
  5. +1
    -1
      blk/263
  6. +1
    -1
      blk/265
  7. +4
    -6
      blk/283
  8. +1
    -1
      blk/284
  9. +1
    -1
      blk/285
  10. +6
    -8
      blk/301
  11. +1
    -3
      blk/302
  12. +1
    -2
      blk/303
  13. +1
    -1
      blk/371
  14. +1
    -2
      blk/373
  15. +1
    -2
      blk/397
  16. 二進制
      emul/forth.bin

+ 1
- 1
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




+ 10
- 11
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.)

+ 6
- 6
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.
addr to PSP, it executes its reference exactly like a
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.





+ 1
- 3
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, ;



+ 1
- 1
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 )


+ 1
- 1
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 )


+ 4
- 6
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 )

+ 1
- 1
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,


+ 1
- 1
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 )


+ 6
- 8
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 )

+ 1
- 3
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,


+ 1
- 2
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 )





+ 1
- 1
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 ;




+ 1
- 2
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. )


+ 1
- 2
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


二進制
emul/forth.bin 查看文件


Loading…
取消
儲存