give better error when using @split wrong

This commit is contained in:
Irmen de Jong 2024-05-20 21:51:07 +02:00
parent ac1d4b4a7a
commit fda8e61be4
4 changed files with 15 additions and 9 deletions

View File

@ -844,6 +844,11 @@ internal class AstChecker(private val program: Program,
if(compilerOptions.zeropage==ZeropageType.DONTUSE && decl.zeropage == ZeropageWish.REQUIRE_ZEROPAGE)
err("zeropage usage has been disabled by options")
if(decl.splitArray) {
if (decl.datatype !in arrayOf(DataType.ARRAY_W, DataType.ARRAY_UW, DataType.ARRAY_W_SPLIT, DataType.ARRAY_UW_SPLIT)) {
errors.err("split can only be used on word arrays", decl.position)
}
}
super.visit(decl)
}

View File

@ -688,7 +688,7 @@ private fun VardeclContext.toAst(type: VarDeclType, value: Expression?): VarDecl
when(arrayDt) {
DataType.ARRAY_UW -> DataType.ARRAY_UW_SPLIT
DataType.ARRAY_W -> DataType.ARRAY_W_SPLIT
else -> throw SyntaxError("split can only be used on word arrays", toPosition())
else -> arrayDt // type error will be generated later in the ast check
}
} else arrayDt
} else origDt

View File

@ -231,11 +231,6 @@ class VarDecl(val type: VarDeclType,
override lateinit var parent: Node
var allowInitializeWithZero = true
init {
if(splitArray)
require(datatype in ArrayDatatypes) { "array dt mismatch" }
}
companion object {
private var autoHeapValueSequenceNumber = 0

View File

@ -2,8 +2,14 @@
main {
sub start() {
repeat cx16.r0 {
cx16.r1L++
}
bool @split bb
ubyte @split bt
byte[200] @split ba
float @split fl
float[10] @split fla
bb=true
bt++
fl++
}
}