comparison src/number.s @ 103:2f97bfecffab

Reorganize the operand matching routine
author William Astle <lost@l-w.ca>
date Mon, 30 Oct 2023 22:20:06 -0600
parents b0422868a7b1
children 9d57279c900e
comparison
equal deleted inserted replaced
102:baead5689afc 103:2f97bfecffab
16 ; * If both operands are the same, ensure the type is numeric and return 16 ; * If both operands are the same, ensure the type is numeric and return
17 ; * If one operand is floating point, convert the other to floating point, as long as it is numeric 17 ; * If one operand is floating point, convert the other to floating point, as long as it is numeric
18 ; * If one or both operands are not numeric, raise a type mismatch 18 ; * If one or both operands are not numeric, raise a type mismatch
19 ; The operands are in val0 and val1 19 ; The operands are in val0 and val1
20 val_matchtypes ldb val0+val.type ; get the type of first argument 20 val_matchtypes ldb val0+val.type ; get the type of first argument
21 cmpb #valtype_int ; is it integer? 21 cmpb val1+val.type ; do types match?
22 beq val_matchtypes0 ; brif so 22 bne val_matchtypes1 ; brif not
23 cmpb #valtype_float ; is it floating point? 23 cmpb #valtype_int ; integer?
24 beq val_matchtypes1 ; brif so 24 beq val_matchtypes0 ; brif so - it's good
25 cmpb #valtype_float ; floating point?
26 bne TMERROR ; brif not
27 val_matchtypes0 rts ; types match and are good
25 TMERROR ldb #err_tm ; raise a type mismatch 28 TMERROR ldb #err_tm ; raise a type mismatch
26 jmp ERROR 29 jmp ERROR
27 val_matchtypes0 ldb val1+val.type ; get type of second operand 30 val_matchtypes1 cmpb #valtype_float ; is first argument float?
31 bne val_matchtypes2 ; brif not
32 ldb val1+val.type ; get second type
28 cmpb #valtype_int ; is it integer? 33 cmpb #valtype_int ; is it integer?
29 bne val_matchtypes2 ; brif not 34 bne TMERROR ; brif not - don't know how to convert
30 val_matchtypes3 rts ; both types int - we're good so return 35 ldx #val1 ; go convert val1 to floating point
31 val_matchtypes2 cmpb #valtype_float ; is it floating point?
32 bne TMERROR ; brif not - raise error
33 ldx #val0 ; convert the first argument to floating point
34 jmp fps_fromint 36 jmp fps_fromint
35 val_matchtypes1 ldb val1+val.type ; get second argument type 37 val_matchtypes2 cmpb #valtype_int ; are we an integer?
38 bne TMERROR ; brif not - we don't know how to convert
39 ldb val1+val.type ; get second type
36 cmpb #valtype_float ; is it floating point? 40 cmpb #valtype_float ; is it floating point?
37 beq val_matchtypes3 ; brif so - we're good 41 bne TMERROR ; brif not - we don't know how to convert
38 cmpb #valtype_int ; is it integer? 42 ldx #val0 ; convert val0 to floating point
39 bne TMERROR ; brif not - invalid type combination
40 ldx #val1 ; convert the second argument to floating point
41 jmp fps_fromint 43 jmp fps_fromint
42 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 44 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
43 ; Parse a number to either an integer or a floating point value and return the result in val0 45 ; Parse a number to either an integer or a floating point value and return the result in val0
44 ; 46 ;
45 ; This works by first detecting any sign indicators and handling those. Multiple prefix signs are supported. Note that 47 ; This works by first detecting any sign indicators and handling those. Multiple prefix signs are supported. Note that