Support const-bound counter loop generation for 'downTo'

This commit is contained in:
Dmitry Petrov
2017-12-12 13:47:17 +03:00
parent 2f0df832c0
commit 5f7460a8c7
14 changed files with 213 additions and 10 deletions
@@ -0,0 +1,16 @@
// WITH_RUNTIME
import kotlin.test.assertEquals
fun low() = 4
fun high() = 1
fun box(): String {
var sum = 0
for (i in low() downTo high()) {
sum = sum * 10 + i
}
assertEquals(4321, sum)
return "OK"
}
@@ -0,0 +1,15 @@
// WITH_RUNTIME
const val M = 0.toChar()
fun box(): String {
var count = 0
for (i in M downTo M) {
++count
if (count > 1) {
throw AssertionError("Loop should be executed once")
}
}
if (count != 1) throw AssertionError("Should be executed once")
return "OK"
}
@@ -0,0 +1,15 @@
// WITH_RUNTIME
const val M = Int.MIN_VALUE
fun box(): String {
var count = 0
for (i in M downTo M) {
++count
if (count > 1) {
throw AssertionError("Loop should be executed once")
}
}
if (count != 1) throw AssertionError("Should be executed once")
return "OK"
}
@@ -0,0 +1,15 @@
// WITH_RUNTIME
const val M = Long.MIN_VALUE
fun box(): String {
var count = 0
for (i in M downTo M) {
++count
if (count > 1) {
throw AssertionError("Loop should be executed once")
}
}
if (count != 1) throw AssertionError("Should be executed once")
return "OK"
}
@@ -29,4 +29,7 @@ fun box(): String {
// 0 getFirst
// 0 getLast
// 0 getStep
// 0 IF_ICMPEQ
// 0 IFEQ
// 0 IF_ICMPEQ
// 2 IF_ICMPLT
// 1 LCMP
@@ -12,4 +12,6 @@ fun test(): Int {
// 0 getStart
// 0 getEnd
// 0 getFirst
// 0 getLast
// 0 getLast
// 0 IF_ICMPEQ
// 1 IF_ICMPLT