diff --git a/codeOptimizers/src/prog8/optimizer/StatementOptimizer.kt b/codeOptimizers/src/prog8/optimizer/StatementOptimizer.kt index e61ee6815..30e012084 100644 --- a/codeOptimizers/src/prog8/optimizer/StatementOptimizer.kt +++ b/codeOptimizers/src/prog8/optimizer/StatementOptimizer.kt @@ -18,7 +18,7 @@ class StatementOptimizer(private val program: Program, override fun before(functionCallExpr: FunctionCallExpression, parent: Node): Iterable { // if the first instruction in the called subroutine is a return statement with a simple value (NOT being a parameter), - // remove the jump altogeter and inline the returnvalue directly. + // remove the jump altogeter and inline the returnvalue directly. (only if not part of a pipe expression) fun scopePrefix(variable: IdentifierReference): IdentifierReference { val target = variable.targetStatement(program) as INamedStatement @@ -28,7 +28,7 @@ class StatementOptimizer(private val program: Program, val subroutine = functionCallExpr.target.targetSubroutine(program) if(subroutine!=null) { val first = subroutine.statements.asSequence().filterNot { it is VarDecl || it is Directive }.firstOrNull() - if(first is Return && first.value?.isSimple==true) { + if(first is Return && first.value?.isSimple==true && parent !is IPipe) { val copy = when(val orig = first.value!!) { is AddressOf -> { val scoped = scopePrefix(orig.identifier) diff --git a/compiler/res/prog8lib/virtual/math.p8 b/compiler/res/prog8lib/virtual/math.p8 index 12942459e..4cb939f64 100644 --- a/compiler/res/prog8lib/virtual/math.p8 +++ b/compiler/res/prog8lib/virtual/math.p8 @@ -3,5 +3,68 @@ ; Written by Irmen de Jong (irmen@razorvine.net) - license: GNU GPL 3.0 math { - ; required by the compiler, but the vm implements all math operations as instructions. + + sub sin8u(ubyte angle) -> ubyte { + return 42 ; TODO + } + + sub cos8u(ubyte angle) -> ubyte { + return 42 ; TODO + } + + sub sin8(ubyte angle) -> byte { + return 42 ; TODO + } + + sub cos8(ubyte angle) -> byte { + return 42 ; TODO + } + + sub sin16(ubyte angle) -> word { + return 4242 ; TODO + } + + sub cos16(ubyte angle) -> word { + return 4242 ; TODO + } + + sub sin16u(ubyte angle) -> uword { + return 4242 ; TODO + } + + sub cos16u(ubyte angle) -> uword { + return 4242 ; TODO + } + + sub sinr8u(ubyte radians) -> ubyte { + return 42 ; TODO + } + + sub cosr8u(ubyte radians) -> ubyte { + return 42 ; TODO + } + + sub sinr8(ubyte radians) -> byte { + return 42 ; TODO + } + + sub cosr8(ubyte radians) -> byte { + return 42 ; TODO + } + + sub sinr16(ubyte radians) -> word { + return 4242 ; TODO + } + + sub cosr16(ubyte radians) -> word { + return 4242 ; TODO + } + + sub sinr16u(ubyte radians) -> uword { + return 4242 ; TODO + } + + sub cosr16u(ubyte radians) -> uword { + return 4242 ; TODO + } } diff --git a/compilerAst/src/prog8/ast/AstToSourceTextConverter.kt b/compilerAst/src/prog8/ast/AstToSourceTextConverter.kt index aa277706b..fcc75904a 100644 --- a/compilerAst/src/prog8/ast/AstToSourceTextConverter.kt +++ b/compilerAst/src/prog8/ast/AstToSourceTextConverter.kt @@ -472,6 +472,7 @@ class AstToSourceTextConverter(val output: (text: String) -> Unit, val program: private fun printPipe(source: Expression, segments: Iterable) { source.accept(this) + output(" |> ") segments.first().accept(this) outputln("") scopelevel++ diff --git a/examples/test.p8 b/examples/test.p8 index 6199152d7..f6c30d0b7 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,4 +1,5 @@ %import textio +%import math %zeropage dontuse @@ -7,31 +8,11 @@ main { sub start() { - const ubyte times=3 + ubyte source=99 + ubyte value= source |> math.sin8u() |> math.cos8u() + txt.print_ub(value) + ; expected output: aaabbb aaa bbb - txt.print("aaa"+"bbb"+"ccc") - txt.nl() -; txt.print("aaa") -; txt.nl() -; txt.print("bbb") -; txt.nl() - ; expected output: xxx xxxxxx xxxxxxxxx xxx -; txt.print("xxx"*(times-2)) -; txt.nl() -; txt.print("xxx"*(times-1)) -; txt.nl() - txt.print("xxx"*times) - txt.nl() -; txt.print("xxx") -; txt.nl() - sys.exit(42) -; floats.print_f(-42.42) -; float f1 = 1.2345 -; float f2 = -9.99 -; float f3 -; f3 = floats.sin(f3) -; floats.print_f(f3) -; txt.nl() ; float f1 = 1.555 ; floats.print_f(floats.sin(f1))