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

zasm: remove SYM_CTX

This commit is contained in:
Virgil Dupras 2019-07-22 15:59:47 -04:00
parent 311d04e9aa
commit f4f91ebd79
6 changed files with 32 additions and 42 deletions

View File

@ -142,7 +142,7 @@ handleEQU:
jr nz, .badarg jr nz, .badarg
ld hl, DIREC_SCRATCHPAD ld hl, DIREC_SCRATCHPAD
push ix \ pop de push ix \ pop de
call symRegister ; A and Z set call symRegisterGlobal ; A and Z set
jr .end jr .end
.badfmt: .badfmt:
ld a, ERR_BAD_FMT ld a, ERR_BAD_FMT

View File

@ -164,6 +164,7 @@ _parseLabel:
call symIsLabelLocal call symIsLabelLocal
jr z, .success ; local? don't do anything. jr z, .success ; local? don't do anything.
ld ix, SYM_GLOBAL_REGISTRY
call zasmIsFirstPass call zasmIsFirstPass
jr z, .registerLabel ; When we encounter a label in the first jr z, .registerLabel ; When we encounter a label in the first
; pass, we register it in the symbol ; pass, we register it in the symbol
@ -174,6 +175,7 @@ _parseLabel:
call _beginLocalPass call _beginLocalPass
jr .success jr .success
.processLocalPass: .processLocalPass:
ld ix, SYM_LOCAL_REGISTRY
call symIsLabelLocal call symIsLabelLocal
jr z, .registerLabel ; local label? all good, register it jr z, .registerLabel ; local label? all good, register it
; normally ; normally
@ -209,12 +211,10 @@ _beginLocalPass:
; Empty local label registry ; Empty local label registry
xor a xor a
ld (SYM_LOC_NAMES), a ld (SYM_LOC_NAMES), a
call symSelectLocalRegistry
ret ret
_endLocalPass: _endLocalPass:
call symSelectGlobalRegistry
; recall I/O pos ; recall I/O pos
call ioRecallPos call ioRecallPos
; recall PC ; recall PC

View File

