From f4f91ebd79792e094c13b77e4930508dd5ab7a2f Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Mon, 22 Jul 2019 15:59:47 -0400 Subject: [PATCH] zasm: remove SYM_CTX --- apps/zasm/directive.asm | 2 +- apps/zasm/main.asm | 4 +-- apps/zasm/symbol.asm | 60 +++++++++++++------------------ tools/emul/zasm/zasm.bin | Bin 4662 -> 4658 bytes tools/tests/unit/test_expr.asm | 4 +-- tools/tests/unit/test_symbol.asm | 4 +-- 6 files changed, 32 insertions(+), 42 deletions(-) diff --git a/apps/zasm/directive.asm b/apps/zasm/directive.asm index cc8201d..8536cfd 100644 --- a/apps/zasm/directive.asm +++ b/apps/zasm/directive.asm @@ -142,7 +142,7 @@ handleEQU: jr nz, .badarg ld hl, DIREC_SCRATCHPAD push ix \ pop de - call symRegister ; A and Z set + call symRegisterGlobal ; A and Z set jr .end .badfmt: ld a, ERR_BAD_FMT diff --git a/apps/zasm/main.asm b/apps/zasm/main.asm index 4b0facf..8baa671 100644 --- a/apps/zasm/main.asm +++ b/apps/zasm/main.asm @@ -164,6 +164,7 @@ _parseLabel: call symIsLabelLocal jr z, .success ; local? don't do anything. + ld ix, SYM_GLOBAL_REGISTRY call zasmIsFirstPass jr z, .registerLabel ; When we encounter a label in the first ; pass, we register it in the symbol @@ -174,6 +175,7 @@ _parseLabel: call _beginLocalPass jr .success .processLocalPass: + ld ix, SYM_LOCAL_REGISTRY call symIsLabelLocal jr z, .registerLabel ; local label? all good, register it ; normally @@ -209,12 +211,10 @@ _beginLocalPass: ; Empty local label registry xor a ld (SYM_LOC_NAMES), a - call symSelectLocalRegistry ret _endLocalPass: - call symSelectGlobalRegistry ; recall I/O pos call ioRecallPos ; recall PC diff --git a/apps/zasm/symbol.asm b/apps/zasm/symbol.asm index 5fa063d..cf60f07 100644 --- a/apps/zasm/symbol.asm +++ b/apps/zasm/symbol.asm @@ -36,11 +36,8 @@ .equ SYM_LOC_VALUES SYM_NAMES+SYM_BUFSIZE .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 -.equ SYM_CTX_PTR SYM_CTX+2 +.equ SYM_CTX_PTR SYM_LOC_NAMES+SYM_LOC_BUFSIZE .equ SYM_RAMEND SYM_CTX_PTR+2 ; *** Registries *** @@ -80,20 +77,6 @@ symInit: ld (SYM_LOC_NAMES), a ; 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) symIsLabelLocal: ld a, '.' @@ -147,18 +130,30 @@ _symNamesEnd: pop iy 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 ; set its value in that registry to DE. ; If successful, Z is set and A is the symbol index. Otherwise, Z is unset and ; A is an error code (ERR_*). symRegister: - push ix ; --> lvl 1 - ld ix, (SYM_CTX) call _symFind jr z, .alreadyThere - push hl ; --> lvl 2. it's the symbol to add - push de ; --> lvl 3. it's our value. + push hl ; --> lvl 1. it's the symbol to add + push de ; --> lvl 2. it's our value. ; First, let's get our strlen @@ -169,16 +164,16 @@ symRegister: jr nz, .outOfMemory ; Is our new name going to make us go out of bounds? - push hl ; --> lvl 4 - push de ; --> lvl 5 + push hl ; --> lvl 3 + push de ; --> lvl 4 ld e, (ix+2) ld d, (ix+3) ; DE --> names end ld a, c call addHL call cpHLDE - pop de ; <-- lvl 5 - pop hl ; <-- lvl 4 + pop de ; <-- lvl 4 + pop hl ; <-- lvl 3 jr nc, .outOfMemory ; HL >= DE ; Success. At this point, we have: @@ -189,11 +184,11 @@ symRegister: ; Let's start with the value. 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. ; Good! now, the string. - pop hl ; <-- lvl 2. string to register + pop hl ; <-- lvl 1. string to register push ix \ pop de ; string destination ; Copy HL into DE until we reach null char call strcpyM @@ -202,16 +197,14 @@ symRegister: ; list. DE is already correctly placed, A is already zero ld (de), a - pop ix ; <-- lvl 1 cp a ; ensure Z ret .outOfMemory: ld a, ERR_OOM call unsetZ - pop de ; <-- lvl 3 - pop hl ; <-- lvl 2 - pop ix ; <-- lvl 1 + pop de ; <-- lvl 2 + pop hl ; <-- lvl 1 ret .alreadyThere: @@ -232,9 +225,6 @@ symRegister: ; then it's an error condition. If it's not first pass, then we need ; 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 jr z, .duplicateError ; Second pass. Don't error out, just update value diff --git a/tools/emul/zasm/zasm.bin b/tools/emul/zasm/zasm.bin index 08913aa399cf9c0931fcf813dba0666b88ce466b..89cdc3c4f16339f554eec2e07167c8b4000448e5 100644 GIT binary patch delta 487 zcmXX?&ubG=5Pt8)G^s_?ZILED?S_>udy+LIVTGW##1y^ReJ!+U3q=sG(mhB{<>7ff z_)oNaBlPI~Tr7B6F zN)nYuQ0Oj%va2ZfTNPWxoTgJ+0f1Ni;WpVAH*Jkh~bXQdl*9MQF8Cus>E}jwbr1A#l5ZpqU zym?s(DWQR+P#IJPbsSLUJKNN0?V$C)r&L;toqQ`A?6P(3Y?iem@O`_S81k z>~yokppLZ4d_jfXWza$HoQ;r)P@nLi%S;r3gMt-i*2-q=uQ0#I{5uSe2Jm;?-lnj8 zzmI(_{Yb4#_Nx+)&*9|H5GRp&s63Vis37Ub|K`D!+wj;L$s{O;BAJ_BkSjinNv3Fh^~>9K^Z&>~~5 mU%}zQ&~u_zz|O+y*kivvf{P)CN(j$~Ucg#TR0h>l%Krn{pwhVj diff --git a/tools/tests/unit/test_expr.asm b/tools/tests/unit/test_expr.asm index 3b323d2..b4a9d6e 100644 --- a/tools/tests/unit/test_expr.asm +++ b/tools/tests/unit/test_expr.asm @@ -63,11 +63,11 @@ test: call symInit ld hl, sFOO ld de, 0x4000 - call symRegister + call symRegisterGlobal jp nz, fail ld hl, sBAR ld de, 0x20 - call symRegister + call symRegisterGlobal jp nz, fail ld hl, s3 diff --git a/tools/tests/unit/test_symbol.asm b/tools/tests/unit/test_symbol.asm index 66cb5bd..1505a7f 100644 --- a/tools/tests/unit/test_symbol.asm +++ b/tools/tests/unit/test_symbol.asm @@ -26,11 +26,11 @@ test: call symInit ld hl, sFOOBAR ld de, 42 - call symRegister + call symRegisterGlobal jp nz, fail ld hl, sFOO ld de, 43 - call symRegister + call symRegisterGlobal jp nz, fail ld hl, sFOO