diff --git a/apps/forth/dict.asm b/apps/forth/dict.asm index aa9ab4d..1978337 100644 --- a/apps/forth/dict.asm +++ b/apps/forth/dict.asm @@ -42,6 +42,25 @@ sysvarWord: push hl jp exit +; This is not a word, but a number literal. This works a bit differently than +; others: PF means nothing and the actual number is placed next to the +; numberWord reference in the compiled word list. What we need to do to fetch +; that number is to play with the Return stack: We pop it, read the number, push +; it to the Parameter stack and then push an increase Interpreter Pointer back +; to RS. +numberWord: + call popRS + ld e, (hl) + inc hl + ld d, (hl) + inc hl + call pushRS + push de + jp exit +NUMBER: + .dw numberWord + + ; ( R:I -- ) EXIT: .db "EXIT", 0, 0, 0, 0 @@ -127,10 +146,7 @@ DEFINE: .end: ; end chain with EXIT ld hl, EXIT+CODELINK_OFFSET - ld (iy), l - inc iy - ld (iy), h - inc iy + call wrCompHL ld (HERE), iy jp exit .issemicol: diff --git a/apps/forth/glue.asm b/apps/forth/glue.asm index b907b59..c89d689 100644 --- a/apps/forth/glue.asm +++ b/apps/forth/glue.asm @@ -3,6 +3,7 @@ jp forthMain .inc "core.asm" .inc "lib/util.asm" +.inc "lib/parse.asm" .inc "lib/ari.asm" .inc "lib/fmt.asm" .equ FORTH_RAMSTART RAMSTART diff --git a/apps/forth/util.asm b/apps/forth/util.asm index b41aa91..31c8ef8 100644 --- a/apps/forth/util.asm +++ b/apps/forth/util.asm @@ -74,21 +74,34 @@ find: inc a ret +; Write compiled data from HL into IY, advancing IY at the same time. +wrCompHL: + ld (iy), l + inc iy + ld (iy), h + inc iy + ret + ; Compile word string at (HL) and write down its compiled version in IY, ; advancing IY to the byte next to the last written byte. ; Set Z on success, unset on failure. compile: call find + jr nz, .maybeNum ret nz ; DE is a word offset, we need a code link ld hl, CODELINK_OFFSET add hl, de - ld (iy), l - inc iy - ld (iy), h - inc iy xor a ; set Z - ret + jr wrCompHL +.maybeNum: + call parseLiteral + ret nz + ; a valid number! + ld hl, NUMBER + call wrCompHL + ex de, hl ; number in HL + jr wrCompHL ; Spit name + prev in (HERE) and adjust (HERE) and (CURRENT) ; HL points to new (HERE)