From cba502e87af716de4bcbb2f052911ebb288aed03 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Tue, 8 Dec 2020 22:27:42 +0100 Subject: [PATCH] fixed crash when trying to assign a string literal to an array element in a string-array --- .../src/prog8/ast/processing/AstChecker.kt | 2 +- .../codegen/assignment/AssignmentAsmGen.kt | 5 +++-- examples/test.p8 | 21 +++++++++++++++++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/compiler/src/prog8/ast/processing/AstChecker.kt b/compiler/src/prog8/ast/processing/AstChecker.kt index db1d6af90..938d50053 100644 --- a/compiler/src/prog8/ast/processing/AstChecker.kt +++ b/compiler/src/prog8/ast/processing/AstChecker.kt @@ -384,7 +384,7 @@ internal class AstChecker(private val program: Program, if(valueDt.isKnown && !(valueDt isAssignableTo targetDt)) { if(targetDt.typeOrElse(DataType.STRUCT) in IterableDatatypes) errors.err("cannot assign value to string or array", assignment.value.position) - else + else if(!(valueDt.istype(DataType.STR) && targetDt.istype(DataType.UWORD))) errors.err("value's type doesn't match target", assignment.value.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 dd9da521c..b1d79f57a 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/assignment/AssignmentAsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/assignment/AssignmentAsmGen.kt @@ -725,10 +725,11 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen """) } TargetStorageKind.MEMORY -> { - throw AssemblyError("no asm gen for assign address $sourceName to memory word $target") + throw AssemblyError("can't store word into memory byte") } TargetStorageKind.ARRAY -> { - throw AssemblyError("no asm gen for assign address $sourceName to array ${target.asmVarname}") + asmgen.out(" lda #<$sourceName | ldy #>$sourceName") + assignRegisterpairWord(target, RegisterOrPair.AY) } TargetStorageKind.REGISTER -> { when(target.register!!) { diff --git a/examples/test.p8 b/examples/test.p8 index ad1a9262f..8b1d39e9e 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -18,8 +18,25 @@ errors { ; char = c64.CHRIN() ; TODO fix undefined symbol error, should refer to 'char' above in the subroutine's scope ; } until char==0 - ; TODO fix compiler crash: - ; str[max_files] names + str[4] names1 = ["one", "two", "three", "four"] + str[4] names2 + + names2[0] = "four" + names2[1] = "three" + names2[2] = "two" + names2[3] = "one" + + uword xx + for xx in names1 { + txt.print(xx) + txt.chrout(',') + } + txt.chrout('\n') + for xx in names2 { + txt.print(xx) + txt.chrout(',') + } + txt.chrout('\n') } }