forth: transform (find) into FIND which is an indirect call
You'll see where I'm going with this...
This commit is contained in:
parent
b162ef84f5
commit
243c70a4b7
Binary file not shown.
@ -6,7 +6,7 @@
|
|||||||
: LITS LIT SCPY ;
|
: LITS LIT SCPY ;
|
||||||
: LIT< WORD LITS ; IMMEDIATE
|
: LIT< WORD LITS ; IMMEDIATE
|
||||||
: _err LIT< word-not-found (print) ABORT ;
|
: _err LIT< word-not-found (print) ABORT ;
|
||||||
: ' WORD (find) NOT (?br) [ 4 , ] _err ;
|
: ' WORD FIND NOT (?br) [ 4 , ] _err ;
|
||||||
: ['] ' LITN ; IMMEDIATE
|
: ['] ' LITN ; IMMEDIATE
|
||||||
: COMPILE ' LITN ['] , , ; IMMEDIATE
|
: COMPILE ' LITN ['] , , ; IMMEDIATE
|
||||||
: [COMPILE] ' , ; IMMEDIATE
|
: [COMPILE] ' , ; IMMEDIATE
|
||||||
@ -106,16 +106,16 @@
|
|||||||
|
|
||||||
: (sysv)
|
: (sysv)
|
||||||
( Get new sysv addr )
|
( Get new sysv addr )
|
||||||
( RAM+46 (2e) == SYSVNXT )
|
( RAM+48 (30) == SYSVNXT )
|
||||||
46 RAM+ @
|
48 RAM+ @
|
||||||
CONSTANT
|
CONSTANT
|
||||||
( increase current sysv counter )
|
( increase current sysv counter )
|
||||||
2 46 RAM+ +!
|
2 48 RAM+ +!
|
||||||
;
|
;
|
||||||
|
|
||||||
( Set up initial SYSVNXT value, which is 2 bytes after its
|
( Set up initial SYSVNXT value, which is 2 bytes after its
|
||||||
own address )
|
own address )
|
||||||
46 RAM+ DUP 2 + SWAP !
|
48 RAM+ DUP 2 + SWAP !
|
||||||
|
|
||||||
: ."
|
: ."
|
||||||
LIT
|
LIT
|
||||||
|
@ -32,8 +32,6 @@ directly, but as part of another word.
|
|||||||
"*I*" in description indicates an IMMEDIATE word.
|
"*I*" in description indicates an IMMEDIATE word.
|
||||||
|
|
||||||
*** Defining words ***
|
*** 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
|
: x ... -- Define a new word
|
||||||
; R:I -- Exit a colon definition
|
; R:I -- Exit a colon definition
|
||||||
, n -- Write n in HERE and advance it.
|
, 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.
|
COMPILE x -- Meta compiles. Kind of blows the mind. See below.
|
||||||
CONSTANT x n -- Creates cell x that when called pushes its value
|
CONSTANT x n -- Creates cell x that when called pushes its value
|
||||||
DOES> -- See description at top of file
|
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.
|
IMMED? a -- f Checks whether wordref at a is immediate.
|
||||||
IMMEDIATE -- Flag the latest defined word as immediate.
|
IMMEDIATE -- Flag the latest defined word as immediate.
|
||||||
LITN n -- Write number n as a literal.
|
LITN n -- Write number n as a literal.
|
||||||
|
@ -130,6 +130,11 @@
|
|||||||
LIT< stack-underflow _c (print) _c ABORT
|
LIT< stack-underflow _c (print) _c ABORT
|
||||||
;
|
;
|
||||||
|
|
||||||
|
: FIND
|
||||||
|
( 0e == FINDPTR )
|
||||||
|
0x0e _c RAM+ _c @ EXECUTE
|
||||||
|
;
|
||||||
|
|
||||||
: C<
|
: C<
|
||||||
( 0c == CINPTR )
|
( 0c == CINPTR )
|
||||||
0x0c _c RAM+ _c @ EXECUTE
|
0x0c _c RAM+ _c @ EXECUTE
|
||||||
@ -159,8 +164,8 @@
|
|||||||
( Read word from C<, copy to WORDBUF, null-terminate, and
|
( Read word from C<, copy to WORDBUF, null-terminate, and
|
||||||
return, make HL point to WORDBUF. )
|
return, make HL point to WORDBUF. )
|
||||||
: WORD
|
: WORD
|
||||||
( 0e == WORDBUF )
|
( 10 == WORDBUF )
|
||||||
0x0e _c RAM+ ( a )
|
0x10 _c RAM+ ( a )
|
||||||
_c TOWORD ( a c )
|
_c TOWORD ( a c )
|
||||||
BEGIN
|
BEGIN
|
||||||
( We take advantage of the fact that char MSB is
|
( We take advantage of the fact that char MSB is
|
||||||
@ -173,7 +178,7 @@
|
|||||||
( a this point, PS is: a WS )
|
( a this point, PS is: a WS )
|
||||||
( null-termination is already written )
|
( null-termination is already written )
|
||||||
_c 2DROP
|
_c 2DROP
|
||||||
0x0e _c RAM+
|
0x10 _c RAM+
|
||||||
;
|
;
|
||||||
|
|
||||||
: (entry)
|
: (entry)
|
||||||
@ -194,7 +199,7 @@
|
|||||||
: INTERPRET
|
: INTERPRET
|
||||||
BEGIN
|
BEGIN
|
||||||
_c WORD
|
_c WORD
|
||||||
_c (find)
|
_c FIND
|
||||||
IF
|
IF
|
||||||
1 _c FLAGS _c !
|
1 _c FLAGS _c !
|
||||||
EXECUTE
|
EXECUTE
|
||||||
@ -206,12 +211,16 @@
|
|||||||
;
|
;
|
||||||
|
|
||||||
: BOOT
|
: BOOT
|
||||||
LIT< (parse) _c (find) _c DROP _c (parse*) _c !
|
( write (find) in PARSEPTR, RAM+0e )
|
||||||
LIT< (c<) _c (find) _c
|
( a bit wasteful, but otherwise I have bootstrap
|
||||||
NOT IF LIT< KEY _c (find) _c DROP THEN
|
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 )
|
( 0c == CINPTR )
|
||||||
0x0c _c RAM+ _c !
|
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
|
_c INTERPRET
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -234,7 +243,7 @@
|
|||||||
[ 32 H@ ! 2 ALLOT 14 H@ ! 2 ALLOT ] _c ,
|
[ 32 H@ ! 2 ALLOT 14 H@ ! 2 ALLOT ] _c ,
|
||||||
BEGIN
|
BEGIN
|
||||||
_c WORD
|
_c WORD
|
||||||
_c (find)
|
_c FIND
|
||||||
( is word )
|
( is word )
|
||||||
IF _c DUP _c IMMED? IF EXECUTE ELSE _c , THEN
|
IF _c DUP _c IMMED? IF EXECUTE ELSE _c , THEN
|
||||||
( maybe number )
|
( maybe number )
|
||||||
|
@ -85,9 +85,10 @@ RAMSTART INITIAL_SP
|
|||||||
+08 FLAGS
|
+08 FLAGS
|
||||||
+0a PARSEPTR
|
+0a PARSEPTR
|
||||||
+0c CINPTR
|
+0c CINPTR
|
||||||
+0e WORDBUF
|
+0e FINDPTR
|
||||||
+2e SYSVNXT
|
+10 WORDBUF
|
||||||
+4e RAMEND
|
+30 SYSVNXT
|
||||||
|
+50 RAMEND
|
||||||
|
|
||||||
INITIAL_SP holds the initial Stack Pointer value so that we know where to reset
|
INITIAL_SP holds the initial Stack Pointer value so that we know where to reset
|
||||||
it on ABORT
|
it on ABORT
|
||||||
@ -104,6 +105,8 @@ PARSEPTR holds routine address called on (parse)
|
|||||||
|
|
||||||
CINPTR holds routine address called on C<
|
CINPTR holds routine address called on C<
|
||||||
|
|
||||||
|
FINDPTR holds routine address called on FIND
|
||||||
|
|
||||||
WORDBUF is the buffer used by WORD
|
WORDBUF is the buffer used by WORD
|
||||||
|
|
||||||
SYSVNXT is the buffer+tracker used by (sysv)
|
SYSVNXT is the buffer+tracker used by (sysv)
|
||||||
|
Loading…
Reference in New Issue
Block a user