Support Boolean in interop varargs and function pointers invocation
This commit is contained in:
committed by
SvyatoslavScherbina
parent
571fe47571
commit
99dd7227dc
@@ -70,6 +70,10 @@ private fun invokeImplUnitRet(ptr: COpaquePointer, vararg args: Any?): Unit = me
|
||||
callWithVarargs(ptr.rawValue, nativeNullPtr, FFI_TYPE_KIND_VOID, args, emptyArray(), memScope)
|
||||
}
|
||||
|
||||
@ExportForCompiler
|
||||
private fun invokeImplBooleanRet(ptr: COpaquePointer, vararg args: Any?): Boolean =
|
||||
invokeImplByteRet(ptr, *args).toBoolean()
|
||||
|
||||
@ExportForCompiler
|
||||
private fun invokeImplByteRet(ptr: COpaquePointer, vararg args: Any?): Byte = memScoped {
|
||||
val resultBuffer = allocFfiReturnValueBuffer<ByteVar>(ByteVar)
|
||||
|
||||
@@ -38,6 +38,8 @@ private tailrec fun convertArgument(
|
||||
FFI_TYPE_KIND_SINT64
|
||||
}
|
||||
|
||||
is Boolean -> convertArgument(argument.toByte(), isVariadic, location, additionalPlacement)
|
||||
|
||||
is Byte -> if (isVariadic) {
|
||||
convertArgument(argument.toInt(), isVariadic, location, additionalPlacement)
|
||||
} else {
|
||||
|
||||
+1
@@ -116,6 +116,7 @@ internal class InteropBuiltIns(builtIns: KonanBuiltIns) {
|
||||
|
||||
val invokeImpls = mapOf(
|
||||
builtIns.unit to "invokeImplUnitRet",
|
||||
builtIns.boolean to "invokeImplBooleanRet",
|
||||
builtIns.byte to "invokeImplByteRet",
|
||||
builtIns.short to "invokeImplShortRet",
|
||||
builtIns.int to "invokeImplIntRet",
|
||||
|
||||
@@ -2051,7 +2051,7 @@ task interop3(type: RunInteropKonanTest) {
|
||||
|
||||
task interop4(type: RunInteropKonanTest) {
|
||||
disabled = (project.testTarget == 'wasm32') // No interop for wasm yet.
|
||||
goldValue = "a b -1 2 3 9223372036854775807 0.1 0.2\n1 42\n"
|
||||
goldValue = "a b -1 2 3 9223372036854775807 0.1 0.2 1 0\n1 42\n"
|
||||
source = "interop/basics/4.kt"
|
||||
interop = 'cstdio'
|
||||
}
|
||||
@@ -2064,7 +2064,7 @@ task interop_bitfields(type: RunInteropKonanTest) {
|
||||
|
||||
task interop_funptr(type: RunInteropKonanTest) {
|
||||
disabled = (project.testTarget == 'wasm32') // No interop for wasm yet.
|
||||
goldValue = "42\n17\n"
|
||||
goldValue = "42\n17\n1\n0\n"
|
||||
source = "interop/basics/funptr.kt"
|
||||
interop = 'cfunptr'
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ val stdout
|
||||
get() = getStdout()
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
fprintf(stdout, "%s %s %d %d %d %lld %.1f %.1lf\n",
|
||||
"a", "b".cstr, (-1).toByte(), 2.toShort(), 3, Long.MAX_VALUE, 0.1.toFloat(), 0.2)
|
||||
fprintf(stdout, "%s %s %d %d %d %lld %.1f %.1lf %d %d\n",
|
||||
"a", "b".cstr, (-1).toByte(), 2.toShort(), 3, Long.MAX_VALUE, 0.1.toFloat(), 0.2, true, false)
|
||||
|
||||
memScoped {
|
||||
val aVar = alloc<IntVar>()
|
||||
|
||||
@@ -41,4 +41,14 @@ typedef int (*doubleToIntPtrType)(double);
|
||||
|
||||
static doubleToIntPtrType getDoubleToIntPtr() {
|
||||
return &__doubleToInt;
|
||||
}
|
||||
|
||||
static _Bool __isIntPositive(int x) {
|
||||
return x > 0;
|
||||
}
|
||||
|
||||
typedef _Bool (*isIntPositivePtrType)(int);
|
||||
|
||||
static isIntPositivePtrType getIsIntPositivePtr() {
|
||||
return &__isIntPositive;
|
||||
}
|
||||
@@ -18,4 +18,11 @@ fun main(args: Array<String>) {
|
||||
getAddPtr()!!(5.1, 12.2)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
val isIntPositivePtr = getIsIntPositivePtr()!!
|
||||
|
||||
printIntPtr(isIntPositivePtr(42).ifThenOneElseZero())
|
||||
printIntPtr(isIntPositivePtr(-42).ifThenOneElseZero())
|
||||
}
|
||||
|
||||
fun Boolean.ifThenOneElseZero() = if (this) 1 else 0
|
||||
Reference in New Issue
Block a user