mirror of
https://github.com/KarolS/millfork.git
synced 2024-10-25 05:24:11 +00:00
More aggressive constant simplification
This commit is contained in:
parent
a2171aeef0
commit
60b9378554
@ -745,7 +745,7 @@ object ExpressionCompiler {
|
|||||||
if (neg) MathOperator.DecimalMinus else MathOperator.DecimalPlus
|
if (neg) MathOperator.DecimalMinus else MathOperator.DecimalPlus
|
||||||
} else {
|
} else {
|
||||||
if (neg) MathOperator.Minus else MathOperator.Plus
|
if (neg) MathOperator.Minus else MathOperator.Plus
|
||||||
}, c, v)
|
}, c, v).quickSimplify
|
||||||
}
|
}
|
||||||
exprTypeAndVariable.map(x => compileConstant(ctx, value.quickSimplify, x._2)).getOrElse(Nil)
|
exprTypeAndVariable.map(x => compileConstant(ctx, value.quickSimplify, x._2)).getOrElse(Nil)
|
||||||
} else {
|
} else {
|
||||||
|
16
src/main/scala/millfork/env/Constant.scala
vendored
16
src/main/scala/millfork/env/Constant.scala
vendored
@ -170,6 +170,22 @@ case class CompoundConstant(operator: MathOperator.Value, lhs: Constant, rhs: Co
|
|||||||
val l = lhs.quickSimplify
|
val l = lhs.quickSimplify
|
||||||
val r = rhs.quickSimplify
|
val r = rhs.quickSimplify
|
||||||
(l, r) match {
|
(l, r) match {
|
||||||
|
case (CompoundConstant(MathOperator.Plus, a, ll@NumericConstant(lv, _)), rr@NumericConstant(rv,_)) if operator == MathOperator.Plus =>
|
||||||
|
CompoundConstant(MathOperator.Plus, a, ll + rr).quickSimplify
|
||||||
|
case (CompoundConstant(MathOperator.Minus, a, ll@NumericConstant(lv, _)), rr@NumericConstant(rv,_)) if operator == MathOperator.Minus =>
|
||||||
|
CompoundConstant(MathOperator.Minus, a, ll + rr).quickSimplify
|
||||||
|
case (CompoundConstant(MathOperator.Plus, a, ll@NumericConstant(lv, _)), rr@NumericConstant(rv,_)) if operator == MathOperator.Minus =>
|
||||||
|
if (lv >= rv) {
|
||||||
|
CompoundConstant(MathOperator.Plus, a, ll - rr).quickSimplify
|
||||||
|
} else {
|
||||||
|
CompoundConstant(MathOperator.Minus, a, rr - ll).quickSimplify
|
||||||
|
}
|
||||||
|
case (CompoundConstant(MathOperator.Minus, a, ll@NumericConstant(lv, _)), rr@NumericConstant(rv,_)) if operator == MathOperator.Plus =>
|
||||||
|
if (lv >= rv) {
|
||||||
|
CompoundConstant(MathOperator.Minus, a, ll - rr).quickSimplify
|
||||||
|
} else {
|
||||||
|
CompoundConstant(MathOperator.Plus, a, rr - ll).quickSimplify
|
||||||
|
}
|
||||||
case (CompoundConstant(MathOperator.Shl, HalfWordConstant(c1, true), NumericConstant(8, _)), HalfWordConstant(c2, false)) if operator == MathOperator.Or && c1 == c2 => c1
|
case (CompoundConstant(MathOperator.Shl, HalfWordConstant(c1, true), NumericConstant(8, _)), HalfWordConstant(c2, false)) if operator == MathOperator.Or && c1 == c2 => c1
|
||||||
case (NumericConstant(lv, ls), NumericConstant(rv, rs)) =>
|
case (NumericConstant(lv, ls), NumericConstant(rv, rs)) =>
|
||||||
var size = ls max rs
|
var size = ls max rs
|
||||||
|
Loading…
Reference in New Issue
Block a user