Support unsigned integers in intrinsic range values

This commit is contained in:
Dmitry Petrov
2018-12-27 14:54:06 +03:00
parent d22a31cb90
commit 68e2d8dcd9
13 changed files with 496 additions and 20 deletions
@@ -0,0 +1,93 @@
// IGNORE_BACKEND: JVM_IR
// WITH_RUNTIME
const val MaxUI = UInt.MAX_VALUE
const val MinUI = UInt.MIN_VALUE
const val MaxUL = ULong.MAX_VALUE
const val MinUL = ULong.MIN_VALUE
val M = MaxUI.toULong()
fun testSimpleUIntLoop() {
var s = 0
for (i in 6u downTo 1u) {
s = s*10 + i.toInt()
}
if (s != 654321) throw AssertionError("$s")
}
fun testEmptyUIntLoop() {
var s = 0
for (i in 1u downTo 6u) {
s = s*10 + i.toInt()
}
if (s != 0) throw AssertionError("$s")
}
fun testSimpleULongLoop() {
var s = 0
for (i in 6UL downTo 1UL) {
s = s*10 + i.toInt()
}
if (s != 654321) throw AssertionError("$s")
}
fun testEmptyULongLoop() {
var s = 0
for (i in 1UL downTo 6UL) {
s = s*10 + i.toInt()
}
if (s != 0) throw AssertionError("$s")
}
fun testULongLoop() {
var s = 0
for (i in M+6UL downTo M+1UL) {
s = s*10 + (i-M).toInt()
}
if (s != 654321) throw AssertionError("$s")
}
fun testEmptyULongLoop2() {
var s = 0
for (i in M+1UL downTo M+6UL) {
s = s*10 + (i-M).toInt()
}
if (s != 0) throw AssertionError("$s")
}
fun testMaxUIdownToMinUI() {
val xs = ArrayList<UInt>()
for (i in MinUI downTo MaxUI) {
xs.add(i)
if (xs.size > 23) break
}
if (xs.size > 0) {
throw AssertionError("Wrong elements for MaxUI..MinUI: $xs")
}
}
fun testMaxULdownToMinUL() {
val xs = ArrayList<ULong>()
for (i in MinUL downTo MaxUL) {
xs.add(i)
if (xs.size > 23) break
}
if (xs.size > 0) {
throw AssertionError("Wrong elements for MaxUI..MinUI: $xs")
}
}
fun box(): String {
testSimpleUIntLoop()
testEmptyUIntLoop()
testSimpleULongLoop()
testEmptyULongLoop()
testULongLoop()
testEmptyULongLoop2()
testMaxUIdownToMinUI()
testMaxULdownToMinUL()
return "OK"
}
@@ -0,0 +1,93 @@
// IGNORE_BACKEND: JVM_IR
// WITH_RUNTIME
const val MaxUI = UInt.MAX_VALUE
const val MinUI = UInt.MIN_VALUE
const val MaxUL = ULong.MAX_VALUE
const val MinUL = ULong.MIN_VALUE
val M = MaxUI.toULong()
fun testSimpleUIntLoop() {
var s = 0
for (i in 1u .. 6u) {
s = s*10 + i.toInt()
}
if (s != 123456) throw AssertionError("$s")
}
fun testEmptyUIntLoop() {
var s = 0
for (i in 6u .. 1u) {
s = s*10 + i.toInt()
}
if (s != 0) throw AssertionError("$s")
}
fun testSimpleULongLoop() {
var s = 0
for (i in 1UL .. 6UL) {
s = s*10 + i.toInt()
}
if (s != 123456) throw AssertionError("$s")
}
fun testEmptyULongLoop() {
var s = 0
for (i in 6UL .. 1UL) {
s = s*10 + i.toInt()
}
if (s != 0) throw AssertionError("$s")
}
fun testULongLoop() {
var s = 0
for (i in M+1UL..M+6UL) {
s = s*10 + (i-M).toInt()
}
if (s != 123456) throw AssertionError("$s")
}
fun testEmptyULongLoop2() {
var s = 0
for (i in M+6UL..M+1UL) {
s = s*10 + (i-M).toInt()
}
if (s != 0) throw AssertionError("$s")
}
fun testMaxUItoMinUI() {
val xs = ArrayList<UInt>()
for (i in MaxUI..MinUI) {
xs.add(i)
if (xs.size > 23) break
}
if (xs.size > 0) {
throw AssertionError("Wrong elements for MaxUI..MinUI: $xs")
}
}
fun testMaxULtoMinUL() {
val xs = ArrayList<ULong>()
for (i in MaxUL..MinUL) {
xs.add(i)
if (xs.size > 23) break
}
if (xs.size > 0) {
throw AssertionError("Wrong elements for MaxUI..MinUI: $xs")
}
}
fun box(): String {
testSimpleUIntLoop()
testEmptyUIntLoop()
testSimpleULongLoop()
testEmptyULongLoop()
testULongLoop()
testEmptyULongLoop2()
testMaxUItoMinUI()
testMaxULtoMinUL()
return "OK"
}
@@ -0,0 +1,93 @@
// IGNORE_BACKEND: JVM_IR
// WITH_RUNTIME
const val MaxUI = UInt.MAX_VALUE
const val MinUI = UInt.MIN_VALUE
const val MaxUL = ULong.MAX_VALUE
const val MinUL = ULong.MIN_VALUE
val M = MaxUI.toULong()
fun testSimpleUIntLoop() {
var s = 0
for (i in 1u until 6u) {
s = s*10 + i.toInt()
}
if (s != 12345) throw AssertionError("$s")
}
fun testEmptyUIntLoop() {
var s = 0
for (i in 6u until 1u) {
s = s*10 + i.toInt()
}
if (s != 0) throw AssertionError("$s")
}
fun testSimpleULongLoop() {
var s = 0
for (i in 1UL until 6UL) {
s = s*10 + i.toInt()
}
if (s != 12345) throw AssertionError("$s")
}
fun testEmptyULongLoop() {
var s = 0
for (i in 6UL until 1UL) {
s = s*10 + i.toInt()
}
if (s != 0) throw AssertionError("$s")
}
fun testULongLoop() {
var s = 0
for (i in M+1UL until M+6UL) {
s = s*10 + (i-M).toInt()
}
if (s != 12345) throw AssertionError("$s")
}
fun testEmptyULongLoop2() {
var s = 0
for (i in M+6UL until M+1UL) {
s = s*10 + (i-M).toInt()
}
if (s != 0) throw AssertionError("$s")
}
fun testMaxUItoMinUI() {
val xs = ArrayList<UInt>()
for (i in MaxUI until MinUI) {
xs.add(i)
if (xs.size > 23) break
}
if (xs.size > 0) {
throw AssertionError("Wrong elements for MaxUI..MinUI: $xs")
}
}
fun testMaxULtoMinUL() {
val xs = ArrayList<ULong>()
for (i in MaxUL until MinUL) {
xs.add(i)
if (xs.size > 23) break
}
if (xs.size > 0) {
throw AssertionError("Wrong elements for MaxUI..MinUI: $xs")
}
}
fun box(): String {
testSimpleUIntLoop()
testEmptyUIntLoop()
testSimpleULongLoop()
testEmptyULongLoop()
testULongLoop()
testEmptyULongLoop2()
testMaxUItoMinUI()
testMaxULtoMinUL()
return "OK"
}
@@ -0,0 +1,42 @@
// IGNORE_BACKEND: JVM_IR
// WITH_RUNTIME
const val MaxUI = UInt.MAX_VALUE
const val MinUI = UInt.MIN_VALUE
const val MaxUL = ULong.MAX_VALUE
const val MinUL = ULong.MIN_VALUE
val M1 = MaxUI.toULong()
val M2 = M1 + 10UL
fun box(): String {
if (0u in 1u..10u) throw AssertionError()
if (1u !in 1u..10u) throw AssertionError()
if (5u !in 1u..10u) throw AssertionError()
if (10u !in 1u..10u) throw AssertionError()
if (20u in 1u..10u) throw AssertionError()
if (0UL in 1UL..10UL) throw AssertionError()
if (1UL !in 1UL..10UL) throw AssertionError()
if (5UL !in 1UL..10UL) throw AssertionError()
if (10UL !in 1UL..10UL) throw AssertionError()
if (20UL in 1UL..10UL) throw AssertionError()
if (0u !in MinUI..MaxUI) throw AssertionError()
if (MinUI !in MinUI..MaxUI) throw AssertionError()
if (MaxUI !in MinUI..MaxUI) throw AssertionError()
if (0UL !in MinUL..MaxUL) throw AssertionError()
if (MinUL !in MinUL..MaxUL) throw AssertionError()
if (MaxUL !in MinUL..MaxUL) throw AssertionError()
if (0UL in M1..M2) throw AssertionError()
if (1UL in M1..M2) throw AssertionError()
if (10UL in M1..M2) throw AssertionError()
if (M1 !in M1..M2) throw AssertionError()
if (M1+1UL !in M1..M2) throw AssertionError()
if (M2 !in M1..M2) throw AssertionError()
return "OK"
}