Konstantin Anisimov bd715df0d6 CODEGEN: construction body evaluation
for code:
--------8<--------
> cat ../backend.native/tests/codegen/object/initialization.kt
open class A(val a:Int, val b:Int)

open class B(val c:Int, d:Int):A(c, d)

open class C(i:Int, j:Int):B(i + j, 42)

class D (i: Int, j:Int) : C(i, j){
   constructor(i: Int, j:Int, k:Int) : this(i, j) {
      foo(i)
   }
   constructor():this(1, 2)
}

fun foo(i:Int) : Unit {}

fun foo(i:Int, j:Int):Int {
   val c = D(i, j)
   return c.c
}
--------8<--------

folowing code is generated:
--------8<--------
; ModuleID = '../backend.native/tests/codegen/object/initialization.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:C.<init>(Int;Int)"(i8*, i32, i32) {
entry:
  %this = alloca i8*
  store i8* %0, i8** %this
  %i = alloca i32
  store i32 %1, i32* %i
  %j = alloca i32
  store i32 %2, i32* %j
  %tmp_0 = load i8*, i8** %this
  %tmp_3 = load i32, i32* %i
  %tmp_4 = load i32, i32* %j
  %tmp_2 = call i32 @Kotlin_Int_plus_Int(i32 %tmp_3, i32 %tmp_4)
  %tmp_6 = load i8*, i8** %this
  %tmp_1 = call i8* @"kfun:B.<init>(Int;Int)"(i8* %tmp_6, i32 %tmp_2, i32 42)
  ret i8* %tmp_0
}

define i8* @"kfun:D.<init>(Int;Int)"(i8*, i32, i32) {
entry:
  %this = alloca i8*
  store i8* %0, i8** %this
  %i = alloca i32
  store i32 %1, i32* %i
  %j = alloca i32
  store i32 %2, i32* %j
  %tmp_0 = load i8*, i8** %this
  %tmp_2 = load i32, i32* %i
  %tmp_3 = load i32, i32* %j
  %tmp_4 = load i8*, i8** %this
  %tmp_1 = call i8* @"kfun:C.<init>(Int;Int)"(i8* %tmp_4, i32 %tmp_2, i32 %tmp_3)
  ret i8* %tmp_0
}

define i8* @"kfun:D.<init>(Int;Int;Int)"(i8*, i32, i32, i32) {
entry:
  %this = alloca i8*
  store i8* %0, i8** %this
  %i = alloca i32
  store i32 %1, i32* %i
  %j = alloca i32
  store i32 %2, i32* %j
  %k = alloca i32
  store i32 %3, i32* %k
  %tmp_0 = load i8*, i8** %this
  %tmp_2 = load i32, i32* %i
  %tmp_3 = load i32, i32* %j
  %tmp_4 = load i8*, i8** %this
  %tmp_1 = call i8* @"kfun:D.<init>(Int;Int)"(i8* %tmp_4, i32 %tmp_2, i32 %tmp_3)
  %tmp_5 = load i32, i32* %i
  call void @"kfun:foo(Int)"(i32 %tmp_5)
  ret i8* %tmp_0
}

--------8<--------
2016-11-22 21:13:25 +03:00
2016-10-27 13:52:00 +03:00
2016-11-22 14:36:09 +03:00
2016-10-07 14:14:00 +03:00
2016-10-27 13:52:00 +03:00
2016-10-27 13:52:00 +03:00

Kotlin-native backend

Build

Download dependencies:

gradle :dependencies:update

To run native translator just use:

gradle :backend.native:run

And it will run simple example (currently prints out IR of test file). For more tests, use:

gradle :backend.native:tests:run
S
Description
The Kotlin Programming Language.
Readme 2.1 GiB
Languages
Kotlin 79.9%
Java 10.4%
Swift 4.3%
C 2.8%
C++ 2.1%
Other 0.3%