@(..) argument must be of type UWORD

This commit is contained in:
Irmen de Jong 2023-07-08 22:34:47 +02:00
parent 4cc0dfa10b
commit e6b158bc97
2 changed files with 29 additions and 2 deletions

View File

@ -1384,6 +1384,32 @@ internal class AstChecker(private val program: Program,
super.visit(containment) super.visit(containment)
} }
override fun visit(memread: DirectMemoryRead) {
if(!memread.addressExpression.inferType(program).istype(DataType.UWORD)) {
errors.err("address for memory access isn't uword", memread.position)
}
val tc = memread.addressExpression as? TypecastExpression
if(tc!=null && tc.implicit) {
if(!tc.expression.inferType(program).istype(DataType.UWORD)) {
errors.err("address for memory access isn't uword", memread.position)
}
}
super.visit(memread)
}
override fun visit(memwrite: DirectMemoryWrite) {
if(!memwrite.addressExpression.inferType(program).istype(DataType.UWORD)) {
errors.err("address for memory access isn't uword", memwrite.position)
}
val tc = memwrite.addressExpression as? TypecastExpression
if(tc!=null && tc.implicit) {
if(!tc.expression.inferType(program).istype(DataType.UWORD)) {
errors.err("address for memory access isn't uword", memwrite.position)
}
}
super.visit(memwrite)
}
private fun checkFunctionOrLabelExists(target: IdentifierReference, statement: Statement): Statement? { private fun checkFunctionOrLabelExists(target: IdentifierReference, statement: Statement): Statement? {
when (val targetStatement = target.targetStatement(program)) { when (val targetStatement = target.targetStatement(program)) {
is Label, is Subroutine, is BuiltinFunctionPlaceholder -> return targetStatement is Label, is Subroutine, is BuiltinFunctionPlaceholder -> return targetStatement

View File

@ -143,8 +143,9 @@ main {
}""" }"""
val errors = ErrorReporterForTests() val errors = ErrorReporterForTests()
compileText(C64Target(), false, text, writeAssembly = true, errors = errors) compileText(C64Target(), false, text, writeAssembly = true, errors = errors)
errors.errors.size shouldBe 1 errors.errors.size shouldBe 2
errors.errors[0] shouldContain "undefined symbol: doesnotexist" errors.errors[0] shouldContain "isn't uword"
errors.errors[1] shouldContain "undefined symbol: doesnotexist"
} }
test("shifting by word value is ok") { test("shifting by word value is ok") {