diff --git a/apps/basic/main.asm b/apps/basic/main.asm index 5317513..bd444bb 100644 --- a/apps/basic/main.asm +++ b/apps/basic/main.asm @@ -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 diff --git a/apps/basic/parse.asm b/apps/basic/parse.asm index a0f8511..6af0a50 100644 --- a/apps/basic/parse.asm +++ b/apps/basic/parse.asm @@ -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 diff --git a/apps/basic/tok.asm b/apps/basic/tok.asm index d0c9f3e..3631a59 100644 --- a/apps/basic/tok.asm +++ b/apps/basic/tok.asm @@ -91,7 +91,7 @@ rdExpr: call rdWord push hl ex de, hl - call parseExprDE + call parseExpr push de \ pop ix pop hl ret diff --git a/apps/basic/var.asm b/apps/basic/var.asm index a6f7af6..a10a2be 100644 --- a/apps/basic/var.asm +++ b/apps/basic/var.asm @@ -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 diff --git a/apps/lib/expr.asm b/apps/lib/expr.asm index 3a17a43..75a7559 100644 --- a/apps/lib/expr.asm +++ b/apps/lib/expr.asm @@ -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) diff --git a/apps/zasm/avr.asm b/apps/zasm/avr.asm index 2f559bd..7137614 100644 --- a/apps/zasm/avr.asm +++ b/apps/zasm/avr.asm @@ -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 diff --git a/apps/zasm/directive.asm b/apps/zasm/directive.asm index 303dea3..270c9a1 100644 --- a/apps/zasm/directive.asm +++ b/apps/zasm/directive.asm @@ -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 diff --git a/apps/zasm/instr.asm b/apps/zasm/instr.asm index 7cfdea5..da0ff64 100644 --- a/apps/zasm/instr.asm +++ b/apps/zasm/instr.asm @@ -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: diff --git a/tools/tests/unit/test_expr.asm b/tools/tests/unit/test_expr.asm index 260d42a..42f6b50 100644 --- a/tools/tests/unit/test_expr.asm +++ b/tools/tests/unit/test_expr.asm @@ -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)