diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index ff3bdc59fd4..564d1a55f77 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -158,6 +158,10 @@ task fields(type: UnitKonanTest) { source = "$codegen/klass/basic.kt" } */ +task check_type(type: UnitKonanTest) { + source = "codegen/basics/check_type.kt" +} + task aritmetic(type: UnitKonanTest) { source = "codegen/function/arithmetic.kt" } diff --git a/backend.native/tests/codegen/basics/check_type-test.c b/backend.native/tests/codegen/basics/check_type-test.c new file mode 100644 index 00000000000..837879463f6 --- /dev/null +++ b/backend.native/tests/codegen/basics/check_type-test.c @@ -0,0 +1,16 @@ +#include + +extern void *resolve_symbol(const char*); + +int +run_test() { + int (*check_type)() = resolve_symbol("kfun:check_type()"); + int (*check_not_type)() = resolve_symbol("kfun:check_not_type()"); + int (*check_interface)() = resolve_symbol("kfun:check_interface()"); + + if (!check_type()) return 1; + if (!check_not_type()) return 1; + if (!check_interface()) return 1; + + return 0; +} diff --git a/backend.native/tests/codegen/basics/check_type.kt b/backend.native/tests/codegen/basics/check_type.kt new file mode 100644 index 00000000000..fe21db31457 --- /dev/null +++ b/backend.native/tests/codegen/basics/check_type.kt @@ -0,0 +1,52 @@ +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) +} + +//interface AI { +// fun v():Int +//} +// +//val global:Int = 1 +//class A1() : AI { +// override fun v():Int = global +//} +// +//fun smartCast(a:Any): Int { +// if (a is AI) { +// return a.v() +// } +// return 24 +//} \ No newline at end of file diff --git a/backend.native/tests/codegen/cycles/cycle_for.kt b/backend.native/tests/codegen/cycles/cycle_for.kt new file mode 100644 index 00000000000..738169fcbed --- /dev/null +++ b/backend.native/tests/codegen/cycles/cycle_for.kt @@ -0,0 +1,7 @@ +fun cycle_for(arr: Array) : Int { + var sum = 0 + for (i in arr) { + sum += i + } + return sum +}