diff --git a/compiler/src/prog8/compiler/functions/BuiltinFunctions.kt b/compiler/src/prog8/compiler/functions/BuiltinFunctions.kt index dba87f73e..ba7bb0fef 100644 --- a/compiler/src/prog8/compiler/functions/BuiltinFunctions.kt +++ b/compiler/src/prog8/compiler/functions/BuiltinFunctions.kt @@ -366,7 +366,7 @@ private fun builtinLen(args: List, 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) diff --git a/compiler/src/prog8/optimizer/StatementOptimizer.kt b/compiler/src/prog8/optimizer/StatementOptimizer.kt index 16b1f2046..c4b49e3df 100644 --- a/compiler/src/prog8/optimizer/StatementOptimizer.kt +++ b/compiler/src/prog8/optimizer/StatementOptimizer.kt @@ -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() @@ -296,18 +296,6 @@ internal class StatementOptimizer(private val program: Program, return noModifications } - override fun after(whenStatement: WhenStatement, parent: Node): Iterable { - // 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 { // if the jump is to the next statement, remove the jump val scope = jump.definingScope() diff --git a/docs/source/todo.rst b/docs/source/todo.rst index a71c000a0..50a4c48b5 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -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) diff --git a/examples/cx16/tehtriz.p8 b/examples/cx16/tehtriz.p8 index 37a0a1c21..3de5cb93d 100644 --- a/examples/cx16/tehtriz.p8 +++ b/examples/cx16/tehtriz.p8 @@ -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 diff --git a/examples/test.p8 b/examples/test.p8 index 060185a4c..81d0a1a3d 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -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" -}