diff --git a/src/main/scala/millfork/compiler/AbstractExpressionCompiler.scala b/src/main/scala/millfork/compiler/AbstractExpressionCompiler.scala index 90dcb2ac..b39a0cf1 100644 --- a/src/main/scala/millfork/compiler/AbstractExpressionCompiler.scala +++ b/src/main/scala/millfork/compiler/AbstractExpressionCompiler.scala @@ -494,12 +494,14 @@ object AbstractExpressionCompiler { case List(1, 1) | List(2, 1) => b case List(1, 2) | List(2, 2) => w case List(0, _) | List(_, 0) => b - case _ => log.error("Combining values bigger than words", expr.position); w + case List(n, _) if n >= 3 => env.get[Type]("int" + n * 8) + case _ => log.error(s"Invalid parameters to %%", expr.position); w } - case FunctionCallExpression("*" | "|" | "&" | "^" | "/", params) => params.map { e => getExpressionTypeImpl(env, log, e, loosely).size }.max match { + case FunctionCallExpression(op@("*" | "|" | "&" | "^" | "/"), params) => params.map { e => getExpressionTypeImpl(env, log, e, loosely).size }.max match { case 0 | 1 => b case 2 => w - case _ => log.error("Combining values bigger than words", expr.position); w + case n if n >= 3 => env.get[Type]("int" + n * 8) + case _ => log.error(s"Invalid parameters to " + op, expr.position); w } case FunctionCallExpression("<<", List(a1, a2)) => if (getExpressionTypeImpl(env, log, a2, loosely).size > 1) log.error("Shift amount too large", a2.position) diff --git a/src/test/scala/millfork/test/ConstantSuite.scala b/src/test/scala/millfork/test/ConstantSuite.scala index a637e342..ad3ce869 100644 --- a/src/test/scala/millfork/test/ConstantSuite.scala +++ b/src/test/scala/millfork/test/ConstantSuite.scala @@ -145,4 +145,22 @@ class ConstantSuite extends FunSuite with Matchers { """.stripMargin) m.readByte(0xc000) should equal(1) } + + test("Large constants should work") { + EmuUnoptimizedCrossPlatformRun(Cpu.Mos, Cpu.Z80)( + """ + | const int24 A = 200 + | const int24 B = 8 + | const int24 C = A/B + | array(int24) arr[10] @$c000 + | void main() { + | arr[0] = C + | arr[1] = A/B + | } + | + """.stripMargin) {m => + m.readMedium(0xc000) should equal(200/8) + m.readMedium(0xc003) should equal(200/8) + } + } }