mirror of
https://github.com/irmen/prog8.git
synced 2024-11-27 03:50:27 +00:00
non-optimized typecast assignments now attempt to not use evalstack
This commit is contained in:
parent
23961f695d
commit
1d2d217b94
@ -11,9 +11,12 @@ import prog8.compiler.target.C64Target
|
||||
import prog8.compiler.target.Cx16Target
|
||||
import prog8.compiler.target.cbm.AssemblyProgram
|
||||
import prog8.compiler.target.cbm.loadAsmIncludeFile
|
||||
import prog8.compiler.target.cpu6502.codegen.assignment.*
|
||||
import prog8.compiler.target.cpu6502.codegen.assignment.AsmAssignSource
|
||||
import prog8.compiler.target.cpu6502.codegen.assignment.AsmAssignTarget
|
||||
import prog8.compiler.target.cpu6502.codegen.assignment.AsmAssignment
|
||||
import prog8.compiler.target.cpu6502.codegen.assignment.AssignmentAsmGen
|
||||
import prog8.compiler.target.cpu6502.codegen.assignment.SourceStorageKind
|
||||
import prog8.compilerinterface.*
|
||||
import prog8.parser.SourceCode
|
||||
import java.nio.file.Path
|
||||
@ -872,6 +875,30 @@ class AsmGen(private val program: Program,
|
||||
}
|
||||
}
|
||||
|
||||
internal fun assignExpressionTo(value: Expression, target: AsmAssignTarget) {
|
||||
// don't use asmgen.translateExpression() to avoid evalstack
|
||||
when (target.datatype) {
|
||||
in ByteDatatypes -> {
|
||||
assignExpressionToRegister(value, RegisterOrPair.A)
|
||||
assignRegister(RegisterOrPair.A, target)
|
||||
}
|
||||
in WordDatatypes, in PassByReferenceDatatypes -> {
|
||||
assignExpressionToRegister(value, RegisterOrPair.AY)
|
||||
translateNormalAssignment(
|
||||
AsmAssignment(
|
||||
AsmAssignSource(SourceStorageKind.REGISTER, program, this, target.datatype, register=RegisterOrPair.AY),
|
||||
target, false, program.memsizer, value.position
|
||||
)
|
||||
)
|
||||
}
|
||||
DataType.FLOAT -> {
|
||||
assignExpressionToRegister(value, RegisterOrPair.FAC1)
|
||||
assignRegister(RegisterOrPair.FAC1, target)
|
||||
}
|
||||
else -> throw AssemblyError("weird dt ${target.datatype}")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun translateSubroutine(sub: Subroutine) {
|
||||
var onlyVariables = false
|
||||
|
@ -13,7 +13,6 @@ import prog8.compiler.target.AssemblyError
|
||||
import prog8.compiler.target.cpu6502.codegen.assignment.AsmAssignSource
|
||||
import prog8.compiler.target.cpu6502.codegen.assignment.AsmAssignTarget
|
||||
import prog8.compiler.target.cpu6502.codegen.assignment.AsmAssignment
|
||||
import prog8.compiler.target.cpu6502.codegen.assignment.SourceStorageKind
|
||||
import prog8.compiler.target.cpu6502.codegen.assignment.TargetStorageKind
|
||||
import prog8.compilerinterface.CpuType
|
||||
|
||||
@ -148,28 +147,10 @@ internal class FunctionCallAsmGen(private val program: Program, private val asmg
|
||||
if(arg.isSimple) { // TODO FOR ALL ARG TYPES?
|
||||
// note this stuff below is needed to (eventually) avoid calling asmgen.translateExpression()
|
||||
// TODO but This STILL requires the translateNormalAssignment() to be fixed to avoid stack eval for expressions...
|
||||
// println("*** ALT PARAM PASSING FOR ASMSUB $stmt $arg") // TODO DEBUG
|
||||
when (val dt = arg.inferType(program).getOr(DataType.UNDEFINED)) {
|
||||
in ByteDatatypes -> {
|
||||
asmgen.assignExpressionToRegister(arg, RegisterOrPair.A)
|
||||
asmgen.assignRegister(RegisterOrPair.A, AsmAssignTarget(TargetStorageKind.STACK, program, asmgen, dt, sub))
|
||||
}
|
||||
in WordDatatypes, in PassByReferenceDatatypes -> {
|
||||
asmgen.assignExpressionToRegister(arg, RegisterOrPair.AY)
|
||||
asmgen.translateNormalAssignment(
|
||||
AsmAssignment(
|
||||
AsmAssignSource(SourceStorageKind.REGISTER, program, asmgen, dt, register=RegisterOrPair.AY),
|
||||
AsmAssignTarget(TargetStorageKind.STACK, program, asmgen, dt, sub),
|
||||
false, program.memsizer, arg.position
|
||||
)
|
||||
)
|
||||
}
|
||||
DataType.FLOAT -> {
|
||||
asmgen.assignExpressionToRegister(arg, RegisterOrPair.FAC1)
|
||||
asmgen.assignRegister(RegisterOrPair.FAC1, AsmAssignTarget(TargetStorageKind.STACK, program, asmgen, dt, sub))
|
||||
}
|
||||
else -> throw AssemblyError("weird dt $dt")
|
||||
}
|
||||
println("*** ALT PARAM PASSING FOR ASMSUB $stmt $arg") // TODO DEBUG
|
||||
val dt = arg.inferType(program).getOr(DataType.UNDEFINED)
|
||||
val target = AsmAssignTarget(TargetStorageKind.STACK, program, asmgen, dt, sub)
|
||||
asmgen.assignExpressionTo(arg, target)
|
||||
} else {
|
||||
asmgen.translateExpression(arg) // TODO GET RID OF THIS, if the above actually produces compact code
|
||||
}
|
||||
|
@ -427,11 +427,9 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
|
||||
}
|
||||
}
|
||||
|
||||
// give up, do it via eval stack
|
||||
// No more special optmized cases yet. Do the rest via more complex evaluation
|
||||
// note: cannot use assignTypeCastedValue because that is ourselves :P
|
||||
// TODO optimize typecasts for more special cases?
|
||||
asmgen.translateExpression(origTypeCastExpression) // this performs the actual type cast in translateExpression(Typecast)
|
||||
assignStackValue(target)
|
||||
asmgen.assignExpressionTo(origTypeCastExpression, target)
|
||||
}
|
||||
|
||||
private fun assignCastViaLsbFunc(value: Expression, target: AsmAssignTarget) {
|
||||
|
@ -181,8 +181,9 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
// TODO OTHER EVALUATION HERE
|
||||
asmgen.translateExpression(memory.addressExpression)
|
||||
asmgen.out(" jsr prog8_lib.read_byte_from_address_on_stack | sta P8ZP_SCRATCH_B1")
|
||||
asmgen.out(" jsr prog8_lib.read_byte_from_address_on_stack | sta P8ZP_SCRATCH_B1") // TODO don't use estack to transfer the address to read from
|
||||
when {
|
||||
valueLv != null -> inplaceModification_byte_litval_to_variable("P8ZP_SCRATCH_B1", DataType.UBYTE, operator, valueLv.toInt())
|
||||
ident != null -> inplaceModification_byte_variable_to_variable("P8ZP_SCRATCH_B1", DataType.UBYTE, operator, ident)
|
||||
@ -193,7 +194,7 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
|
||||
}
|
||||
else -> inplaceModification_byte_value_to_variable("P8ZP_SCRATCH_B1", DataType.UBYTE, operator, value)
|
||||
}
|
||||
asmgen.out(" lda P8ZP_SCRATCH_B1 | jsr prog8_lib.write_byte_to_address_on_stack | inx")
|
||||
asmgen.out(" lda P8ZP_SCRATCH_B1 | jsr prog8_lib.write_byte_to_address_on_stack | inx") // TODO don't use estack to transfer the address to read from
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
%import textio
|
||||
%zeropage basicsafe
|
||||
|
||||
main {
|
||||
@ -5,6 +6,8 @@ main {
|
||||
uword xx=$2000
|
||||
ubyte yy=30
|
||||
ubyte zz=9
|
||||
sys.memset(xx+200, yy*2, zz+yy)
|
||||
; sys.memset(xx+200, yy*2, zz+yy)
|
||||
|
||||
@($d020) = (xx+(yy*zz)) as ubyte
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user