1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-23 16:18:05 +11:00

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.
parseArg:
call strlen
cp 0
or a
ret z ; empty string? A already has our result: 0
push bc
@ -157,7 +157,7 @@ parseArg:
call enterParens
jr z, .withParens
; (HL) has no parens
call parseExpr
call .maybeParseExpr
jr nz, .nomatch
; We have a proper number in no parens. Number in IX.
ld a, 'N'
@ -181,7 +181,7 @@ parseArg:
.notY:
ld c, 'x'
.parseNumberInParens:
call parseExpr
call .maybeParseExpr
jr nz, .nomatch
; We have a proper number in parens. Number in IX
ld a, c ; M, x, or y
@ -200,6 +200,16 @@ parseArg:
pop bc
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
isGroupId:
cp 0xc ; max group id + 1

View File

@ -19,6 +19,7 @@ s1: .db "2+2", 0
s2: .db "0x4001+0x22", 0
s3: .db "FOO+BAR", 0
s4: .db "3*3", 0
s5: .db "FOO-3", 0
sFOO: .db "FOO", 0
sBAR: .db "BAR", 0
@ -82,6 +83,17 @@ test:
jp nz, fail
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
xor a
halt

View File

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