1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-12-24 15:29:23 +00:00

Fix various compiler crashes

This commit is contained in:
Karol Stasiak 2019-08-03 20:34:02 +02:00
parent 778d04ce21
commit dcbf54872b
3 changed files with 16 additions and 0 deletions

View File

@ -268,6 +268,18 @@ object AbstractExpressionCompiler {
case 3 => env.get[Type]("int24")
case 4 => env.get[Type]("long")
}
case ConstantArrayElementExpression(constant) =>
(constant.quickSimplify match {
case SubbyteConstant(_, _) => false -> 1
case NumericConstant(v, s) => (v < 0) -> s
case CompoundConstant(MathOperator.Minus, NumericConstant(_, ls), NumericConstant(_, rs)) => true -> (ls max rs)
}) match {
case (false, 1) => b
case (true, 1) => env.get[Type]("sbyte")
case (_, 2) => b
case (_, 3) => env.get[Type]("int24")
case (_, 4) => env.get[Type]("long")
}
case GeneratedConstantExpression(_, typ) => typ
case TextLiteralExpression(_) => env.get[Type]("pointer")
case VariableExpression(name) =>

View File

@ -137,6 +137,9 @@ object Z80Comparisons {
import ZOpcode._
val calculateLeft = Z80ExpressionCompiler.compileToHL(ctx, l)
val calculateRight = Z80ExpressionCompiler.compileToHL(ctx, r)
if (branches == NoBranching) {
return calculateLeft ++ calculateRight
}
val fastEqualityComparison: Option[List[ZLine]] = (calculateLeft, calculateRight) match {
case (List(ZLine0(LD_16, TwoRegisters(HL, IMM_16), NumericConstant(0, _))), _) =>
Some(calculateRight ++ List(ZLine.ld8(A, H), ZLine.register(OR, L)))

View File

@ -156,6 +156,7 @@ abstract class AbstractAssembler[T <: AbstractCode](private val program: Program
case MathOperator.Shl => l << r
case MathOperator.Shl9 => (l << r) & 0x1ff
case MathOperator.Shr => l >>> r
case MathOperator.Shr9 => ((l & 0x1ff) >>> r) & 0xff
case MathOperator.DecimalPlus => asDecimal(l, r, _ + _)
case MathOperator.DecimalPlus9 => asDecimal(l, r, _ + _) & 0x1ff
case MathOperator.DecimalMinus => asDecimal(l, r, _ - _)