remove unneeded sibling methods

This commit is contained in:
Irmen de Jong 2021-10-31 16:50:15 +01:00
parent fe17566370
commit 1b576f826d
5 changed files with 17 additions and 29 deletions

View File

@ -1304,7 +1304,7 @@ $repeatLabel lda $counterVar
} }
inits.add(stmt) inits.add(stmt)
} else { } else {
val next = (stmt.parent as IStatementContainer).nextSibling(stmt) val next = stmt.nextSibling()
if (next !is ForLoop || next.loopVar.nameInSource.single() != stmt.name) { if (next !is ForLoop || next.loopVar.nameInSource.single() != stmt.name) {
assignInitialValueToVar(stmt, listOf(stmt.name)) assignInitialValueToVar(stmt, listOf(stmt.name))
} }

View File

@ -51,7 +51,7 @@ class UnusedCodeRemover(private val program: Program,
} }
private fun reportUnreachable(stmt: Statement, parent: IStatementContainer) { 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 -> {} null, is Label, is Directive, is VarDecl, is InlineAssembly, is Subroutine -> {}
else -> errors.warn("unreachable code", next.position) else -> errors.warn("unreachable code", next.position)
} }

View File

@ -56,22 +56,6 @@ interface IStatementContainer {
return result 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 { fun indexOfChild(stmt: Statement): Int {
val idx = statements.indexOfFirst { it===stmt } val idx = statements.indexOfFirst { it===stmt }
if(idx>=0) if(idx>=0)

View File

@ -4,6 +4,7 @@ TODO
For next compiler release (7.2) For next compiler release (7.2)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- fix the asm-labels problem (github issue #62) - 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? - find a way to optimize asm-subroutine param passing where it now sometimes uses the evalstack?

View File

@ -1,23 +1,26 @@
%import textio %import textio
%zeropage basicsafe %zeropage dontuse
main { main {
sub start() { sub start() {
ubyte xx = 100 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 ; ubyte cv
;yy = xx & %0001 ; doesn't use stack... because it uses AugmentableAssignmentAsmGen ; sys.memset($1000+xx, 10, 255) ; TODO uses stack eval now to precalc parameters
;
;ubyte yy = xx & %0001 ; TODO uses stack eval.... ; xx = xx & %0001 ; doesn't use stack... because it uses AugmentableAssignmentAsmGen
if xx & %0001 { ; TODO why does this use stack? because it uses asmgen.assignExpressionToRegister eventually line 253 in AssignmentAsmGen no augmentable-assignment. ; ;yy = xx & %0001 ; doesn't use stack... because it uses AugmentableAssignmentAsmGen
xx-- ;
} ; ;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 ; if xx+1 { ; TODO why does this use stack? see above
; xx++ ; xx++