[IR] CommonBackendContext and Symbols refactoring
* add [suspend]functionN factory factions * add `getContinuation` property * add `internalPackageName` property * fix lowerings
This commit is contained in:
@@ -135,13 +135,10 @@ class JsIrBackendContext(
|
||||
|
||||
val intrinsics = JsIntrinsics(irBuiltIns, this)
|
||||
|
||||
override val internalPackageFqn = JS_PACKAGE_FQNAME
|
||||
|
||||
private val operatorMap = referenceOperators()
|
||||
|
||||
// TODO: get rid of this
|
||||
|
||||
fun functionN(n: Int) = symbolTable.lazyWrapper.referenceClass(builtIns.getFunction(n))
|
||||
fun suspendFunctionN(n: Int) = symbolTable.lazyWrapper.referenceClass(builtIns.getSuspendFunction(n))
|
||||
|
||||
private fun primitivesWithImplicitCompanionObject(): List<Name> {
|
||||
val numbers = PrimitiveType.NUMBER_TYPES
|
||||
.filter { it.name != "LONG" && it.name != "CHAR" } // skip due to they have own explicit companions
|
||||
@@ -184,6 +181,8 @@ class JsIrBackendContext(
|
||||
NoLookupLocation.FROM_BACKEND
|
||||
).filterNot { it.isExpect }.single().getter!!
|
||||
)
|
||||
|
||||
override val getContinuation = symbolTable.referenceSimpleFunction(getJsInternalFunction("getContinuation"))
|
||||
}
|
||||
|
||||
override fun shouldGenerateHandlerParameterForDefaultBodyFun() = true
|
||||
|
||||
+3
-3
@@ -210,7 +210,7 @@ class CallableReferenceLowering(val context: JsIrBackendContext) : FileLoweringP
|
||||
val additionalDeclarations = generateFactoryBodyWithGuard(factoryFunction) {
|
||||
val statements = mutableListOf<IrStatement>(getterFunction)
|
||||
|
||||
val getterFunctionTypeSymbol = context.functionN(getterFunction.valueParameters.size + 1)
|
||||
val getterFunctionTypeSymbol = context.ir.symbols.functionN(getterFunction.valueParameters.size + 1)
|
||||
|
||||
val getterFunctionIrType = IrSimpleTypeImpl(getterFunctionTypeSymbol, false, emptyList(), emptyList())
|
||||
val irGetReference = JsIrBuilder.buildFunctionReference(getterFunctionIrType, getterFunction.symbol)
|
||||
@@ -226,7 +226,7 @@ class CallableReferenceLowering(val context: JsIrBackendContext) : FileLoweringP
|
||||
|
||||
if (setterFunction != null) {
|
||||
statements += setterFunction
|
||||
val setterFunctionTypeSymbol = context.functionN(setterFunction.valueParameters.size + 1)
|
||||
val setterFunctionTypeSymbol = context.ir.symbols.functionN(setterFunction.valueParameters.size + 1)
|
||||
val setterFunctionIrType = IrSimpleTypeImpl(setterFunctionTypeSymbol, false, emptyList(), emptyList())
|
||||
val irSetReference = JsIrBuilder.buildFunctionReference(setterFunctionIrType, setterFunction.symbol)
|
||||
statements += JsIrBuilder.buildCall(context.intrinsics.jsSetJSField.symbol).apply {
|
||||
@@ -280,7 +280,7 @@ class CallableReferenceLowering(val context: JsIrBackendContext) : FileLoweringP
|
||||
val additionalDeclarations = generateFactoryBodyWithGuard(factoryFunction) {
|
||||
val statements = mutableListOf<IrStatement>(closureFunction)
|
||||
|
||||
val getterFunctionTypeSymbol = context.functionN(closureFunction.valueParameters.size + 1)
|
||||
val getterFunctionTypeSymbol = context.ir.symbols.functionN(closureFunction.valueParameters.size + 1)
|
||||
val getterFunctionIrType = IrSimpleTypeImpl(getterFunctionTypeSymbol, false, emptyList(), emptyList())
|
||||
val irGetReference = JsIrBuilder.buildFunctionReference(getterFunctionIrType, closureFunction.symbol)
|
||||
val irVar = JsIrBuilder.buildVar(getterFunctionIrType, factoryFunction, initializer = irGetReference)
|
||||
|
||||
+1
-2
@@ -50,8 +50,7 @@ class JsDefaultArgumentStubGenerator(override val context: JsIrBackendContext) :
|
||||
|
||||
private fun resolveInvoke(paramCount: Int): IrSimpleFunction {
|
||||
assert(paramCount > 0)
|
||||
val fqn = FqName.fromSegments(listOf("kotlin", "Function$paramCount"))
|
||||
val functionKlass = context.functionN(paramCount).owner
|
||||
val functionKlass = context.ir.symbols.functionN(paramCount).owner
|
||||
return functionKlass.declarations.filterIsInstance<IrSimpleFunction>().first { it.name == Name.identifier("invoke") }
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -61,7 +61,7 @@ class TestGenerator(val context: JsIrBackendContext) : FileLoweringPass {
|
||||
putValueArgument(0, JsIrBuilder.buildString(context.irBuiltIns.stringType, name))
|
||||
putValueArgument(1, JsIrBuilder.buildBoolean(context.irBuiltIns.booleanType, ignored))
|
||||
|
||||
val refType = IrSimpleTypeImpl(context.functionN(0), false, emptyList(), emptyList())
|
||||
val refType = IrSimpleTypeImpl(context.ir.symbols.functionN(0), false, emptyList(), emptyList())
|
||||
putValueArgument(2, JsIrBuilder.buildFunctionReference(refType, function.symbol))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user