mirror of
https://github.com/KarolS/millfork.git
synced 2024-07-05 09:28:54 +00:00
Decimal subtraction fixes
This commit is contained in:
parent
1e822239d0
commit
749defd05a
@ -825,6 +825,7 @@ object BuiltIns {
|
|||||||
if (l.+(1).quickSimplify == h) {
|
if (l.+(1).quickSimplify == h) {
|
||||||
return List(AssemblyLine.zeropage(INC_W, l))
|
return List(AssemblyLine.zeropage(INC_W, l))
|
||||||
}
|
}
|
||||||
|
case _ =>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ctx.options.flags(CompilationFlag.EmitNative65816Opcodes)) {
|
if (ctx.options.flags(CompilationFlag.EmitNative65816Opcodes)) {
|
||||||
@ -1016,7 +1017,7 @@ object BuiltIns {
|
|||||||
???
|
???
|
||||||
}
|
}
|
||||||
buffer ++= staTo(LDA, targetBytes(i))
|
buffer ++= staTo(LDA, targetBytes(i))
|
||||||
buffer ++= ldTo(SBC, addendByteRead(i))
|
buffer ++= wrapInSedCldIfNeeded(decimal, ldTo(SBC, addendByteRead(i)))
|
||||||
buffer ++= targetBytes(i)
|
buffer ++= targetBytes(i)
|
||||||
} else {
|
} else {
|
||||||
if (i >= addendSize) {
|
if (i >= addendSize) {
|
||||||
|
8
src/main/scala/millfork/env/Constant.scala
vendored
8
src/main/scala/millfork/env/Constant.scala
vendored
@ -232,6 +232,9 @@ case class CompoundConstant(operator: MathOperator.Value, lhs: Constant, rhs: Co
|
|||||||
case (_, CompoundConstant(MathOperator.Plus, a, b)) if operator == MathOperator.Minus =>
|
case (_, CompoundConstant(MathOperator.Plus, a, b)) if operator == MathOperator.Minus =>
|
||||||
((l - a) - b).quickSimplify
|
((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.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)) =>
|
case (NumericConstant(lv, ls), NumericConstant(rv, rs)) =>
|
||||||
var size = ls max rs
|
var size = ls max rs
|
||||||
val value = operator match {
|
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.Or => lv | rv
|
||||||
case MathOperator.And => lv & rv
|
case MathOperator.And => lv & rv
|
||||||
case MathOperator.DecimalPlus if ls == 1 && rs == 1 =>
|
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
|
case _ => return this
|
||||||
}
|
}
|
||||||
operator match {
|
operator match {
|
||||||
@ -285,6 +290,7 @@ case class CompoundConstant(operator: MathOperator.Value, lhs: Constant, rhs: Co
|
|||||||
case MathOperator.DecimalPlus => c
|
case MathOperator.DecimalPlus => c
|
||||||
case MathOperator.DecimalPlus9 => c
|
case MathOperator.DecimalPlus9 => c
|
||||||
case MathOperator.Minus => c
|
case MathOperator.Minus => c
|
||||||
|
case MathOperator.DecimalMinus => c
|
||||||
case MathOperator.Times => Constant.Zero
|
case MathOperator.Times => Constant.Zero
|
||||||
case MathOperator.Shl => c
|
case MathOperator.Shl => c
|
||||||
case MathOperator.Shr => c
|
case MathOperator.Shr => c
|
||||||
|
@ -222,7 +222,7 @@ abstract class MfParser[T](fileId: String, input: String, currentDirectory: Stri
|
|||||||
case List("+") | List("-") | List("+", "-") | List("-", "+") =>
|
case List("+") | List("-") | List("+", "-") | List("-", "+") =>
|
||||||
SumExpression(xs.toPairList("+").map { case (op, value) => (op == "-", p(value, level + 1)) }, decimal = false)
|
SumExpression(xs.toPairList("+").map { case (op, value) => (op == "-", p(value, level + 1)) }, decimal = false)
|
||||||
case List("+'") | List("-'") | List("+'", "-'") | List("-'", "+'") =>
|
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(":") =>
|
case List(":") =>
|
||||||
if (xs.size != 2) {
|
if (xs.size != 2) {
|
||||||
ErrorReporting.error("The `:` operator can have only two arguments", xs.head.head.position)
|
ErrorReporting.error("The `:` operator can have only two arguments", xs.head.head.position)
|
||||||
|
Loading…
Reference in New Issue
Block a user