swap() checks for unsupported code gen

This commit is contained in:
Irmen de Jong 2022-06-03 23:41:24 +02:00
parent 5fe6aa2800
commit 73a3a61729
3 changed files with 14 additions and 7 deletions

View File

@ -710,11 +710,6 @@ internal class BuiltinFunctionsAsmGen(private val program: Program,
val first = fcall.args[0]
val second = fcall.args[1]
val arrayVarDecl1 = (first as? ArrayIndexedExpression)?.arrayvar?.targetVarDecl(program)
val arrayVarDecl2 = (second as? ArrayIndexedExpression)?.arrayvar?.targetVarDecl(program)
if((arrayVarDecl1!=null && !arrayVarDecl1.isArray) || (arrayVarDecl2!=null && !arrayVarDecl2.isArray))
throw AssemblyError("no asm gen for swapping bytes to and/or from indexed pointer var ${fcall.position}")
// optimized simple case: swap two variables
if(first is IdentifierReference && second is IdentifierReference) {
val firstName = asmgen.asmVariableName(first)
@ -816,6 +811,11 @@ internal class BuiltinFunctionsAsmGen(private val program: Program,
}
if(first is ArrayIndexedExpression && second is ArrayIndexedExpression) {
val arrayVarDecl1 = first.arrayvar.targetVarDecl(program)!!
val arrayVarDecl2 = second.arrayvar.targetVarDecl(program)!!
if(!arrayVarDecl1.isArray || !arrayVarDecl2.isArray)
throw AssemblyError("no asm gen for swapping bytes to and/or from indexed pointer var ${fcall.position}")
val arrayVarName1 = asmgen.asmVariableName(first.arrayvar)
val arrayVarName2 = asmgen.asmVariableName(second.arrayvar)
val elementIDt = first.inferType(program)
@ -841,6 +841,11 @@ internal class BuiltinFunctionsAsmGen(private val program: Program,
}
}
val arrayVarDecl1 = (first as? ArrayIndexedExpression)?.arrayvar?.targetVarDecl(program)
val arrayVarDecl2 = (second as? ArrayIndexedExpression)?.arrayvar?.targetVarDecl(program)
if((arrayVarDecl1!=null && !arrayVarDecl1.isArray) || (arrayVarDecl2!=null && !arrayVarDecl2.isArray))
throw AssemblyError("no asm gen for swapping bytes to and/or from indexed pointer var ${fcall.position}")
// all other types of swap() calls are done via a temporary variable
fun targetFromExpr(expr: Expression, datatype: DataType): AsmAssignTarget {

View File

@ -1176,8 +1176,8 @@ internal class AstChecker(private val program: Program,
override fun visit(arrayIndexedExpression: ArrayIndexedExpression) {
val target = arrayIndexedExpression.arrayvar.targetStatement(program)
if(target is VarDecl) {
if(target.datatype !in IterableDatatypes)
errors.err("indexing requires an iterable variable", arrayIndexedExpression.position)
if(target.datatype !in IterableDatatypes && target.datatype!=DataType.UWORD)
errors.err("indexing requires an iterable or address uword variable", arrayIndexedExpression.position)
val arraysize = target.arraysize?.constIndex()
if(arraysize!=null) {
// check out of bounds

View File

@ -3,6 +3,8 @@ TODO
For next release
^^^^^^^^^^^^^^^^
- fix macptr issue in non-cx16 diskio
- why is this code so much larger:
uword xx
for xx in 0 to size-1 {