From 1462c57d0c244b39084131b4961ceb3c3e88f202 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Thu, 16 Dec 2021 21:00:38 +0100 Subject: [PATCH] no need for intermediary returnvalue var for prefix expressions --- .../cpu6502/codegen/FunctionCallAsmGen.kt | 23 +++++++++---------- .../assignment/AugmentableAssignmentAsmGen.kt | 6 ++--- .../src/prog8/optimizer/StatementOptimizer.kt | 18 ++++----------- docs/source/todo.rst | 4 ---- 4 files changed, 19 insertions(+), 32 deletions(-) diff --git a/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/FunctionCallAsmGen.kt b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/FunctionCallAsmGen.kt index 2396b5bef..a9e466170 100644 --- a/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/FunctionCallAsmGen.kt +++ b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/FunctionCallAsmGen.kt @@ -312,22 +312,21 @@ internal class FunctionCallAsmGen(private val program: Program, private val asmg is IdentifierReference -> { val sourceName = asmgen.asmVariableName(value) asmgen.out(""" - pha - clc - lda $sourceName - beq + - sec - + pla - """) + pha + clc + lda $sourceName + beq + + sec ++ pla""") } else -> { asmgen.assignExpressionToRegister(value, RegisterOrPair.A) asmgen.out(""" - beq + - sec - bcs ++ - + clc - +""") + beq + + sec + bcs ++ ++ clc ++""") } } } else throw AssemblyError("can only use Carry as status flag parameter") diff --git a/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/assignment/AugmentableAssignmentAsmGen.kt b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/assignment/AugmentableAssignmentAsmGen.kt index dc91ffea4..e20e0b9ce 100644 --- a/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/assignment/AugmentableAssignmentAsmGen.kt +++ b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/assignment/AugmentableAssignmentAsmGen.kt @@ -1824,18 +1824,18 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, cmp #0 beq + lda #1 - + eor #1""") ++ eor #1""") RegisterOrPair.X -> asmgen.out(""" txa beq + lda #1 - + eor #1 ++ eor #1 tax""") RegisterOrPair.Y -> asmgen.out(""" tya beq + lda #1 - + eor #1 ++ eor #1 tay""") else -> throw AssemblyError("invalid reg dt for byte not") } diff --git a/codeOptimizers/src/prog8/optimizer/StatementOptimizer.kt b/codeOptimizers/src/prog8/optimizer/StatementOptimizer.kt index 7f176dbea..a88726714 100644 --- a/codeOptimizers/src/prog8/optimizer/StatementOptimizer.kt +++ b/codeOptimizers/src/prog8/optimizer/StatementOptimizer.kt @@ -466,21 +466,13 @@ class StatementOptimizer(private val program: Program, return null } - when(returnStmt.value) { - is PrefixExpression -> { - val mod = returnViaIntermediaryVar(returnStmt.value!!) - if(mod!=null) - return mod - } - is BinaryExpression -> { - val mod = returnViaIntermediaryVar(returnStmt.value!!) - if(mod!=null) - return mod - } - else -> {} + if(returnStmt.value is BinaryExpression) { + val mod = returnViaIntermediaryVar(returnStmt.value!!) + if(mod!=null) + return mod } - return super.after(returnStmt, parent) + return noModifications } private fun hasBreak(scope: IStatementContainer): Boolean { diff --git a/docs/source/todo.rst b/docs/source/todo.rst index ed35a51c7..72167e591 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -3,10 +3,6 @@ TODO For next compiler release (7.6) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -why does the following use a intermediate return value and not just A? - sub pushing_start() -> ubyte { - return joy_info & 16 - } ...