From 6be3b62d786c01330f89eb4d921ddbf5f22cc001 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Fri, 1 Apr 2022 18:06:39 +0200 Subject: [PATCH] fix new Ast gosub node translation --- .../src/prog8/compiler/IntermediateAstMaker.kt | 14 +++++++------- .../compiler/astprocessing/BeforeAsmAstChanger.kt | 2 -- docs/source/todo.rst | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/compiler/src/prog8/compiler/IntermediateAstMaker.kt b/compiler/src/prog8/compiler/IntermediateAstMaker.kt index f289e507a..9708e3abc 100644 --- a/compiler/src/prog8/compiler/IntermediateAstMaker.kt +++ b/compiler/src/prog8/compiler/IntermediateAstMaker.kt @@ -4,6 +4,7 @@ import com.github.michaelbull.result.Ok import com.github.michaelbull.result.Result import com.github.michaelbull.result.getOrElse import com.github.michaelbull.result.mapError +import prog8.ast.IFunctionCall import prog8.ast.IStatementContainer import prog8.ast.Program import prog8.ast.base.FatalAstException @@ -232,15 +233,14 @@ class IntermediateAstMaker(val program: Program) { } // instead of just assigning to the parameters, another way is to use push()/pop() if(previousNodes.isNotEmpty()) { - val first = previousNodes[0] as? FunctionCallStatement - if(first!=null && first.target.nameInSource == listOf("pop")) { - val numPops = previousNodes.indexOfFirst { (it as? FunctionCallStatement)?.target?.nameInSource != listOf("pop") } + val first = previousNodes[0] as? IFunctionCall + if(first!=null && (first.target.nameInSource.singleOrNull() in arrayOf("pop", "popw"))) { + val numPops = previousNodes.indexOfFirst { (it as? IFunctionCall)?.target?.nameInSource?.singleOrNull() !in arrayOf("pop", "popw") } val pops = previousNodes.subList(0, numPops) - val pushes = previousNodes.subList(numPops, numPops+numPops) - // TODO one of these has to be reversed? + val pushes = previousNodes.subList(numPops, numPops+numPops).reversed() for ((push, pop) in pushes.zip(pops)) { - val name = ((pop as FunctionCallStatement).args.single() as IdentifierReference).nameInSource.last() - val arg = (push as FunctionCallStatement).args.single() + val name = ((pop as IFunctionCall).args.single() as IdentifierReference).nameInSource.last() + val arg = (push as IFunctionCall).args.single() paramValues[name] = arg } } diff --git a/compiler/src/prog8/compiler/astprocessing/BeforeAsmAstChanger.kt b/compiler/src/prog8/compiler/astprocessing/BeforeAsmAstChanger.kt index 9cb2d42ad..35494a45b 100644 --- a/compiler/src/prog8/compiler/astprocessing/BeforeAsmAstChanger.kt +++ b/compiler/src/prog8/compiler/astprocessing/BeforeAsmAstChanger.kt @@ -29,8 +29,6 @@ internal class BeforeAsmAstChanger(val program: Program, } override fun after(containment: ContainmentCheck, parent: Node): Iterable { - if(containment.element !is IdentifierReference && containment.element !is NumericLiteral) - throw InternalCompilerException("element in containmentcheck should be identifier or constant number") if(containment.iterable !is IdentifierReference) throw InternalCompilerException("iterable in containmentcheck should be identifier (referencing string or array)") return noModifications diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 7b1539e86..3f9f6ab9a 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -3,7 +3,7 @@ TODO For next release ^^^^^^^^^^^^^^^^ -- fix assembler application compiler crash +- fix assembler application included file loading problem (hello4.asm) - x16: add new keyboard APIs https://github.com/commanderx16/x16-docs/blob/master/Commander%20X16%20Programmer%27s%20Reference%20Guide.md#keyboard - x16: optimize diskio load_raw because headerless files are now supported https://github.com/commanderx16/x16-rom/pull/216 note: must still work on c64/c128 that don't have this!