From 0adce9b9c60a669472fbe8e223c9b57c5c42b5a7 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sat, 22 Jul 2023 22:11:30 +0200 Subject: [PATCH] removed complexity restriction on array indexing expressions --- .../compiler/astprocessing/AstExtensions.kt | 2 +- .../astprocessing/BeforeAsmAstChanger.kt | 48 +------------------ 2 files changed, 2 insertions(+), 48 deletions(-) diff --git a/compiler/src/prog8/compiler/astprocessing/AstExtensions.kt b/compiler/src/prog8/compiler/astprocessing/AstExtensions.kt index 30ce50201..df3577760 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstExtensions.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstExtensions.kt @@ -27,7 +27,7 @@ internal fun Program.processAstBeforeAsmGeneration(compilerOptions: CompilationO boolRemover.visit(this) boolRemover.applyModifications() - val fixer = BeforeAsmAstChanger(this, compilerOptions, errors) + val fixer = BeforeAsmAstChanger(this, compilerOptions) fixer.visit(this) while (errors.noErrors() && fixer.applyModifications() > 0) { fixer.visit(this) diff --git a/compiler/src/prog8/compiler/astprocessing/BeforeAsmAstChanger.kt b/compiler/src/prog8/compiler/astprocessing/BeforeAsmAstChanger.kt index 82b862fb7..d5b04dd38 100644 --- a/compiler/src/prog8/compiler/astprocessing/BeforeAsmAstChanger.kt +++ b/compiler/src/prog8/compiler/astprocessing/BeforeAsmAstChanger.kt @@ -9,14 +9,10 @@ import prog8.ast.getTempVar import prog8.ast.statements.* import prog8.ast.walk.AstWalker import prog8.ast.walk.IAstModification -import prog8.ast.walk.IAstVisitor import prog8.code.core.* import prog8.code.target.VMTarget -internal class BeforeAsmAstChanger(val program: Program, - private val options: CompilationOptions, - private val errors: IErrorReporter -) : AstWalker() { +internal class BeforeAsmAstChanger(val program: Program, private val options: CompilationOptions) : AstWalker() { override fun before(breakStmt: Break, parent: Node): Iterable { throw InternalCompilerException("break should have been replaced by goto $breakStmt") @@ -219,12 +215,6 @@ internal class BeforeAsmAstChanger(val program: Program, override fun after(arrayIndexedExpression: ArrayIndexedExpression, parent: Node): Iterable { if(options.compTarget.name!=VMTarget.NAME) { // don't apply this optimization/check for Vm target - val containingStatement = getContainingStatement(arrayIndexedExpression) - if(getComplexArrayIndexedExpressions(containingStatement).size > 1) { - errors.err("it's not possible to use more than one complex array indexing expression in a single statement; break it up via a temporary variable for instance", containingStatement.position) - return noModifications - } - val index = arrayIndexedExpression.indexer.indexExpr if (index !is NumericLiteral && index !is IdentifierReference) { // replace complex indexing expression with a temp variable to hold the computed index first @@ -235,42 +225,6 @@ internal class BeforeAsmAstChanger(val program: Program, return noModifications } - private fun getComplexArrayIndexedExpressions(stmt: Statement): List { - - class Searcher : IAstVisitor { - val complexArrayIndexedExpressions = mutableListOf() - override fun visit(arrayIndexedExpression: ArrayIndexedExpression) { - val ix = arrayIndexedExpression.indexer.indexExpr - if(ix !is NumericLiteral && ix !is IdentifierReference) - complexArrayIndexedExpressions.add(arrayIndexedExpression) - } - - override fun visit(branch: ConditionalBranch) {} - - override fun visit(forLoop: ForLoop) {} - - override fun visit(ifElse: IfElse) { - ifElse.condition.accept(this) - } - - override fun visit(untilLoop: UntilLoop) { - untilLoop.condition.accept(this) - } - } - - val searcher = Searcher() - stmt.accept(searcher) - return searcher.complexArrayIndexedExpressions - } - - private fun getContainingStatement(expression: Expression): Statement { - var node: Node = expression - while(node !is Statement) - node = node.parent - - return node - } - private fun getAutoIndexerVarFor(expr: ArrayIndexedExpression): MutableList { val modifications = mutableListOf() val statement = expr.containingStatement