From d91af99fde240c30df7b8e81368c2862a9e6a8d7 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Tue, 17 Mar 2020 15:54:17 -0400 Subject: [PATCH] forth: make "'" push 0 when not finding a word --- apps/forth/dict.asm | 19 ++++++++----------- apps/forth/dictionary.txt | 4 ++-- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/apps/forth/dict.asm b/apps/forth/dict.asm index 2af2fcb..581b9d2 100644 --- a/apps/forth/dict.asm +++ b/apps/forth/dict.asm @@ -453,25 +453,22 @@ LITS: .fill 6 .dw LITS .db 0 -APOS: +FIND: .dw nativeWord call readword call find - jr nz, .notfound + jr z, .found + ; not found + ld de, 0 +.found: push de jp next -.notfound: - ld hl, .msg - call printstr - jp abort -.msg: - .db "word not found", 0 .db "[']" .fill 4 - .dw APOS + .dw FIND .db 0b01 ; IMMEDIATE -APOSI: +FINDI: .dw nativeWord call readword call find @@ -494,7 +491,7 @@ APOSI: ; ( -- c ) .db "KEY" .fill 4 - .dw APOSI + .dw FINDI .db 0 KEY: .dw nativeWord diff --git a/apps/forth/dictionary.txt b/apps/forth/dictionary.txt index 17db2dd..a556349 100644 --- a/apps/forth/dictionary.txt +++ b/apps/forth/dictionary.txt @@ -35,9 +35,9 @@ directly, but as part of another word. : x ... -- Define a new word ; R:I -- Exit a colon definition , n -- Write n in HERE and advance it. -' x -- a Push addr of word x to a. +' x -- a Push addr of word x to a. If not found, push 0 ['] x -- *I* Like "'", but spits the addr as a number - literal. + literal. If not found, aborts. ( -- *I* Comment. Ignore rest of line until ")" is read. ALLOT n -- Move HERE by n bytes C, b -- Write byte b in HERE and advance it.