mirror of
https://github.com/irmen/prog8.git
synced 2024-12-27 20:33:39 +00:00
assign type relax
This commit is contained in:
parent
f4dafec645
commit
84ec1be8a4
@ -124,6 +124,9 @@ internal class AsmAssignSource(val type: AsmSourceStorageType,
|
||||
AsmSourceStorageType.STACK -> TODO()
|
||||
}
|
||||
|
||||
fun withAdjustedDt(newType: DataType) =
|
||||
AsmAssignSource(type, program, newType, astVariable, astArray, astMemory, register, numLitval, astExpression)
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -131,4 +134,8 @@ internal class AsmAssignment(val source: AsmAssignSource,
|
||||
val target: AsmAssignTarget,
|
||||
val isAugmentable: Boolean,
|
||||
val position: Position) {
|
||||
|
||||
init {
|
||||
require(source.datatype==target.datatype) {"source and target datatype must be identical"}
|
||||
}
|
||||
}
|
||||
|
@ -19,18 +19,20 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
|
||||
private val augmentableAsmGen = AugmentableAssignmentAsmGen(program, this, asmgen)
|
||||
|
||||
internal fun translate(assignment: Assignment) {
|
||||
val source = AsmAssignSource.fromAstSource(assignment.value, program)
|
||||
var source = AsmAssignSource.fromAstSource(assignment.value, program)
|
||||
val target = AsmAssignTarget.fromAstAssignment(assignment, program, asmgen)
|
||||
val assign = AsmAssignment(source, target, assignment.isAugmentable, assignment.position)
|
||||
|
||||
// assert that the source and target types are identical (with some signed/unsigned relaxations)
|
||||
// allow some signed/unsigned relaxations
|
||||
if(target.datatype!=source.datatype) {
|
||||
if (!(target.datatype in ByteDatatypes && source.datatype in ByteDatatypes ||
|
||||
target.datatype in WordDatatypes && source.datatype in WordDatatypes)) {
|
||||
throw AssemblyError("assignment type incompatibility ${target.datatype}=${source.datatype}")
|
||||
if(target.datatype in ByteDatatypes && source.datatype in ByteDatatypes) {
|
||||
source = source.withAdjustedDt(target.datatype)
|
||||
} else if(target.datatype in WordDatatypes && source.datatype in WordDatatypes) {
|
||||
source = source.withAdjustedDt(target.datatype)
|
||||
}
|
||||
}
|
||||
|
||||
val assign = AsmAssignment(source, target, assignment.isAugmentable, assignment.position)
|
||||
|
||||
when {
|
||||
source.type==AsmSourceStorageType.LITERALNUMBER -> translateConstantValueAssignment(assign)
|
||||
source.type==AsmSourceStorageType.VARIABLE -> translateVariableAssignment(assign)
|
||||
|
Loading…
Reference in New Issue
Block a user