From bccf933ea94066ba563ee500e6846bf7d4812636 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sat, 18 May 2019 21:06:31 -0400 Subject: [PATCH] zasm: try for regular number or symbol before parsing expr Previously, we would mess up literals like '-'. --- apps/zasm/expr.asm | 7 ++++++- tools/tests/zasm/test1.asm | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/zasm/expr.asm b/apps/zasm/expr.asm index dbd82a9..41c8049 100644 --- a/apps/zasm/expr.asm +++ b/apps/zasm/expr.asm @@ -2,6 +2,11 @@ ; 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 @@ -19,7 +24,7 @@ _parseExpr: ld a, '*' call _findAndSplit jp z, _applyMult - jp parseNumberOrSymbol + ret ; failure ; 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 diff --git a/tools/tests/zasm/test1.asm b/tools/tests/zasm/test1.asm index 89f7b40..0aa25b2 100644 --- a/tools/tests/zasm/test1.asm +++ b/tools/tests/zasm/test1.asm @@ -24,3 +24,4 @@ label2: .dw 0x42 rl d rr e rlc c + cp '-'