1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-05-31 18:41:30 +00:00

Generate warnings on some too complex separate bytes expressions

This commit is contained in:
Karol Stasiak 2018-01-08 01:03:08 +01:00
parent 0c66dac3ae
commit 14a5a58134
2 changed files with 31 additions and 27 deletions

View File

@ -862,6 +862,10 @@ object BuiltIns {
case IndexedExpression(variable, index) =>
List(MlCompiler.compileByteStorage(ctx, Register.A, lhs))
case SeparateBytesExpression(h: LhsExpression, l: LhsExpression) =>
if (simplicity(ctx.env, h) < 'J' || simplicity(ctx.env, l) < 'J') {
// a[b]:c[d] is the most complex expression that doesn't cause the following warning
ErrorReporting.warn("Too complex expression given to the `:` operator, generated code might be wrong", ctx.options, lhs.position)
}
List(
getStorageForEachByte(ctx, l).head,
MlCompiler.preserveRegisterIfNeeded(ctx, Register.A, getStorageForEachByte(ctx, h).head))

View File

@ -135,31 +135,31 @@ class SeparateBytesSuite extends FunSuite with Matchers {
""".stripMargin)(_.readWord(0xc000) should equal(0x707))
}
ignore("Complex separate addition") {
EmuBenchmarkRun("""
| array hi [25] @$c000
| array lo [25] @$c080
| void main () {
| byte i
| hi[0] = 0
| lo[0] = 0
| hi[1] = 0
| lo[1] = 1
| for i,0,until,lo.length-2 {
| barrier()
| hi[addTwo(i)]:lo[i + (one() << 1)] = hi[i + one()]:lo[1+i]
| barrier()
| hi[addTwo(i)]:lo[i + (one() << 1)] += hi[i]:lo[i]
| barrier()
| }
| }
| byte one() { return 1 }
| byte addTwo(byte x) { return x + 2 }
| void barrier() {}
""".stripMargin){m =>
val h = m.readWord(0xc000 + 24)
val l = m.readWord(0xc080 + 24)
(h * 0x100 + l) should equal(46368)
}
}
// test("Complex separate addition") {
// EmuBenchmarkRun("""
// | array hi [25] @$c000
// | array lo [25] @$c080
// | void main () {
// | byte i
// | hi[0] = 0
// | lo[0] = 0
// | hi[1] = 0
// | lo[1] = 1
// | for i,0,until,lo.length-2 {
// | barrier()
// | hi[addTwo(i)]:lo[i + (one() << 1)] = hi[i + one()]:lo[1+i]
// | barrier()
// | hi[addTwo(i)]:lo[i + (one() << 1)] += hi[i]:lo[i]
// | barrier()
// | }
// | }
// | byte one() { return 1 }
// | byte addTwo(byte x) { return x + 2 }
// | void barrier() {}
// """.stripMargin){m =>
// val h = m.readWord(0xc000 + 24)
// val l = m.readWord(0xc080 + 24)
// (h * 0x100 + l) should equal(46368)
// }
// }
}