1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-12-25 19:08:05 +11:00

forth: transform (find) into FIND which is an indirect call

You'll see where I'm going with this...
This commit is contained in:
Virgil Dupras 2020-04-02 14:05:18 -04:00
parent 9c41744e46
commit dcd68fc40b
5 changed files with 31 additions and 19 deletions

Binary file not shown.

View File

@ -6,7 +6,7 @@
: LITS LIT SCPY ;
: LIT< WORD LITS ; IMMEDIATE
: _err LIT< word-not-found (print) ABORT ;
: ' WORD (find) NOT (?br) [ 4 , ] _err ;
: ' WORD FIND NOT (?br) [ 4 , ] _err ;
: ['] ' LITN ; IMMEDIATE
: COMPILE ' LITN ['] , , ; IMMEDIATE
: [COMPILE] ' , ; IMMEDIATE
@ -106,16 +106,16 @@
: (sysv)
( Get new sysv addr )
( RAM+46 (2e) == SYSVNXT )
46 RAM+ @
( RAM+48 (30) == SYSVNXT )
48 RAM+ @
CONSTANT
( increase current sysv counter )
2 46 RAM+ +!
2 48 RAM+ +!
;
( Set up initial SYSVNXT value, which is 2 bytes after its
own address )
46 RAM+ DUP 2 + SWAP !
48 RAM+ DUP 2 + SWAP !
: ."
LIT

View File

@ -32,8 +32,6 @@ directly, but as part of another word.
"*I*" in description indicates an IMMEDIATE word.
*** Defining words ***
(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.
: x ... -- Define a new word
; R:I -- Exit a colon definition
, n -- Write n in HERE and advance it.
@ -49,6 +47,8 @@ CREATE x -- Create cell named x. Doesn't allocate a PF.
COMPILE x -- Meta compiles. Kind of blows the mind. See below.
CONSTANT x n -- Creates cell x that when called pushes its value
DOES> -- 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.

View File

@ -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 )

View File

@ -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)