From e876008427b1006c7280eadd3160befb06925c1c Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Thu, 26 Nov 2020 19:21:07 +0100 Subject: [PATCH] tiny tweak of typecasting str to uword --- .../compiler/BeforeAsmGenerationAstChanger.kt | 6 +++++ .../codegen/assignment/AssignmentAsmGen.kt | 9 ++++--- examples/test.p8 | 26 ++++++++++--------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/compiler/src/prog8/compiler/BeforeAsmGenerationAstChanger.kt b/compiler/src/prog8/compiler/BeforeAsmGenerationAstChanger.kt index 49604c8ba..cc19ec0db 100644 --- a/compiler/src/prog8/compiler/BeforeAsmGenerationAstChanger.kt +++ b/compiler/src/prog8/compiler/BeforeAsmGenerationAstChanger.kt @@ -170,6 +170,12 @@ internal class BeforeAsmGenerationAstChanger(val program: Program, val errors: E AddressOf(typecast.expression as IdentifierReference, typecast.position), parent )) + } else if(typecast.expression is IFunctionCall) { + return listOf(IAstModification.ReplaceNode( + typecast, + typecast.expression, + parent + )) } } else { errors.err("cannot cast pass-by-reference value to type ${typecast.type} (only to UWORD)", typecast.position) diff --git a/compiler/src/prog8/compiler/target/c64/codegen/assignment/AssignmentAsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/assignment/AssignmentAsmGen.kt index 9edafe041..793dbc5b3 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/assignment/AssignmentAsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/assignment/AssignmentAsmGen.kt @@ -274,22 +274,23 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen when (valueDt) { in ByteDatatypes -> { assignExpressionToRegister(value, RegisterOrPair.A) - return assignTypeCastedRegisters(target.asmVarname, targetDt, RegisterOrPair.A, valueDt) + assignTypeCastedRegisters(target.asmVarname, targetDt, RegisterOrPair.A, valueDt) } in WordDatatypes -> { assignExpressionToRegister(value, RegisterOrPair.AY) - return assignTypeCastedRegisters(target.asmVarname, targetDt, RegisterOrPair.AY, valueDt) + assignTypeCastedRegisters(target.asmVarname, targetDt, RegisterOrPair.AY, valueDt) } DataType.FLOAT -> { assignExpressionToRegister(value, RegisterOrPair.FAC1) - return assignTypecastedFloatFAC1(target.asmVarname, targetDt) + assignTypecastedFloatFAC1(target.asmVarname, targetDt) } in PassByReferenceDatatypes -> { // str/array value cast (most likely to UWORD, take address-of) - return assignExpressionToVariable(value, target.asmVarname, targetDt, null) // TODO test this cast + assignExpressionToVariable(value, target.asmVarname, targetDt, null) } else -> throw AssemblyError("strange dt in typecast assign to var: $valueDt --> $targetDt") } + return } // give up, do it via eval stack diff --git a/examples/test.p8 b/examples/test.p8 index 7f3ef76b5..48d8c2b56 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -12,26 +12,28 @@ main { uword uw byte bb ubyte ub + str string1 = "irmen" + uword[] array = [1111,2222,3333] - - fl = 9997.999 - ww = (fl+1.1) as word - uw = (fl+1.1) as uword - fl = 97.999 - bb = (fl+1.1) as byte - ub = (fl+1.1) as ubyte - - txt.print_w(ww) + uw = string1 as uword + txt.print_uwhex(uw,1) txt.chrout('\n') - txt.print_uw(uw) + uw = array as uword + txt.print_uwhex(uw,1) txt.chrout('\n') - txt.print_b(bb) + uw = name() as uword + txt.print_uwhex(uw,1) txt.chrout('\n') - txt.print_ub(ub) + uw = name() + txt.print_uwhex(uw,1) txt.chrout('\n') test_stack.test() } + + sub name() -> str { + return "irmen" + } }