fix compiler error

This commit is contained in:
Irmen de Jong 2024-04-04 02:00:55 +02:00
parent 34f3169dda
commit 5f11f485a2
3 changed files with 21 additions and 11 deletions

View File

@ -463,14 +463,16 @@ class TypecastsAdder(val program: Program, val options: CompilationOptions, val
override fun after(whenChoice: WhenChoice, parent: Node): Iterable<IAstModification> {
val conditionDt = (whenChoice.parent as When).condition.inferType(program)
val values = whenChoice.values
values?.toTypedArray()?.withIndex()?.forEach { (index, value) ->
val valueDt = value.inferType(program)
if(valueDt!=conditionDt) {
val castedValue = value.typecastTo(conditionDt.getOr(DataType.UNDEFINED), valueDt.getOr(DataType.UNDEFINED), true)
if(castedValue.first) {
castedValue.second.linkParents(whenChoice)
values[index] = castedValue.second
if(conditionDt.isKnown) {
val values = whenChoice.values
values?.toTypedArray()?.withIndex()?.forEach { (index, value) ->
val valueDt = value.inferType(program)
if(valueDt!=conditionDt) {
val castedValue = value.typecastTo(conditionDt.getOr(DataType.UNDEFINED), valueDt.getOr(DataType.UNDEFINED), true)
if(castedValue.first) {
castedValue.second.linkParents(whenChoice)
values[index] = castedValue.second
}
}
}
}

View File

@ -1,8 +1,6 @@
TODO
====
chess fails to compile (crash)
remove redundant assignments in calls like this where the result registers are the same as the assigment targets:
void, cx16.r0s, cx16.r1s = cx16.mouse_pos()
(6502 + IR)

View File

@ -4,6 +4,16 @@
main {
sub start() {
void, cx16.r0s, cx16.r1s = cx16.mouse_pos()
cx16.mouse_config2(1)
wait_mousebutton()
sub wait_mousebutton() {
do {
cx16.r0L, void, void = cx16.mouse_pos()
} until cx16.r0L!=0
do {
cx16.r0L, void, void = cx16.mouse_pos()
} until cx16.r0L==0
}
}
}