[WASM] Bootstrap std compatibility fix
This commit is contained in:
@@ -173,7 +173,7 @@ class WasmSymbols(
|
||||
val wasmClassId = getInternalFunction("wasmClassId")
|
||||
val wasmInterfaceId = getInternalFunction("wasmInterfaceId")
|
||||
|
||||
val isInterface = getInternalFunction("isInterface")
|
||||
val wasmIsInterface = getInternalFunction("wasmIsInterface")
|
||||
|
||||
val nullableEquals = getInternalFunction("nullableEquals")
|
||||
val ensureNotNull = getInternalFunction("ensureNotNull")
|
||||
|
||||
+1
-1
@@ -402,7 +402,7 @@ class BodyGenerator(
|
||||
body.buildConstI32Symbol(context.referenceInterfaceId(irInterface.symbol))
|
||||
}
|
||||
|
||||
wasmSymbols.isInterface -> {
|
||||
wasmSymbols.wasmIsInterface -> {
|
||||
val irInterface = call.getTypeArgument(0)!!.getClass()
|
||||
?: error("No interface given for wasmInterfaceId intrinsic")
|
||||
assert(irInterface.isInterface)
|
||||
|
||||
+1
-1
@@ -300,7 +300,7 @@ class WasmBaseTypeOperatorTransformer(val context: WasmBackendContext) : IrEleme
|
||||
}
|
||||
|
||||
private fun generateIsInterface(argument: IrExpression, toType: IrType): IrExpression {
|
||||
return builder.irCall(symbols.isInterface).apply {
|
||||
return builder.irCall(symbols.wasmIsInterface).apply {
|
||||
putValueArgument(0, argument)
|
||||
putTypeArgument(0, toType)
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ internal fun isInterfaceById(obj: Any, interfaceId: Int): Boolean {
|
||||
}
|
||||
|
||||
@ExcludedFromCodegen
|
||||
internal fun <T> isInterface(obj: Any): Boolean =
|
||||
internal fun <T> wasmIsInterface(obj: Any): Boolean =
|
||||
implementedAsIntrinsic
|
||||
|
||||
@ExcludedFromCodegen
|
||||
@@ -61,4 +61,50 @@ internal fun <T> wasmInterfaceId(): Int =
|
||||
|
||||
@ExcludedFromCodegen
|
||||
internal fun <T> wasmGetTypeInfoData(): TypeInfoData =
|
||||
implementedAsIntrinsic
|
||||
implementedAsIntrinsic
|
||||
|
||||
|
||||
//REMOVE AFTER COMPILER BOOTSTRAP
|
||||
internal const val TYPE_INFO_ITABLE_PTR_OFFSET = TYPE_INFO_SUPER_TYPE_OFFSET + TYPE_INFO_ELEMENT_SIZE
|
||||
internal const val TYPE_INFO_VTABLE_LENGTH_OFFSET = TYPE_INFO_ITABLE_PTR_OFFSET + TYPE_INFO_ELEMENT_SIZE
|
||||
internal const val TYPE_INFO_VTABLE_OFFSET = TYPE_INFO_VTABLE_LENGTH_OFFSET + TYPE_INFO_ELEMENT_SIZE
|
||||
|
||||
internal fun getVtablePtr(obj: Any): Int =
|
||||
obj.typeInfo + TYPE_INFO_VTABLE_OFFSET
|
||||
|
||||
internal fun getVtableLength(obj: Any): Int =
|
||||
wasm_i32_load(obj.typeInfo + TYPE_INFO_VTABLE_LENGTH_OFFSET)
|
||||
|
||||
internal fun getItablePtr(obj: Any): Int =
|
||||
wasm_i32_load(obj.typeInfo + TYPE_INFO_ITABLE_PTR_OFFSET)
|
||||
|
||||
internal fun getInterfaceListLength(itablePtr: Int): Int =
|
||||
wasm_i32_load(itablePtr + TYPE_INFO_VTABLE_LENGTH_OFFSET)
|
||||
|
||||
internal fun getVirtualMethodId(obj: Any, virtualFunctionSlot: Int): Int {
|
||||
val vtablePtr = getVtablePtr(obj)
|
||||
val methodIdPtr = vtablePtr + virtualFunctionSlot * TYPE_INFO_ELEMENT_SIZE
|
||||
return wasm_i32_load(methodIdPtr)
|
||||
}
|
||||
|
||||
// Returns -1 if obj does not implement interface
|
||||
internal fun getInterfaceImplId(obj: Any, interfaceId: Int): Int {
|
||||
val interfaceListSizePtr = getItablePtr(obj)
|
||||
val interfaceListPtr = interfaceListSizePtr + TYPE_INFO_ELEMENT_SIZE
|
||||
val interfaceListSize = wasm_i32_load(interfaceListSizePtr)
|
||||
|
||||
var interfaceSlot = 0
|
||||
while (interfaceSlot < interfaceListSize) {
|
||||
val supportedInterface = wasm_i32_load(interfaceListPtr + interfaceSlot * TYPE_INFO_ELEMENT_SIZE)
|
||||
if (supportedInterface == interfaceId) {
|
||||
return wasm_i32_load(interfaceListPtr + interfaceListSize * TYPE_INFO_ELEMENT_SIZE + interfaceSlot * TYPE_INFO_ELEMENT_SIZE)
|
||||
}
|
||||
interfaceSlot++
|
||||
}
|
||||
|
||||
return -1
|
||||
}
|
||||
|
||||
internal fun isInterface(obj: Any, interfaceId: Int): Boolean {
|
||||
return getInterfaceImplId(obj, interfaceId) != -1
|
||||
}
|
||||
Reference in New Issue
Block a user