diff --git a/blk/070 b/blk/070 index 3575ad3..6904e1b 100644 --- a/blk/070 +++ b/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 diff --git a/blk/085 b/blk/085 index 5395e9b..b41ca34 100644 --- a/blk/085 +++ b/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.) diff --git a/blk/086 b/blk/086 index 745db83..d20b032 100644 --- a/blk/086 +++ b/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. + + + + diff --git a/blk/243 b/blk/243 index 24ddadd..6f1a1ce 100644 --- a/blk/243 +++ b/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, ; diff --git a/blk/263 b/blk/263 index 9f2c2a9..b3a73be 100644 --- a/blk/263 +++ b/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 ) diff --git a/blk/265 b/blk/265 index 0fc8380..cac8ccb 100644 --- a/blk/265 +++ b/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 ) diff --git a/blk/283 b/blk/283 index 3b12696..9a18688 100644 --- a/blk/283 +++ b/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 ) diff --git a/blk/284 b/blk/284 index 122eb60..de85525 100644 --- a/blk/284 +++ b/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, diff --git a/blk/285 b/blk/285 index 94a215b..5ba13bb 100644 --- a/blk/285 +++ b/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 ) diff --git a/blk/301 b/blk/301 index 65f6bf2..7a6b45c 100644 --- a/blk/301 +++ b/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 ) diff --git a/blk/302 b/blk/302 index 8fa1aa4..cb37c5b 100644 --- a/blk/302 +++ b/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, diff --git a/blk/303 b/blk/303 index 6d8ca26..6aecef4 100644 --- a/blk/303 +++ b/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 ) - diff --git a/blk/371 b/blk/371 index cac2325..a9e00f2 100644 --- a/blk/371 +++ b/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 ; diff --git a/blk/373 b/blk/373 index 227c662..1eb9891 100644 --- a/blk/373 +++ b/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. ) diff --git a/blk/397 b/blk/397 index 7bbb860..9773573 100644 --- a/blk/397 +++ b/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 diff --git a/emul/forth.bin b/emul/forth.bin index 84b00f8..4f59a8a 100644 Binary files a/emul/forth.bin and b/emul/forth.bin differ