Boundary values and their toString() test. (#90)

This commit is contained in:
Nikolay Igotti
2016-12-06 16:03:23 +03:00
committed by GitHub
parent de493313f8
commit 527efa661b
7 changed files with 100 additions and 29 deletions
@@ -620,6 +620,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
LLVMSetInitializer(objectPtr, codegen.kNullObjHeaderPtr)
}
val bbCurrent = codegen.currentBlock
val bbInit = codegen.basicBlock("label_init")
val bbExit = codegen.basicBlock("label_continue")
val onePtr = codegen.intToPtr(kImmInt64One, codegen.kObjHeaderPtr, codegen.newVar())
@@ -633,11 +634,16 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
val initFunction = value.descriptor.constructors.first { it.valueParameters.size == 0 }
val ctor = codegen.llvmFunction(initFunction)
val args = listOf(objectPtr, typeInfo, allocHint, ctor)
currentCodeContext.genCall(context.initInstanceFunction, args, codegen.newVar())
val newValue = currentCodeContext.genCall(
context.initInstanceFunction, args, codegen.newVar())
codegen.br(bbExit)
codegen.positionAtEnd(bbExit)
return objectVal
val valuePhi = codegen.phi(codegen.getLLVMType(value.type), codegen.newVar())
codegen.addPhiIncoming(valuePhi,
bbCurrent to objectVal, bbInit to newValue)
return valuePhi
}
//-------------------------------------------------------------------------//
+10 -2
View File
@@ -342,6 +342,14 @@ task tostring2(type: RunKonanTest) {
source = "runtime/basic/tostring2.kt"
}
task tostring3(type: RunKonanTest) {
goldValue = "-128\n127\n-32768\n32767\n" +
"-2147483648\n2147483647\n-9223372036854775808\n9223372036854775807\n" +
"1.17549E-38\n3.40282E+38\n-INF\nINF\nNAN\n" +
"4.94066E-324\n1.79769E+308\nINF\nINF\nNAN\n"
source = "runtime/basic/tostring3.kt"
}
task empty_substring(type: RunKonanTest) {
goldValue = "\n"
source = "runtime/basic/empty_substring.kt"
@@ -349,12 +357,12 @@ task empty_substring(type: RunKonanTest) {
task array0(type: RunKonanTest) {
goldValue = "5\n6\n7\n8\n9\n10\n11\n12\n13\n"
source = "runtime/basic/array0.kt"
source = "runtime/collections/array0.kt"
}
task array1(type: RunKonanTest) {
goldValue = "4 2\n1-1\n69\n38\n"
source = "runtime/basic/array1.kt"
source = "runtime/collections/array1.kt"
}
task if_else(type: UnitKonanTest) {
@@ -0,0 +1,69 @@
fun testByte() {
val values = ByteArray(2)
values[0] = Byte.MIN_VALUE
values[1] = Byte.MAX_VALUE
for (v in values) {
println(v)
}
}
fun testShort() {
val values = ShortArray(2)
values[0] = Short.MIN_VALUE
values[1] = Short.MAX_VALUE
for (v in values) {
println(v)
}
}
fun testInt() {
val values = IntArray(2)
values[0] = Int.MIN_VALUE
values[1] = Int.MAX_VALUE
for (v in values) {
println(v)
}
}
fun testLong() {
val values = LongArray(2)
values[0] = Long.MIN_VALUE
values[1] = Long.MAX_VALUE
for (v in values) {
println(v)
}
}
fun testFloat() {
val values = FloatArray(5)
values[0] = Float.MIN_VALUE
values[1] = Float.MAX_VALUE
values[2] = Float.NEGATIVE_INFINITY
values[3] = Float.POSITIVE_INFINITY
values[4] = Float.NaN
for (v in values) {
println(v)
}
}
fun testDouble() {
val values = DoubleArray(5)
values[0] = Double.MIN_VALUE
values[1] = Double.MAX_VALUE
values[2] = Double.NEGATIVE_INFINITY
values[3] = Double.POSITIVE_INFINITY
values[4] = Double.NaN
for (v in values) {
println(v)
}
}
fun main(args : Array<String>) {
testByte()
testShort()
testInt()
testLong()
testFloat()
testDouble()
}
+10 -10
View File
@@ -915,27 +915,27 @@ public final class Float : Number(), Comparable<Float> {
/**
* A constant holding the smallest *positive* nonzero value of Float.
*/
//public const val MIN_VALUE: Float
public const val MIN_VALUE: Float = 1.17549435E-38f
/**
* A constant holding the largest positive finite value of Float.
*/
//public const val MAX_VALUE: Float
public const val MAX_VALUE: Float = 3.4028235E+38f
/**
* A constant holding the positive infinity value of Float.
*/
//public val POSITIVE_INFINITY: Float
public val POSITIVE_INFINITY: Float = 1.0f / 0.0f
/**
* A constant holding the negative infinity value of Float.
*/
//public const val NEGATIVE_INFINITY: Float
public val NEGATIVE_INFINITY: Float = -1.0f / 0.0f
/**
* A constant holding the "not a number" value of Float.
*/
//public const val NaN: Float
public val NaN: Float = 0.0f / 0.0f
}
/**
@@ -1125,27 +1125,27 @@ public final class Double : Number(), Comparable<Double> {
/**
* A constant holding the smallest *positive* nonzero value of Double.
*/
//public const val MIN_VALUE: Double
public const val MIN_VALUE: Double = 4.9e-324
/**
* A constant holding the largest positive finite value of Double.
*/
//public const val MAX_VALUE: Double
public const val MAX_VALUE: Double = 1.7976931348623157e+308
/**
* A constant holding the positive infinity value of Double.
*/
// public const val POSITIVE_INFINITY: Double
public val POSITIVE_INFINITY: Double = 1.0 / 0.0
/**
* A constant holding the negative infinity value of Double.
*/
// public const val NEGATIVE_INFINITY: Double
public val NEGATIVE_INFINITY: Double = -1.0 / 0.0
/**
* A constant holding the "not a number" value of Double.
*/
// public const val NaN: Double
public val NaN: Double = 0.0 / 0.0
}
/**
@@ -1,16 +1,5 @@
package kotlin.collections
// TODO: remove
private val MAGIC: Long = 2654435769 // golden ratio
private val INITIAL_CAPACITY = 8
private val INITIAL_MAX_PROBE_DISTANCE = 2
private val TOMBSTONE = -1
private fun computeHashSize(capacity: Int): Int = (capacity.coerceAtLeast(1) * 3).highestOneBit()
private fun computeShift(hashSize: Int): Int = hashSize.numberOfLeadingZeros() + 1
class HashMap<K, V> private constructor(
private var keysArray: Array<K>,
private var valuesArray: Array<V>?, // allocated only when actually used, always null in pure HashSet
@@ -182,7 +171,7 @@ class HashMap<K, V> private constructor(
return newValuesArray
}
private fun hash(key: K) = (key.hashCode() * MAGIC.toInt()) ushr hashShift
private fun hash(key: K) = (key.hashCode() * MAGIC) ushr hashShift
private fun compact() {
var i = 0
@@ -475,8 +464,7 @@ class HashMap<K, V> private constructor(
internal fun valuesIterator() = ValuesItr(this)
internal fun entriesIterator() = EntriesItr(this)
// TODO: fix!
/* private companion object {
private companion object {
const val MAGIC = 2654435769L.toInt() // golden ratio
const val INITIAL_CAPACITY = 8
const val INITIAL_MAX_PROBE_DISTANCE = 2
@@ -485,7 +473,7 @@ class HashMap<K, V> private constructor(
fun computeHashSize(capacity: Int): Int = (capacity.coerceAtLeast(1) * 3).highestOneBit()
fun computeShift(hashSize: Int): Int = hashSize.numberOfLeadingZeros() + 1
} */
}
internal open class Itr<K, V>(
internal val map: HashMap<K, V>