mirror of
https://github.com/hsoft/collapseos.git
synced 2024-12-26 15:48:05 +11:00
forth: add number literals support
This commit is contained in:
parent
30f188b984
commit
ad2aca4620
@ -42,6 +42,25 @@ sysvarWord:
|
|||||||
push hl
|
push hl
|
||||||
jp exit
|
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 -- )
|
; ( R:I -- )
|
||||||
EXIT:
|
EXIT:
|
||||||
.db "EXIT", 0, 0, 0, 0
|
.db "EXIT", 0, 0, 0, 0
|
||||||
@ -127,10 +146,7 @@ DEFINE:
|
|||||||
.end:
|
.end:
|
||||||
; end chain with EXIT
|
; end chain with EXIT
|
||||||
ld hl, EXIT+CODELINK_OFFSET
|
ld hl, EXIT+CODELINK_OFFSET
|
||||||
ld (iy), l
|
call wrCompHL
|
||||||
inc iy
|
|
||||||
ld (iy), h
|
|
||||||
inc iy
|
|
||||||
ld (HERE), iy
|
ld (HERE), iy
|
||||||
jp exit
|
jp exit
|
||||||
.issemicol:
|
.issemicol:
|
||||||
|
@ -3,6 +3,7 @@ jp forthMain
|
|||||||
|
|
||||||
.inc "core.asm"
|
.inc "core.asm"
|
||||||
.inc "lib/util.asm"
|
.inc "lib/util.asm"
|
||||||
|
.inc "lib/parse.asm"
|
||||||
.inc "lib/ari.asm"
|
.inc "lib/ari.asm"
|
||||||
.inc "lib/fmt.asm"
|
.inc "lib/fmt.asm"
|
||||||
.equ FORTH_RAMSTART RAMSTART
|
.equ FORTH_RAMSTART RAMSTART
|
||||||
|
@ -74,21 +74,34 @@ find:
|
|||||||
inc a
|
inc a
|
||||||
ret
|
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,
|
; 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:
|
||||||
call find
|
call find
|
||||||
|
jr nz, .maybeNum
|
||||||
ret nz
|
ret nz
|
||||||
; DE is a word offset, we need a code link
|
; DE is a word offset, we need a code link
|
||||||
ld hl, CODELINK_OFFSET
|
ld hl, CODELINK_OFFSET
|
||||||
add hl, de
|
add hl, de
|
||||||
ld (iy), l
|
|
||||||
inc iy
|
|
||||||
ld (iy), h
|
|
||||||
inc iy
|
|
||||||
xor a ; set Z
|
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)
|
; Spit name + prev in (HERE) and adjust (HERE) and (CURRENT)
|
||||||
; HL points to new (HERE)
|
; HL points to new (HERE)
|
||||||
|
Loading…
Reference in New Issue
Block a user