From 3723c22054540c5a4cc0cce34c03405f060f63b8 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Tue, 2 Jun 2020 02:09:42 +0200 Subject: [PATCH] fix string param type --- .../target/c64/codegen/FunctionCallAsmGen.kt | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/compiler/src/prog8/compiler/target/c64/codegen/FunctionCallAsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/FunctionCallAsmGen.kt index ffccdb3fc..186a2ef0b 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/FunctionCallAsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/FunctionCallAsmGen.kt @@ -43,7 +43,7 @@ internal class FunctionCallAsmGen(private val program: Program, private val asmg if(!argumentTypeCompatible(sourceDt, parameter.value.type)) throw AssemblyError("argument type incompatible") if(sub.asmParameterRegisters.isEmpty()) { - // pass parameter via a variable + // pass parameter via a regular variable (not via registers) val paramVar = parameter.value val scopedParamVar = (sub.scopedname+"."+paramVar.name).split(".") val target = AssignTarget(null, IdentifierReference(scopedParamVar, sub.position), null, null, sub.position) @@ -55,7 +55,7 @@ internal class FunctionCallAsmGen(private val program: Program, private val asmg in ByteDatatypes -> asmgen.assignFromByteConstant(target, value.number.toShort()) in WordDatatypes -> asmgen.assignFromWordConstant(target, value.number.toInt()) DataType.FLOAT -> asmgen.assignFromFloatConstant(target, value.number.toDouble()) - in PassByReferenceDatatypes -> throw AssemblyError("can't pass string/array as arguments?") + in PassByReferenceDatatypes -> throw AssemblyError("can't pass string/array as argument via a variable?") // TODO huh else -> throw AssemblyError("weird parameter datatype") } } @@ -65,7 +65,7 @@ internal class FunctionCallAsmGen(private val program: Program, private val asmg in ByteDatatypes -> asmgen.assignFromByteVariable(target, value) in WordDatatypes -> asmgen.assignFromWordVariable(target, value) DataType.FLOAT -> asmgen.assignFromFloatVariable(target, value) - in PassByReferenceDatatypes -> throw AssemblyError("can't pass string/array as arguments?") + in PassByReferenceDatatypes -> throw AssemblyError("can't pass string/array as argument via a variable?") // TODO huh else -> throw AssemblyError("weird parameter datatype") } } @@ -203,11 +203,20 @@ internal class FunctionCallAsmGen(private val program: Program, private val asmg } is IdentifierReference -> { val sourceName = asmgen.asmIdentifierName(value) - when (register) { - RegisterOrPair.AX -> asmgen.out(" lda $sourceName | ldx $sourceName+1") - RegisterOrPair.AY -> asmgen.out(" lda $sourceName | ldy $sourceName+1") - RegisterOrPair.XY -> asmgen.out(" ldx $sourceName | ldy $sourceName+1") - else -> {} + if(sourceDt in PassByReferenceDatatypes) { + when (register) { + RegisterOrPair.AX -> asmgen.out(" lda #<$sourceName | ldx #>$sourceName") + RegisterOrPair.AY -> asmgen.out(" lda #<$sourceName | ldy #>$sourceName") + RegisterOrPair.XY -> asmgen.out(" ldx #<$sourceName | ldy #>$sourceName") + else -> {} + } + } else { + when (register) { + RegisterOrPair.AX -> asmgen.out(" lda $sourceName | ldx $sourceName+1") + RegisterOrPair.AY -> asmgen.out(" lda $sourceName | ldy $sourceName+1") + RegisterOrPair.XY -> asmgen.out(" ldx $sourceName | ldy $sourceName+1") + else -> {} + } } } else -> {