From 48f09f71abe857e37f4c88243bb586e08a4052e0 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sat, 2 Dec 2023 21:10:51 +0100 Subject: [PATCH] fix TODO crash on uword[0] = uword[0] or 128 (byte register assign to word array) --- .../cpu6502/assignment/AssignmentAsmGen.kt | 18 +++++++++++++++--- compiler/test/TestStringEncodings.kt | 15 ++++++--------- compiler/test/helpers/Dummies.kt | 1 - docs/source/todo.rst | 2 -- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt index 19b1f20d2..3d259c405 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt @@ -2952,9 +2952,21 @@ internal class AssignmentAsmGen(private val program: PtProgram, storeRegisterAInMemoryAddress(target.memory!!) } TargetStorageKind.ARRAY -> { - if(assignAsWord) - TODO("assign register byte as word into Array not yet supported") - assignRegisterByteToByteArray(target, register) + if(assignAsWord) { + when(register) { + CpuRegister.A -> {} + CpuRegister.X -> asmgen.out(" txa") + CpuRegister.Y -> asmgen.out(" tya") + } + if(extendWord) { + asmgen.signExtendAYlsb(if(target.datatype in SignedDatatypes) DataType.BYTE else DataType.UBYTE) + } else { + asmgen.out(" ldy #0") + } + assignRegisterpairWord(target, RegisterOrPair.AY) + } else { + assignRegisterByteToByteArray(target, register) + } } TargetStorageKind.REGISTER -> { when(register) { diff --git a/compiler/test/TestStringEncodings.kt b/compiler/test/TestStringEncodings.kt index 8650b19db..035911abd 100644 --- a/compiler/test/TestStringEncodings.kt +++ b/compiler/test/TestStringEncodings.kt @@ -7,7 +7,6 @@ import io.kotest.assertions.withClue import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe -import io.kotest.matchers.string.shouldContain import prog8.code.core.Encoding import prog8.code.core.unescape import prog8.code.target.C64Target @@ -260,7 +259,7 @@ class TestStringEncodings: FunSpec({ errors.errors.size shouldBe 0 } - test("unsupported string encoding iso for C64 compilationtarget") { + test("iso string encoding also on C64 compilationtarget") { val source=""" main { str string1 = "default" @@ -271,12 +270,11 @@ class TestStringEncodings: FunSpec({ } }""" val errors = ErrorReporterForTests() - compileText(C64Target(), false, source, errors, writeAssembly = false) shouldBe null - errors.errors.size shouldBe 1 - errors.errors[0] shouldContain "text encoding" + compileText(C64Target(), false, source, errors, writeAssembly = false) shouldNotBe null + errors.errors.size shouldBe 0 } - test("unsupported char encoding iso for C64 compilationtarget") { + test("iso char encoding also on C64 compilationtarget") { val source=""" main { ubyte char1 = 'd' @@ -287,9 +285,8 @@ class TestStringEncodings: FunSpec({ } }""" val errors = ErrorReporterForTests() - compileText(C64Target(), false, source, errors, writeAssembly = false) shouldBe null - errors.errors.size shouldBe 1 - errors.errors[0] shouldContain "text encoding" + compileText(C64Target(), false, source, errors, writeAssembly = false) shouldNotBe null + errors.errors.size shouldBe 0 } test("all encodings supported for Cx16 target") { diff --git a/compiler/test/helpers/Dummies.kt b/compiler/test/helpers/Dummies.kt index e1ce7d4d2..b0973de40 100644 --- a/compiler/test/helpers/Dummies.kt +++ b/compiler/test/helpers/Dummies.kt @@ -55,7 +55,6 @@ internal object AsciiStringEncoder : IStringEncoding { internal object DummyCompilationTarget : ICompilationTarget { override val name: String = "dummy" override val machine: IMachineDefinition = VirtualMachineDefinition() // not really true but I don't want to implement a full dummy machinedef - override val supportedEncodings = setOf(Encoding.PETSCII, Encoding.SCREENCODES, Encoding.ISO) override val defaultEncoding = Encoding.PETSCII override fun encodeString(str: String, encoding: Encoding): List { diff --git a/docs/source/todo.rst b/docs/source/todo.rst index b682fdbf7..e1661ef9e 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -2,8 +2,6 @@ TODO ==== -- fix crash on uword[0] = uword[0] or 128 -- uword scanline_buf = memory("scanline", 320, 0) different result when inside a sub or outside a sub??! (imageviewer iff module) - [on branch: shortcircuit] investigate McCarthy evaluation again? this may also reduce code size perhaps for things like if a>4 or a<2 .... - once VAL_1 is merged into the kernal properly, remove all the workarounds in cx16 floats.parse_f()