From e6b158bc97aae33cc65a4bd50ce531be9d137d2d Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sat, 8 Jul 2023 22:34:47 +0200 Subject: [PATCH] @(..) argument must be of type UWORD --- .../compiler/astprocessing/AstChecker.kt | 26 +++++++++++++++++++ .../test/codegeneration/TestVariousCodeGen.kt | 5 ++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt index 516a322cd..f914336bb 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt @@ -1384,6 +1384,32 @@ internal class AstChecker(private val program: Program, 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? { when (val targetStatement = target.targetStatement(program)) { is Label, is Subroutine, is BuiltinFunctionPlaceholder -> return targetStatement diff --git a/compiler/test/codegeneration/TestVariousCodeGen.kt b/compiler/test/codegeneration/TestVariousCodeGen.kt index bc7556faa..aeb5c4465 100644 --- a/compiler/test/codegeneration/TestVariousCodeGen.kt +++ b/compiler/test/codegeneration/TestVariousCodeGen.kt @@ -143,8 +143,9 @@ main { }""" val errors = ErrorReporterForTests() compileText(C64Target(), false, text, writeAssembly = true, errors = errors) - errors.errors.size shouldBe 1 - errors.errors[0] shouldContain "undefined symbol: doesnotexist" + errors.errors.size shouldBe 2 + errors.errors[0] shouldContain "isn't uword" + errors.errors[1] shouldContain "undefined symbol: doesnotexist" } test("shifting by word value is ok") {