From d8de8a058a9abef42b3fb2872821980e841cfe6a Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Wed, 15 Apr 2020 15:15:31 -0400 Subject: [PATCH] Make word routine refs 1b instead of 2 Saves quite a bit of binary space. More than 300 bytes in forth1.bin --- blk/077 | 2 +- blk/078 | 4 +++- emul/forth/z80c.bin | Bin 2239 -> 2170 bytes forth/boot.fs | 3 +-- forth/core.fs | 6 +++--- forth/icore.fs | 2 +- forth/link.fs | 4 ++-- forth/xcomp.fs | 2 +- forth/z80a.fs | 2 +- 9 files changed, 13 insertions(+), 12 deletions(-) diff --git a/blk/077 b/blk/077 index 37a2eb3..17e7a12 100644 --- a/blk/077 +++ b/blk/077 @@ -6,7 +6,7 @@ A dictionary entry has this structure: bigger than input buffer, of course). not null-terminated - 2b prev offset - 1b size + IMMEDIATE flag -- 2b code pointer +- 1b code pointer (always jumps in the <0x100 range) - Parameter field (PF) The prev offset is the number of bytes between the prev field diff --git a/blk/078 b/blk/078 index f7dcc86..5b0f02c 100644 --- a/blk/078 +++ b/blk/078 @@ -1,7 +1,9 @@ (cont.) The code pointer point to "word routines". These routines expect to be called with IY pointing to the PF. They themselves are expected to end by jumping to the address at -(IP). They will usually do so with "jp next". +(IP). They will usually do so with "jp next". They are 1b +because all those routines live in the first 0x100 bytes of +the boot binary. The 0 MSB is assumed. That's for "regular" words (words that are part of the dict chain). There are also "special words", for example NUMBER, diff --git a/emul/forth/z80c.bin b/emul/forth/z80c.bin index 19c0d5793e5f6ffb23fc564c59d920cd07f7b540..2ca9802e6fec60c4f7eeca6937f6091f9fe87e74 100644 GIT binary patch literal 2170 zcmYjSUu;u#6h6Ou+q>>x_YW9bA-P?b*{*kG8 z_&{P}VoZGBgAwIHL)ak17m}^%!$Ov@NN1vHVrMRvkZTAr(WrHP=XY16OV)e7bIy0p z`Odj%`fExrlKiAU5$P$Bt`O;sqWFN)agpv4m+5o540n34kp4_K-=oeqMMwIRM6O0! z+CVK@A>GV0!IP7rdIsCI!fS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& l0$)RS882W+b7tR!>)z@qRdFG71lQrJK=o5Y(`E9#21X6w48rPXb% z8*?87zl_257i{bWWFj)F?8~5BiUcWGx-eM{7{-+=a)VQS!Njhv+c#$HShu<>88r+3 z)<>WI9H{sE`~1Hu(e(TMg(uiqY4#^ow)H2az^~W4O7r<*7=JH7@jS~H zb5P8(Vzd~|s~58GeHejYfY~P{t6Ix!11pL@x9zFYy_P?UX2}arZ`=C4mfvu=#Tdpa z*2uWeXQ#Ocg)$9Y&cQY)hs)u|IN_of%4UfRfOt8}Oq`)?;`n8=oRi8~*({d~H)xBAF2|QhahV2oPXlB8mEdRXH}1 zy|a<*C6XKWK}cH@M@TMA>+wYH`tGjlaMX4%Uw7acMYInjViV_b0T52VAI-2(`5HHavLLZ+kk4Nw4jH^o2L%# zF^=>$aRh;FV826A{k&&!h1}lmCZ1yMzhbsRz+paSG52pV%WtMf=K(~DhlK%p4+rqY zr0@eL;tf>e1AJDe&P}INkw(CSvM&O?wFK$uh=(A0!w^b$*Hc9g`rO&TwS*zvcT(^iTb3-Gg`O=o`EF>~cs@`{AlP19dT{xrGm2m}!8W@Pj_VX*JNtUG%B)xVSfb w@R=L7;I)n`4`kB!b$%N&HMELxMJTWl_b}{Qt>i#_2+vc@f7m4y7~Tu)f6h5_G5`Po diff --git a/forth/boot.fs b/forth/boot.fs index 3081cd8..03c630e 100644 --- a/forth/boot.fs +++ b/forth/boot.fs @@ -315,7 +315,6 @@ PC ORG @ 0x34 + ! ( execute ) H 0 LDrn, ( HL points to code pointer ) IY INCss, - IY INCss, ( IY points to PFA ) JP(HL), @@ -338,7 +337,7 @@ PC ORG @ 0x0f + ! ( compiledWord ) 0x33 JPnn, ( 33 == execute ) PC ORG @ 0x0c + ! ( cellWord ) -( Pushes the PFA directly ) +( Pushes PFA directly ) IY PUSHqq, JPNEXT, diff --git a/forth/core.fs b/forth/core.fs index 174a460..b8cdab3 100644 --- a/forth/core.fs +++ b/forth/core.fs @@ -58,7 +58,7 @@ : CREATE (entry) ( empty header with name ) 11 ( 11 == cellWord ) - , ( write it ) + C, ( write it ) ; ( We run this when we're in an entry creation context. Many @@ -71,11 +71,11 @@ : DOES> ( Overwrite cellWord in CURRENT ) ( 43 == doesWord ) - 43 CURRENT @ ! + 43 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. ) - CURRENT @ 4 + HERE ! + CURRENT @ 3 + HERE ! ( HERE points to where we should write R> ) R> , ( We're done. Because we've popped RS, we'll exit parent diff --git a/forth/icore.fs b/forth/icore.fs index 3f78412..1f8757f 100644 --- a/forth/icore.fs +++ b/forth/icore.fs @@ -237,7 +237,7 @@ XCURRENT @ ( to PSP ) ( We cannot use LITN as IMMEDIATE because of bootstrapping issues. Same thing for ",". 32 == NUMBER 14 == compiledWord ) - [ 32 H@ ! 2 ALLOT 14 H@ ! 2 ALLOT ] , + [ 32 H@ ! 2 ALLOT 14 H@ ! 2 ALLOT ] C, BEGIN WORD (find) diff --git a/forth/link.fs b/forth/link.fs index 6188626..f869fb3 100644 --- a/forth/link.fs +++ b/forth/link.fs @@ -82,7 +82,7 @@ ) ( ol o a1 a2 -- ) : RLWORD - SWAP DUP @ ( ol o a2 a1 n ) + SWAP DUP C@ ( ol o a2 a1 n ) ( 0e == compiledWord, 2b == doesWord ) DUP <>{ 0x0e &= 0x2b |= <>} NOT IF ( unwind all args ) @@ -95,7 +95,7 @@ ( ol o a2 a1 n ) 0x2b = IF 2 + THEN ( ol o a2 a1 ) - 2 + ( ol o a2 a1+2 ) + 1 + ( ol o a2 a1+1 ) BEGIN ( ol o a2 a1 ) 2OVER ( ol o a2 a1 ol o ) SWAP ( ol o a2 a1 o ol ) diff --git a/forth/xcomp.fs b/forth/xcomp.fs index 76cfc6f..310ec7d 100644 --- a/forth/xcomp.fs +++ b/forth/xcomp.fs @@ -34,7 +34,7 @@ VARIABLE XOFF : X: (xentry) ( 0e == compiledWord ) - [ 0x0e LITN ] , + [ 0x0e LITN ] C, BEGIN WORD ( cross compile CURRENT ) diff --git a/forth/z80a.fs b/forth/z80a.fs index e095fc2..a9a4328 100644 --- a/forth/z80a.fs +++ b/forth/z80a.fs @@ -324,7 +324,7 @@ ( same as CREATE, but with native word ) (entry) ( 23 == nativeWord ) - 23 , + 23 C, ; : ;CODE JPNEXT, ;