diff src/expr.s @ 80:bb50ac9fdf37

Checkpoint with very basic integer and floating point arithmetic, untested This commit has implementations for floating point add, subtract, multiply, and divide, along with 32 bit signed integer equivalents. These can probably be optimized and they are untested.
author William Astle <lost@l-w.ca>
date Sat, 07 Oct 2023 02:56:59 -0600
parents ba559f231929
children f959c92bc329
line wrap: on
line diff
--- a/src/expr.s	Sun Sep 10 23:18:17 2023 -0600
+++ b/src/expr.s	Sat Oct 07 02:56:59 2023 -0600
@@ -88,8 +88,10 @@
 ; 15. Read a character and go to step 7
 ;
 ; If the result ends up being larger than a floating point value can hold, return Overflow
-eval_number     ldb #valtype_int                ; flag result as an integer
-                stb val0_val.type
+eval_number     
+                if 0
+                ldb #valtype_int                ; flag result as an integer
+                stb val0+val.type
                 ldx zero                        ; blank out the value except type
                 stx val0
                 stx val0+2
@@ -101,7 +103,7 @@
                 beq eval_number3                ; brif so
                 cmpa #tok_minus                 ; negative (operator negative)?
                 bne eval_number2                ; brif not
-eval_number3    com val0+val.fpsign             ; invert sign (multiple negatives will flip this multiple times)
+eval_number3    com val0+val.fpssign             ; invert sign (multiple negatives will flip this multiple times)
                 bra eval_number0                ; deal with next input
 eval_number2    cmpa #'+                        ; unary +?
                 beq eval_number0                ; brif so - skip it
@@ -122,12 +124,12 @@
                 rol val0+val.int+2
                 rol val0+val.int+1
                 rol val0+val.int
-                rol val0+val.fpexp              ; overflow into fp exponent
+                rol val0+val.fpsexp              ; overflow into fp exponent
                 lsl val0+val.int+3              ; times 4
                 rol val0+val.int+2
                 rol val0+val.int+1
                 rol val0+val.int
-                rol val0+val.fpexp              ; brif overflowed
+                rol val0+val.fpsexp              ; brif overflowed
                 ldd val0+val.int+2              ; times 5 (add original value)
                 addd ,s++
                 std val0+val.int+2
@@ -135,14 +137,14 @@
                 adcb 1,s
                 adca ,s++
                 std val0+val.int
-                ldb val0+val.fpexp              ; and handle overflow bits
+                ldb val0+val.fpsexp              ; and handle overflow bits
                 adcb #0
-                stb val0+val.fpexp
+                stb val0+val.fpsexp
                 lsl val0+val.int+3              ; times 10
                 rol val0+val.int+2
                 rol val0+val.int+1
                 rol val0+val.int
-                rol val0+val.fpexp
+                rol val0+val.fpsexp
                 ldd val0+val.int+2              ; get low word
                 addb ,s+                        ; add in current digit
                 adca #0
@@ -151,9 +153,9 @@
                 adcb #0
                 adca #0
                 std val0+val.int
-                lda val0+val.fpexp              ; and handle overflow
+                lda val0+val.fpsexp              ; and handle overflow
                 adca #0
-                sta val0+val.fpexp
+                sta val0+val.fpsexp
                 bne eval_number11               ; if we overflowed, go continue parsing as floating point
                 lda val0+val.int                ; get back high byte and check for overflow
                 bpl eval_number4                ; brif we haven't wrapped negative
@@ -167,28 +169,28 @@
                 beq eval_number8                ; brif so
                 cmpa #'e                        ; base 10 exponent in lower case?
                 beq eval_number8                ; brif so
-                ldb val0+val.fpsign             ; did we want a negative value?
+                ldb val0+val.fpssign             ; did we want a negative value?
                 beq eval_number7                ; brif not
                 jsr val_negint32                ; negate the 32 bit integer to correct two's complement
-eval_number7    clr val0+val.fpsign             ; clear sign bits for book keeping
+eval_number7    clr val0+val.fpssign             ; clear sign bits for book keeping
                 rts
 eval_number11   jsr nextchar                    ; each the character already processed
 eval_number8    lda #0x9f                       ; exponent if binary point is to the right of the mantissa                           
                 clr val0extra                   ; clear extra precision bits for val0
                 ldb #valtype_float              ; flag value as floating point
                 stb val0+val.type
-                ldb val0+val.fpexp              ; do we have overflow bits to shift?
+                ldb val0+val.fpsexp              ; do we have overflow bits to shift?
                 beq eval_number10               ; brif not
 eval_number9    inca                            ; bump exponent to account for extra bits
                 lsrb                            ; shift some bits over
-                ror val0+val.fpmant
-                ror val0+val.fpmant+1
-                ror val0+val.fpmant+2
-                ror val0+val.fpmant+3
+                ror val0+val.fpssig
+                ror val0+val.fpssig+1
+                ror val0+val.fpssig+2
+                ror val0+val.fpssig+3
                 ror val0extra
                 tstb                            ; all bits shifted into mantissa?
                 bne eval_number9                ; brif not
-eval_number10   sta val0+val.fpexp              ; save adjusted exponent
+eval_number10   sta val0+val.fpsexp              ; save adjusted exponent
                 ldx #val0                       ; normalize the result for further operations
                 jsr fp_normalize
                 clr ,-s                         ; flag for decimal point seen
@@ -261,6 +263,7 @@
                 jsr val_int32tofloat            ; convert to floating point
                 jsr fp_add                      ; add val1 to val0
                 bra eval_number40               ; go handle another character
+                endc
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ; Operator table
 ;