[KT-42830][Reverse C Interop] Add API to get value of boxed primitives

Merge-request: KT-MR-6836
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
This commit is contained in:
Vladimir Sukharev
2022-08-17 13:24:27 +00:00
committed by Space
parent c1191e141b
commit 6f945aa2fc
6 changed files with 194 additions and 5 deletions
@@ -0,0 +1,36 @@
true
true
true
￿
￿
￿
-128
-128
-128
-32768
-32768
-32768
-2147483648
-2147483648
-2147483648
-9223372036854775808
-9223372036854775808
-9223372036854775808
3.4028235E38
3.4028235E38
3.4028235E38
1.7976931348623157E308
1.7976931348623157E308
1.7976931348623157E308
255
255
255
65535
65535
65535
4294967295
4294967295
4294967295
18446744073709551615
18446744073709551615
18446744073709551615
@@ -0,0 +1,45 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
fun printAny(v: Any?) {
println(v)
}
fun printBoolean(v: Boolean) {
println(v)
}
fun printChar(v: Char) {
println(v)
}
fun printByte(v: Byte) {
println(v)
}
fun printShort(v: Short) {
println(v)
}
fun printInt(v: Int) {
println(v)
}
fun printLong(v: Long) {
println(v)
}
fun printFloat(v: Float) {
println(v)
}
fun printDouble(v: Double) {
println(v)
}
fun printUByte(v: UByte) {
println(v)
}
fun printUShort(v: UShort) {
println(v)
}
fun printUInt(v: UInt) {
println(v)
}
fun printULong(v: ULong) {
println(v)
}
@@ -0,0 +1,37 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
#include "testlib_api.h"
#define __ testlib_symbols()->
#define T_(x) testlib_kref_ ## x
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <float.h>
#define TEST_TYPE_VAL(TYPE_C, TYPE, VAL) \
TYPE_C primitive##TYPE = VAL; \
__ kotlin.root.print##TYPE (primitive##TYPE); \
T_(kotlin_##TYPE) nullable##TYPE = __ createNullable##TYPE (primitive##TYPE); \
T_(kotlin_Any) any##TYPE = { .pinned = nullable##TYPE.pinned }; \
__ kotlin.root.printAny (any##TYPE); \
TYPE_C unboxed##TYPE = __ getNonNullValueOf##TYPE (nullable##TYPE); \
__ kotlin.root.print##TYPE (unboxed##TYPE);
int main(int argc, char** argv) {
TEST_TYPE_VAL(bool, Boolean, true);
TEST_TYPE_VAL(uint16_t, Char, UINT16_MAX);
TEST_TYPE_VAL(int8_t, Byte, INT8_MIN);
TEST_TYPE_VAL(int16_t, Short, INT16_MIN);
TEST_TYPE_VAL(int32_t, Int, INT32_MIN);
TEST_TYPE_VAL(int64_t, Long, INT64_MIN);
TEST_TYPE_VAL(float, Float, FLT_MAX);
TEST_TYPE_VAL(double, Double, DBL_MAX);
TEST_TYPE_VAL(uint8_t, UByte, UINT8_MAX);
TEST_TYPE_VAL(uint16_t, UShort, UINT16_MAX);
TEST_TYPE_VAL(uint32_t, UInt, UINT32_MAX);
TEST_TYPE_VAL(uint64_t, ULong, UINT64_MAX);
}