Merge branch 'master' into inline
This commit is contained in:
@@ -41,11 +41,11 @@ abstract class KonanTest extends DefaultTask {
|
||||
project.javaexec {
|
||||
main = 'org.jetbrains.kotlin.cli.bc.K2NativeKt'
|
||||
classpath = project.configurations.cli_bc
|
||||
jvmArgs "-ea",
|
||||
jvmArgs "-ea",
|
||||
"-Dkonan.home=${dist.canonicalPath}",
|
||||
"-Djava.library.path=${dist.canonicalPath}/konan/nativelib"
|
||||
args("-output", output,
|
||||
source,
|
||||
source,
|
||||
*moreArgs,
|
||||
*project.globalArgs)
|
||||
}
|
||||
@@ -88,7 +88,7 @@ abstract class KonanTest extends DefaultTask {
|
||||
|
||||
class RunKonanTest extends KonanTest {
|
||||
void compileTest(String source, String exe) {
|
||||
runCompiler(source, exe, [])
|
||||
runCompiler(source, exe, [])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ class LinkKonanTest extends KonanTest {
|
||||
void compileTest(String source, String exe) {
|
||||
def libDir = project.file(lib).absolutePath
|
||||
def libBc = "${libDir}.bc"
|
||||
|
||||
|
||||
runCompiler(lib, libBc, ['-nolink', '-nostdlib'])
|
||||
runCompiler(source, exe, ['-library', libBc])
|
||||
}
|
||||
@@ -149,6 +149,12 @@ task objectInitialization(type: RunKonanTest) {
|
||||
source = "codegen/object/initialization.kt"
|
||||
}
|
||||
|
||||
task objectInitialization1(type: RunKonanTest) {
|
||||
disabled = true
|
||||
goldValue = "init\nfield\nconstructor1\ninit\nfield\nconstructor1\nconstructor2\n"
|
||||
source = "codegen/object/initialization1.kt"
|
||||
}
|
||||
|
||||
task check_type(type: RunKonanTest) {
|
||||
goldValue = "true\nfalse\ntrue\ntrue\ntrue\ntrue\n"
|
||||
source = "codegen/basics/check_type.kt"
|
||||
@@ -173,6 +179,41 @@ task sum2(type: RunKonanTest) {
|
||||
source = "codegen/function/sum_imm.kt"
|
||||
}
|
||||
|
||||
task defaults(type: RunKonanTest) {
|
||||
source = "codegen/function/defaults.kt"
|
||||
}
|
||||
|
||||
task defaults1(type: RunKonanTest) {
|
||||
source = "codegen/function/defaults1.kt"
|
||||
}
|
||||
|
||||
task defaults2(type: RunKonanTest) {
|
||||
source = "codegen/function/defaults2.kt"
|
||||
}
|
||||
|
||||
task defaults3(type: RunKonanTest) {
|
||||
source = "codegen/function/defaults3.kt"
|
||||
}
|
||||
|
||||
task defaults4(type: RunKonanTest) {
|
||||
disabled = true
|
||||
goldValue = "43\n"
|
||||
source = "codegen/function/defaults4.kt"
|
||||
}
|
||||
|
||||
task defaults5(type: RunKonanTest) {
|
||||
disabled = true
|
||||
goldValue = "5\n6\n"
|
||||
source = "codegen/function/defaults5.kt"
|
||||
}
|
||||
|
||||
task defaults6(type: RunKonanTest) {
|
||||
disabled = true
|
||||
goldValue = "42\n"
|
||||
source = "codegen/function/defaults6.kt"
|
||||
}
|
||||
|
||||
|
||||
task sum_3const(type: RunKonanTest) {
|
||||
source = "codegen/function/sum_3const.kt"
|
||||
}
|
||||
@@ -195,7 +236,6 @@ task null_check(type: RunKonanTest) {
|
||||
}
|
||||
|
||||
task array_to_any(type: RunKonanTest) {
|
||||
disabled = true
|
||||
source = "codegen/basics/array_to_any.kt"
|
||||
}
|
||||
|
||||
@@ -247,8 +287,8 @@ task tostring3(type: RunKonanTest) {
|
||||
"1.17549E-38\n3.40282E+38\n-INF\nINF\n" +
|
||||
// Linux version prints -NAN.
|
||||
// "NAN\n" +
|
||||
"4.94066E-324\n1.79769E+308\n-INF\nINF\n"
|
||||
// "NAN\n"
|
||||
"4.94066E-324\n1.79769E+308\n-INF\nINF\n"
|
||||
// "NAN\n"
|
||||
source = "runtime/basic/tostring3.kt"
|
||||
}
|
||||
|
||||
@@ -267,6 +307,11 @@ task array1(type: RunKonanTest) {
|
||||
source = "runtime/collections/array1.kt"
|
||||
}
|
||||
|
||||
task array2(type: RunKonanTest) {
|
||||
goldValue = "0\n2\n4\n6\n8\n40\n"
|
||||
source = "runtime/collections/array2.kt"
|
||||
}
|
||||
|
||||
task if_else(type: RunKonanTest) {
|
||||
source = "codegen/branching/if_else.kt"
|
||||
}
|
||||
@@ -308,6 +353,11 @@ task bool_yes(type: RunKonanTest) {
|
||||
source = "codegen/function/boolean.kt"
|
||||
}
|
||||
|
||||
task named(type: RunKonanTest) {
|
||||
source = "codegen/function/named.kt"
|
||||
}
|
||||
|
||||
|
||||
task plus_eq(type: RunKonanTest) {
|
||||
source = "codegen/function/plus_eq.kt"
|
||||
}
|
||||
@@ -360,7 +410,7 @@ task intrinsic(type: RunKonanTest) {
|
||||
}
|
||||
|
||||
/*
|
||||
Disabled until we extract the classes that should be
|
||||
Disabled until we extract the classes that should be
|
||||
always present from stdlib.kt.bc into a separate binary.
|
||||
|
||||
task link(type: LinkKonanTest) {
|
||||
@@ -386,7 +436,6 @@ task statements0(type: RunKonanTest) {
|
||||
}
|
||||
|
||||
task boxing0(type: RunKonanTest) {
|
||||
disabled = true
|
||||
goldValue = "17\n"
|
||||
source = "codegen/boxing/boxing0.kt"
|
||||
}
|
||||
@@ -498,6 +547,10 @@ task moderately_large_array(type: RunKonanTest) {
|
||||
source = "runtime/collections/moderately_large_array.kt"
|
||||
}
|
||||
|
||||
task moderately_large_array1(type: RunKonanTest) {
|
||||
goldValue = "-45392\n"
|
||||
source = "runtime/collections/moderately_large_array1.kt"
|
||||
}
|
||||
|
||||
task string_builder0(type: RunKonanTest) {
|
||||
goldValue = "OK\n"
|
||||
@@ -807,6 +860,11 @@ task memory_throw_cleanup(type: RunKonanTest) {
|
||||
source = "runtime/memory/throw_cleanup.kt"
|
||||
}
|
||||
|
||||
task memory_collect_cycles(type: RunKonanTest) {
|
||||
goldValue = "42\n"
|
||||
source = "runtime/memory/cycles0.kt"
|
||||
}
|
||||
|
||||
task unit1(type: RunKonanTest) {
|
||||
goldValue = "First\nkotlin.Unit\n"
|
||||
source = "codegen/basics/unit1.kt"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
fun main(args: Array<String>) {
|
||||
println(foo().toString())
|
||||
foo().hashCode()
|
||||
}
|
||||
|
||||
fun foo(): Any {
|
||||
return Array<Any?>(0)
|
||||
return Array<Any?>(0, { i -> null })
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/**
|
||||
* Created by minamoto on 12/26/16.
|
||||
*/
|
||||
//package defaults
|
||||
|
||||
open class A(val a:Int) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other == null || other as? A == null) return false
|
||||
return (other as A).a == a // Where is smart casting?
|
||||
}
|
||||
|
||||
companion object {
|
||||
val zero = A(0)
|
||||
val one = A(1)
|
||||
val magic = A(42)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// FUN public fun foo(a: defaults.A = ...): kotlin.Int
|
||||
// a: EXPRESSION_BODY
|
||||
// CALL '<get-magic>(): A' type=defaults.A origin=GET_PROPERTY
|
||||
// $this: GET_OBJECT 'companion object of A' type=defaults.A.Companion
|
||||
// BLOCK_BODY
|
||||
// RETURN type=kotlin.Nothing from='foo(A = ...): Int'
|
||||
// CALL '<get-a>(): Int' type=kotlin.Int origin=GET_PROPERTY
|
||||
// $this: GET_VAR 'value-parameter a: A = ...' type=defaults.A origin=null
|
||||
fun foo(a: A = A.magic, b:Int = 0xdeadbeef.toInt()) = a.a
|
||||
|
||||
// FUN public fun bar(a: defaults.A, inc: kotlin.Int = ...): defaults.A
|
||||
// inc: EXPRESSION_BODY
|
||||
// CONST Int type=kotlin.Int value='0'
|
||||
// BLOCK_BODY
|
||||
// RETURN type=kotlin.Nothing from='bar(A, Int = ...): A'
|
||||
// CALL 'constructor A(Int)' type=defaults.A origin=null
|
||||
// a: CALL 'plus(Int): Int' type=kotlin.Int origin=PLUS
|
||||
// $this: CALL '<get-a>(): Int' type=kotlin.Int origin=GET_PROPERTY
|
||||
// $this: GET_VAR 'value-parameter a: A' type=defaults.A origin=null
|
||||
// other: GET_VAR 'value-parameter inc: Int = ...' type=kotlin.Int origin=null
|
||||
fun bar(a:A, inc:Int = 0) = A(a.a + inc)
|
||||
|
||||
|
||||
fun main(args:Array<String>) {
|
||||
|
||||
// if: CALL 'NOT(Boolean): Boolean' type=kotlin.Boolean origin=EXCLEQ
|
||||
// arg0: CALL 'EQEQ(Any?, Any?): Boolean' type=kotlin.Boolean origin=EXCLEQ
|
||||
// arg0: CALL 'foo(A = ...): Int' type=kotlin.Int origin=null
|
||||
// arg1: CALL '<get-a>(): Int' type=kotlin.Int origin=GET_PROPERTY
|
||||
// $this: CALL '<get-magic>(): A' type=defaults.A origin=GET_PROPERTY
|
||||
// $this: GET_OBJECT 'companion object of A' type=defaults.A.Companion
|
||||
if (foo() != A.magic.a) {
|
||||
println("magic failed")
|
||||
throw Error()
|
||||
}
|
||||
|
||||
// if: CALL 'NOT(Boolean): Boolean' type=kotlin.Boolean origin=EXCLEQ
|
||||
// arg0: CALL 'EQEQ(Any?, Any?): Boolean' type=kotlin.Boolean origin=EXCLEQ
|
||||
// arg0: CALL 'foo(A = ...): Int' type=kotlin.Int origin=null
|
||||
// a: CALL 'constructor A(Int)' type=defaults.A origin=null
|
||||
// a: CONST Int type=kotlin.Int value='1'
|
||||
// arg1: CONST Int type=kotlin.Int value='1'
|
||||
if (foo(A(1)) != 1) {
|
||||
println("one failed: foo(A(1))")
|
||||
throw Error()
|
||||
}
|
||||
|
||||
// if: CALL 'NOT(Boolean): Boolean' type=kotlin.Boolean origin=EXCLEQ
|
||||
// arg0: CALL 'EQEQ(Any?, Any?): Boolean' type=kotlin.Boolean origin=EXCLEQ
|
||||
// arg0: CALL 'bar(A, Int = ...): A' type=defaults.A origin=null
|
||||
// a: CALL '<get-one>(): A' type=defaults.A origin=GET_PROPERTY <---
|
||||
// $this: GET_OBJECT 'companion object of A' type=defaults.A.Companion
|
||||
// arg1: CALL '<get-one>(): A' type=defaults.A origin=GET_PROPERTY
|
||||
// $this: GET_OBJECT 'companion object of A' type=defaults.A.Companion
|
||||
|
||||
if (bar(A.one) != A.one) {
|
||||
println("A one failed")
|
||||
throw Error()
|
||||
}
|
||||
|
||||
|
||||
// if: CALL 'NOT(Boolean): Boolean' type=kotlin.Boolean origin=EXCLEQ
|
||||
// arg0: CALL 'EQEQ(Any?, Any?): Boolean' type=kotlin.Boolean origin=EXCLEQ
|
||||
// arg0: CALL '<get-a>(): Int' type=kotlin.Int origin=GET_PROPERTY
|
||||
// $this: CALL 'bar(A, Int = ...): A' type=defaults.A origin=null
|
||||
// a: CALL '<get-one>(): A' type=defaults.A origin=GET_PROPERTY
|
||||
// $this: GET_OBJECT 'companion object of A' type=defaults.A.Companion
|
||||
// inc: CONST Int type=kotlin.Int value='1'
|
||||
// arg1: CONST Int type=kotlin.Int value='2'
|
||||
if (bar(A.one, 1).a != 2) {
|
||||
println("A one + 1 failed")
|
||||
throw Error()
|
||||
}
|
||||
println("all tests passed")
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
fun foo(x:Int = 0, y:Int = x + 1, z:Int = x + y + 1) = x + y + z
|
||||
|
||||
fun main(arg:Array<String>) {
|
||||
val v = foo()
|
||||
if (v != 3) {
|
||||
println("test failed $v expected 3")
|
||||
throw Error()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
|
||||
fun Int.foo(inc0:Int, inc:Int = 0) = this + inc0 + inc
|
||||
|
||||
fun main(arg:Array<String>) {
|
||||
val v = 42.foo(0)
|
||||
if (v != 42) {
|
||||
println("test failed v:$v expected:42")
|
||||
throw Error()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fun foo(a:Int = 2, b:String = "Hello", c:Int = 4):String = "$b-$c$a"
|
||||
fun foo(a:Int = 3, b:Int = a + 1, c:Int = a + b) = a + b + c
|
||||
|
||||
fun main(arg:Array<String>){
|
||||
val a = foo(b="Universe")
|
||||
if (a != "Universe-42")
|
||||
throw Error()
|
||||
|
||||
val b = foo(b = 5)
|
||||
if (b != (/* a = */ 3 + /* b = */ 5 + /* c = */ (3 + 5)))
|
||||
throw Error()
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
open class A {
|
||||
open fun foo(x: Int = 42) = println(x)
|
||||
}
|
||||
|
||||
class B : A() {
|
||||
override fun foo(x: Int) = println(x + 1)
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
B().foo()
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
class Test(val x: Int) {
|
||||
fun foo(y: Int = x) {
|
||||
println(y)
|
||||
}
|
||||
}
|
||||
|
||||
fun Test.bar(y: Int = x) {
|
||||
println(y)
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
Test(5).foo()
|
||||
Test(6).bar()
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
open class Foo(val x: Int = 42)
|
||||
class Bar : Foo()
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
println(Bar().x)
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
fun foo(a:Int, b:Int) = a - b
|
||||
fun main(args:Array<String>) {
|
||||
if (foo(b = 24, a = 42) != 18)
|
||||
throw Error()
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
class Test {
|
||||
constructor() {
|
||||
println("constructor1")
|
||||
}
|
||||
|
||||
constructor(x: Int) : this() {
|
||||
println("constructor2")
|
||||
}
|
||||
|
||||
init {
|
||||
println("init")
|
||||
}
|
||||
|
||||
val f = println("field")
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
Test()
|
||||
Test(1)
|
||||
}
|
||||
@@ -24,6 +24,6 @@ fun main(args : Array<String>) {
|
||||
val booleanArray = BooleanArray(12)
|
||||
println(booleanArray.size.toString())
|
||||
|
||||
val stringArray = Array<String>(13)
|
||||
val stringArray = Array<String>(13, { i -> ""})
|
||||
println(stringArray.size.toString())
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fun main(args : Array<String>) {
|
||||
val byteArray = Array<Byte>(5, { i -> (i * 2).toByte() })
|
||||
byteArray.map { println(it) }
|
||||
|
||||
val intArray = Array<Int>(5, { i -> i * 4 })
|
||||
println(intArray.sum())
|
||||
}
|
||||
@@ -181,7 +181,6 @@ fun testPutEntry() {
|
||||
assertTrue(expected == m)
|
||||
}
|
||||
|
||||
/* Fails due to variance.
|
||||
fun testRemoveAllEntries() {
|
||||
val expected = mapOf("a" to "1", "b" to "2", "c" to "3")
|
||||
val m = HashMap(expected)
|
||||
@@ -199,7 +198,7 @@ fun testRetainAllEntries() {
|
||||
assertEquals(expected, m)
|
||||
assertTrue(m.entries.retainAll(mapOf("b" to "22", "c" to "3", "d" to "4").entries))
|
||||
assertEquals(mapOf("c" to "3"), m)
|
||||
} */
|
||||
}
|
||||
|
||||
fun testContainsAllValues() {
|
||||
val m = HashMap(mapOf("a" to "1", "b" to "2", "c" to "3"))
|
||||
@@ -256,8 +255,8 @@ fun main(args : Array<String>) {
|
||||
testHashCode()
|
||||
testToString()
|
||||
testPutEntry()
|
||||
//testRemoveAllEntries()
|
||||
//testRetainAllEntries()
|
||||
testRemoveAllEntries()
|
||||
testRetainAllEntries()
|
||||
testContainsAllValues()
|
||||
testRemoveValue()
|
||||
testRemoveAllValues()
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fun main(args: Array<String>) {
|
||||
val a = Array<Byte>(100000, { i -> i.toByte()})
|
||||
|
||||
var sum = 0
|
||||
for (b in a) {
|
||||
sum += b
|
||||
}
|
||||
|
||||
println(sum)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
data class Node(val data: Int, var next: Node?, var prev: Node?, val outer: Node?)
|
||||
|
||||
fun makeCycle(len: Int, outer: Node?): Node {
|
||||
val start = Node(0, null, null, outer)
|
||||
var prev = start
|
||||
for (i in 1 .. len - 1) {
|
||||
prev = Node(i, prev, null, outer)
|
||||
}
|
||||
start.next = prev
|
||||
return start
|
||||
}
|
||||
|
||||
fun makeDoubleCycle(len: Int): Node {
|
||||
val start = makeCycle(len, null)
|
||||
var prev = start
|
||||
var cur = prev.next
|
||||
while (cur != start) {
|
||||
cur!!.prev = prev
|
||||
prev = cur
|
||||
cur = cur.next
|
||||
}
|
||||
start.prev = prev
|
||||
return start
|
||||
}
|
||||
|
||||
fun createCycles(junk: Node) {
|
||||
val cycle1 = makeCycle(1, junk)
|
||||
val cycle2 = makeCycle(2, junk)
|
||||
val cycle10 = makeCycle(10, junk)
|
||||
val cycle100 = makeCycle(100, junk)
|
||||
val dcycle1 = makeDoubleCycle(1)
|
||||
val dcycle2 = makeDoubleCycle(2)
|
||||
val dcycle10 = makeDoubleCycle(10)
|
||||
val dcycle100 = makeDoubleCycle(100)
|
||||
|
||||
}
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
// Create outer link from cyclic garbage.
|
||||
val outer = Node(42, null, null, null)
|
||||
createCycles(outer)
|
||||
konan.internal.GC.collect()
|
||||
// Ensure outer is not collected.
|
||||
println(outer.data)
|
||||
}
|
||||
Reference in New Issue
Block a user