From c40bc329d5cf5a242846b051d4531f301c24100a Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Mon, 20 May 2019 10:46:27 -0400 Subject: [PATCH] zasm: fix expr returning wrong values on first pass To run a parseExpr on first pass would always return a false success with dummy value because symbols are configured to always succeed on first pass. This would make expressions like ".fill 0x38-$" so bad things to labels because "0x38-$" wouldn't return the same thing on first and second pass. Revert to parsing literals and symbols after having scanned for expressions and add a special case specifically for char literals (which is why we scanned for literals and symbols first in the first place). --- apps/zasm/directive.asm | 1 + apps/zasm/expr.asm | 29 +++++++++++++++++++++++------ tools/emul/zasm/zasm.bin | Bin 4022 -> 4042 bytes 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/apps/zasm/directive.asm b/apps/zasm/directive.asm index 9c42901..8d4c8da 100644 --- a/apps/zasm/directive.asm +++ b/apps/zasm/directive.asm @@ -118,6 +118,7 @@ handleFIL: call ioPutC djnz .loop pop bc + ret handleINC: call readWord diff --git a/apps/zasm/expr.asm b/apps/zasm/expr.asm index 2b315fc..958af50 100644 --- a/apps/zasm/expr.asm +++ b/apps/zasm/expr.asm @@ -2,11 +2,6 @@ ; We expect (HL) to be disposable: we mutate it to avoid having to make a copy. ; Sets Z on success, unset on error. parseExpr: - ; Before we evaluate an expression, we first try for a regular number or - ; symbol. We do this because parsing expressions can mess up some values - ; with its splitting logic. For example '-' is going to end up '\0'. - call parseNumberOrSymbol - ret z push de push hl call _parseExpr @@ -24,7 +19,7 @@ _parseExpr: ld a, '*' call _findAndSplit jp z, _applyMult - ret ; failure + jp parseNumberOrSymbol ; Given a string in (HL) and a separator char in A, return a splitted string, ; that is, the same (HL) string but with the found A char replaced by a null @@ -32,6 +27,7 @@ _parseExpr: ; Sets Z if found, unset if not found. _findAndSplit: push hl + call .skipCharLiteral call findchar jr nz, .end ; nothing found ; Alright, we have our char and we're pointing at it. Let's replace it @@ -45,6 +41,27 @@ _findAndSplit: pop hl ; HL is back to the start ret +.skipCharLiteral: + ; special case: if our first char is ', skip the first 3 characters + ; so that we don't mistake a literal for an iterator + push af + ld a, (hl) + cp 0x27 ; ' + jr nz, .skipCharLiteralEnd ; not a ' + xor a ; check for null char during skipping + ; skip 3 + inc hl + cp (hl) + jr z, .skipCharLiteralEnd + inc hl + cp (hl) + jr z, .skipCharLiteralEnd + inc hl +.skipCharLiteralEnd: + pop af + ret +.find: + ; parse expression on the left (HL) and the right (DE) and put the results in ; DE (left) and IX (right) _resolveLeftAndRight: diff --git a/tools/emul/zasm/zasm.bin b/tools/emul/zasm/zasm.bin index f842fac705d8cda1d955db5b8f30288aa4d5765c..162e76ed72ee1f12025a04c1c18cdb79d92f4c4a 100644 GIT binary patch delta 1200 zcmY*ZZ)h837{5QsCG9oWWvR_=X__}Z+n#MFZP+?!;Wkia+gy@Pdx;8;3LX98%KAZ< zfTjvU<_E!gANoZQ!7qXsx4Ov%q7kYSNSPCUj4MT)c_&a2O*cH)P7-{;To zd7dA?_kC|8wiRP)zpXO+bkFLa65YKXrQe{r^QzniKd!&egz1&9vT!p?+8bbI8>UsS z7`5)44Ffsbv@GLUs$s)s(yANEFl;BcI8{02?t-cexqD2lT~FHZI0+Goc+1zMX2ml0 ziq0TuFH4)U7e89sHDDuIZJKtywvmLtl2!9W#c1ue)#T5f+j$vhxe;CP4A86k8P7QV zK!3|4j@?s9TuFW#@zN zhg!vm_s%0)?u3!79CMGP6F$p{&$w=@1MmJ*nieeTE1fYhlr`Xq2BXtMa;dLp-kqHo IELDtu0A&5iH~;_u delta 1264 zcmY*ZZ)h837{9xuY1*XMCGE`FH0_&3?X`8V1#Mx~+X}iR%fD(bIUKAOS@B!3pj!f( zC``I9g5?lDIVkv12s6;ZJ~YW+L~I*Kl429IME{rR%i-c6%5d4BtC%zI?0!VeL3)IP-K)rft9Evp5)aJCdDK`AMO_yoKb zCwwR$3R&+EJD(FcJ`3ozQ#b4*g)1{J?tSd@frEL{YOr=ja0eG> z1Y7X>%oEnh)VEi~j$d2};ZNg}mDkIHy$ZdIQPtKr?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