[Wasm][Temporary] Stubs for typeOf and ::class constructs

This commit is contained in:
Igor Laevsky
2021-10-22 20:36:28 +03:00
parent 43eeaa925f
commit 8dc81b6c57
13 changed files with 21 additions and 28 deletions
@@ -45,6 +45,11 @@ class WasmSymbols(
private val kotlinTestPackage: PackageViewDescriptor =
context.module.getPackage(FqName("kotlin.test"))
private val kotlinReflectPackage: PackageViewDescriptor =
context.module.getPackage(FqName("kotlin.reflect"))
val typeOf = getFunction("typeOf", kotlinReflectPackage)
override val throwNullPointerException = getInternalFunction("THROW_NPE")
override val throwISE = getInternalFunction("THROW_ISE")
override val throwTypeCastException = getInternalFunction("THROW_CCE")
@@ -64,6 +64,17 @@ class BodyGenerator(val context: WasmFunctionCodegenContext) : IrElementVisitorV
error("Unexpected element of type ${element::class}")
}
override fun visitClassReference(expression: IrClassReference) {
body.buildCall(context.referenceFunction(wasmSymbols.throwISE))
body.buildUnreachable()
}
override fun visitGetClass(expression: IrGetClass) {
body.buildCall(context.referenceFunction(wasmSymbols.throwISE))
body.buildUnreachable()
}
override fun visitThrow(expression: IrThrow) {
generateExpression(expression.value)
body.buildThrow(context.tagIdx)
@@ -333,6 +344,11 @@ class BodyGenerator(val context: WasmFunctionCodegenContext) : IrElementVisitorV
}
when (function.symbol) {
wasmSymbols.typeOf -> {
body.buildCall(context.referenceFunction(wasmSymbols.throwISE))
body.buildGetUnit()
}
wasmSymbols.wasmClassId -> {
val klass = call.getTypeArgument(0)!!.getClass()
?: error("No class given for wasmClassId intrinsic")