zasm: fix false truncation error on "-" expressions

This commit is contained in:
Virgil Dupras 2019-05-18 14:51:11 -04:00
parent 650eec23de
commit 068e4327ec
3 changed files with 27 additions and 3 deletions

View File

@ -128,7 +128,7 @@ parseIXY:
; the value of that constant. ; the value of that constant.
parseArg: parseArg:
call strlen call strlen
cp 0 or a
ret z ; empty string? A already has our result: 0 ret z ; empty string? A already has our result: 0
push bc push bc
@ -157,7 +157,7 @@ parseArg:
call enterParens call enterParens
jr z, .withParens jr z, .withParens
; (HL) has no parens ; (HL) has no parens
call parseExpr call .maybeParseExpr
jr nz, .nomatch jr nz, .nomatch
; We have a proper number in no parens. Number in IX. ; We have a proper number in no parens. Number in IX.
ld a, 'N' ld a, 'N'
@ -181,7 +181,7 @@ parseArg:
.notY: .notY:
ld c, 'x' ld c, 'x'
.parseNumberInParens: .parseNumberInParens:
call parseExpr call .maybeParseExpr
jr nz, .nomatch jr nz, .nomatch
; We have a proper number in parens. Number in IX ; We have a proper number in parens. Number in IX
ld a, c ; M, x, or y ld a, c ; M, x, or y
@ -200,6 +200,16 @@ parseArg:
pop bc pop bc
ret ret
.maybeParseExpr:
; Before we try to parse expr in (HL), first check if we're in first
; pass if we are, skip parseExpr. Most of the time, that parse is
; harmless, but in some cases it causes false failures. For example,
; a "-" operator can cause is to falsely overflow and generate
; truncation error.
call zasmIsFirstPass
ret z
jp parseExpr
; Returns, with Z, whether A is a groupId ; Returns, with Z, whether A is a groupId
isGroupId: isGroupId:
cp 0xc ; max group id + 1 cp 0xc ; max group id + 1

View File

@ -19,6 +19,7 @@ s1: .db "2+2", 0
s2: .db "0x4001+0x22", 0 s2: .db "0x4001+0x22", 0
s3: .db "FOO+BAR", 0 s3: .db "FOO+BAR", 0
s4: .db "3*3", 0 s4: .db "3*3", 0
s5: .db "FOO-3", 0
sFOO: .db "FOO", 0 sFOO: .db "FOO", 0
sBAR: .db "BAR", 0 sBAR: .db "BAR", 0
@ -82,6 +83,17 @@ test:
jp nz, fail jp nz, fail
call nexttest call nexttest
ld hl, s5
call parseExpr
jp nz, fail
ld a, ixh
cp 0x3f
jp nz, fail
ld a, ixl
cp 0xfd
jp nz, fail
call nexttest
; success ; success
xor a xor a
halt halt

View File

@ -19,3 +19,5 @@ label2: .dw 0x42
ld (ix+1), l ld (ix+1), l
ld l, (ix+1) ld l, (ix+1)
ld hl, 0x100 ld hl, 0x100
.equ baz 0x20
ld b, baz-3