parseExprDE --> parseExpr

This commit is contained in:
Virgil Dupras 2019-12-23 19:13:44 -05:00
parent 5301200d6f
commit 6d88c3a754
9 changed files with 35 additions and 47 deletions

View File

@ -222,7 +222,7 @@ basPRINT:
call rdWord
push hl ; --> lvl 1
ex de, hl
call parseExprDE
call parseExpr
jr nz, .parseError
ld hl, SCRATCHPAD
call fmtDecimalS
@ -251,7 +251,7 @@ basGOTO:
ld de, SCRATCHPAD
call rdWord
ex de, hl
call parseExprDE
call parseExpr
ret nz
call bufFind
jr nz, .notFound
@ -314,7 +314,7 @@ basINPUT:
call spitQuoted
call rdSep
call stdioReadLine
call parseExprDE
call parseExpr
ld (VAR_TBL), de
call printcrlf
cp a ; ensure Z

View File

@ -40,7 +40,7 @@ parseTruth:
ret
.simple:
call parseExprDE
call parseExpr
jr nz, .end
ld a, d
or e
@ -132,11 +132,11 @@ parseTruth:
.parseLeftRight:
; let's start with HL
push de ; --> lvl 1
call parseExprDE
call parseExpr
pop hl ; <-- lvl 1, orig DE
ret nz
push de ; --> lvl 1. save HL value in stack.
; Now, for DE. (DE) is now in HL
call parseExprDE ; DE in place
call parseExpr ; DE in place
pop hl ; <-- lvl 1. restore saved HL
ret

View File

@ -91,7 +91,7 @@ rdExpr:
call rdWord
push hl
ex de, hl
call parseExprDE
call parseExpr
push de \ pop ix
pop hl
ret

View File

@ -52,7 +52,7 @@ varTryAssign:
call rdWord
ex de, hl
; Now, evaluate that expression now in (HL)
call parseExprDE ; --> number in DE
call parseExpr ; --> number in DE
jr nz, .exprErr
pop af ; <-- lvl 4
call varAssign

View File

@ -11,25 +11,12 @@
;
; *** Code ***
;
; Parse expression in string at (HL) and returns the result in IX.
; Parse expression in string at (HL) and returns the result in DE.
; **This routine mutates (HL).**
; We expect (HL) to be disposable: we mutate it to avoid having to make a copy.
; Sets Z on success, unset on error.
; TODO: the IX output register is a bit awkward. Nearly everywhere, I need
; to push \ pop that thing. See if we could return the result in DE
; instead.
parseExpr:
push de
push hl
call _parseExpr
pop hl
pop de
ret
; Same as parseExpr, but preserves IX and puts result in DE. This is a
; transitionary routine and will replace parseExpr when everyone has jumped
; ship.
parseExprDE:
push ix
push hl
call _parseExpr
@ -116,17 +103,18 @@ _resolveLeftAndRight:
or a
jr z, .skip
; Parse left operand in (HL)
push de ; --> lvl 1
call parseExpr
pop hl ; <-- lvl 1, orig DE
ret nz ; return immediately if error
.skip:
; Now we have parsed everything to the left and we have its result in
; IX. What we need to do now is the same thing on (DE) and then apply
; the + operator. Let's save IX somewhere and parse this.
ex de, hl ; right expr now in HL
push ix ; --> lvl 1
call parseExpr
pop hl ; <-- lvl 1. left
push ix \ pop de ; right
; DE. What we need to do now is the same thing on (DE) and then apply
; the + operator. Let's save DE somewhere and parse this.
push de ; --> lvl 1
; right expr in (HL)
call parseExpr ; DE is set
pop hl ; <-- lvl 1. left value
ret ; Z is parseExpr's result
; Routines in here all have the same signature: they take two numbers, DE (left)

View File

@ -644,7 +644,7 @@ _readK8:
_readDouble:
push de
call parseExprDE
call parseExpr
jr nz, .end
ld b, d
ld c, e
@ -658,7 +658,7 @@ _readk7:
push hl
push de
push ix
call parseExprDE
call parseExpr
jr nz, .end
; If we're in first pass, stop now. The value of HL doesn't matter and
; truncation checks might falsely fail.
@ -742,7 +742,7 @@ _readExpr:
push de
push bc
ld b, a
call parseExprDE
call parseExpr
jr nz, .end
ld a, b
call _DE2A

View File

@ -48,7 +48,7 @@ handleDB:
ld hl, scratchpad
call enterDoubleQuotes
jr z, .stringLiteral
call parseExprDE
call parseExpr
jr nz, .badarg
ld a, d
or a ; cp 0
@ -96,7 +96,7 @@ handleDW:
call readWord
jr nz, .badfmt
ld hl, scratchpad
call parseExprDE
call parseExpr
jr nz, .badarg
ld a, e
call ioPutB
@ -148,7 +148,7 @@ handleEQU:
call readWord
jr nz, .badfmt
ld hl, scratchpad
call parseExprDE
call parseExpr
jr nz, .badarg
ld hl, DIREC_SCRATCHPAD
; Save value in "@" special variable
@ -183,7 +183,7 @@ handleORG:
push de
call readWord
jr nz, .badfmt
call parseExprDE
call parseExpr
jr nz, .badarg
ex de, hl
ld (DIREC_LASTVAL), hl
@ -204,7 +204,7 @@ handleORG:
handleFIL:
call readWord
jr nz, .badfmt
call parseExprDE
call parseExpr
jr nz, .badarg
ld a, d
cp 0xd0
@ -243,7 +243,7 @@ handleOUT:
call zasmIsFirstPass ; No .out during first pass
jr z, .end
ld hl, scratchpad
call parseExprDE
call parseExpr
jr nz, .badarg
ld a, d
out (ZASM_DEBUG_PORT), a

View File

@ -246,7 +246,7 @@ parseArg:
ld de, 0 ; in first pass, return a clean zero
call zasmIsFirstPass
ret z
jp parseExprDE
jp parseExpr
; Returns, with Z, whether A is a groupId
isGroupId:

View File

@ -52,14 +52,14 @@ test:
; Old-style tests, not touching them now.
ld hl, s1
call parseExprDE
call parseExpr
call assertZ
ld hl, 4
call assertEQW
call nexttest
ld hl, s2
call parseExprDE
call parseExpr
call assertZ
ld hl, 0x4023
call assertEQW
@ -77,28 +77,28 @@ test:
jp nz, fail
ld hl, s3
call parseExprDE
call parseExpr
call assertZ
ld hl, 0x4020
call assertEQW
call nexttest
ld hl, s4
call parseExprDE
call parseExpr
call assertZ
ld hl, 0x60
call assertEQW
call nexttest
ld hl, s5
call parseExprDE
call parseExpr
call assertZ
ld hl, 0x3ffd
call assertEQW
call nexttest
ld hl, s6
call parseExprDE
call parseExpr
call assertZ
ld hl, 0x4080
call assertEQW
@ -132,7 +132,7 @@ testParseExpr:
.testEQ:
push iy \ pop hl
inc hl \ inc hl
call parseExprDE
call parseExpr
call assertZ
ld l, (iy)
ld h, (iy+1)