From 42e4402afa4f72bcbaa2fb1bd1b7b6a921cce15c Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Sun, 7 Jun 2020 15:40:32 +0200 Subject: [PATCH] expression evaluation optimizations --- c64/basic/engine/ad9e.frmevl.s | 55 +++++++++++++--------------------- c64/basic/operators/oper_add.s | 2 +- 2 files changed, 22 insertions(+), 35 deletions(-) diff --git a/c64/basic/engine/ad9e.frmevl.s b/c64/basic/engine/ad9e.frmevl.s index e29c85e5..fd7f4475 100644 --- a/c64/basic/engine/ad9e.frmevl.s +++ b/c64/basic/engine/ad9e.frmevl.s @@ -34,7 +34,7 @@ FRMEVL: // XXX we also need TEMMPPT, LASTPT and TEMPST - // Put the sentinel to the stack + // Push the sentinel to the stack lda #$00 pha @@ -123,7 +123,7 @@ FRMEVL_fetch_string: FRMEVL_got_value: jsr end_of_statement_check - bcs FRMEVL_calculate + bcs FRMEVL_continue // calculate the stack if expression ended // FALLTROUGH @@ -133,48 +133,24 @@ FRMEVL_fetch_operator: // there is an operator waiting to be served jsr fetch_operator - bcs FRMEVL_calculate // branch if operator not recognized + bcs FRMEVL_continue // if operator not recognized, calculate what we have + // on stack and quit - // We have a two-argument operator - check if there is enough stack space - // XXX this can probably be checked later + // XXX check the priorities - possibly execute the current stack first + // FALLTROUGH + +FRMEVL_push_value_operator: + + // Ccheck if there is enough stack space tsx cpx #$40 // XXX is this a safe threshold? bcc_16 do_FORMULA_TOO_COMPLEX_error - // XXX check the priorities - either push to stack, or execute it immediately - - bcs FRMEVL_push_value_operator // branch always - -FRMEVL_calculate: // this is the exit point for the operators - - // Now, we have to calculate all the operations; at this point we - // should have a value in FAC1 and (possibly) operator on the top of the stack - - pla - beq FRMEVL_done // branch if sentinel - - // Priority does not matter at this point - just jump to the operator - - // FALLTROUGH - -FRMEVL_done: - - rts - -FRMEVL_push_value_operator: - // Move the operator ID in .Y tay - // Push the return address - - lda #>(FRMEVL_calculate - 1) - pha - lda #<(FRMEVL_calculate - 1) - pha - // Push the value from FAC1 ldx VALTYP @@ -199,6 +175,8 @@ FRMEVL_push_string: txa pha + // FALLTROUGH + FRMEVL_push_operator_address: // Push the operator address to stack, in a form @@ -219,3 +197,12 @@ FRMEVL_push_operator_address: // Continue jmp FRMEVL_loop + + +FRMEVL_continue: // this is the exit point for the operators + + // Now, we have to calculate all the operations; at this point we + // should have a value in FAC1 and (possibly) operator on the top of the stack + + pla // priority does not matter here, get rid of it + rts // this either jumps to operator, or quits FRMEVL diff --git a/c64/basic/operators/oper_add.s b/c64/basic/operators/oper_add.s index 5593ffab..f4d03945 100644 --- a/c64/basic/operators/oper_add.s +++ b/c64/basic/operators/oper_add.s @@ -39,4 +39,4 @@ oper_add_strings: // XXX merge strings here - rts + jmp FRMEVL_continue