mirror of
https://github.com/KarolS/millfork.git
synced 2025-01-27 11:30:19 +00:00
Typecheck division of large constants
This commit is contained in:
parent
b5c51e48be
commit
0913c5037c
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user