1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-06-30 21:29:36 +00:00

Decimal subtraction fixes

This commit is contained in:
Karol Stasiak 2018-07-24 23:14:09 +02:00
parent 1e822239d0
commit 749defd05a
3 changed files with 10 additions and 3 deletions

View File

@ -825,6 +825,7 @@ object BuiltIns {
if (l.+(1).quickSimplify == h) {
return List(AssemblyLine.zeropage(INC_W, l))
}
case _ =>
}
}
if (ctx.options.flags(CompilationFlag.EmitNative65816Opcodes)) {
@ -1016,7 +1017,7 @@ object BuiltIns {
???
}
buffer ++= staTo(LDA, targetBytes(i))
buffer ++= ldTo(SBC, addendByteRead(i))
buffer ++= wrapInSedCldIfNeeded(decimal, ldTo(SBC, addendByteRead(i)))
buffer ++= targetBytes(i)
} else {
if (i >= addendSize) {

View File

@ -232,6 +232,9 @@ case class CompoundConstant(operator: MathOperator.Value, lhs: Constant, rhs: Co
case (_, CompoundConstant(MathOperator.Plus, a, b)) if operator == MathOperator.Minus =>
((l - a) - b).quickSimplify
case (CompoundConstant(MathOperator.Shl, SubbyteConstant(c1, 1), NumericConstant(8, _)), SubbyteConstant(c2, 0)) if operator == MathOperator.Or && c1 == c2 => c1
case (_, CompoundConstant(MathOperator.DecimalMinus, a, b)) if operator == MathOperator.DecimalPlus =>
CompoundConstant(MathOperator.DecimalMinus, CompoundConstant(MathOperator.DecimalPlus, l, a), b).quickSimplify
case (NumericConstant(lv, ls), NumericConstant(rv, rs)) =>
var size = ls max rs
val value = operator match {
@ -247,7 +250,9 @@ case class CompoundConstant(operator: MathOperator.Value, lhs: Constant, rhs: Co
case MathOperator.Or => lv | rv
case MathOperator.And => lv & rv
case MathOperator.DecimalPlus if ls == 1 && rs == 1 =>
asDecimal(lv, rv, _ + _) & 0xff
asDecimal(lv & 0xff, rv & 0xff, _ + _) & 0xff
case MathOperator.DecimalMinus if ls == 1 && rs == 1 && lv.&(0xff) >= rv.&(0xff) =>
asDecimal(lv & 0xff, rv & 0xff, _ - _) & 0xff
case _ => return this
}
operator match {
@ -285,6 +290,7 @@ case class CompoundConstant(operator: MathOperator.Value, lhs: Constant, rhs: Co
case MathOperator.DecimalPlus => c
case MathOperator.DecimalPlus9 => c
case MathOperator.Minus => c
case MathOperator.DecimalMinus => c
case MathOperator.Times => Constant.Zero
case MathOperator.Shl => c
case MathOperator.Shr => c

View File

@ -222,7 +222,7 @@ abstract class MfParser[T](fileId: String, input: String, currentDirectory: Stri
case List("+") | List("-") | List("+", "-") | List("-", "+") =>
SumExpression(xs.toPairList("+").map { case (op, value) => (op == "-", p(value, level + 1)) }, decimal = false)
case List("+'") | List("-'") | List("+'", "-'") | List("-'", "+'") =>
SumExpression(xs.toPairList("+").map { case (op, value) => (op == "-", p(value, level + 1)) }, decimal = true)
SumExpression(xs.toPairList("+").map { case (op, value) => (op == "-'", p(value, level + 1)) }, decimal = true)
case List(":") =>
if (xs.size != 2) {
ErrorReporting.error("The `:` operator can have only two arguments", xs.head.head.position)