From 73a3a617290a546f074ca845af79d1974ad5af5f Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Fri, 3 Jun 2022 23:41:24 +0200 Subject: [PATCH] swap() checks for unsupported code gen --- .../codegen/cpu6502/BuiltinFunctionsAsmGen.kt | 15 ++++++++++----- .../prog8/compiler/astprocessing/AstChecker.kt | 4 ++-- docs/source/todo.rst | 2 ++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/BuiltinFunctionsAsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/BuiltinFunctionsAsmGen.kt index 5abf3b414..3e5c5452d 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/BuiltinFunctionsAsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/BuiltinFunctionsAsmGen.kt @@ -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 { diff --git a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt index 1f00f1797..c90e36362 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt @@ -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 diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 1c5502c7c..c5653a43d 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -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 {