Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ kotlin.mpp.import.enableKgpDependencyResolution=true

android.useAndroidX=true

knee.version=1.2.0
knee.version=1.3.0
knee.group=io.deepmedia.tools.knee
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.0-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion knee-compiler-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
kotlin("jvm")
kotlin("plugin.serialization")
id("io.deepmedia.tools.deployer")
id("com.github.johnrengelman.shadow") version "8.1.1"
id("com.gradleup.shadow") version "9.4.1"
}

dependencies {
Expand Down
41 changes: 28 additions & 13 deletions knee-compiler-plugin/src/main/kotlin/Classes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.types.KotlinType

fun preprocessClass(klass: KneeClass, context: KneeContext) {
context.mapper.register(ClassCodec(
symbols = context.symbols,
irClass = klass.source,
irConstructors = klass.constructors.map { it.source.symbol },
))
context.mapper.register(
ClassCodec(
symbols = context.symbols,
irClass = klass.source,
irConstructors = klass.constructors.map { it.source.symbol },
)
)
}

fun processClass(klass: KneeClass, context: KneeContext, codegen: KneeCodegen, initInfo: InitInfo) {
Expand All @@ -57,7 +59,7 @@ fun processClass(klass: KneeClass, context: KneeContext, codegen: KneeCodegen, i
* because we already create a KneeFunction for it. Just make sure it gets the right name.
*/
private fun KneeClass.makeCodegen(codegen: KneeCodegen) {
val container = codegen.prepareContainer(source, importInfo)
val container = codegen.ensureContainer(source, importInfo)
codegenClone = container.addChildIfNeeded(CodegenClass(source.asTypeSpec())).apply {
if (codegen.verbose) spec.addKdoc("knee:classes")
spec.addModifiers(source.visibility.asModifier())
Expand All @@ -80,6 +82,7 @@ class ClassCodec(
fun encodedTypeForFir(module: org.jetbrains.kotlin.descriptors.ModuleDescriptor): KotlinType {
return module.builtIns.longType
}

fun encodedTypeForIr(symbols: KneeSymbols): JniType {
return JniType.Long(symbols)
}
Expand All @@ -93,18 +96,24 @@ class ClassCodec(
* We must create a stable ref for this class so that it can be passed to the frontend.
* In addition, if this class is owned by some other, we must add the stable ref to the owner list.
*/
override fun IrStatementsBuilder<*>.irEncode(irContext: IrCodecContext, local: IrValueDeclaration): IrExpression {
override fun IrStatementsBuilder<*>.irEncode(
irContext: IrCodecContext,
local: IrValueDeclaration
): IrExpression {
return irCall(encode).apply {
putValueArgument(0, irGet(local))
arguments[0] = irGet(local)
}
}

// NOTE: in theory it is possible here to check whether this is a disposer and if it is,
// release the stable refs here.
override fun IrStatementsBuilder<*>.irDecode(irContext: IrCodecContext, jni: IrValueDeclaration): IrExpression {
override fun IrStatementsBuilder<*>.irDecode(
irContext: IrCodecContext,
jni: IrValueDeclaration
): IrExpression {
return irCall(decode).apply {
putTypeArgument(0, localIrType)
putValueArgument(0, irGet(jni))
typeArguments[0] = localIrType
arguments[0] = irGet(jni)
}
}

Expand All @@ -113,7 +122,10 @@ class ClassCodec(
* accepting the reference. If this is a constructor, we should instead call this(knee = $bridge),
* which means returning bridge value with no edits.
*/
override fun CodeBlock.Builder.codegenDecode(codegenContext: CodegenCodecContext, jni: String): String {
override fun CodeBlock.Builder.codegenDecode(
codegenContext: CodegenCodecContext,
jni: String
): String {
val isConstructor = codegenContext.functionSymbol in irConstructors
return when {
isConstructor -> jni
Expand All @@ -124,7 +136,10 @@ class ClassCodec(
/**
* A JVM class must reach the native world. This means that we must pass the native reference instead.
*/
override fun CodeBlock.Builder.codegenEncode(codegenContext: CodegenCodecContext, local: String): String {
override fun CodeBlock.Builder.codegenEncode(
codegenContext: CodegenCodecContext,
local: String
): String {
return "$local.`${InstancesCodegen.HandleField}`"
}
}
Loading