Skip to content

Commit

Permalink
use less tempvars
Browse files Browse the repository at this point in the history
  • Loading branch information
irmen committed Sep 2, 2023
1 parent e1b3582 commit 10d0b03
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2172,23 +2172,21 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram,
// the other variable is a BYTE type so optimize for that
when (operator) {
"+" -> {
// name += byteexpression
if(valueDt==DataType.UBYTE) {
// TODO optimize: don't use scratch var
asmgen.assignExpressionToVariable(value, "P8ZP_SCRATCH_B1", valueDt)
asmgen.assignExpressionToRegister(value, RegisterOrPair.A, false)
asmgen.out("""
lda $name
clc
adc P8ZP_SCRATCH_B1
adc $name
sta $name
bcc +
inc $name+1
+""")
} else {
// TODO optimize: don't use scratch var
asmgen.assignExpressionToVariable(value, "P8ZP_SCRATCH_B1", valueDt)
asmgen.assignExpressionToRegister(value, RegisterOrPair.A, true)
asmgen.out("""
ldy #0
lda P8ZP_SCRATCH_B1
cmp #0
bpl +
dey ; sign extend
+ clc
Expand All @@ -2200,7 +2198,7 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram,
}
}
"-" -> {
// TODO optimize: don't use scratch var
// name -= byteexpression
asmgen.assignExpressionToVariable(value, "P8ZP_SCRATCH_B1", valueDt)
if(valueDt==DataType.UBYTE)
asmgen.out("""
Expand Down
1 change: 0 additions & 1 deletion docs/source/todo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ TODO
- fix on c64 target: examples/cube3d-float (broken since 9.3 with the evalstack removal) it works on x16 target, oddly enough.
More detailed and simpler code for this problem in floatproblem64.p8 / floatproblem64.asm (the minified version)

- optimize: search for TODO optimize: don't use scratch var
- prefix prog8 subroutines with p8s_ instead of p8_ to not let them clash with variables in the asm?
- allow 'chained' array indexing for expressions: value = ptrarray[0][0]
- allow 'chained' array indexing for assign targets: ptrarray[0][0] = 42 this is just evaluating the lhs as a uword pointer expression
Expand Down
9 changes: 4 additions & 5 deletions examples/test.p8
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
main {
sub start() {

uword ww= 300
@($4000) = 100
ww -= @($4000)
ww -= 100
txt.print_uw(ww) ; 100
byte bb = 20
word ww= 300
ww += bb*3
txt.print_w(ww) ; 240

; ubyte index = 100
; ubyte[] t_index = [1,2,3,4,5]
Expand Down

0 comments on commit 10d0b03

Please sign in to comment.