Mercurial > hg > index.cgi
annotate 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 |
rev | line source |
---|---|
75
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
1 *pragmapush list |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
2 *pragma list |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
4 ; The LET command which is the default if no token begins a statement |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
5 cmd_let jmp SNERROR ; not yet implemented |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
6 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
7 ; Expression Evaluation Package |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
8 ; |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
9 ; This is the expression evaluator. It handles everything from parsing numbers to dispatching function calls. The main |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
10 ; entry point is eval_expr which will evaluate an arbitrary expression. It returns as soon as it reaches something it |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
11 ; doesn't understand as part of an expression. |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
12 ; |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
13 ; The special handling for relational operators is required because Basic allows them in all |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
14 eval_expr clrb ; flag previous operator as minimum precdence (end of expression) |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
15 eval_expraux jsr eval_term ; evaluate the first term of the expression |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
16 eval_expr0 jsr curchar ; fetch current input |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
17 beq eval_expr1 ; brif end of expression - we're done |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
18 cmpa #tok_or ; is it above operators? |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
19 bhi eval_expr1 ; brif so |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
20 suba #tok_plus ; offset to zero for first operator token |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
21 bcc eval_expr2 ; brif it is an operator |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
22 eval_expr1 rts |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
23 eval_expr2 pshs b ; save previous operator precedence |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
24 ldx #oper_tab ; point to operator table |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
25 tfr a,b ; shift to B for "ABX" |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
26 abx ; add three times (3 bytes per entry) |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
27 abx ; OBS: TFR + ABX + ABX + ABX is faster than LDB + MUL + ABX |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
28 abx ; now X points to the operator entry in the table |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
29 ldb ,x ; get precedence of current operation |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
30 cmpb ,s ; is it higher than the current operation? |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
31 bhi eval_expr3 ; brif so - process this operator |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
32 puls b,pc ; return current value to complete previous operation |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
33 eval_expr3 jsr nextchar ; eat the operator token |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
34 ldx 1,x ; get handler address of this operator |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
35 leas -val.size,s ; make room for the result accumulator |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
36 pshs x ; save handler address for later |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
37 lda val0+val.type ; get current value type |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
38 ldx val0 ; get value accumlator contents (6 bytes) |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
39 ldy val0+2 |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
40 ldu val0+4 |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
41 pshs a,x,y,u ; save it on the stack |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
42 jsr eval_expraux ; evaluate the following term and higher precedence expressions |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
43 puls a,x,y,u ; get back saved value |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
44 stx val1 ; save it to the second value accumulator |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
45 sty val1+2 |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
46 stu val1+4 |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
47 sta val1+val.type ; save previous value type |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
48 ldx #val1 ; point to left operand |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
49 ldu #val0 ; point to right operand |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
50 leay 2,s ; point to return value location |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
51 jsr [,s++] ; go handle the operator |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
52 puls a,x,y,u ; get return value |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
53 sta val0 |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
54 stx val0+1 |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
55 sty val0+3 |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
56 stu val0+5 |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
57 puls b ; get back the previous operator precedence |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
58 bra eval_expr0 ; go process another operator or end of expression |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
59 eval_term jsr curchar ; get current input character |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
60 beq eval_term0 ; brif end of input - this is an error |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
61 bcs eval_number ; brif digit - we have a number |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
62 ; bmi eval_func ; brif we have a token - handle function call |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
63 cmpa #'. ; decimal point? |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
64 beq eval_number ; brif so - evaluate number |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
65 cmpa #'- ; negative sign? |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
66 beq eval_number ; brif so - evaluate number |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
67 cmpa #'+ ; positive sign? |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
68 beq eval_number ; brif so - evaluate number |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
69 eval_term0 jmp SNERROR ; we have something unrecognized - raise error |
77
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
70 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
71 ; Evaluate a numeric constant. This process works as follows: |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
72 ; |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
73 ; 0. Clear the value to a zero integer |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
74 ; 1. Check for signs and flag appropriately |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
75 ; 2. Read character |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
76 ; 3. If decimal or exponential indicator, go to step 6 |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
77 ; 4. If not digit, return integer result |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
78 ; 5. Multiply accumulator by 10 and add digit value; go back to step 2 |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
79 ; 6. Convert accumulator to floating point; set accumulated decimal exponent and decimal flag to 0 |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
80 ; 7. If decimal point, flag decimal seen (0xff) and go to step 15 (or raise error if second decimal point) |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
81 ; 8. If digit, multiply by 10 and add digit value; go to step 15 |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
82 ; 9. If E or e, go handle decimal exponent at step 12 |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
83 ; 10. Apply accumulated decimal exponent to the result (through multiplication/division by 10) |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
84 ; 11. Return floating point result |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
85 ; 12. Read character |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
86 ; 13. If not digit, go handle return at step 10 |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
87 ; 14. Multiply exponent accumulator by 10 and add digit value; raise error on overflow or go back to step 12 |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
88 ; 15. Read a character and go to step 7 |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
89 ; |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
90 ; If the result ends up being larger than a floating point value can hold, return Overflow |
80
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
77
diff
changeset
|
91 eval_number |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
77
diff
changeset
|
92 if 0 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
77
diff
changeset
|
93 ldb #valtype_int ; flag result as an integer |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
77
diff
changeset
|
94 stb val0+val.type |
77
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
95 ldx zero ; blank out the value except type |
75
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
96 stx val0 |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
97 stx val0+2 |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
98 stx val0+4 |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
99 bra eval_number1 ; go do the parsing |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
100 eval_number0 jsr nextchar ; fetch next input |
77
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
101 beq eval_number6 ; brif end of expression - bail |
75
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
102 eval_number1 cmpa #'- ; negative (ascii sign)? |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
103 beq eval_number3 ; brif so |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
104 cmpa #tok_minus ; negative (operator negative)? |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
105 bne eval_number2 ; brif not |
80
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
77
diff
changeset
|
106 eval_number3 com val0+val.fpssign ; invert sign (multiple negatives will flip this multiple times) |
75
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
107 bra eval_number0 ; deal with next input |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
108 eval_number2 cmpa #'+ ; unary +? |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
109 beq eval_number0 ; brif so - skip it |
77
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
110 cmpa #tok_plus ; unary + (operator plus)? |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
111 beq eval_number0 ; brif so - skip it |
75
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
112 eval_number5 cmpa #'. ; decimal point? |
77
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
113 beq eval_number8 ; brif decimal - force float |
75
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
114 cmpa #'0 ; is it a number? |
77
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
115 blo eval_number6 ; brif below digit |
75
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
116 cmpa #'9 ; is it still a number? |
77
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
117 bhi eval_number6 ; brif above digit |
75
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
118 suba #'0 ; offset to binary digit value |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
119 pshs a ; save digit value |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
120 ldx val0+val.int ; get current value for later (for quick multiply by 10) |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
121 ldd val0+val.int+2 |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
122 pshs d,x ; stored with words swapped on stack for efficiency for later |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
123 lsl val0+val.int+3 ; times 2 |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
124 rol val0+val.int+2 |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
125 rol val0+val.int+1 |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
126 rol val0+val.int |
80
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
77
diff
changeset
|
127 rol val0+val.fpsexp ; overflow into fp exponent |
75
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
128 lsl val0+val.int+3 ; times 4 |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
129 rol val0+val.int+2 |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
130 rol val0+val.int+1 |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
131 rol val0+val.int |
80
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
77
diff
changeset
|
132 rol val0+val.fpsexp ; brif overflowed |
75
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
133 ldd val0+val.int+2 ; times 5 (add original value) |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
134 addd ,s++ |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
135 std val0+val.int+2 |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
136 ldd val0+val.int |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
137 adcb 1,s |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
138 adca ,s++ |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
139 std val0+val.int |
80
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
77
diff
changeset
|
140 ldb val0+val.fpsexp ; and handle overflow bits |
77
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
141 adcb #0 |
80
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
77
diff
changeset
|
142 stb val0+val.fpsexp |
75
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
143 lsl val0+val.int+3 ; times 10 |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
144 rol val0+val.int+2 |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
145 rol val0+val.int+1 |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
146 rol val0+val.int |
80
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
77
diff
changeset
|
147 rol val0+val.fpsexp |
75
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
148 ldd val0+val.int+2 ; get low word |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
149 addb ,s+ ; add in current digit |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
150 adca #0 |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
151 std val0+val.int+2 |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
152 ldd val0+val.int |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
153 adcb #0 |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
154 adca #0 |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
155 std val0+val.int |
80
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
77
diff
changeset
|
156 lda val0+val.fpsexp ; and handle overflow |
77
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
157 adca #0 |
80
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
77
diff
changeset
|
158 sta val0+val.fpsexp |
77
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
159 bne eval_number11 ; if we overflowed, go continue parsing as floating point |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
160 lda val0+val.int ; get back high byte and check for overflow |
75
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
161 bpl eval_number4 ; brif we haven't wrapped negative |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
162 cmpd #0x8000 ; is it valid negative two's complement? |
77
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
163 bhi eval_number11 ; brif not - we're in floating point territory |
75
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
164 ldd val0+val.int+2 ; is it still valid two's complement (max negative)? |
77
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
165 bne eval_number11 ; brif not - we're in floating point territory |
75
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
166 eval_number4 jsr nextchar ; fetch next input character |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
167 bra eval_number5 ; go handle it |
77
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
168 eval_number6 cmpa #'E ; base 10 exponent? |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
169 beq eval_number8 ; brif so |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
170 cmpa #'e ; base 10 exponent in lower case? |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
171 beq eval_number8 ; brif so |
80
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
77
diff
changeset
|
172 ldb val0+val.fpssign ; did we want a negative value? |
77
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
173 beq eval_number7 ; brif not |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
174 jsr val_negint32 ; negate the 32 bit integer to correct two's complement |
80
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
77
diff
changeset
|
175 eval_number7 clr val0+val.fpssign ; clear sign bits for book keeping |
77
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
176 rts |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
177 eval_number11 jsr nextchar ; each the character already processed |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
178 eval_number8 lda #0x9f ; exponent if binary point is to the right of the mantissa |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
179 clr val0extra ; clear extra precision bits for val0 |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
180 ldb #valtype_float ; flag value as floating point |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
181 stb val0+val.type |
80
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
77
diff
changeset
|
182 ldb val0+val.fpsexp ; do we have overflow bits to shift? |
77
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
183 beq eval_number10 ; brif not |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
184 eval_number9 inca ; bump exponent to account for extra bits |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
185 lsrb ; shift some bits over |
80
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
77
diff
changeset
|
186 ror val0+val.fpssig |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
77
diff
changeset
|
187 ror val0+val.fpssig+1 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
77
diff
changeset
|
188 ror val0+val.fpssig+2 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
77
diff
changeset
|
189 ror val0+val.fpssig+3 |
77
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
190 ror val0extra |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
191 tstb ; all bits shifted into mantissa? |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
192 bne eval_number9 ; brif not |
80
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
77
diff
changeset
|
193 eval_number10 sta val0+val.fpsexp ; save adjusted exponent |
77
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
194 ldx #val0 ; normalize the result for further operations |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
195 jsr fp_normalize |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
196 clr ,-s ; flag for decimal point seen |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
197 clr ,-s ; current decimal exponent value |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
198 jsr curchar ; get current input character |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
199 bra eval_number20 ; go evaluate the floating point value |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
200 eval_number40 jsr nextchar ; fetch next input |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
201 eval_number20 bcs eval_number29 ; brif digit |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
202 cmpa #'. ; is it a decimal? |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
203 bne eval_number21 ; brif not |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
204 com 1,s ; flag decimal seen |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
205 bne eval_number40 |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
206 jmp SNERROR ; brif unexpected second decimal point |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
207 eval_number21 cmpa #'E ; decimal exponent? |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
208 beq eval_number26 ; brif so |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
209 cmpa #'e ; decimal exponent lower case? |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
210 beq eval_number26 |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
211 eval_number22 ldb ,s ; get decimal exponent count and set flags |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
212 beq eval_number25 ; brif no adjustment needed |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
213 bmi eval_number24 ; brif we need to divide |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
214 eval_number23 jsr fp_mul10 ; multiply by 10 |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
215 dec ,s ; done? |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
216 bne eval_number23 ; brif not |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
217 rts |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
218 eval_number24 jsr fp_div10 ; divide by 10 |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
219 inc ,s ; done? |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
220 bne eval_number24 ; brif not |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
221 eval_number25 rts |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
222 eval_number26 clrb ; blank out decimal exponent accumulator |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
223 clr ,-s ; set sign positive |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
224 jsr nextchar ; get next input |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
225 bcs eval_number28 ; brif digit - positive exponent |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
226 cmpa #'+ ; positive? |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
227 beq eval_number27 ; brif so - skip it |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
228 cmpa #tok_plus ; positive (plus operator)? |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
229 beq eval_number27 |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
230 cmpa #'- ; negative? |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
231 beq eval_number30 ; brif so |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
232 cmpa #tok_minus ; negative (minus operator)? |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
233 bne eval_number31 ; brif not |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
234 eval_number30 com ,s ; get sign negative |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
235 eval_number27 jsr nextchar ; get next character |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
236 bcs eval_number28 ; brif digit |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
237 eval_number31 lda ,s+ ; get negative flag, set flags, and clean up the stack |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
238 beq eval_number32 ; brif positive |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
239 negb ; we have a negative decimal exponent - handle it |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
240 eval_number32 addb ,s ; add in decimal exponent adjustment |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
241 stb ,s ; save it for cleanup |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
242 bra eval_number22 ; go finish up |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
243 eval_number28 suba #'0 ; digit-ize it |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
244 pshs a ; save it for later |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
245 lda #10 ; multiply value by 10 and add digit |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
246 mul |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
247 addb ,s+ |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
248 bpl eval_number27 ; go handle another digit if we didn't overflow negative |
75
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
249 OVERROR ldb #err_ov ; flag overflow |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
250 jmp ERROR |
77
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
251 eval_number29 ldb ,s ; get exponent adjustment |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
252 addb 1,s ; subtract if decimal point was seen for later fixup |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
253 stb 1,s |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
254 suba #'0 ; digit-ize the character |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
255 pshs a ; save it for later |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
256 jsr fp_mul10 ; multiply by 10 |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
257 jsr val0toval1 ; save residue |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
258 puls b ; get back digit value |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
259 clra ; make it floating point |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
260 std val0+val.int+2 |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
261 sta val0+val.int+1 |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
262 sta val0+val.int |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
263 jsr val_int32tofloat ; convert to floating point |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
264 jsr fp_add ; add val1 to val0 |
ba559f231929
Initial modification for number parser that handles floats and ints
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
265 bra eval_number40 ; go handle another character |
80
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
77
diff
changeset
|
266 endc |
75
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
267 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
268 ; Operator table |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
269 ; |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
270 ; Each entry starts with the precedence value followed by the handler routine. Each handler will receive its left |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
271 ; operand in val1 and its right operand in val0 and should return its result in val0. |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
272 oper_tab fcb 0x79 ; addition |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
273 fdb oper_plus |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
274 fcb 0x79 ; subtraction |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
275 fdb oper_minus |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
276 fcb 0x7b ; multiplication |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
277 fdb SNERROR |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
278 fcb 0x7b ; division |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
279 fdb SNERROR |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
280 fcb 0x7f ; exponentiation |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
281 fdb SNERROR |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
282 fcb 0x64 ; less than |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
283 fdb SNERROR |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
284 fcb 0x64 ; equal to |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
285 fdb SNERROR |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
286 fcb 0x64 ; greater than |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
287 fdb SNERROR |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
288 fcb 0x64 ; less than or equal to |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
289 fdb SNERROR |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
290 fcb 0x64 ; greater than or equal to |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
291 fdb SNERROR |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
292 fcb 0x64 ; not equal to |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
293 fdb SNERROR |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
294 fcb 0x50 ; boolean AND |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
295 fdb SNERROR |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
296 fcb 0x46 ; boolean OR |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
297 fdb SNERROR |
76
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
75
diff
changeset
|
298 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
75
diff
changeset
|
299 ; Operator handling routines |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
75
diff
changeset
|
300 ; |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
75
diff
changeset
|
301 ; binary plus: addition and concatenation |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
75
diff
changeset
|
302 oper_plus ldb val.type,x ; get type of the left operand |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
75
diff
changeset
|
303 cmpb valtype_string ; is it string? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
75
diff
changeset
|
304 bne oper_plus0 ; brif not |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
75
diff
changeset
|
305 cmpb val.type,u ; is right operand also string? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
75
diff
changeset
|
306 lbeq SNERROR ; brif so - do string concatenation |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
75
diff
changeset
|
307 oper_plus0 jsr val_matchtypes ; go match data types |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
75
diff
changeset
|
308 jmp val_add ; go add the values |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
75
diff
changeset
|
309 ; binary minus: subtraction |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
75
diff
changeset
|
310 oper_minus jsr val_matchtypes ; go match data types |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
75
diff
changeset
|
311 jmp val_sub ; do subtraction |
75
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
312 *pragmapop list |