mirror of
https://github.com/hsoft/collapseos.git
synced 2024-12-26 05:18:05 +11:00
forth: add number literals support
This commit is contained in:
parent
30f188b984
commit
ad2aca4620
@ -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:
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user