diff --git a/codeOptimizers/src/prog8/optimizer/ExpressionSimplifier.kt b/codeOptimizers/src/prog8/optimizer/ExpressionSimplifier.kt index 3b498c12a..2f1d4aab8 100644 --- a/codeOptimizers/src/prog8/optimizer/ExpressionSimplifier.kt +++ b/codeOptimizers/src/prog8/optimizer/ExpressionSimplifier.kt @@ -348,7 +348,8 @@ class ExpressionSimplifier(private val program: Program) : AstWalker() { } else if(segments.size>1) { // replace source+firstsegment by firstsegment(source) call as the new source val firstSegment = segments.removeAt(0) as IFunctionCall - val call = FunctionCallExpression(firstSegment.target, mutableListOf(pipe.source), pipe.position) + val newArgs = listOf(pipe.source) + firstSegment.args + val call = FunctionCallExpression(firstSegment.target, newArgs.toMutableList(), pipe.position) return listOf(IAstModification.ReplaceNode(pipe.source, call, pipe as Node)) } } diff --git a/examples/test.p8 b/examples/test.p8 index dabf2364d..587fea1dc 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -29,26 +29,39 @@ main { ; } + sub func1(ubyte a1, ubyte a2) -> ubyte { + return a1+a2+42 + } + + sub func2(ubyte a1, ubyte a2) -> ubyte { + return 200-a1-a2 + } + sub start() { ; mcCarthy() + ; 9+10+42 = 61 + ; 200-61-2 = 137 + ubyte result = 9 |> func1(10) |> func2(2) + txt.print_ub(result) + txt.nl() ; a "pixelshader": - sys.gfx_enable(0) ; enable lo res screen - ubyte shifter - - repeat { - uword xx - uword yy = 0 - repeat 240 { - xx = 0 - repeat 320 { - sys.gfx_plot(xx, yy, xx*yy + shifter as ubyte) - xx++ - } - yy++ - } - shifter+=4 - } +; sys.gfx_enable(0) ; enable lo res screen +; ubyte shifter +; +; repeat { +; uword xx +; uword yy = 0 +; repeat 240 { +; xx = 0 +; repeat 320 { +; sys.gfx_plot(xx, yy, xx*yy + shifter as ubyte) +; xx++ +; } +; yy++ +; } +; shifter+=4 +; } } }