mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-23 23:08:06 +11:00
forth: make branching offsets 1 byte
Those bytes, those precious bytes!
This commit is contained in:
parent
abdf2c8adc
commit
ea5f33558a
@ -51,19 +51,15 @@ doesWord:
|
|||||||
push hl \ pop iy
|
push hl \ pop iy
|
||||||
jr compiledWord
|
jr compiledWord
|
||||||
|
|
||||||
; This word is followed by *relative* offset (to the cell's addr) to where to
|
; This word is followed by 1b *relative* offset (to the cell's addr) to where to
|
||||||
; branch to. For example, The branching cell of "IF THEN" would contain 4. Add
|
; branch to. For example, The branching cell of "IF THEN" would contain 3. Add
|
||||||
; this value to RS.
|
; this value to RS.
|
||||||
branchWord:
|
branchWord:
|
||||||
push de
|
push de
|
||||||
ld l, (ix)
|
ld l, (ix)
|
||||||
ld h, (ix+1)
|
ld h, (ix+1)
|
||||||
ld e, (hl)
|
ld a, (hl)
|
||||||
inc hl
|
call addHL
|
||||||
ld d, (hl)
|
|
||||||
dec hl
|
|
||||||
or a ; clear carry
|
|
||||||
add hl, de
|
|
||||||
ld (ix), l
|
ld (ix), l
|
||||||
ld (ix+1), h
|
ld (ix+1), h
|
||||||
pop de
|
pop de
|
||||||
@ -78,8 +74,12 @@ cbranchWord:
|
|||||||
ld a, h
|
ld a, h
|
||||||
or l
|
or l
|
||||||
jr z, branchWord
|
jr z, branchWord
|
||||||
; skip next 2 bytes
|
; skip next byte in RS
|
||||||
call skipRS
|
ld l, (ix)
|
||||||
|
ld h, (ix+1)
|
||||||
|
inc hl
|
||||||
|
ld (ix), l
|
||||||
|
ld (ix+1), h
|
||||||
jp exit
|
jp exit
|
||||||
|
|
||||||
CBRANCH:
|
CBRANCH:
|
||||||
@ -527,17 +527,14 @@ CMP:
|
|||||||
.dw CMP
|
.dw CMP
|
||||||
IF:
|
IF:
|
||||||
.dw nativeWord
|
.dw nativeWord
|
||||||
; Spit a conditional branching atom, followed by 2 empty bytes. Then,
|
; Spit a conditional branching atom, followed by an empty 1b cell. Then,
|
||||||
; push the address of those 2 bytes on the PS. ELSE or THEN will pick
|
; push the address of that cell on the PS. ELSE or THEN will pick
|
||||||
; them up and set their own address in those 2 bytes.
|
; them up and set the offset.
|
||||||
ld hl, (CMPDST)
|
ld hl, (CMPDST)
|
||||||
ld de, CBRANCH
|
ld de, CBRANCH
|
||||||
call DEinHL
|
call DEinHL
|
||||||
push hl ; address of cell to fill
|
push hl ; address of cell to fill
|
||||||
; For now, let's fill it with a reference to ABORT in case we have a
|
inc hl ; empty 1b cell
|
||||||
; malformed construct
|
|
||||||
ld de, ABORTREF
|
|
||||||
call DEinHL
|
|
||||||
ld (CMPDST), hl
|
ld (CMPDST), hl
|
||||||
jp exit
|
jp exit
|
||||||
|
|
||||||
@ -551,11 +548,11 @@ ELSE:
|
|||||||
pop de ; cell's address
|
pop de ; cell's address
|
||||||
ld hl, (CMPDST)
|
ld hl, (CMPDST)
|
||||||
; also skip ELSE word.
|
; also skip ELSE word.
|
||||||
inc hl \ inc hl \ inc hl \ inc hl
|
inc hl \ inc hl \ inc hl
|
||||||
or a ; clear carry
|
or a ; clear carry
|
||||||
sbc hl, de ; HL now has relative offset
|
sbc hl, de ; HL now has relative offset
|
||||||
ex de, hl ; HL has branching cell
|
ld a, l
|
||||||
call DEinHL
|
ld (de), a
|
||||||
; Set IF's branching cell to current atom address and spit our own
|
; Set IF's branching cell to current atom address and spit our own
|
||||||
; uncondition branching cell, which will then be picked up by THEN.
|
; uncondition branching cell, which will then be picked up by THEN.
|
||||||
; First, let's spit our 4 bytes
|
; First, let's spit our 4 bytes
|
||||||
@ -563,8 +560,7 @@ ELSE:
|
|||||||
ld de, BRANCH
|
ld de, BRANCH
|
||||||
call DEinHL
|
call DEinHL
|
||||||
push hl ; address of cell to fill
|
push hl ; address of cell to fill
|
||||||
ld de, ABORTREF
|
inc hl ; empty 1b cell
|
||||||
call DEinHL
|
|
||||||
ld (CMPDST), hl
|
ld (CMPDST), hl
|
||||||
jp exit
|
jp exit
|
||||||
|
|
||||||
@ -580,8 +576,8 @@ THEN:
|
|||||||
; There is nothing to skip because THEN leaves nothing.
|
; There is nothing to skip because THEN leaves nothing.
|
||||||
or a ; clear carry
|
or a ; clear carry
|
||||||
sbc hl, de ; HL now has relative offset
|
sbc hl, de ; HL now has relative offset
|
||||||
ex de, hl ; HL has branching cell
|
ld a, l
|
||||||
call DEinHL
|
ld (de), a
|
||||||
jp exit
|
jp exit
|
||||||
|
|
||||||
.db "RECURSE"
|
.db "RECURSE"
|
||||||
|
@ -99,9 +99,9 @@ HLPointsQUIT:
|
|||||||
; to after null-termination.
|
; to after null-termination.
|
||||||
compSkip:
|
compSkip:
|
||||||
call HLPointsNUMBER
|
call HLPointsNUMBER
|
||||||
jr z, .isNumOrBranch
|
jr z, .isNum
|
||||||
call HLPointsBRANCH
|
call HLPointsBRANCH
|
||||||
jr z, .isNumOrBranch
|
jr z, .isBranch
|
||||||
call HLPointsLIT
|
call HLPointsLIT
|
||||||
jr nz, .isWord
|
jr nz, .isWord
|
||||||
; We have a literal
|
; We have a literal
|
||||||
@ -109,9 +109,13 @@ compSkip:
|
|||||||
call strskip
|
call strskip
|
||||||
inc hl ; byte after word termination
|
inc hl ; byte after word termination
|
||||||
ret
|
ret
|
||||||
.isNumOrBranch:
|
.isNum:
|
||||||
; skip by 4
|
; skip by 4
|
||||||
inc hl \ inc hl
|
inc hl
|
||||||
|
; continue to isBranch
|
||||||
|
.isBranch:
|
||||||
|
; skip by 3
|
||||||
|
inc hl
|
||||||
; continue to isWord
|
; continue to isWord
|
||||||
.isWord:
|
.isWord:
|
||||||
; skip by 2
|
; skip by 2
|
||||||
|
Loading…
Reference in New Issue
Block a user