Skip to content

Commit

Permalink
fix compiler error
Browse files Browse the repository at this point in the history
  • Loading branch information
irmen committed Apr 4, 2024
1 parent 34f3169 commit 5f11f48
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
18 changes: 10 additions & 8 deletions compiler/src/prog8/compiler/astprocessing/TypecastsAdder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions docs/source/todo.rst
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
12 changes: 11 additions & 1 deletion examples/test.p8
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

0 comments on commit 5f11f48

Please sign in to comment.