mirror of
https://github.com/irmen/prog8.git
synced 2024-12-23 09:32:43 +00:00
fix void optimization issue
This commit is contained in:
parent
dd4c073e18
commit
2668bf8519
@ -139,13 +139,20 @@ class UnusedCodeRemover(private val program: Program,
|
||||
)
|
||||
} else if(assignment.value is IFunctionCall) {
|
||||
// replace the unused variable's initializer function call by a void
|
||||
errors.warn("replaced unused variable '${decl.name}' with void call, maybe this can be removed altogether", decl.position)
|
||||
val fcall = assignment.value as IFunctionCall
|
||||
val voidCall = FunctionCallStatement(fcall.target, fcall.args, true, fcall.position)
|
||||
return listOf(
|
||||
IAstModification.ReplaceNode(decl, voidCall, parent),
|
||||
IAstModification.Remove(assignment, assignment.parent as IStatementContainer)
|
||||
)
|
||||
// but only if the vardecl immediately precedes it!
|
||||
if(singleUse.parent.parent === parent) {
|
||||
val declIndex = (parent as IStatementContainer).statements.indexOf(decl)
|
||||
val singleUseIndex = (parent as IStatementContainer).statements.indexOf(singleUse.parent)
|
||||
if(declIndex==singleUseIndex-1) {
|
||||
errors.warn("replaced unused variable '${decl.name}' with void call, maybe this can be removed altogether", decl.position)
|
||||
val fcall = assignment.value as IFunctionCall
|
||||
val voidCall = FunctionCallStatement(fcall.target, fcall.args, true, fcall.position)
|
||||
return listOf(
|
||||
IAstModification.ReplaceNode(decl, voidCall, parent),
|
||||
IAstModification.Remove(assignment, assignment.parent as IStatementContainer)
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
errors.warn("variable '${decl.name}' is unused but has non-trivial initialization assignment. Leaving this in but maybe it can be removed altogether", decl.position)
|
||||
}
|
||||
|
@ -2,16 +2,6 @@
|
||||
TODO
|
||||
====
|
||||
|
||||
|
||||
- fix problem with conversion to void call messing up the return '!':
|
||||
if cx16.r0L==9 {
|
||||
; process TAB
|
||||
uword cmd = grab_cmdline()
|
||||
return '!'
|
||||
}
|
||||
|
||||
|
||||
|
||||
- [on branch: shortcircuit] investigate McCarthy evaluation again? this may also reduce code size perhaps for things like if a>4 or a<2 ....
|
||||
|
||||
...
|
||||
|
@ -1,9 +1,44 @@
|
||||
%option enable_floats
|
||||
%import textio
|
||||
%import string
|
||||
%zeropage basicsafe
|
||||
|
||||
main {
|
||||
sub start() {
|
||||
uword w1 = 000_1234_5__
|
||||
uword w2 = $ff_ee
|
||||
uword w3 = %11_0000_111111__0000
|
||||
float fl = 3_000_001.141_592_654
|
||||
cx16.set_chrin_keyhandler(0, &keystroke_handler)
|
||||
cbm.CHRIN()
|
||||
}
|
||||
|
||||
sub keystroke_handler() -> ubyte {
|
||||
%asm {{
|
||||
sta cx16.r0L
|
||||
}}
|
||||
uword cmdxx = grab_cmdline()
|
||||
if_cs {
|
||||
; first entry, decide if we want to override
|
||||
if cx16.r0L==9 {
|
||||
; intercept TAB
|
||||
sys.clear_carry()
|
||||
return 0
|
||||
}
|
||||
sys.set_carry()
|
||||
return 0
|
||||
} else {
|
||||
if cx16.r0L==9 {
|
||||
%asm {{
|
||||
brk ; BOOM
|
||||
}}
|
||||
uword cmd = grab_cmdline()
|
||||
if cmd and cmd[0] {
|
||||
;cx16.r5++
|
||||
}
|
||||
return '!'
|
||||
}
|
||||
return 0 ; eat all other characters
|
||||
}
|
||||
|
||||
sub grab_cmdline() -> uword {
|
||||
cx16.r9++
|
||||
return $5000
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user