mirror of
https://github.com/irmen/prog8.git
synced 2025-02-04 17:38:37 +00:00
ir: keep correct child node order in blocks
This commit is contained in:
parent
7b6c742178
commit
483f313eda
@ -180,14 +180,12 @@ class IRCodeGen(
|
|||||||
private fun flattenNestedSubroutines() {
|
private fun flattenNestedSubroutines() {
|
||||||
// this moves all nested subroutines up to the block scope.
|
// this moves all nested subroutines up to the block scope.
|
||||||
// also changes the name to be the fully scoped one, so it becomes unique at the top level.
|
// also changes the name to be the fully scoped one, so it becomes unique at the top level.
|
||||||
// also moves the start() entrypoint as first subroutine.
|
|
||||||
val flattenedSubs = mutableListOf<Pair<PtBlock, PtSub>>()
|
val flattenedSubs = mutableListOf<Pair<PtBlock, PtSub>>()
|
||||||
val flattenedAsmSubs = mutableListOf<Pair<PtBlock, PtAsmSub>>()
|
val flattenedAsmSubs = mutableListOf<Pair<PtBlock, PtAsmSub>>()
|
||||||
val removalsSubs = mutableListOf<Pair<PtSub, PtSub>>()
|
val removalsSubs = mutableListOf<Pair<PtSub, PtSub>>()
|
||||||
val removalsAsmSubs = mutableListOf<Pair<PtSub, PtAsmSub>>()
|
val removalsAsmSubs = mutableListOf<Pair<PtSub, PtAsmSub>>()
|
||||||
val renameSubs = mutableListOf<Pair<PtBlock, PtSub>>()
|
val renameSubs = mutableListOf<Pair<PtBlock, PtSub>>()
|
||||||
val renameAsmSubs = mutableListOf<Pair<PtBlock, PtAsmSub>>()
|
val renameAsmSubs = mutableListOf<Pair<PtBlock, PtAsmSub>>()
|
||||||
val entrypoint = program.entrypoint()
|
|
||||||
|
|
||||||
fun flattenNestedAsmSub(block: PtBlock, parentSub: PtSub, asmsub: PtAsmSub) {
|
fun flattenNestedAsmSub(block: PtBlock, parentSub: PtSub, asmsub: PtAsmSub) {
|
||||||
val flattened = PtAsmSub(asmsub.scopedName.joinToString("."),
|
val flattened = PtAsmSub(asmsub.scopedName.joinToString("."),
|
||||||
@ -236,17 +234,8 @@ class IRCodeGen(
|
|||||||
renameSubs.forEach { (parent, sub) ->
|
renameSubs.forEach { (parent, sub) ->
|
||||||
val renamedSub = PtSub(sub.scopedName.joinToString("."), sub.parameters, sub.returntype, sub.inline, sub.position)
|
val renamedSub = PtSub(sub.scopedName.joinToString("."), sub.parameters, sub.returntype, sub.inline, sub.position)
|
||||||
sub.children.forEach { renamedSub.add(it) }
|
sub.children.forEach { renamedSub.add(it) }
|
||||||
parent.children.remove(sub)
|
val subindex = parent.children.indexOf(sub)
|
||||||
if (sub === entrypoint) {
|
parent.children[subindex] = renamedSub // keep the order of nodes the same
|
||||||
// entrypoint sub must be first sub
|
|
||||||
val firstsub = parent.children.withIndex().firstOrNull() { it.value is PtSub || it.value is PtAsmSub }
|
|
||||||
if(firstsub!=null)
|
|
||||||
parent.add(firstsub.index, renamedSub)
|
|
||||||
else
|
|
||||||
parent.add(renamedSub)
|
|
||||||
} else {
|
|
||||||
parent.add(renamedSub)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
renameAsmSubs.forEach { (parent, sub) ->
|
renameAsmSubs.forEach { (parent, sub) ->
|
||||||
val renamedSub = PtAsmSub(sub.scopedName.joinToString("."),
|
val renamedSub = PtAsmSub(sub.scopedName.joinToString("."),
|
||||||
@ -260,8 +249,8 @@ class IRCodeGen(
|
|||||||
|
|
||||||
if(sub.children.isNotEmpty())
|
if(sub.children.isNotEmpty())
|
||||||
renamedSub.add(sub.children.single())
|
renamedSub.add(sub.children.single())
|
||||||
parent.children.remove(sub)
|
val subindex = parent.children.indexOf(sub)
|
||||||
parent.add(renamedSub)
|
parent.children[subindex] = renamedSub // keep the order of nodes the same
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,9 +3,8 @@ TODO
|
|||||||
|
|
||||||
For next release
|
For next release
|
||||||
^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^
|
||||||
- ir/vm: check weird asm chunks appearing in block?
|
|
||||||
- try to get the cx16 adpcm example to output audio
|
- try to get the cx16 adpcm example to output audio
|
||||||
- duplicate diskio for cx16 (get rid of cx16diskio, just copy diskio and tweak everything)
|
- duplicate diskio for cx16 (get rid of cx16diskio, just copy diskio and tweak everything) + documentation
|
||||||
- get f_seek_w working like in the BASIC program - this needs the changes to diskio.f_open to use suffixes ,p,m
|
- get f_seek_w working like in the BASIC program - this needs the changes to diskio.f_open to use suffixes ,p,m
|
||||||
- attempt to fix the expression codegen bug with reused temp vars (github #89)
|
- attempt to fix the expression codegen bug with reused temp vars (github #89)
|
||||||
- AstIdentifiersChecker: can a subroutine really not have the same name as its enclosing block? 64tass problem?
|
- AstIdentifiersChecker: can a subroutine really not have the same name as its enclosing block? 64tass problem?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user