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)
} 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))
}

View File

@ -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)
}

View File

@ -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)

View File

@ -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?

View File

@ -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++