diff --git a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt index f1538df5c..11bc16ff6 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt @@ -563,8 +563,9 @@ internal class AstChecker(private val program: Program, } } VarDeclType.MEMORY -> { - if(decl.arraysize!=null) { - val arraySize = decl.arraysize!!.constIndex() ?: 1 + val arraysize = decl.arraysize + if(arraysize!=null) { + val arraySize = arraysize.constIndex() ?: 1 when(decl.datatype) { DataType.ARRAY_B, DataType.ARRAY_UB -> if(arraySize > 256) @@ -578,10 +579,9 @@ internal class AstChecker(private val program: Program, else -> {} } } - - if(decl.value is NumericLiteralValue) { - val value = decl.value as NumericLiteralValue - if (value.type !in IntegerDatatypes || value.number.toInt() < 0 || value.number.toInt() > 65535) { + val numvalue = decl.value as? NumericLiteralValue + if(numvalue!=null) { + if (numvalue.type !in IntegerDatatypes || numvalue.number.toInt() < 0 || numvalue.number.toInt() > 65535) { err("memory address must be valid integer 0..\$ffff", decl.value?.position) } } else { @@ -599,9 +599,9 @@ internal class AstChecker(private val program: Program, // array length limits and constant lenghts if(decl.isArray) { - val length = decl.arraysize!!.constIndex() + val length = decl.arraysize?.constIndex() if(length==null) - err("array length must be a constant") + err("array length must be known at compile-time") else { when (decl.datatype) { DataType.STR, DataType.ARRAY_UB, DataType.ARRAY_B -> { diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 54c6e1906..922e4d584 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -2,8 +2,10 @@ TODO ==== -- mark vardecls 'shared' to indicate they should not be optimized away because they're shared with assembly code?? -- github issue: make strings no longer immutable? fixes weird optimization issue. Deduplication via command line switch? +- possible idea: option to mark vardecls 'shared' to indicate they should not be optimized away because they're shared with assembly code? + However: who even needs variables declared in prog8 code that are only used by assembly??? +- github issue: make strings no longer immutable? Deduplication selectable via command line switch? + - test all examples before release of the new version - simplify cx16.joystick_get2() once this cx16 rom issue is resolved: https://github.com/commanderx16/x16-rom/issues/203 diff --git a/examples/test.p8 b/examples/test.p8 index 88b74163b..37a4c513c 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -3,7 +3,15 @@ %option no_sysinit main { - sub start() { + + byte[] xs1 = "foo1" ; <<<<<<<<<<<< + str xs2 = "foo2" ; <<<<<<<<<<<< + sub start() { + txt.print(xs1) + stringopt() + } + + sub stringopt() { str message = "a" txt.print(message)