# HG changeset patch # User William Astle # Date 1688286833 21600 # Node ID f4b2406d7352e297cd3ae8f7990d337b205bf462 # Parent eb7c96671f5b2bb72ae1fd137640c947d167e9b6 Add numeric argument matching routine Numeric calculations need to either match types or do type promotion to matching types. Add a routine to handle that and have the routine through a type mismatch if the types are not compatible or not numeric. Note that this will require special handling for string concatenation and comparision which are obviously not numeric. diff -r eb7c96671f5b -r f4b2406d7352 src/lwbasic.s --- a/src/lwbasic.s Sun Jul 02 01:58:58 2023 -0600 +++ b/src/lwbasic.s Sun Jul 02 02:33:53 2023 -0600 @@ -1865,6 +1865,38 @@ ; ; Most routines take a pointer to a value accumulator in X. Some take two pointers with the second in U. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Match operands for a numeric calculation. This works as follows: +; +; * If both operands are the same, ensure the type is numeric and return +; * If one operand is floating point, convert the other to floating point, as long as it is numeric +; * If one or both oeprands are not numeric, raise a type mismatch +; The operands are in (X) and (U) +val_matchtypes ldb val.type,x ; 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 +TMERROR ldb #err_tm ; raise a type mismatch + jmp ERROR +val_matchtypes0 ldb val.type,u ; get type of second operand + cmpb #valtype_int ; is it integer? + bne val_matchtypes2 ; brif not +val_matchtypes3 rts +val_matchtypes2 cmpb #valtype_float ; is it floating point? + bne TMERROR ; brif not - raise error + pshs u ; save pointer to second operand + bsr val_int32tofp ; convert first argument to floating point + puls u,pc ; restore second operand pointer and return +val_matchtypes1 ldb val.type,u ; get second argument 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 + pshs x,u ; save value pointers + leax ,u ; convert (U) to floating point + bsr val_int32tofp + puls x,u,pc ; restore argument pointers and return +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Negate the 32 bit integer (for fp mantissa) at (X) val_negint32 ldd zero ; subtract integer value from zero subd val.int+2,x