1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-30 22:28:08 +11:00

forth: Word-ify "[']" and "'"

This commit is contained in:
Virgil Dupras 2020-03-17 16:02:01 -04:00
parent d91af99fde
commit b72901175e
2 changed files with 37 additions and 22 deletions

View File

@ -449,44 +449,57 @@ LITS:
ld (HERE), de ld (HERE), de
jp next jp next
.db "'" .db "(find)"
.fill 6 .fill 1
.dw LITS .dw LITS
.db 0 .db 0
FIND: FIND_:
.dw nativeWord .dw nativeWord
call readword call readword
call find call find
jr z, .found jr z, .found
; not found ; not found
push hl
ld de, 0 ld de, 0
.found:
push de push de
jp next jp next
.found:
push de
ld de, 1
push de
jp next
.db "'"
.fill 6
.dw FIND_
.db 0
FIND:
.dw compiledWord
.dw FIND_
.dw CSKIP
.dw FINDERR
.dw EXIT
.db "[']" .db "[']"
.fill 4 .fill 4
.dw FIND .dw FIND
.db 0b01 ; IMMEDIATE .db 0b01 ; IMMEDIATE
FINDI: FINDI:
.dw nativeWord .dw compiledWord
call readword .dw FIND_
call find .dw CSKIP
jr nz, .notfound .dw FINDERR
ld hl, (HERE) .dw LITN
push de ; --> lvl 1 .dw EXIT
ld de, NUMBER
call DEinHL .db 0b10 ; UNWORD
pop de ; <-- lvl 1 FINDERR:
call DEinHL .dw compiledWord
ld (HERE), hl .dw DROP ; Drop str addr, we don't use it
jp next .dw LIT
.notfound:
ld hl, .msg
call printstr
jp abort
.msg:
.db "word not found", 0 .db "word not found", 0
.dw PRINT
.dw ABORT
; ( -- c ) ; ( -- c )
.db "KEY" .db "KEY"

View File

@ -32,10 +32,12 @@ 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) x -- a f Read word x 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.
' x -- a Push addr of word x to a. If not found, push 0 ' x -- a Push addr of word x to a. If not found, aborts
['] x -- *I* Like "'", but spits the addr as a number ['] x -- *I* Like "'", but spits the addr as a number
literal. If not found, aborts. literal. If not found, aborts.
( -- *I* Comment. Ignore rest of line until ")" is read. ( -- *I* Comment. Ignore rest of line until ")" is read.