From 2a8b65e29cd97ba113aab51a11ea8f92b449f049 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 10 Mar 2024 23:45:44 +0100 Subject: [PATCH] test str to uword change in function params --- compiler/test/TestTypecasts.kt | 52 ++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/compiler/test/TestTypecasts.kt b/compiler/test/TestTypecasts.kt index 7e9007bff..77ff90fa4 100644 --- a/compiler/test/TestTypecasts.kt +++ b/compiler/test/TestTypecasts.kt @@ -11,6 +11,8 @@ import prog8.ast.expressions.* import prog8.ast.statements.Assignment import prog8.ast.statements.IfElse import prog8.ast.statements.VarDecl +import prog8.code.ast.PtAsmSub +import prog8.code.ast.PtSub import prog8.code.core.DataType import prog8.code.core.Position import prog8.code.target.C64Target @@ -1108,4 +1110,54 @@ main { }""" compileText(C64Target(), true, src2, writeAssembly = false) shouldBe null } + + test("str replaced with uword in subroutine params and return types") { + val src=""" +main { + sub start() { + derp("hello") + mult3("hello") + } + + sub derp(str arg) -> str { + cx16.r0++ + return arg + } + + asmsub mult3(str input @XY) -> str @XY { + %asm {{ + ldx #100 + ldy #101 + rts + }} + } +}""" + compileText(C64Target(), true, src, writeAssembly = true) shouldNotBe null + val result = compileText(VMTarget(), true, src, writeAssembly = true)!! + val main = result.codegenAst!!.allBlocks().first() + val derp = main.children.single { it is PtSub && it.name=="main.derp"} as PtSub + derp.returntype shouldBe DataType.UWORD + derp.parameters.single().type shouldBe DataType.UWORD + val mult3 = main.children.single { it is PtAsmSub && it.name=="main.mult3"} as PtAsmSub + mult3.parameters.single().second.type shouldBe DataType.UWORD + mult3.returns.single().second shouldBe DataType.UWORD + } + + test("return 0 for str converted to uword") { + val src=""" +main { + sub start() { + cx16.r0 = test() + } + + sub test() -> str { + cx16.r0++ + if cx16.r0L==255 + return 0 + + return 42 + } +}""" + compileText(C64Target(), true, src, writeAssembly = true) shouldNotBe null + } })