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
2016-10-27 13:52:00 +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%