compiler warning instead of crash when attempting to assign invalid array value to other array

This commit is contained in:
Irmen de Jong 2021-03-24 22:01:22 +01:00
parent 292640b17a
commit 1b14da6c03
3 changed files with 34 additions and 26 deletions

View File

@ -298,6 +298,10 @@ internal class StatementReorderer(val program: Program, val errors: IErrorReport
if(targetVar.arraysize==null) if(targetVar.arraysize==null)
errors.err("array has no defined size", assign.position) errors.err("array has no defined size", assign.position)
if(assign.value !is IdentifierReference) {
errors.err("invalid array value to assign to other array", assign.value.position)
return noModifications
}
val sourceIdent = assign.value as IdentifierReference val sourceIdent = assign.value as IdentifierReference
val sourceVar = sourceIdent.targetVarDecl(program)!! val sourceVar = sourceIdent.targetVarDecl(program)!!
if(!sourceVar.isArray) { if(!sourceVar.isArray) {
@ -310,7 +314,7 @@ internal class StatementReorderer(val program: Program, val errors: IErrorReport
} }
if(!errors.isEmpty()) if(!errors.isEmpty())
return emptyList() return noModifications
val memcopy = FunctionCallStatement(IdentifierReference(listOf("sys", "memcopy"), assign.position), val memcopy = FunctionCallStatement(IdentifierReference(listOf("sys", "memcopy"), assign.position),
mutableListOf( mutableListOf(

View File

@ -270,8 +270,8 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
} }
} }
} }
TargetStorageKind.REGISTER -> TODO("reg in-place modification") TargetStorageKind.REGISTER -> throw AssemblyError("missing codegen for reg in-place modification")
TargetStorageKind.STACK -> TODO("stack in-place modification") TargetStorageKind.STACK -> throw AssemblyError("missing codegen for stack in-place modification")
} }
} }
@ -1732,9 +1732,9 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
} }
} }
} }
TargetStorageKind.ARRAY -> TODO("in-place not of ubyte array") TargetStorageKind.ARRAY -> throw AssemblyError("missing codegen for in-place not of ubyte array")
TargetStorageKind.REGISTER -> TODO("reg not") TargetStorageKind.REGISTER -> throw AssemblyError("missing codegen for reg not")
TargetStorageKind.STACK -> TODO("stack not") TargetStorageKind.STACK -> throw AssemblyError("missing codegen for stack not")
} }
} }
DataType.UWORD -> { DataType.UWORD -> {
@ -1751,9 +1751,9 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
sta ${target.asmVarname}+1""") sta ${target.asmVarname}+1""")
} }
TargetStorageKind.MEMORY -> throw AssemblyError("no asm gen for uword-memory not") TargetStorageKind.MEMORY -> throw AssemblyError("no asm gen for uword-memory not")
TargetStorageKind.ARRAY -> TODO("in-place not of uword array") TargetStorageKind.ARRAY -> throw AssemblyError("missing codegen for in-place not of uword array")
TargetStorageKind.REGISTER -> TODO("reg not") TargetStorageKind.REGISTER -> throw AssemblyError("missing codegen for reg not")
TargetStorageKind.STACK -> TODO("stack not") TargetStorageKind.STACK -> throw AssemblyError("missing codegen for stack not")
} }
} }
else -> throw AssemblyError("boolean-not of invalid type") else -> throw AssemblyError("boolean-not of invalid type")
@ -1798,9 +1798,9 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
} }
} }
} }
TargetStorageKind.ARRAY -> TODO("in-place invert ubyte array") TargetStorageKind.ARRAY -> throw AssemblyError("missing codegen for in-place invert ubyte array")
TargetStorageKind.REGISTER -> TODO("reg invert") TargetStorageKind.REGISTER -> throw AssemblyError("missing codegen for reg invert")
TargetStorageKind.STACK -> TODO("stack invert") TargetStorageKind.STACK -> throw AssemblyError("missing codegen for stack invert")
} }
} }
DataType.UWORD -> { DataType.UWORD -> {
@ -1815,9 +1815,9 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
sta ${target.asmVarname}+1""") sta ${target.asmVarname}+1""")
} }
TargetStorageKind.MEMORY -> throw AssemblyError("no asm gen for uword-memory invert") TargetStorageKind.MEMORY -> throw AssemblyError("no asm gen for uword-memory invert")
TargetStorageKind.ARRAY -> TODO("in-place invert uword array") TargetStorageKind.ARRAY -> throw AssemblyError("missing codegen for in-place invert uword array")
TargetStorageKind.REGISTER -> TODO("reg invert") TargetStorageKind.REGISTER -> throw AssemblyError("missing codegen for reg invert")
TargetStorageKind.STACK -> TODO("stack invert") TargetStorageKind.STACK -> throw AssemblyError("missing codegen for stack invert")
} }
} }
else -> throw AssemblyError("invert of invalid type") else -> throw AssemblyError("invert of invalid type")
@ -1836,9 +1836,9 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
sta ${target.asmVarname}""") sta ${target.asmVarname}""")
} }
TargetStorageKind.MEMORY -> throw AssemblyError("can't in-place negate memory ubyte") TargetStorageKind.MEMORY -> throw AssemblyError("can't in-place negate memory ubyte")
TargetStorageKind.ARRAY -> TODO("in-place negate byte array") TargetStorageKind.ARRAY -> throw AssemblyError("missing codegen for in-place negate byte array")
TargetStorageKind.REGISTER -> TODO("reg negate") TargetStorageKind.REGISTER -> throw AssemblyError("missing codegen for reg negate")
TargetStorageKind.STACK -> TODO("stack negate") TargetStorageKind.STACK -> throw AssemblyError("missing codegen for stack negate")
} }
} }
DataType.WORD -> { DataType.WORD -> {
@ -1853,10 +1853,10 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
sbc ${target.asmVarname}+1 sbc ${target.asmVarname}+1
sta ${target.asmVarname}+1""") sta ${target.asmVarname}+1""")
} }
TargetStorageKind.ARRAY -> TODO("in-place negate word array") TargetStorageKind.ARRAY -> throw AssemblyError("missing codegen for in-place negate word array")
TargetStorageKind.MEMORY -> throw AssemblyError("no asm gen for word memory negate") TargetStorageKind.MEMORY -> throw AssemblyError("no asm gen for word memory negate")
TargetStorageKind.REGISTER -> TODO("reg negate") TargetStorageKind.REGISTER -> throw AssemblyError("missing codegen for reg negate")
TargetStorageKind.STACK -> TODO("stack negate") TargetStorageKind.STACK -> throw AssemblyError("missing codegen for stack negate")
} }
} }
DataType.FLOAT -> { DataType.FLOAT -> {
@ -1869,8 +1869,8 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
sta ${target.asmVarname}+1 sta ${target.asmVarname}+1
""") """)
} }
TargetStorageKind.ARRAY -> TODO("in-place negate float array") TargetStorageKind.ARRAY -> throw AssemblyError("missing codegen for in-place negate float array")
TargetStorageKind.STACK -> TODO("stack float negate") TargetStorageKind.STACK -> throw AssemblyError("missing codegen for stack float negate")
else -> throw AssemblyError("weird target kind for float") else -> throw AssemblyError("weird target kind for float")
} }
} }

View File

@ -9,10 +9,14 @@ main {
str string2 = "hello" str string2 = "hello"
uword xx = $f000 uword xx = $f000
word ww
ubyte[] arr = [1,2,3]
arr = ~ arr
cx16.r0 = ~cx16.r0
ww = -cx16.r0
cx16.r0 = not cx16.r0
; string1 = xx
; string1 = string2
string1 = string2 as uword
; ubyte[] array = [1,2,3,4] ; ubyte[] array = [1,2,3,4]
; ubyte ix ; ubyte ix