Commit Graph

1132 Commits

Author SHA1 Message Date
Svyatoslav Scherbina 453a360707 Interop/Runtime: add minor code improvements 2016-11-22 16:47:05 +07:00
Svyatoslav Scherbina 950bc62c7b Review feedback, part 1 2016-11-22 16:45:31 +07:00
Svyatoslav Scherbina a58d682d40 Interop: remove old version 2016-11-22 13:19:49 +07:00
Svyatoslav Scherbina 183f6a6d2f Interop/Indexer: update prebuilts with new interop versions
also port Interop/Runtime/libcallbacks to new interop
2016-11-22 13:19:49 +07:00
Svyatoslav Scherbina c5f00c3301 InteropExample: port to new interop 2016-11-22 13:19:49 +07:00
Svyatoslav Scherbina 8a486d7fae backend: partially port code to new interop 2016-11-22 13:02:07 +07:00
Svyatoslav Scherbina f0df5f9435 Interop: implement new version 2016-11-22 13:02:07 +07:00
Svyatoslav Scherbina 3095044420 build: use Kotlin 1.1-M02 to build all Kotlin JVM sources 2016-11-22 13:01:14 +07:00
Svyatoslav Scherbina 8a66de216d Interop: rework String auto conversion
use memScoped
2016-11-22 13:01:04 +07:00
Svyatoslav Scherbina 53884f8da6 Interop/StubGenerator: add minor code improvements 2016-11-22 13:01:04 +07:00
Konstantin Anisimov 0cd4512dd5 CODEGEN: Support for "null" constant implemented
for code:
--------8<--------
> cat ../backend.native/tests/codegen/basics/null_check.kt
//--- Test "eqeq" -------------------------------------------------------------//

fun check_eqeq(a: Any?) = a == null

fun null_check_eqeq1() : Boolean {
  return check_eqeq(Any())
}

fun null_check_eqeq2() : Boolean {
  return check_eqeq(null)
}

//--- Test "eqeqeq" -----------------------------------------------------------//

fun check_eqeqeq(a: Any?) = a === null

fun null_check_eqeqeq1() : Boolean {
  return check_eqeqeq(Any())
}

fun null_check_eqeqeq2() : Boolean {
  return check_eqeqeq(null)
}

--------8<--------

code generator produces, following code:

--------8<--------
> llvm-dis-mp-3.8 ../backend.native/tests/codegen/basics/null_check.kt.bc -o -
; ModuleID = '../backend.native/tests/codegen/basics/null_check.kt.bc'
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.12.0"
...
define i1 @"kfun:check_eqeq(Any?)"(i8*) {
entry:
  %a = alloca i8*
  store i8* %0, i8** %a
  %tmp_1 = load i8*, i8** %a
  %tmp_3 = alloca i1
  %tmp_4 = icmp eq i8* %tmp_1, null
  br i1 %tmp_4, label %label_1, label %label_0

label_0:                                          ; preds = %entry
  %tmp_7 = bitcast i8* %tmp_1 to i8**
  %tmp_8 = load i8*, i8** %tmp_7
  %tmp_9 = bitcast i8* %tmp_8 to %struct.TypeInfo*
  %tmp_10 = call i8* @LookupOpenMethod(%struct.TypeInfo* %tmp_9, i64 5922905592022884074)
  %tmp_11 = bitcast i8* %tmp_10 to i1 (i8*, i8*)*
  %tmp_6 = call i1 %tmp_11(i8* %tmp_1, i8* null)
  store i1 %tmp_6, i1* %tmp_3
  br label %label_2

label_1:                                          ; preds = %entry
  %tmp_5 = icmp eq i8* %tmp_1, null
  store i1 %tmp_5, i1* %tmp_3
  br label %label_2

label_2:                                          ; preds = %label_1, %label_0
  %tmp_0 = load i1, i1* %tmp_3
  ret i1 %tmp_0
}

define i1 @"kfun:null_check_eqeq1()"() {
entry:
  %tmp_1 = call i8* @AllocInstance(%struct.TypeInfo* @"ktype:kotlin.Any", i32 1)
  %tmp_11 = call i8* @"kfun:kotlin.Any.<init>()"(i8* %tmp_1)
  %tmp_0 = call i1 @"kfun:check_eqeq(Any?)"(i8* %tmp_11)
  ret i1 %tmp_0
}

