From 31cbb3d42d71d8a5a98c362e2e39ff27ab839a0e Mon Sep 17 00:00:00 2001 From: Karol Stasiak Date: Wed, 31 Jul 2019 23:36:08 +0200 Subject: [PATCH] Fix optimized struct assignments (again) --- .../compiler/z80/Z80StatementCompiler.scala | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/scala/millfork/compiler/z80/Z80StatementCompiler.scala b/src/main/scala/millfork/compiler/z80/Z80StatementCompiler.scala index 668016e9..ea10e537 100644 --- a/src/main/scala/millfork/compiler/z80/Z80StatementCompiler.scala +++ b/src/main/scala/millfork/compiler/z80/Z80StatementCompiler.scala @@ -196,13 +196,18 @@ object Z80StatementCompiler extends AbstractStatementCompiler[ZLine] { case s: ContinueStatement => compileContinueStatement(ctx, s) -> Nil case ExpressionStatement(e@FunctionCallExpression(name, params)) => - env.lookupFunction(name, params.map(p => Z80ExpressionCompiler.getExpressionType(ctx, p) -> p)) match { - case Some(i: MacroFunction) => - val (paramPreparation, inlinedStatements) = Z80MacroExpander.inlineFunction(ctx, i, params, e.position) - val (main, extra) = compile(ctx.withInlinedEnv(i.environment, ctx.nextLabel("en")), inlinedStatements) - paramPreparation ++ main -> extra + env.maybeGet[Type](name) match { + case Some(_) => + params.flatMap(p => Z80ExpressionCompiler.compile(ctx, p, ZExpressionTarget.NOTHING)) -> Nil case _ => - Z80ExpressionCompiler.compile(ctx, e, ZExpressionTarget.NOTHING) -> Nil + env.lookupFunction(name, params.map(p => Z80ExpressionCompiler.getExpressionType(ctx, p) -> p)) match { + case Some(i: MacroFunction) => + val (paramPreparation, inlinedStatements) = Z80MacroExpander.inlineFunction(ctx, i, params, e.position) + val (main, extra) = compile(ctx.withInlinedEnv(i.environment, ctx.nextLabel("en")), inlinedStatements) + paramPreparation ++ main -> extra + case _ => + Z80ExpressionCompiler.compile(ctx, e, ZExpressionTarget.NOTHING) -> Nil + } } case ExpressionStatement(e) => Z80ExpressionCompiler.compile(ctx, e, ZExpressionTarget.NOTHING) -> Nil