From 7cf78ca2bd72c4ab1f7df20b2edc36af238cff29 Mon Sep 17 00:00:00 2001 From: Karol Stasiak Date: Mon, 6 Aug 2018 19:16:42 +0200 Subject: [PATCH] Use one statement preprocessor per function. --- .../scala/millfork/compiler/AbstractStatementCompiler.scala | 4 +--- src/main/scala/millfork/compiler/mos/MosCompiler.scala | 2 +- .../scala/millfork/compiler/mos/MosStatementCompiler.scala | 3 --- src/main/scala/millfork/compiler/z80/Z80Compiler.scala | 2 +- .../scala/millfork/compiler/z80/Z80StatementCompiler.scala | 3 --- 5 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/main/scala/millfork/compiler/AbstractStatementCompiler.scala b/src/main/scala/millfork/compiler/AbstractStatementCompiler.scala index d915c98c..020a521f 100644 --- a/src/main/scala/millfork/compiler/AbstractStatementCompiler.scala +++ b/src/main/scala/millfork/compiler/AbstractStatementCompiler.scala @@ -12,11 +12,9 @@ import millfork.node._ abstract class AbstractStatementCompiler[T <: AbstractCode] { def compile(ctx: CompilationContext, statements: List[ExecutableStatement]): List[T] = { - getStatementPreprocessor(ctx, statements)().flatMap(s => compile(ctx, s)) + statements.flatMap(s => compile(ctx, s)) } - def getStatementPreprocessor(ctx: CompilationContext, statements: List[ExecutableStatement]): AbstractStatementPreprocessor - def compile(ctx: CompilationContext, statement: ExecutableStatement): List[T] def labelChunk(labelName: String): List[T] diff --git a/src/main/scala/millfork/compiler/mos/MosCompiler.scala b/src/main/scala/millfork/compiler/mos/MosCompiler.scala index 5e612476..7cd3d378 100644 --- a/src/main/scala/millfork/compiler/mos/MosCompiler.scala +++ b/src/main/scala/millfork/compiler/mos/MosCompiler.scala @@ -15,7 +15,7 @@ object MosCompiler extends AbstractCompiler[AssemblyLine] { override def compile(ctx: CompilationContext): List[AssemblyLine] = { ctx.env.nameCheck(ctx.function.code) - val chunk = MosStatementCompiler.compile(ctx, ctx.function.code) + val chunk = MosStatementCompiler.compile(ctx, new MosStatementPreprocessor(ctx, ctx.function.code)()) val zpRegisterSize = ctx.options.zpRegisterSize val storeParamsFromRegisters = ctx.function.params match { diff --git a/src/main/scala/millfork/compiler/mos/MosStatementCompiler.scala b/src/main/scala/millfork/compiler/mos/MosStatementCompiler.scala index b6a2d03d..bef8f073 100644 --- a/src/main/scala/millfork/compiler/mos/MosStatementCompiler.scala +++ b/src/main/scala/millfork/compiler/mos/MosStatementCompiler.scala @@ -307,7 +307,4 @@ object MosStatementCompiler extends AbstractStatementCompiler[AssemblyLine] { } AssemblyLine.implied(TSX) :: (List.fill(m.stackVariablesSize)(AssemblyLine.implied(INX)) :+ AssemblyLine.implied(TXS)) // this TXS is fine, it won't appear in 65816 code } - - override def getStatementPreprocessor(ctx: CompilationContext, statements: List[ExecutableStatement]): AbstractStatementPreprocessor = - new MosStatementPreprocessor(ctx, statements) } diff --git a/src/main/scala/millfork/compiler/z80/Z80Compiler.scala b/src/main/scala/millfork/compiler/z80/Z80Compiler.scala index b9d76816..9d8dec61 100644 --- a/src/main/scala/millfork/compiler/z80/Z80Compiler.scala +++ b/src/main/scala/millfork/compiler/z80/Z80Compiler.scala @@ -13,7 +13,7 @@ object Z80Compiler extends AbstractCompiler[ZLine] { override def compile(ctx: CompilationContext): List[ZLine] = { ctx.env.nameCheck(ctx.function.code) - val chunk = Z80StatementCompiler.compile(ctx, ctx.function.code) + val chunk = Z80StatementCompiler.compile(ctx, new Z80StatementPreprocessor(ctx, ctx.function.code)()) val label = ZLine.label(Label(ctx.function.name)).copy(elidable = false) val storeParamsFromRegisters = ctx.function.params match { case NormalParamSignature(List(param)) if param.typ.size == 1 => diff --git a/src/main/scala/millfork/compiler/z80/Z80StatementCompiler.scala b/src/main/scala/millfork/compiler/z80/Z80StatementCompiler.scala index 0f16dca0..4c4d93d5 100644 --- a/src/main/scala/millfork/compiler/z80/Z80StatementCompiler.scala +++ b/src/main/scala/millfork/compiler/z80/Z80StatementCompiler.scala @@ -265,7 +265,4 @@ object Z80StatementCompiler extends AbstractStatementCompiler[ZLine] { override def compileExpressionForBranching(ctx: CompilationContext, expr: Expression, branching: BranchSpec): List[ZLine] = Z80ExpressionCompiler.compile(ctx, expr, ZExpressionTarget.NOTHING, branching) - - override def getStatementPreprocessor(ctx: CompilationContext, statements: List[ExecutableStatement]): AbstractStatementPreprocessor = - new Z80StatementPreprocessor(ctx, statements) }