declare i8* @"kfun:kotlin.Any.<init>()"(i8*)

define i1 @"kfun:null_check_eqeq2()"() {
entry:
  %tmp_0 = call i1 @"kfun:check_eqeq(Any?)"(i8* null)
  ret i1 %tmp_0
}

define i1 @"kfun:check_eqeqeq(Any?)"(i8*) {
entry:
  %a = alloca i8*
  store i8* %0, i8** %a
  %tmp_1 = load i8*, i8** %a
  %tmp_0 = icmp eq i8* %tmp_1, null
  ret i1 %tmp_0
}

define i1 @"kfun:null_check_eqeqeq1()"() {
entry:
  %tmp_1 = call i8* @AllocInstance(%struct.TypeInfo* @"ktype:kotlin.Any", i32 1)
  %tmp_11 = call i8* @"kfun:kotlin.Any.<init>()"(i8* %tmp_1)
  %tmp_0 = call i1 @"kfun:check_eqeqeq(Any?)"(i8* %tmp_11)
  ret i1 %tmp_0
}

define i1 @"kfun:null_check_eqeqeq2()"() {
entry:
  %tmp_0 = call i1 @"kfun:check_eqeqeq(Any?)"(i8* null)
  ret i1 %tmp_0
}
...
--------8<--------
2016-11-21 21:08:36 +03:00
Konstantin Anisimov df358e8bd4 TEST: Tests for "null" constant added 2016-11-21 21:08:36 +03:00
Vasily Levchenko cf466e0cd7 codegen: fix implementation of branch generation to generate 'ternary' operator
for code:
--------8<--------
> cat ../backend.native/tests/runtime/basic/hello4.kt
fun main(args : Array<String>) {
    val x = 2
    println(if (x == 2) "Hello" else "Привет")
    println(if (x == 3) "Bye" else "Пока")
 }
--------8<--------
code generator produces:
--------8<--------
> llvm-dis-mp-3.8 ../backend.native/tests/runtime/basic/hello4.kt.bc -o -
; ModuleID = '../backend.native/tests/runtime/basic/hello4.kt.bc'
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.12.0"

...
define void @"kfun:main(Array<String>)"(i8*) {
entry:
  %args = alloca i8*
  store i8* %0, i8** %args
  %x = alloca i32
  store i32 2, i32* %x
  %tmp_1 = alloca i8*                             ; allocation of temporal variable (0)
  %tmp_3 = load i32, i32* %x
  %tmp_2 = icmp eq i32 %tmp_3, 2
  br i1 %tmp_2, label %label_2, label %label_1

label_0:                                          ; preds = %label_2, %label_1
  %tmp_0 = load i8*, i8** %tmp_1                  ; load value from tmp_1 (2)
  call void @Kotlin_io_Console_println(i8* %tmp_0)
  %tmp_8 = alloca i8*
  %tmp_10 = load i32, i32* %x
  %tmp_9 = icmp eq i32 %tmp_10, 3
  br i1 %tmp_9, label %label_5, label %label_4

label_1:                                          ; preds = %entry  store value to tmp_1 (1)
  store i8* @"kstr:KAWujn4S8YITX5L7kIQ7sQgNO+g=", i8** %tmp_1
  br label %label_0

label_2:                                          ; preds = %entry
  store i8* @"kstr:9/+ei3uy4Jtwk1pdeF4MxdnQq/A=", i8** %tmp_1
  br label %label_0

label_3:                                          ; preds = %label_5, %label_4
  %tmp_7 = load i8*, i8** %tmp_8
  call void @Kotlin_io_Console_println(i8* %tmp_7)
  ret void

label_4:                                          ; preds = %label_0
  store i8* @"kstr:q9lt9dN14ItE52B0fKxQuwMq4cc=", i8** %tmp_8
  br label %label_3

label_5:                                          ; preds = %label_0
  store i8* @"kstr:95JCQGTQyhp9FO/gWI8QwFLSjmk=", i8** %tmp_8
  br label %label_3
}

