Back near the end of 2020 I presented the source code for Fleet Forth's new (ABORT") , which is so much faster than the old version when there is no error.
Code: Select all
CODE (ABORT") ( F -- )
0 ,X LDA, 1 ,X ORA,
0= IF,
IP )Y LDA, SEC,
IP ADC, IP STA,
CS IF, IP 1+ INC, THEN,
POP JMP,
THEN,
>FORTH
WHERE CR R@ S?
ABORT ;
-2 ALLOT
The following snippet of code skips Fleet Forth's instruction pointer, IP , over an inline counted string.
Code: Select all
IP )Y LDA, SEC,
IP ADC, IP STA,
CS IF, IP 1+ INC, THEN,
There are two other words in Fleet Forth which skip over an inline string. They are (.") and (") .
Code: Select all
: (.") ( -- )
R> COUNT 2DUP + >R TYPE ;
: (") ( -- ADR )
R> DUP COUNT + >R ;
Fleet Forth's kernel can be made smaller by taking the string skipping code out of (ABORT") and placing it in (") .
Code: Select all
: (") ( -- ADR )
R@
>ASSEM
IP )Y LDA SEC
IP ADC IP STA
CS IF IP 1+ INC THEN
NEXT JMP END-CODE
: (.") ( -- )
R@ COUNT TYPE
BRANCH
[ ' (") >BODY 2+ , ] ; -2 ALLOT
The new (") is six bytes bigger and the new (.") is four bytes smaller.
The newest (ABORT") is twelve bytes smaller for a net savings of ten bytes.
Code: Select all
CODE (ABORT") ( F -- )
INX INX
$FE ,X LDA $FF ,X ORA
' (") >BODY 4 + 0= BRAN
>FORTH
WHERE CR R> S?
ABORT ; -2 ALLOT
(ABORT") is still fast. When there is no error, this version of (ABORT") should be two cycles faster. The branch does not cross a page boundary, my metacompiler reports page boundary crossings. I get a print file of the metacompiler messages by typing LOGGER before loading the kernel source.
There is also this code in ?BRANCH
Code: Select all
LABEL 2.IP.+!
CLC
IP LDA 2 # ADC IP STA
NEXT CS NOT BRAN
IP 1+ INC
NEXT 0= NOT BRAN // ALWAYS
which skips IP over a cell.
Note: LABEL creates a label in the metacompiler's host vocabulary with the present value of THERE , the target's HERE , as its value. It does not increase the size of the target in any way.
This code fragment, 2.IP.+! can also be used by (IS) , the word compiled by IS , and COMPILE .
The original source.
Code: Select all
: (IS)
R> DUP 2+ >R @ >BODY ! ;
: COMPILE
?COMP R> DUP 2+ >R @ , ;
And the new.
Code: Select all
: (IS) ( -- )
R@ @ >BODY !
LABEL SKIP.CELL
>ASSEM
2.IP.+! JMP END-CODE
: COMPILE
?COMP R@ @ , BRANCH
[ SKIP.CELL , ] ; -2 ALLOT
The new (IS) is three bytes smaller and the new COMPILE is four bytes smaller.