diff --git a/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt index 79ba9fd67..6a60a76c4 100644 --- a/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt +++ b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt @@ -1304,7 +1304,7 @@ $repeatLabel lda $counterVar } inits.add(stmt) } else { - val next = (stmt.parent as IStatementContainer).nextSibling(stmt) + val next = stmt.nextSibling() if (next !is ForLoop || next.loopVar.nameInSource.single() != stmt.name) { assignInitialValueToVar(stmt, listOf(stmt.name)) } diff --git a/codeOptimizers/src/prog8/optimizer/UnusedCodeRemover.kt b/codeOptimizers/src/prog8/optimizer/UnusedCodeRemover.kt index 770215803..9fd0cf848 100644 --- a/codeOptimizers/src/prog8/optimizer/UnusedCodeRemover.kt +++ b/codeOptimizers/src/prog8/optimizer/UnusedCodeRemover.kt @@ -51,7 +51,7 @@ class UnusedCodeRemover(private val program: Program, } private fun reportUnreachable(stmt: Statement, parent: IStatementContainer) { - when(val next = parent.nextSibling(stmt)) { + when(val next = stmt.nextSibling()) { null, is Label, is Directive, is VarDecl, is InlineAssembly, is Subroutine -> {} else -> errors.warn("unreachable code", next.position) } diff --git a/compilerAst/src/prog8/ast/AstToplevel.kt b/compilerAst/src/prog8/ast/AstToplevel.kt index 0879b609f..7e8ef2b85 100644 --- a/compilerAst/src/prog8/ast/AstToplevel.kt +++ b/compilerAst/src/prog8/ast/AstToplevel.kt @@ -56,22 +56,6 @@ interface IStatementContainer { return result } - fun nextSibling(stmt: Statement): Statement? { - val nextIdx = statements.indexOfFirst { it===stmt } + 1 - return if(nextIdx < statements.size) - statements[nextIdx] - else - null - } - - fun previousSibling(stmt: Statement): Statement? { - val previousIdx = statements.indexOfFirst { it===stmt } - 1 - return if(previousIdx>=0) - statements[previousIdx] - else - null - } - fun indexOfChild(stmt: Statement): Int { val idx = statements.indexOfFirst { it===stmt } if(idx>=0) diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 20b73e8cf..22cf93b71 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -4,6 +4,7 @@ TODO For next compiler release (7.2) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - fix the asm-labels problem (github issue #62) +- fix that "uword qq =$1000+xx" uses stack eval, while "uword qq; qq=$1000+xx" uses optimized code - find a way to optimize asm-subroutine param passing where it now sometimes uses the evalstack? diff --git a/examples/test.p8 b/examples/test.p8 index 90e3c76a2..f0c3ed87a 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,23 +1,26 @@ %import textio -%zeropage basicsafe +%zeropage dontuse main { sub start() { - ubyte xx = 100 - ubyte cv + uword qq =$1234+xx ; TODO FIX THAT THIS USES STACK - sys.memset($1000+xx, 10, 255) ; TODO uses stack eval now to precalc parameters + uword ww + ww=$1234+xx - xx = xx & %0001 ; doesn't use stack... because it uses AugmentableAssignmentAsmGen - ;yy = xx & %0001 ; doesn't use stack... because it uses AugmentableAssignmentAsmGen - - ;ubyte yy = xx & %0001 ; TODO uses stack eval.... - if xx & %0001 { ; TODO why does this use stack? because it uses asmgen.assignExpressionToRegister eventually line 253 in AssignmentAsmGen no augmentable-assignment. - xx-- - } +; ubyte cv +; sys.memset($1000+xx, 10, 255) ; TODO uses stack eval now to precalc parameters +; +; xx = xx & %0001 ; doesn't use stack... because it uses AugmentableAssignmentAsmGen +; ;yy = xx & %0001 ; doesn't use stack... because it uses AugmentableAssignmentAsmGen +; +; ;ubyte yy = xx & %0001 ; TODO uses stack eval.... +; if xx & %0001 { ; TODO why does this use stack? because it uses asmgen.assignExpressionToRegister eventually line 253 in AssignmentAsmGen no augmentable-assignment. +; xx-- +; } ; if xx+1 { ; TODO why does this use stack? see above ; xx++