mirror of
https://github.com/irmen/prog8.git
synced 2025-01-11 13:29:45 +00:00
refactor
This commit is contained in:
parent
d5d6dd3614
commit
ef46fb2685
@ -427,15 +427,11 @@ internal class AssignmentAsmGen(private val program: PtProgram,
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO use utility function assignExpressionWordOperandsLeftAYRightScratchW1() etc.
|
assignExpressionWordOperandsLeftAYRightScratchW1(expr)
|
||||||
assignExpressionToRegister(expr.left, RegisterOrPair.AY, false)
|
|
||||||
asmgen.saveRegisterStack(CpuRegister.A, false)
|
|
||||||
asmgen.saveRegisterStack(CpuRegister.Y, false)
|
|
||||||
assignExpressionToVariable(expr.right, "P8ZP_SCRATCH_W1", DataType.UWORD)
|
|
||||||
when (expr.operator) {
|
when (expr.operator) {
|
||||||
"&", "and" -> asmgen.out(" pla | and P8ZP_SCRATCH_W1+1 | tay | pla | and P8ZP_SCRATCH_W1")
|
"&", "and" -> asmgen.out(" and P8ZP_SCRATCH_W1 | pha | tya | and P8ZP_SCRATCH_W1+1 | tay | pla")
|
||||||
"|", "or" -> asmgen.out(" pla | ora P8ZP_SCRATCH_W1+1 | tay | pla | ora P8ZP_SCRATCH_W1")
|
"|", "or" -> asmgen.out(" ora P8ZP_SCRATCH_W1 | pha | tya | ora P8ZP_SCRATCH_W1+1 | tay | pla")
|
||||||
"^", "xor" -> asmgen.out(" pla | eor P8ZP_SCRATCH_W1+1 | tay | pla | eor P8ZP_SCRATCH_W1")
|
"^", "xor" -> asmgen.out(" eor P8ZP_SCRATCH_W1 | pha | tya | eor P8ZP_SCRATCH_W1+1 | tay | pla")
|
||||||
else -> throw AssemblyError("invalid operator")
|
else -> throw AssemblyError("invalid operator")
|
||||||
}
|
}
|
||||||
assignRegisterpairWord(assign.target, RegisterOrPair.AY)
|
assignRegisterpairWord(assign.target, RegisterOrPair.AY)
|
||||||
@ -473,13 +469,7 @@ internal class AssignmentAsmGen(private val program: PtProgram,
|
|||||||
return true
|
return true
|
||||||
} else if(expr.left.type in WordDatatypes && expr.right.type in WordDatatypes &&
|
} else if(expr.left.type in WordDatatypes && expr.right.type in WordDatatypes &&
|
||||||
expr.left.isSimple() && expr.right.isSimple()) {
|
expr.left.isSimple() && expr.right.isSimple()) {
|
||||||
// TODO use utility function assignExpressionWordOperandsLeftAYRightScratchW1() etc.
|
assignExpressionWordOperandsLeftAYRightScratchW1(expr)
|
||||||
assignExpressionToRegister(expr.left, RegisterOrPair.AY, false)
|
|
||||||
asmgen.saveRegisterStack(CpuRegister.A, false)
|
|
||||||
asmgen.saveRegisterStack(CpuRegister.Y, false)
|
|
||||||
assignExpressionToVariable(expr.right, "P8ZP_SCRATCH_W1", DataType.UWORD)
|
|
||||||
asmgen.restoreRegisterStack(CpuRegister.Y, false)
|
|
||||||
asmgen.restoreRegisterStack(CpuRegister.A, false)
|
|
||||||
if(expr.operator=="==") {
|
if(expr.operator=="==") {
|
||||||
asmgen.out("""
|
asmgen.out("""
|
||||||
cmp P8ZP_SCRATCH_W1
|
cmp P8ZP_SCRATCH_W1
|
||||||
@ -547,29 +537,23 @@ internal class AssignmentAsmGen(private val program: PtProgram,
|
|||||||
} else if(dt in WordDatatypes) {
|
} else if(dt in WordDatatypes) {
|
||||||
|
|
||||||
fun doAddOrSubWordExpr() {
|
fun doAddOrSubWordExpr() {
|
||||||
// TODO use utility function assignExpressionWordOperandsLeftAYRightScratchW1() etc.
|
assignExpressionWordOperandsLeftAYRightScratchW1(expr)
|
||||||
assignExpressionToRegister(left, RegisterOrPair.AY, dt==DataType.WORD)
|
|
||||||
asmgen.saveRegisterStack(CpuRegister.A, false)
|
|
||||||
asmgen.saveRegisterStack(CpuRegister.Y, false)
|
|
||||||
assignExpressionToVariable(right, "P8ZP_SCRATCH_W2", dt)
|
|
||||||
asmgen.restoreRegisterStack(CpuRegister.Y, false)
|
|
||||||
asmgen.restoreRegisterStack(CpuRegister.A, false)
|
|
||||||
if(expr.operator=="+")
|
if(expr.operator=="+")
|
||||||
asmgen.out("""
|
asmgen.out("""
|
||||||
clc
|
clc
|
||||||
adc P8ZP_SCRATCH_W2
|
adc P8ZP_SCRATCH_W1
|
||||||
pha
|
pha
|
||||||
tya
|
tya
|
||||||
adc P8ZP_SCRATCH_W2+1
|
adc P8ZP_SCRATCH_W1+1
|
||||||
tay
|
tay
|
||||||
pla""")
|
pla""")
|
||||||
else
|
else
|
||||||
asmgen.out("""
|
asmgen.out("""
|
||||||
sec
|
sec
|
||||||
sbc P8ZP_SCRATCH_W2
|
sbc P8ZP_SCRATCH_W1
|
||||||
pha
|
pha
|
||||||
tya
|
tya
|
||||||
sbc P8ZP_SCRATCH_W2+1
|
sbc P8ZP_SCRATCH_W1+1
|
||||||
tay
|
tay
|
||||||
pla""")
|
pla""")
|
||||||
assignRegisterpairWord(assign.target, RegisterOrPair.AY)
|
assignRegisterpairWord(assign.target, RegisterOrPair.AY)
|
||||||
@ -749,9 +733,7 @@ internal class AssignmentAsmGen(private val program: PtProgram,
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
in WordDatatypes -> {
|
in WordDatatypes -> {
|
||||||
// TODO use utility function assignExpressionWordOperandsLeftAYRightScratchW1() etc.
|
assignExpressionWordOperandsLeftScratchW1RightAY(expr)
|
||||||
assignExpressionToVariable(expr.left, "P8ZP_SCRATCH_W1", expr.type)
|
|
||||||
assignExpressionToRegister(expr.right, RegisterOrPair.AY, expr.type in SignedDatatypes)
|
|
||||||
asmgen.out("""
|
asmgen.out("""
|
||||||
jsr math.multiply_words
|
jsr math.multiply_words
|
||||||
lda math.multiply_words.result
|
lda math.multiply_words.result
|
||||||
@ -811,17 +793,13 @@ internal class AssignmentAsmGen(private val program: PtProgram,
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
DataType.UWORD -> {
|
DataType.UWORD -> {
|
||||||
// TODO use utility function assignExpressionWordOperandsLeftAYRightScratchW1() etc.
|
assignExpressionWordOperandsLeftScratchW1RightAY(expr)
|
||||||
assignExpressionToVariable(expr.left, "P8ZP_SCRATCH_W1", DataType.UWORD)
|
|
||||||
assignExpressionToRegister(expr.right, RegisterOrPair.AY, false)
|
|
||||||
asmgen.out(" jsr math.divmod_uw_asm")
|
asmgen.out(" jsr math.divmod_uw_asm")
|
||||||
assignRegisterpairWord(assign.target, RegisterOrPair.AY)
|
assignRegisterpairWord(assign.target, RegisterOrPair.AY)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
DataType.WORD -> {
|
DataType.WORD -> {
|
||||||
// TODO use utility function assignExpressionWordOperandsLeftAYRightScratchW1() etc.
|
assignExpressionWordOperandsLeftScratchW1RightAY(expr)
|
||||||
assignExpressionToVariable(expr.left, "P8ZP_SCRATCH_W1", DataType.WORD)
|
|
||||||
assignExpressionToRegister(expr.right, RegisterOrPair.AY, true)
|
|
||||||
asmgen.out(" jsr math.divmod_w_asm")
|
asmgen.out(" jsr math.divmod_w_asm")
|
||||||
assignRegisterpairWord(assign.target, RegisterOrPair.AY)
|
assignRegisterpairWord(assign.target, RegisterOrPair.AY)
|
||||||
return true
|
return true
|
||||||
@ -843,9 +821,7 @@ internal class AssignmentAsmGen(private val program: PtProgram,
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
DataType.UWORD -> {
|
DataType.UWORD -> {
|
||||||
// TODO use utility function assignExpressionWordOperandsLeftAYRightScratchW1() etc.
|
assignExpressionWordOperandsLeftScratchW1RightAY(expr)
|
||||||
assignExpressionToVariable(expr.left, "P8ZP_SCRATCH_W1", DataType.UWORD)
|
|
||||||
assignExpressionToRegister(expr.right, RegisterOrPair.AY, false)
|
|
||||||
asmgen.out(" jsr math.divmod_uw_asm")
|
asmgen.out(" jsr math.divmod_uw_asm")
|
||||||
assignVariableWord(assign.target, "P8ZP_SCRATCH_W2")
|
assignVariableWord(assign.target, "P8ZP_SCRATCH_W2")
|
||||||
return true
|
return true
|
||||||
|
@ -3,7 +3,6 @@ TODO
|
|||||||
|
|
||||||
For next minor release
|
For next minor release
|
||||||
^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^
|
||||||
- AssignmentAsmGen: TODO use utility function <- do that
|
|
||||||
- fix crash: uword remainder = seconds_uword % $0003 ==0
|
- fix crash: uword remainder = seconds_uword % $0003 ==0
|
||||||
- fix VM: void string.copy(".prg", &output_filename + string.length(output_filename))
|
- fix VM: void string.copy(".prg", &output_filename + string.length(output_filename))
|
||||||
- try to optimize newexpr a bit more
|
- try to optimize newexpr a bit more
|
||||||
|
Loading…
x
Reference in New Issue
Block a user