changeset 103:2f97bfecffab

Reorganize the operand matching routine
author William Astle <lost@l-w.ca>
date Mon, 30 Oct 2023 22:20:06 -0600
parents baead5689afc
children eecb576c76c6
files src/number.s
diffstat 1 files changed, 17 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/number.s	Mon Oct 30 20:48:29 2023 -0600
+++ b/src/number.s	Mon Oct 30 22:20:06 2023 -0600
@@ -18,26 +18,28 @@
 ; * If one or both operands are not numeric, raise a type mismatch
 ; The operands are in val0 and val1
 val_matchtypes  ldb val0+val.type               ; get the type of first argument
-                cmpb #valtype_int               ; is it integer?
-                beq val_matchtypes0             ; brif so
-                cmpb #valtype_float             ; is it floating point?
-                beq val_matchtypes1             ; brif so
+                cmpb val1+val.type              ; do types match?
+                bne val_matchtypes1             ; brif not
+                cmpb #valtype_int               ; integer?
+                beq val_matchtypes0             ; brif so - it's good
+                cmpb #valtype_float             ; floating point?
+                bne TMERROR                     ; brif not
+val_matchtypes0 rts                             ; types match and are good
 TMERROR         ldb #err_tm                     ; raise a type mismatch
                 jmp ERROR
-val_matchtypes0 ldb val1+val.type               ; get type of second operand
-                cmpb #valtype_int               ; is it integer?
+val_matchtypes1 cmpb #valtype_float             ; is first argument float?
                 bne val_matchtypes2             ; brif not
-val_matchtypes3 rts                             ; both types int - we're good so return
-val_matchtypes2 cmpb #valtype_float             ; is it floating point?
-                bne TMERROR                     ; brif not - raise error
-                ldx #val0                       ; convert the first argument to floating point
+                ldb val1+val.type               ; get second type
+                cmpb #valtype_int               ; is it integer?
+                bne TMERROR                     ; brif not - don't know how to convert
+                ldx #val1                       ; go convert val1 to floating point
                 jmp fps_fromint
-val_matchtypes1 ldb val1+val.type               ; get second argument type
+val_matchtypes2 cmpb #valtype_int               ; are we an integer?
+                bne TMERROR                     ; brif not - we don't know how to convert
+                ldb val1+val.type               ; get second type
                 cmpb #valtype_float             ; is it floating point?
-                beq val_matchtypes3             ; brif so - we're good
-                cmpb #valtype_int               ; is it integer?
-                bne TMERROR                     ; brif not - invalid type combination
-                ldx #val1                       ; convert the second argument to floating point
+                bne TMERROR                     ; brif not - we don't know how to convert
+                ldx #val0                       ; convert val0 to floating point
                 jmp fps_fromint
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ; Parse a number to either an integer or a floating point value and return the result in val0