From 483f313eda626d91d20f77fdf976eff9d22a6511 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Thu, 24 Nov 2022 01:19:15 +0100 Subject: [PATCH] ir: keep correct child node order in blocks --- .../prog8/codegen/intermediate/IRCodeGen.kt | 19 ++++--------------- docs/source/todo.rst | 3 +-- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/codeGenIntermediate/src/prog8/codegen/intermediate/IRCodeGen.kt b/codeGenIntermediate/src/prog8/codegen/intermediate/IRCodeGen.kt index b2179599e..56463e496 100644 --- a/codeGenIntermediate/src/prog8/codegen/intermediate/IRCodeGen.kt +++ b/codeGenIntermediate/src/prog8/codegen/intermediate/IRCodeGen.kt @@ -180,14 +180,12 @@ class IRCodeGen( private fun flattenNestedSubroutines() { // 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 moves the start() entrypoint as first subroutine. val flattenedSubs = mutableListOf>() val flattenedAsmSubs = mutableListOf>() val removalsSubs = mutableListOf>() val removalsAsmSubs = mutableListOf>() val renameSubs = mutableListOf>() val renameAsmSubs = mutableListOf>() - val entrypoint = program.entrypoint() fun flattenNestedAsmSub(block: PtBlock, parentSub: PtSub, asmsub: PtAsmSub) { val flattened = PtAsmSub(asmsub.scopedName.joinToString("."), @@ -236,17 +234,8 @@ class IRCodeGen( renameSubs.forEach { (parent, sub) -> val renamedSub = PtSub(sub.scopedName.joinToString("."), sub.parameters, sub.returntype, sub.inline, sub.position) sub.children.forEach { renamedSub.add(it) } - parent.children.remove(sub) - if (sub === entrypoint) { - // 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) - } + val subindex = parent.children.indexOf(sub) + parent.children[subindex] = renamedSub // keep the order of nodes the same } renameAsmSubs.forEach { (parent, sub) -> val renamedSub = PtAsmSub(sub.scopedName.joinToString("."), @@ -260,8 +249,8 @@ class IRCodeGen( if(sub.children.isNotEmpty()) renamedSub.add(sub.children.single()) - parent.children.remove(sub) - parent.add(renamedSub) + val subindex = parent.children.indexOf(sub) + parent.children[subindex] = renamedSub // keep the order of nodes the same } } diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 26fd3468e..37cde05f5 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -3,9 +3,8 @@ TODO For next release ^^^^^^^^^^^^^^^^ -- ir/vm: check weird asm chunks appearing in block? - 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 - 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?