mirror of
https://github.com/irmen/prog8.git
synced 2024-12-24 16:29:21 +00:00
remove empty when choices, fixes ir compilation error on those
This commit is contained in:
parent
334d382bfa
commit
d2154f5f2e
@ -99,14 +99,16 @@ class IRCodeGen(
|
||||
// make sure that first chunks in Blocks and Subroutines share the name of the block/sub as label.
|
||||
|
||||
irProg.blocks.forEach { block ->
|
||||
block.children.firstOrNull { it is IRInlineAsmChunk }?.let { first->
|
||||
first as IRInlineAsmChunk
|
||||
if(first.label==null) {
|
||||
val replacement = IRInlineAsmChunk(block.label, first.assembly, first.isIR, first.next)
|
||||
block.children.removeAt(0)
|
||||
block.children.add(0, replacement)
|
||||
} else if(first.label != block.label) {
|
||||
throw AssemblyError("first chunk in block has label that differs from block name")
|
||||
if(block.isNotEmpty()) {
|
||||
val firstAsm = block.children[0] as? IRInlineAsmChunk
|
||||
if(firstAsm!=null) {
|
||||
if(firstAsm.label==null) {
|
||||
val replacement = IRInlineAsmChunk(block.label, firstAsm.assembly, firstAsm.isIR, firstAsm.next)
|
||||
block.children.removeAt(0)
|
||||
block.children.add(0, replacement)
|
||||
} else if(firstAsm.label != block.label) {
|
||||
throw AssemblyError("first chunk in block has label that differs from block name")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -262,5 +262,15 @@ internal class VariousCleanups(val program: Program, val errors: IErrorReporter,
|
||||
}
|
||||
return noModifications
|
||||
}
|
||||
|
||||
override fun after(whenStmt: When, parent: Node): Iterable<IAstModification> {
|
||||
val removals = mutableListOf<Int>()
|
||||
whenStmt.choices.withIndex().forEach { (index, choice) ->
|
||||
if(choice.statements.isEmpty())
|
||||
removals.add(index)
|
||||
}
|
||||
removals.reversed().forEach { whenStmt.choices.removeAt(it) }
|
||||
return noModifications
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -451,4 +451,26 @@ main {
|
||||
}
|
||||
}
|
||||
|
||||
test("asm chunk labels in IR code") {
|
||||
val src="""
|
||||
main {
|
||||
sub start() {
|
||||
instructions.match()
|
||||
}
|
||||
}
|
||||
|
||||
instructions {
|
||||
asmsub match() {
|
||||
%asm {{
|
||||
rts
|
||||
}}
|
||||
}
|
||||
|
||||
%asm {{
|
||||
nop
|
||||
}}
|
||||
}"""
|
||||
compileText(VMTarget(), false, src, writeAssembly = true) shouldNotBe null
|
||||
}
|
||||
|
||||
})
|
@ -1,8 +1,6 @@
|
||||
TODO
|
||||
====
|
||||
|
||||
- Fix expericodegen errors (assem, rockrunners)
|
||||
|
||||
...
|
||||
|
||||
|
||||
|
@ -1,41 +1,18 @@
|
||||
%import textio
|
||||
|
||||
main {
|
||||
|
||||
sub start() {
|
||||
; uword[] routines = [ 0, &command, $4444 ]
|
||||
; cx16.r0 = routines[1]
|
||||
|
||||
&ubyte[5] cells = $4000
|
||||
cells = [1,2,3,4,5]
|
||||
str name = "irmen"
|
||||
|
||||
ubyte[5] othercells = [11,22,33,44,55]
|
||||
|
||||
txt.print_ub(1 in cells)
|
||||
txt.print_ub(44 in othercells)
|
||||
txt.print_ub('a' in name)
|
||||
txt.print_ub('e' in name)
|
||||
txt.nl()
|
||||
txt.print_ub(all(othercells))
|
||||
txt.print_ub(any(othercells))
|
||||
othercells[3] = 0
|
||||
txt.print_ub(all(othercells))
|
||||
txt.print_ub(any(othercells))
|
||||
reverse(othercells)
|
||||
sort(othercells)
|
||||
txt.nl()
|
||||
|
||||
txt.print_ub(all(cells))
|
||||
txt.print_ub(any(cells))
|
||||
cells[3] = 0
|
||||
txt.print_ub(all(cells))
|
||||
txt.print_ub(any(cells))
|
||||
reverse(cells)
|
||||
sort(cells)
|
||||
}
|
||||
|
||||
sub command() {
|
||||
cx16.r0++
|
||||
cx16.r0 = 2
|
||||
when cx16.r0 {
|
||||
1-> {
|
||||
;nothing
|
||||
}
|
||||
2 -> {
|
||||
txt.print("two")
|
||||
}
|
||||
0-> {
|
||||
;nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user