@ -36,11 +36,8 @@
.equ SYM_LOC_VALUES SYM_NAMES+SYM_BUFSIZE .equ SYM_LOC_VALUES SYM_NAMES+SYM_BUFSIZE
.equ SYM_LOC_NAMES SYM_LOC_VALUES+SYM_LOC_MAXCOUNT*2 .equ SYM_LOC_NAMES SYM_LOC_VALUES+SYM_LOC_MAXCOUNT*2
; Pointer to the active registry
.equ SYM_CTX SYM_LOC_NAMES+SYM_LOC_BUFSIZE
; Pointer, in the value list, to the result of the last _symFind ; Pointer, in the value list, to the result of the last _symFind
.equ SYM_CTX_PTR SYM_CTX+2 .equ SYM_CTX_PTR SYM_LOC_NAMES+SYM_LOC_BUFSIZE
.equ SYM_RAMEND SYM_CTX_PTR+2 .equ SYM_RAMEND SYM_CTX_PTR+2
; *** Registries *** ; *** Registries ***
@ -80,20 +77,6 @@ symInit:
ld (SYM_LOC_NAMES), a ld (SYM_LOC_NAMES), a
; Continue to symSelectGlobalRegistry ; Continue to symSelectGlobalRegistry
symSelectGlobalRegistry:
push hl
ld hl, SYM_GLOBAL_REGISTRY
ld (SYM_CTX), hl
pop hl
ret
symSelectLocalRegistry:
push hl
ld hl, SYM_LOCAL_REGISTRY
ld (SYM_CTX), hl
pop hl
ret
; Sets Z according to whether label in (HL) is local (starts with a dot) ; Sets Z according to whether label in (HL) is local (starts with a dot)
symIsLabelLocal: symIsLabelLocal:
ld a, '.' ld a, '.'
@ -147,18 +130,30 @@ _symNamesEnd:
pop iy pop iy
ret ret
symRegisterGlobal:
push ix
ld ix, SYM_GLOBAL_REGISTRY
call symRegister
pop ix
ret
symRegisterLocal:
push ix
ld ix, SYM_LOCAL_REGISTRY
call symRegister
pop ix
ret
; Register label in (HL) (minus the ending ":") into the symbol registry and ; Register label in (HL) (minus the ending ":") into the symbol registry and
; set its value in that registry to DE. ; set its value in that registry to DE.
; If successful, Z is set and A is the symbol index. Otherwise, Z is unset and ; If successful, Z is set and A is the symbol index. Otherwise, Z is unset and
; A is an error code (ERR_*). ; A is an error code (ERR_*).
symRegister: symRegister:
push ix ; --> lvl 1
ld ix, (SYM_CTX)
call _symFind call _symFind
jr z, .alreadyThere jr z, .alreadyThere
push hl ; --> lvl 2. it's the symbol to add push hl ; --> lvl 1. it's the symbol to add
push de ; --> lvl 3. it's our value. push de ; --> lvl 2. it's our value.
; First, let's get our strlen ; First, let's get our strlen
@ -169,16 +164,16 @@ symRegister:
jr nz, .outOfMemory jr nz, .outOfMemory
; Is our new name going to make us go out of bounds? ; Is our new name going to make us go out of bounds?
push hl ; --> lvl 4 push hl ; --> lvl 3
push de ; --> lvl 5 push de ; --> lvl 4
ld e, (ix+2) ld e, (ix+2)
ld d, (ix+3) ld d, (ix+3)
; DE --> names end ; DE --> names end
ld a, c ld a, c
call addHL call addHL
call cpHLDE call cpHLDE
pop de ; <-- lvl 5 pop de ; <-- lvl 4
pop hl ; <-- lvl 4 pop hl ; <-- lvl 3
jr nc, .outOfMemory ; HL >= DE jr nc, .outOfMemory ; HL >= DE
; Success. At this point, we have: ; Success. At this point, we have:
@ -189,11 +184,11 @@ symRegister:
; Let's start with the value. ; Let's start with the value.
push hl \ pop ix ; save HL for later push hl \ pop ix ; save HL for later
pop hl ; <-- lvl 3. value to register pop hl ; <-- lvl 2. value to register
call writeHLinDE ; write value where it goes. call writeHLinDE ; write value where it goes.
; Good! now, the string. ; Good! now, the string.
pop hl ; <-- lvl 2. string to register pop hl ; <-- lvl 1. string to register
push ix \ pop de ; string destination push ix \ pop de ; string destination
; Copy HL into DE until we reach null char ; Copy HL into DE until we reach null char
call strcpyM call strcpyM
@ -202,16 +197,14 @@ symRegister:
; list. DE is already correctly placed, A is already zero ; list. DE is already correctly placed, A is already zero
ld (de), a ld (de), a
pop ix ; <-- lvl 1
cp a ; ensure Z cp a ; ensure Z
ret ret
.outOfMemory: .outOfMemory:
ld a, ERR_OOM ld a, ERR_OOM
call unsetZ call unsetZ
pop de ; <-- lvl 3 pop de ; <-- lvl 2
pop hl ; <-- lvl 2 pop hl ; <-- lvl 1
pop ix ; <-- lvl 1
ret ret
.alreadyThere: .alreadyThere:
@ -232,9 +225,6 @@ symRegister:
; then it's an error condition. If it's not first pass, then we need ; then it's an error condition. If it's not first pass, then we need
; to update our value. ; to update our value.
; Let's pop our lvl 1 IX now, we don't need it any more.
pop ix ; <-- lvl 1
call zasmIsFirstPass call zasmIsFirstPass
jr z, .duplicateError jr z, .duplicateError
; Second pass. Don't error out, just update value ; Second pass. Don't error out, just update value

Binary file not shown.

View File

@ -63,11 +63,11 @@ test:
call symInit call symInit
ld hl, sFOO ld hl, sFOO
ld de, 0x4000 ld de, 0x4000
call symRegister call symRegisterGlobal
jp nz, fail jp nz, fail
ld hl, sBAR ld hl, sBAR
ld de, 0x20 ld de, 0x20
call symRegister call symRegisterGlobal
jp nz, fail jp nz, fail
ld hl, s3 ld hl, s3

View File

@ -26,11 +26,11 @@ test:
call symInit call symInit
ld hl, sFOOBAR ld hl, sFOOBAR
ld de, 42 ld de, 42
call symRegister call symRegisterGlobal
jp nz, fail jp nz, fail
ld hl, sFOO ld hl, sFOO
ld de, 43 ld de, 43
call symRegister call symRegisterGlobal
jp nz, fail jp nz, fail
ld hl, sFOO ld hl, sFOO