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
}
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
}
@ -1193,7 +1193,7 @@ class AsmGen(private val program: Program,
jsr prog8_lib.strcpy""")
}
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("""
lda #<${it.name}_init_value
ldy #>${it.name}_init_value

View File

@ -370,11 +370,13 @@ internal class StatementReorderer(val program: Program,
if(!errors.noErrors())
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),
mutableListOf(
AddressOf(sourceIdent, assign.position),
AddressOf(identifier, assign.position),
NumericLiteralValue.optimalInteger(targetVar.arraysize!!.constIndex()!!, assign.position)
NumericLiteralValue.optimalInteger(numelements*eltsize, assign.position)
),
true,
assign.position

View File

@ -3,6 +3,8 @@ TODO
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:
sub sprite_y_for_row(ubyte row) -> word {
return (8-row as byte)
@ -10,11 +12,6 @@ For next release
- fix crash:
word[33] sprites_x = sprites.sprites_x
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:
ubyte[64] chessboard
sub init() {

View File

@ -3,15 +3,23 @@
main {
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:
uword @shared addr
addr = label
addr = thing
addr = &label
addr = &thing
txt.print_w(sprites.sprites_x[2])
txt.nl()
txt.print_w(sprites.sprites_y[2])
txt.nl()
txt.print_w(sprites_x[2])
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]
}