mirror of
https://github.com/irmen/prog8.git
synced 2025-01-11 13:29:45 +00:00
don't remove empty when choice from the list of choices!
This commit is contained in:
parent
b6ded8501f
commit
b5289511ba
@ -366,7 +366,7 @@ private fun builtinLen(args: List<Expression>, position: Position, program: Prog
|
||||
NumericLiteralValue.optimalInteger(arraySize, args[0].position)
|
||||
}
|
||||
DataType.STR -> {
|
||||
val refLv = target.value as StringLiteralValue
|
||||
val refLv = target.value as? StringLiteralValue ?: throw CannotEvaluateException("len", "stringsize unknown")
|
||||
NumericLiteralValue.optimalInteger(refLv.value.length, args[0].position)
|
||||
}
|
||||
DataType.STRUCT -> throw SyntaxError("cannot use len on struct, did you mean sizeof?", args[0].position)
|
||||
|
@ -20,7 +20,7 @@ internal class StatementOptimizer(private val program: Program,
|
||||
private val errors: IErrorReporter,
|
||||
private val functions: IBuiltinFunctions,
|
||||
private val compTarget: ICompilationTarget,
|
||||
private val asmFileLoader: (filename: String, source: Path)->String
|
||||
asmFileLoader: (filename: String, source: Path)->String
|
||||
) : AstWalker() {
|
||||
|
||||
private val noModifications = emptyList<IAstModification>()
|
||||
@ -296,18 +296,6 @@ internal class StatementOptimizer(private val program: Program,
|
||||
return noModifications
|
||||
}
|
||||
|
||||
override fun after(whenStatement: WhenStatement, parent: Node): Iterable<IAstModification> {
|
||||
// remove empty choices
|
||||
class ChoiceRemover(val choice: WhenChoice) : IAstModification {
|
||||
override fun perform() {
|
||||
whenStatement.choices.remove(choice)
|
||||
}
|
||||
}
|
||||
return whenStatement.choices
|
||||
.filter { !it.statements.containsCodeOrVars() }
|
||||
.map { ChoiceRemover(it) }
|
||||
}
|
||||
|
||||
override fun after(jump: Jump, parent: Node): Iterable<IAstModification> {
|
||||
// if the jump is to the next statement, remove the jump
|
||||
val scope = jump.definingScope()
|
||||
|
@ -2,8 +2,11 @@
|
||||
TODO
|
||||
====
|
||||
|
||||
- compiler error for double when labels
|
||||
|
||||
- add sound to the cx16 tehtriz
|
||||
|
||||
- add const arrays and cost strings
|
||||
- hoist all variable declarations up to the subroutine scope *before* even the constant folding takes place (to avoid undefined symbol errors when referring to a variable from another nested scope in the subroutine)
|
||||
- optimize swap of two memread values with index, using the same pointer expression/variable, like swap(@(ptr+1), @(ptr+2))
|
||||
- optimize several inner loops in gfx2 (highres 4 color mode)
|
||||
|
@ -6,6 +6,7 @@
|
||||
; shows next piece
|
||||
; staged speed increase
|
||||
; TODO: replicate the simple sound effects from the C64 version
|
||||
; how to do this on the Vera PSG without a ADSR envelope...?
|
||||
|
||||
|
||||
%target cx16
|
||||
|
@ -7,40 +7,21 @@ main {
|
||||
; $1F9C0 - $1F9FF PSG registers
|
||||
|
||||
sub start() {
|
||||
uword xx = &b2.zz
|
||||
xx=&b3.zz
|
||||
xx=&b4.zz
|
||||
xx=&b5.zz
|
||||
|
||||
txt.print_uwhex(&main, true)
|
||||
txt.nl()
|
||||
txt.print_uwhex(&b2, true)
|
||||
txt.nl()
|
||||
txt.print_uwhex(&b3, true)
|
||||
txt.nl()
|
||||
txt.print_uwhex(&b4, true)
|
||||
txt.nl()
|
||||
txt.print_uwhex(&b5, true)
|
||||
txt.nl()
|
||||
ubyte xx = '?'
|
||||
when xx {
|
||||
'a' -> txt.print("a\n")
|
||||
'b' -> txt.print("b\n")
|
||||
'?' -> {
|
||||
}
|
||||
else -> txt.print("else\n")
|
||||
}
|
||||
|
||||
; uword freq = 1181
|
||||
; cx16.vpoke(1, $f9c0, lsb(freq))
|
||||
; cx16.vpoke(1, $f9c1, msb(freq))
|
||||
; cx16.vpoke(1, $f9c2, %11111111) ; volume
|
||||
; cx16.vpoke(1, $f9c3, %11000000) ; triangle waveform
|
||||
}
|
||||
}
|
||||
|
||||
b2 {
|
||||
str zz="hello"
|
||||
}
|
||||
|
||||
b3 $4001 {
|
||||
str zz="bye"
|
||||
}
|
||||
|
||||
b4 {
|
||||
%option align_word
|
||||
|
||||
str zz="wut"
|
||||
}
|
||||
|
||||
b5 {
|
||||
%option align_page
|
||||
|
||||
str zz="wut2"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user