fix invalid size copied when assigning non-byte arrays

This commit is contained in:
Irmen de Jong 2022-01-23 02:42:26 +01:00
parent 7afc96112b
commit 1e053783f3
4 changed files with 24 additions and 17 deletions

View File

@ -129,7 +129,7 @@ class AsmGen(private val program: Program,
(vardecl.value as StringLiteralValue).value.length (vardecl.value as StringLiteralValue).value.length
} }
in ArrayDatatypes -> { in ArrayDatatypes -> {
vardecl.arraysize!!.constIndex() vardecl.arraysize!!.constIndex() // TODO wrong size for non-byte arrays??????? or does datatype get taken into account below
} }
else -> null else -> null
} }
@ -1193,7 +1193,7 @@ class AsmGen(private val program: Program,
jsr prog8_lib.strcpy""") jsr prog8_lib.strcpy""")
} }
arrayVarsInZp.forEach { arrayVarsInZp.forEach {
val numelements = (it.value as ArrayLiteralValue).value.size val numelements = (it.value as ArrayLiteralValue).value.size // TODO wrong size for word/float arrays!???
out(""" out("""
lda #<${it.name}_init_value lda #<${it.name}_init_value
ldy #>${it.name}_init_value ldy #>${it.name}_init_value

View File

@ -370,11 +370,13 @@ internal class StatementReorderer(val program: Program,
if(!errors.noErrors()) if(!errors.noErrors())
return noModifications return noModifications
val numelements = targetVar.arraysize!!.constIndex()!!
val eltsize = program.memsizer.memorySize(ArrayToElementTypes.getValue(sourceVar.datatype))
val memcopy = FunctionCallStatement(IdentifierReference(listOf("sys", "memcopy"), assign.position), val memcopy = FunctionCallStatement(IdentifierReference(listOf("sys", "memcopy"), assign.position),
mutableListOf( mutableListOf(
AddressOf(sourceIdent, assign.position), AddressOf(sourceIdent, assign.position),
AddressOf(identifier, assign.position), AddressOf(identifier, assign.position),
NumericLiteralValue.optimalInteger(targetVar.arraysize!!.constIndex()!!, assign.position) NumericLiteralValue.optimalInteger(numelements*eltsize, assign.position)
), ),
true, true,
assign.position assign.position

View File

@ -3,6 +3,8 @@ TODO
For next release For next release
^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^
- check/fix allocateAllZeropageVariables() for wrong array byte size?
- check/fix entrypointInitialization() for non-byte arrays in ZP, memcopy size wrong?
- Fix compiler stack overflow crash: - Fix compiler stack overflow crash:
sub sprite_y_for_row(ubyte row) -> word { sub sprite_y_for_row(ubyte row) -> word {
return (8-row as byte) return (8-row as byte)
@ -10,11 +12,6 @@ For next release
- fix crash: - fix crash:
word[33] sprites_x = sprites.sprites_x word[33] sprites_x = sprites.sprites_x
word[33] sprites_y = sprites.sprites_y word[33] sprites_y = sprites.sprites_y
- fix assignment code generated for: (memcopying manuall does work correctly)
word[33] sprites_x
word[33] sprites_y
sprites_x = sprites.sprites_x
sprites_y = sprites.sprites_y
- Fix: better error message for len() in: - Fix: better error message for len() in:
ubyte[64] chessboard ubyte[64] chessboard
sub init() { sub init() {

View File

@ -3,15 +3,23 @@
main { main {
sub start() { sub start() {
word[3] @shared sprites_x ; = sprites.sprites_x
sprites_x = sprites.sprites_x
word[3] @shared sprites_y ; = sprites.sprites_y
sprites_y = sprites.sprites_y
label: txt.print_w(sprites.sprites_x[2])
uword @shared addr txt.nl()
addr = label txt.print_w(sprites.sprites_y[2])
addr = thing txt.nl()
addr = &label txt.print_w(sprites_x[2])
addr = &thing txt.nl()
} txt.print_w(sprites_y[2])
txt.nl()
sub thing() {
} }
} }
sprites {
word[3] sprites_x = [111,222,333]
word[3] sprites_y = [666,777,888]
}