...
--------8<--------
2016-11-21 20:36:40 +03:00
Nikolay Igotti c54e786c33 TEST: Ternary operator test. 2016-11-21 20:36:40 +03:00
Vasily Levchenko ce059ac54b kotlin-compiler: .1-20161121.132728-268 2016-11-21 18:41:46 +03:00
Alexander Gorshenev 1e87dfeb8b link test 2016-11-21 15:30:08 +04:00
Nikolay Igotti 72da55623c Add basic iterators. (#58) 2016-11-21 13:21:23 +03:00
Konstantin Anisimov d2a51677d5 check return value type on direct call
(cherry picked from commit 70d305ebc48eaf5dbe8e3cd589daff5f49a704a3)
2016-11-21 13:16:38 +03:00
Nikolay Igotti 96797a4b2f Implement Base64 without need of JDK8. (#78) 2016-11-21 10:42:49 +03:00
vvlevchenko 5161155934 Constructor (w/o body) (#74) 2016-11-19 19:45:21 +03:00
Nikolay Igotti 0e1ac89dbf Fix build. 2016-11-18 18:50:10 +03:00
Alexander Gorshenev 1d265bc50c Here goes stdlib separation.
$ gradlew backend.native:stdlib

builds you stdlib.kt.bc now.

The test runs are taught to supply
-library stdlib.kt.bc to kotlin compiler for proper imports resolution,
and then later stdlib.kt.bc is provided to clang for the final link step.
2016-11-18 19:11:38 +04:00
Alexander Gorshenev b0d10e45d8 changed DynamicTypesAllowed() to DynamicTypesSettings() in KonanPlatformConfigurator.kt 2016-11-18 19:11:38 +04:00
Konstantin Anisimov dfd486a9ea RUNTIME: Code rearranged between Memory.* and Types.* 2016-11-18 16:22:27 +03:00
Konstantin Anisimov d86b387f9c CODEGEN: Implemented support for "instanceOf", operations "Boolean" type implemented, operator NOT_INSTANCEOF implemented
for code
--------8<--------
> cat ../backend.native/tests/codegen/basics/check_type.kt
interface I
class A() : I {}
class B() {}

//-----------------------------------------------------------------------------//

fun isTypeOf(a: Any) : Boolean {
  return a is A
}

fun check_type(): Boolean {
  val a = A()
  return isTypeOf(a)
}

//-----------------------------------------------------------------------------//

fun isNotTypeOf(a: Any) : Boolean {
  return a !is A
}

fun check_not_type(): Boolean {
  val b = B()
  return isNotTypeOf(b)
}

//-----------------------------------------------------------------------------//

fun isTypeOfInterface(a: Any) : Boolean {
  return a is I
}

fun check_interface(): Boolean {
  val a = A()
  return isTypeOfInterface(a)
}
--------8<--------

translator generates:

--------8<--------
> llvm-dis-mp-3.8 ../backend.native/tests/codegen/basics/check_type.kt.bc -o -
; ModuleID = '../backend.native/tests/codegen/basics/check_type.kt.bc'
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.12.0"

...
define i1 @"kfun:isTypeOf(Any)"(i8*) {
entry:
  %a = alloca i8*
  store i8* %0, i8** %a
  %tmp_1 = load i8*, i8** %a
  %tmp_2 = bitcast i8* %tmp_1 to %struct.ObjHeader*
  %tmp_3 = call i8 @IsInstance(%struct.ObjHeader* %tmp_2, %struct.TypeInfo* @"ktype:A")
  %tmp_0 = trunc i8 %tmp_3 to i1
  ret i1 %tmp_0
}
...
define i1 @"kfun:isNotTypeOf(Any)"(i8*) {
entry:
  %a = alloca i8*
  store i8* %0, i8** %a
  %tmp_2 = load i8*, i8** %a
  %tmp_3 = bitcast i8* %tmp_2 to %struct.ObjHeader*
  %tmp_4 = call i8 @IsInstance(%struct.ObjHeader* %tmp_3, %struct.TypeInfo* @"ktype:A")
  %tmp_1 = trunc i8 %tmp_4 to i1
  %tmp_0 = xor i1 %tmp_1, true
  ret i1 %tmp_0
}
...
define i1 @"kfun:isTypeOfInterface(Any)"(i8*) {
entry:
  %a = alloca i8*
  store i8* %0, i8** %a
  %tmp_1 = load i8*, i8** %a
  %tmp_2 = bitcast i8* %tmp_1 to %struct.ObjHeader*
  %tmp_3 = call i8 @IsInstance(%struct.ObjHeader* %tmp_2, %struct.TypeInfo* @"ktype:I")
  %tmp_0 = trunc i8 %tmp_3 to i1
  ret i1 %tmp_0
}

--------8<--------
2016-11-18 16:22:27 +03:00
Konstantin Anisimov c1bb762417 TESTS: "for" and INSTANCEOF, NOT_INSTANCEOF, isInstanceOf on interface are added 2016-11-18 16:22:27 +03:00
Konstantin Anisimov 3a49e69046 Support for objects' cast implemented
for code

--------8<--------
> cat ../backend.native/tests/codegen/basics/cast_simple.kt
open class A() {}
class B(): A() {}

fun castSimple(o: Any) : A = o as A

fun castTest(): Boolean {
  val b = B()
  castSimple(b)
  return true
}
--------8<--------
translator generates

--------8<--------
>llvm-dis-mp-3.8 ../backend.native/tests/codegen/basics/cast_simple.kt.bc -o -
; ModuleID = '../backend.native/tests/codegen/basics/cast_simple.kt.bc'
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.12.0"

...

define i8* @"kfun:castSimple(Any)"(i8*) {
entry:
  %o = alloca i8*
  store i8* %0, i8** %o
  %tmp_1 = load i8*, i8** %o
  %tmp_2 = bitcast i8* %tmp_1 to %struct.ObjHeader*
  call void @CheckInstance(%struct.ObjHeader* %tmp_2, %struct.TypeInfo* @"ktype:A")
  ret i8* %tmp_1
}
--------8<--------
2016-11-18 15:47:28 +03:00
Konstantin Anisimov 9c28555e55 Test for cast added 2016-11-18 15:47:28 +03:00
Konstantin Anisimov 103509d75d Tests fixed 2016-11-18 14:30:32 +03:00
Vasily Levchenko f588814927 tests: disable method_call test until #74 won't be applied 2016-11-18 13:56:14 +03:00
Vasily Levchenko 514d1a16ec test: minus_eq fix 2016-11-18 13:54:34 +03:00
Konstantin Anisimov eb2046fe5d Tests fixed 2016-11-18 12:57:47 +03:00
Konstantin Anisimov 04d441ef21 Test fixed 2016-11-18 12:44:00 +03:00
Vasily Levchenko 8b37001cdf typo in unit test runner 2016-11-18 12:30:27 +03:00
Vasily Levchenko 26710e52a1 use exit(3) in unit tests 2016-11-18 12:27:13 +03:00
Vasily Levchenko d00614ce1b to safe kotlin style main with return type Unit.
Revert "runtime: kotlinNativeMain should return status code and main should return it to the system"

This reverts commit 8161c8ddac.
2016-11-18 12:18:53 +03:00
Vasily Levchenko 8161c8ddac runtime: kotlinNativeMain should return status code and main should return it to the system
(cherry picked from commit acef5ed7e2f7e1d9478d77a1d3405873a7537db1)
2016-11-18 11:22:15 +03:00
Vasily Levchenko 72ef6d43a9 let processing IrWhen as any level expresssion
(cherry picked from commit 00bf82fc5c1a67af16aa2c9c386da8e873a02449)
2016-11-18 06:21:51 +03:00
Nikolay Igotti c20df35c78 Exception classes (#68) 2016-11-17 17:56:34 +03:00
Alexander Gorshenev 8321c14e36 Introduced KonanPlatform, KonanConfig, TopDownAnalyzerFacadeForKonan
and several other supporting facilities
2016-11-17 18:16:15 +04:00
Vasily Levchenko cae9094705 cosmetic: visitField log message formating 2016-11-17 14:57:19 +03:00
Vasily Levchenko 4495c86c2c call of void function
(cherry picked from commit feeacab2bb6e1789e91075dc1b519340cd4f4172)
2016-11-17 14:45:31 +03:00
Vasily Levchenko e4c384e99a replace in-place generation llvm values for true and false with constants
(cherry picked from commit 4a16460b2d778e9406b805f7b6b517b162e77dd8)
2016-11-17 14:45:31 +03:00
Nikolay Igotti fa7bcd90e3 Remove duplicated test. 2016-11-17 14:27:45 +03:00
Alexander Gorshenev 16e4107dee kotlin-compiler: 1.1-20161116.235936-256 2016-11-17 14:56:07 +04:00
Konstantin Anisimov 0fff59a516 Support for object properties access implemented. Minor refactoring
following code:

--------8<--------
> cat ../backend.native/tests/codegen/object/method_call.kt
class A(val a:Int) {
  fun foo(i:Int) = a + i
}

fun fortyTwo() = A(41).foo(1)
--------8<--------

translator generates following getter

--------8<--------
> llvm-dis-mp-3.8 ../backend.native/tests/codegen/object/method_call.kt.bc -o -
; ModuleID = '../backend.native/tests/codegen/object/method_call.kt.bc'
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.12.0"
...
define i32 @"kfun:A.<get-a>()"(i8*) {
entry:
  %this = alloca i8*
  store i8* %0, i8** %this
  %tmp_1 = load i8*, i8** %this
  %tmp_2 = bitcast i8* %tmp_1 to %struct.ObjHeader*
  %tmp_3 = getelementptr %struct.ObjHeader, %struct.ObjHeader* %tmp_2, i32 1
  %tmp_4 = bitcast %struct.ObjHeader* %tmp_3 to %"kclass:A"*
  %tmp_5 = getelementptr inbounds %"kclass:A", %"kclass:A"* %tmp_4, i32 0, i32 0
  %tmp_6 = load i32, i32* %tmp_5
  ret i32 %tmp_6
}
...
--------8<--------

similar history for global properties:

--------8<--------
> cat ../backend.native/tests/codegen/object/fields.kt
private var globalValue = 1
var global:Int
    get() = globalValue
    set(value:Int) {globalValue = value}

fun globalTest(i:Int):Int {
    global += i
    return global
}
--------8<--------

translator generates following code:

--------8<--------
> llvm-dis-mp-3.8 ../backend.native/tests/codegen/object/fields.kt.bc -o -
; ModuleID = '../backend.native/tests/codegen/object/fields.kt.bc'
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.12.0"

...

@"kvar:<root>.globalValue" = global i32 1

...

define i32 @"kfun:<get-globalValue>()"() {
entry:
  %tmp_1 = load i32, i32* @"kvar:<root>.globalValue"
  ret i32 %tmp_1
}

define void @"kfun:<set-globalValue>(Int)"(i32) {
entry:
  %"<set-?>" = alloca i32
  store i32 %0, i32* %"<set-?>"
  %tmp_0 = load i32, i32* %"<set-?>"
  store i32 %tmp_0, i32* @"kvar:<root>.globalValue"
  ret void
}

define i32 @"kfun:<get-global>()"() {
entry:
  %tmp_0 = call i32 @"kfun:<get-globalValue>()"()
  ret i32 %tmp_0
}

define void @"kfun:<set-global>(Int)"(i32) {
entry:
  %value = alloca i32
  store i32 %0, i32* %value
  %tmp_0 = load i32, i32* %value
  call void @"kfun:<set-globalValue>(Int)"(i32 %tmp_0)
  ret void
}

--------8<--------
2016-11-17 12:25:12 +03:00
Konstantin Anisimov f80697817e Test for getters/setters added 2016-11-17 12:25:12 +03:00
Konstantin Anisimov f393dc3a03 Pasto fixed 2016-11-17 11:02:55 +03:00
Konstantin Anisimov da230bf7b2 Implementation of simple functions for Char
(cherry picked from commit 462c0fb50e3b85a58220d53e34e90e66081cf1ba)
2016-11-17 10:48:49 +03:00
Svyatoslav Scherbina 69ee5a619a backend: add tests for === 2016-11-17 12:17:47 +07:00