1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-27 15:28:06 +11:00

forth: add word ":"

This commit is contained in:
Virgil Dupras 2020-03-07 18:53:20 -05:00
parent e7cd3182d0
commit 30f188b984
3 changed files with 66 additions and 15 deletions

View File

@ -103,11 +103,51 @@ executeCodeLink:
; IY points to PFA ; IY points to PFA
jp (hl) ; go! jp (hl) ; go!
DEFINE:
.db ":"
.fill 7
.dw EXECUTE
.dw nativeWord
call entryhead
jp nz, quit
ld de, compiledWord
ld (hl), e
inc hl
ld (hl), d
inc hl
push hl \ pop iy
.loop:
call readword
jr nz, .end
call .issemicol
jr z, .end
call compile
jr nz, quit
jr .loop
.end:
; end chain with EXIT
ld hl, EXIT+CODELINK_OFFSET
ld (iy), l
inc iy
ld (iy), h
inc iy
ld (HERE), iy
jp exit
.issemicol:
ld a, (hl)
cp ';'
ret nz
inc hl
ld a, (hl)
dec hl
or a
ret
; ( -- c ) ; ( -- c )
KEY: KEY:
.db "KEY" .db "KEY"
.fill 5 .fill 5
.dw EXECUTE .dw DEFINE
.dw nativeWord .dw nativeWord
call stdioGetC call stdioGetC
ld h, 0 ld h, 0
@ -141,19 +181,8 @@ CREATE:
.db "CREATE", 0, 0 .db "CREATE", 0, 0
.dw INTERPRET .dw INTERPRET
.dw nativeWord .dw nativeWord
call readword call entryhead
jp nz, exit jp nz, quit
ld de, (HERE)
call strcpy
ex de, hl ; (HERE) now in HL
ld de, (CURRENT)
ld (CURRENT), hl
ld a, NAMELEN
call addHL
ld (hl), e
inc hl
ld (hl), d
inc hl
ld de, cellWord ld de, cellWord
ld (hl), e ld (hl), e
inc hl inc hl

View File

@ -2,6 +2,7 @@ Stack notation: "<stack before> -- <stack after>". Rightmost is top of stack
(TOS). For example, in "a b -- c d", b is TOS before, d is TOS (TOS). For example, in "a b -- c d", b is TOS before, d is TOS
after. "R:" means that the Return Stack is modified. after. "R:" means that the Return Stack is modified.
: x ... ; -- Define a new word
. n -- Print n in its decimal form . n -- Print n in its decimal form
@ a -- n Set n to value at address a @ a -- n Set n to value at address a
! n a -- Store n in address a ! n a -- Store n in address a

View File

@ -74,7 +74,7 @@ find:
inc a inc a
ret ret
; Compile word at (DE) and write down its compiled version in IY, ; Compile word string at (HL) and write down its compiled version in IY,
; advancing IY to the byte next to the last written byte. ; advancing IY to the byte next to the last written byte.
; Set Z on success, unset on failure. ; Set Z on success, unset on failure.
compile: compile:
@ -89,3 +89,24 @@ compile:
inc iy inc iy
xor a ; set Z xor a ; set Z
ret ret
; Spit name + prev in (HERE) and adjust (HERE) and (CURRENT)
; HL points to new (HERE)
; Set Z if name could be read, NZ if not
entryhead:
call readword
ret nz
ld de, (HERE)
call strcpy
ex de, hl ; (HERE) now in HL
ld de, (CURRENT)
ld (CURRENT), hl
ld a, NAMELEN
call addHL
ld (hl), e
inc hl
ld (hl), d
inc hl
ld (HERE), hl
xor a ; set Z
ret