diff --git a/codeOptimizers/src/prog8/optimizer/BinExprSplitter.kt b/codeOptimizers/src/prog8/optimizer/BinExprSplitter.kt index 84d9a2f27..cbf5594b2 100644 --- a/codeOptimizers/src/prog8/optimizer/BinExprSplitter.kt +++ b/codeOptimizers/src/prog8/optimizer/BinExprSplitter.kt @@ -45,7 +45,7 @@ X = BinExpr X = LeftExpr */ - if(binExpr.operator in AugmentAssignmentOperators && isSimpleTarget(assignment.target)) { + if(binExpr.operator in AugmentAssignmentOperators + listOf("==", "!=") && isSimpleTarget(assignment.target)) { if(assignment.target isSameAs binExpr.right) return noModifications if(assignment.target isSameAs binExpr.left) { @@ -73,6 +73,15 @@ X = BinExpr X = LeftExpr // ) } + if(binExpr.operator == "==" || binExpr.operator == "!=") { + // don't split if the operand(s) don't fit the type of the resulting variable + val targetDt = assignment.target.inferType(program) + val leftDt = binExpr.left.inferType(program) + val rightDt = binExpr.right.inferType(program) + if(leftDt isNotAssignableTo targetDt || rightDt isNotAssignableTo targetDt) + return noModifications + } + if(binExpr.right.isSimple) { val firstAssign = Assignment(assignment.target.copy(), binExpr.left, binExpr.left.position) val targetExpr = assignment.target.toExpression() diff --git a/compiler/src/prog8/compiler/Compiler.kt b/compiler/src/prog8/compiler/Compiler.kt index f16a77079..45430e3cf 100644 --- a/compiler/src/prog8/compiler/Compiler.kt +++ b/compiler/src/prog8/compiler/Compiler.kt @@ -66,7 +66,10 @@ fun compileProgram(args: CompilerArguments): CompilationResult { program = programresult importedFiles = imported processAst(program, args.errors, compilationOptions) - if (compilationOptions.optimize) + if (compilationOptions.optimize) { +// println("*********** AST RIGHT BEFORE OPTIMIZING *************") +// printProgram(program) + optimizeAst( program, compilationOptions, @@ -74,6 +77,7 @@ fun compileProgram(args: CompilerArguments): CompilationResult { BuiltinFunctionsFacade(BuiltinFunctions), compTarget ) + } postprocessAst(program, args.errors, compilationOptions) // println("*********** AST BEFORE ASSEMBLYGEN *************") diff --git a/examples/test.p8 b/examples/test.p8 index fa34c500e..eaf16d5ce 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -5,12 +5,21 @@ main { sub start() { ubyte @shared xx ubyte @shared yy + ubyte camg + ubyte @shared interlaced = (camg & $04) != 0 + + yy = xx + yy = yy==7 + + yy++ yy = xx==7 - if xx==99 { - xx++ - yy++ - } - txt.nl() + yy++ + +; if xx==99 { +; xx++ +; yy++ +; } +; txt.nl() } }