From 243c70a4b7a13f3f52168432faf3c96361a5fce0 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Thu, 2 Apr 2020 14:05:18 -0400 Subject: [PATCH] forth: transform (find) into FIND which is an indirect call You'll see where I'm going with this... --- emul/forth/z80c.bin | Bin 1781 -> 1823 bytes forth/core.fs | 10 +++++----- forth/dictionary.txt | 4 ++-- forth/icore.fs | 27 ++++++++++++++++++--------- forth/notes.txt | 9 ++++++--- 5 files changed, 31 insertions(+), 19 deletions(-) diff --git a/emul/forth/z80c.bin b/emul/forth/z80c.bin index d5b0fe71e9b9f22f4997f141de0596bf15536d35..3c3dc16749e4baba4ed386348a1c7de17615050b 100644 GIT binary patch delta 336 zcmey$JD+cZ3o}QxL^9`V4o3FPKFr4$CEPsyT;v#7_!txz_!uNuLzw#+oEe;L1SX5J z<~Y1(yUS?9evqkvfdwe~o-u;q-G66>aQ`3|8Hg4Epq6lUekNyT1qMcj>r4<01wdt% zObQGFlMk|rGL}ug&Z@}F$SybeH>)H|8T%c!$r5Zv^=X-TDVhv(S>7{3Y<6Z=V$di^ zEGkabWVpljp3$BaERt*k;)0yO!=S|A?HUP|Q~>fMUq?TvEUw#&DNWiUpyYkv)Qei@_co5FH#5 c47Y$Dwl)Q6Q~(A6Bl}0@_l(XA@%#*o0M-jg!TWuThIjuhnG_g6vd#<|sd*(um74kt?0gIXtRc*ali#o^GQVNtoGid5 z$&$!Emu0dpn^Ap1Vo`CbCc|8o_l)+e&df>-8p$>w?m?yk1|9|_25;9$u%rTz2Q(I< zKn0|tfPsUdpCN*Qh2cHpRd#0vAI}iKU -- See description at top of file +FIND a -- a f Read at a and find it in dict. If found, f=1 and + a = wordref. If not found, f=0 and a = string addr. IMMED? a -- f Checks whether wordref at a is immediate. IMMEDIATE -- Flag the latest defined word as immediate. LITN n -- Write number n as a literal. diff --git a/forth/icore.fs b/forth/icore.fs index ae6e175..6f9cbf6 100644 --- a/forth/icore.fs +++ b/forth/icore.fs @@ -130,6 +130,11 @@ LIT< stack-underflow _c (print) _c ABORT ; +: FIND + ( 0e == FINDPTR ) + 0x0e _c RAM+ _c @ EXECUTE +; + : C< ( 0c == CINPTR ) 0x0c _c RAM+ _c @ EXECUTE @@ -159,8 +164,8 @@ ( Read word from C<, copy to WORDBUF, null-terminate, and return, make HL point to WORDBUF. ) : WORD - ( 0e == WORDBUF ) - 0x0e _c RAM+ ( a ) + ( 10 == WORDBUF ) + 0x10 _c RAM+ ( a ) _c TOWORD ( a c ) BEGIN ( We take advantage of the fact that char MSB is @@ -173,7 +178,7 @@ ( a this point, PS is: a WS ) ( null-termination is already written ) _c 2DROP - 0x0e _c RAM+ + 0x10 _c RAM+ ; : (entry) @@ -194,7 +199,7 @@ : INTERPRET BEGIN _c WORD - _c (find) + _c FIND IF 1 _c FLAGS _c ! EXECUTE @@ -206,12 +211,16 @@ ; : BOOT - LIT< (parse) _c (find) _c DROP _c (parse*) _c ! - LIT< (c<) _c (find) _c - NOT IF LIT< KEY _c (find) _c DROP THEN + ( write (find) in PARSEPTR, RAM+0e ) + ( a bit wasteful, but otherwise I have bootstrap + issues with "," ) + LIT< (find) _c (find) _c DROP 0x0e _c RAM+ _c ! + LIT< (parse) _c FIND _c DROP _c (parse*) _c ! + LIT< (c<) _c FIND _c + NOT IF LIT< KEY _c FIND _c DROP THEN ( 0c == CINPTR ) 0x0c _c RAM+ _c ! - LIT< (c<$) _c (find) IF EXECUTE ELSE _c DROP THEN + LIT< (c<$) _c FIND IF EXECUTE ELSE _c DROP THEN _c INTERPRET ; @@ -234,7 +243,7 @@ [ 32 H@ ! 2 ALLOT 14 H@ ! 2 ALLOT ] _c , BEGIN _c WORD - _c (find) + _c FIND ( is word ) IF _c DUP _c IMMED? IF EXECUTE ELSE _c , THEN ( maybe number ) diff --git a/forth/notes.txt b/forth/notes.txt index 1767368..aef44da 100644 --- a/forth/notes.txt +++ b/forth/notes.txt @@ -85,9 +85,10 @@ RAMSTART INITIAL_SP +08 FLAGS +0a PARSEPTR +0c CINPTR -+0e WORDBUF -+2e SYSVNXT -+4e RAMEND ++0e FINDPTR ++10 WORDBUF ++30 SYSVNXT ++50 RAMEND INITIAL_SP holds the initial Stack Pointer value so that we know where to reset it on ABORT @@ -104,6 +105,8 @@ PARSEPTR holds routine address called on (parse) CINPTR holds routine address called on C< +FINDPTR holds routine address called on FIND + WORDBUF is the buffer used by WORD SYSVNXT is the buffer+tracker used by (sysv)