From a644999aea4df151967cd9c06f0f17303d37d154 Mon Sep 17 00:00:00 2001 From: soywiz Date: Sun, 28 Jan 2024 00:31:16 +0100 Subject: [PATCH 1/7] Kotlin 2.0.0-Beta3 --- .gitignore | 1 + .../korge/gradle/targets/js/Esbuild.kt | 22 ++++++++++++++----- .../korlibs/korge/gradle/targets/js/Wasm.kt | 2 +- .../kotlin/korlibs/root/RootKorlibsPlugin.kt | 2 +- gradle/libs.versions.toml | 2 +- korge-core/src/korlibs/io/dynamic/DynApi.kt | 6 ++++- korge-core/src/korlibs/wasm/WASMLib.kt | 5 ++++- .../korlibs/io/dynamic/DynApiJvm.kt | 6 ++--- .../korlibs/datastructure/FastArrayList.kt | 3 +++ .../korlibs/datastructure/NonJs.kt | 2 +- .../src@js/korlibs/datastructure/Js.kt | 2 +- .../src@wasmJs/korlibs/datastructure/Wasm.kt | 2 +- korlibs-logger/src/korlibs/logger/Logger.kt | 4 +++- .../src@jvm/korlibs/logger/Logger.jvm.kt | 2 +- 14 files changed, 42 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 47389cd609..9028aac9be 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ err.txt *.xcuserstate xcuserdata kotlin-js-store/ +/.kotlin diff --git a/buildSrc/src/main/kotlin/korlibs/korge/gradle/targets/js/Esbuild.kt b/buildSrc/src/main/kotlin/korlibs/korge/gradle/targets/js/Esbuild.kt index ff24040332..3e64b05003 100644 --- a/buildSrc/src/main/kotlin/korlibs/korge/gradle/targets/js/Esbuild.kt +++ b/buildSrc/src/main/kotlin/korlibs/korge/gradle/targets/js/Esbuild.kt @@ -42,11 +42,17 @@ fun Project.configureErrorableEsbuild() { val esbuildVersion = korge.esbuildVersion doFirst { - val npmCmd = arrayOf( - File(env.nodeExecutable), - File(env.nodeDir, "lib/node_modules/npm/bin/npm-cli.js").takeIf { it.exists() } - ?: File(env.nodeDir, "node_modules/npm/bin/npm-cli.js").takeIf { it.exists() } - ?: error("Can't find npm-cli.js in ${env.nodeDir} standard folders") + + //val nodeDir = env.nodeBinDir + val nodeDir = env.dir + val file1: File = File(env.nodeExecutable) + val file2: File? = File(nodeDir, "lib/node_modules/npm/bin/npm-cli.js").takeIf { it.exists() } + val file3: File? = File(nodeDir, "node_modules/npm/bin/npm-cli.js").takeIf { it.exists() } + val npmCmd = arrayOf( + file1, + file2 + ?: file2 + ?: error("Can't find npm-cli.js in ${nodeDir} standard folders") ) environment("PATH", ENV_PATH) @@ -108,7 +114,11 @@ fun Project.configureErrorableEsbuild() { dependsOn(compileExecutableKotlinJs) //println("compileExecutableKotlinJs:" + compileExecutableKotlinJs::class) - val jsPath = compileExecutableKotlinJs.outputFileProperty.get() + //val jsPath = compileExecutableKotlinJs.outputFileProperty.get() + //val jsPath = compileExecutableKotlinJs.destinationDirectory.asFile.get().absolutePath + "/" + compileExecutableKotlinJs.moduleName.get() + ".js" + // @TODO: Check this + val jsPath = compileExecutableKotlinJs.destinationDirectory.asFile.get().absolutePath + val output = File(wwwFolder, "${project.name}.js") //println("jsPath=$jsPath") //println("jsPath.parentFile=${jsPath.parentFile}") diff --git a/buildSrc/src/main/kotlin/korlibs/korge/gradle/targets/js/Wasm.kt b/buildSrc/src/main/kotlin/korlibs/korge/gradle/targets/js/Wasm.kt index 538e5b24fc..f9f7a58116 100644 --- a/buildSrc/src/main/kotlin/korlibs/korge/gradle/targets/js/Wasm.kt +++ b/buildSrc/src/main/kotlin/korlibs/korge/gradle/targets/js/Wasm.kt @@ -34,7 +34,7 @@ fun Project.configureWasm(projectType: ProjectType, binaryen: Boolean = false) { } open class WasmJsCreateIndexTask : DefaultTask() { - private val npmDir: File = project.kotlin.wasmJs().compilations["main"]!!.npmProject.dir + private val npmDir: File = project.kotlin.wasmJs().compilations["main"]!!.npmProject.dir.get().asFile @TaskAction fun run() { diff --git a/buildSrc/src/main/kotlin/korlibs/root/RootKorlibsPlugin.kt b/buildSrc/src/main/kotlin/korlibs/root/RootKorlibsPlugin.kt index e4d0efa565..df8856beb7 100644 --- a/buildSrc/src/main/kotlin/korlibs/root/RootKorlibsPlugin.kt +++ b/buildSrc/src/main/kotlin/korlibs/root/RootKorlibsPlugin.kt @@ -314,7 +314,7 @@ object RootKorlibsPlugin { wasmBrowserTest.doFirst { logger.info("!!!!! wasmBrowserTest PATCH :: $wasmBrowserTest : ${wasmBrowserTest::class.java}") - val npmProjectDir = wasmBrowserTest.compilation.npmProject.dir + val npmProjectDir: File = wasmBrowserTest.compilation.npmProject.dir.get().asFile val projectName = npmProjectDir.name val uninstantiatedMjs = File(npmProjectDir, "kotlin/$projectName.uninstantiated.mjs") diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f096f7afa8..fca76c144b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -15,7 +15,7 @@ jgit = "5.13.1.202206130422-r" #kotlin = "1.9.0" #kotlin = "1.9.10" -kotlin = "1.9.22" +kotlin = "2.0.0-Beta3" kotlinx-coroutines = "1.8.0-RC" kotlinx-serialization = "1.6.2" kotlinx-atomicfu = "0.23.1" diff --git a/korge-core/src/korlibs/io/dynamic/DynApi.kt b/korge-core/src/korlibs/io/dynamic/DynApi.kt index d7681d7a49..eecdcf32b8 100644 --- a/korge-core/src/korlibs/io/dynamic/DynApi.kt +++ b/korge-core/src/korlibs/io/dynamic/DynApi.kt @@ -20,4 +20,8 @@ val defaultDynApi: DynApi get() = DynamicInternal // @TODO: We should be able to plug-in a kotlinx-serialization version for this var dynApi: DynApi = DynamicInternal -internal expect object DynamicInternal : DynApi +internal expect object DynamicInternal : DynApi { + override fun get(instance: Any?, key: String): Any? + override fun set(instance: Any?, key: String, value: Any?) + override fun invoke(instance: Any?, key: String, args: Array): Any? +} diff --git a/korge-core/src/korlibs/wasm/WASMLib.kt b/korge-core/src/korlibs/wasm/WASMLib.kt index 800b4b410a..63530d1939 100644 --- a/korge-core/src/korlibs/wasm/WASMLib.kt +++ b/korge-core/src/korlibs/wasm/WASMLib.kt @@ -4,7 +4,10 @@ import korlibs.io.lang.* import korlibs.memory.* import kotlin.coroutines.* -expect open class WASMLib(content: ByteArray) : IWASMLib +expect open class WASMLib(content: ByteArray) : IWASMLib { + override val content: ByteArray + override fun close() +} interface IWASMLib : Closeable { val isAvailable: Boolean get() = true diff --git a/korge-core/src@jvmAndroid/korlibs/io/dynamic/DynApiJvm.kt b/korge-core/src@jvmAndroid/korlibs/io/dynamic/DynApiJvm.kt index 4df6e202ee..0e4d1136aa 100644 --- a/korge-core/src@jvmAndroid/korlibs/io/dynamic/DynApiJvm.kt +++ b/korge-core/src@jvmAndroid/korlibs/io/dynamic/DynApiJvm.kt @@ -42,9 +42,9 @@ internal actual object DynamicInternal : DynApi { } } - override fun get(instance: Any?, key: String): Any? = getBase(instance, key, doThrow = false) + actual override fun get(instance: Any?, key: String): Any? = getBase(instance, key, doThrow = false) - override fun set(instance: Any?, key: String, value: Any?) { + actual override fun set(instance: Any?, key: String, value: Any?) { if (instance == null) return val static = instance is Class<*> @@ -66,7 +66,7 @@ internal actual object DynamicInternal : DynApi { return getBase(instance, key, doThrow = true) } - override fun invoke(instance: Any?, key: String, args: Array): Any? { + actual override fun invoke(instance: Any?, key: String, args: Array): Any? { return invokeBase(instance, key, args, doThrow = false) } diff --git a/korlibs-datastructure/src/korlibs/datastructure/FastArrayList.kt b/korlibs-datastructure/src/korlibs/datastructure/FastArrayList.kt index 3365457169..9ed59a97a3 100644 --- a/korlibs-datastructure/src/korlibs/datastructure/FastArrayList.kt +++ b/korlibs-datastructure/src/korlibs/datastructure/FastArrayList.kt @@ -34,6 +34,9 @@ expect class FastArrayList : MutableListEx, RandomAccess { fun trimToSize() fun ensureCapacity(minCapacity: Int) + // From MutableListEx + override fun removeRange(fromIndex: Int, toIndex: Int) + // From List override val size: Int diff --git a/korlibs-datastructure/src@concurrent/korlibs/datastructure/NonJs.kt b/korlibs-datastructure/src@concurrent/korlibs/datastructure/NonJs.kt index 04ac53a9ec..a77ab52899 100644 --- a/korlibs-datastructure/src@concurrent/korlibs/datastructure/NonJs.kt +++ b/korlibs-datastructure/src@concurrent/korlibs/datastructure/NonJs.kt @@ -97,7 +97,7 @@ public actual open class FastArrayList internal constructor( return out } - override fun removeRange(fromIndex: Int, toIndex: Int) { + actual override fun removeRange(fromIndex: Int, toIndex: Int) { val count = toIndex - fromIndex if (count <= 0) return val array = this.array diff --git a/korlibs-datastructure/src@js/korlibs/datastructure/Js.kt b/korlibs-datastructure/src@js/korlibs/datastructure/Js.kt index ee93c97f67..10c93ee20e 100644 --- a/korlibs-datastructure/src@js/korlibs/datastructure/Js.kt +++ b/korlibs-datastructure/src@js/korlibs/datastructure/Js.kt @@ -192,7 +192,7 @@ public actual open class FastArrayList internal constructor(@PublishedApi int return false } - override fun removeRange(fromIndex: Int, toIndex: Int) { + actual override fun removeRange(fromIndex: Int, toIndex: Int) { jsArray.splice(fromIndex, toIndex - fromIndex) modCount++ } diff --git a/korlibs-datastructure/src@wasmJs/korlibs/datastructure/Wasm.kt b/korlibs-datastructure/src@wasmJs/korlibs/datastructure/Wasm.kt index 19390ccf71..a32debeec7 100644 --- a/korlibs-datastructure/src@wasmJs/korlibs/datastructure/Wasm.kt +++ b/korlibs-datastructure/src@wasmJs/korlibs/datastructure/Wasm.kt @@ -238,7 +238,7 @@ public actual open class FastArrayList internal constructor( return out } - override fun removeRange(fromIndex: Int, toIndex: Int) { + actual override fun removeRange(fromIndex: Int, toIndex: Int) { val count = toIndex - fromIndex if (count <= 0) return val array = this.array diff --git a/korlibs-logger/src/korlibs/logger/Logger.kt b/korlibs-logger/src/korlibs/logger/Logger.kt index 31db81bc0b..b72da5b29a 100644 --- a/korlibs-logger/src/korlibs/logger/Logger.kt +++ b/korlibs-logger/src/korlibs/logger/Logger.kt @@ -168,4 +168,6 @@ internal val miniEnvironmentVariablesUC: Map get() { return _miniEnvironmentVariablesUC!! } -expect object DefaultLogOutput : Logger.Output +expect object DefaultLogOutput : Logger.Output { + override fun output(logger: Logger, level: Logger.Level, msg: Any?) +} diff --git a/korlibs-logger/src@jvm/korlibs/logger/Logger.jvm.kt b/korlibs-logger/src@jvm/korlibs/logger/Logger.jvm.kt index 037f2c9f76..f38ea5fb1c 100644 --- a/korlibs-logger/src@jvm/korlibs/logger/Logger.jvm.kt +++ b/korlibs-logger/src@jvm/korlibs/logger/Logger.jvm.kt @@ -27,7 +27,7 @@ internal actual val miniEnvironmentVariables: Map by lazy { Syst actual object DefaultLogOutput : Logger.Output { private val DATE_FORMAT = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ") - override fun output(logger: Logger, level: Logger.Level, msg: Any?) { + actual override fun output(logger: Logger, level: Logger.Level, msg: Any?) { if (logger.nativeLogger == null) { logger.nativeLogger = java.util.logging.Logger.getLogger(logger.name).also { nativeLogger -> nativeLogger.useParentHandlers = true From 6c18fd4ac8d394463f183baf760e6e668730b388 Mon Sep 17 00:00:00 2001 From: soywiz Date: Sun, 28 Jan 2024 00:45:29 +0100 Subject: [PATCH 2/7] Some fixes --- korge-core/src/korlibs/io/lang/Charset.kt | 1 - korge-core/src@darwin/korlibs/io/dynamic/DynApiNative.kt | 6 +++--- korge-core/src@js/korlibs/io/dynamic/DynApiJs.kt | 8 ++++---- korge-core/src@wasmJs/korlibs/io/dynamic/DynApiJs.kt | 8 ++++---- korlibs-logger/src@darwin/korlibs/logger/Logger.darwin.kt | 2 +- korlibs-logger/src@js/korlibs/logger/Logger.js.kt | 2 +- korlibs-logger/src@linux/korlibs/logger/Logger.linux.kt | 2 +- korlibs-logger/src@mingw/korlibs/logger/Logger.mingw.kt | 2 +- korlibs-logger/src@wasmJs/korlibs/logger/Logger.wasm.kt | 2 +- 9 files changed, 16 insertions(+), 17 deletions(-) diff --git a/korge-core/src/korlibs/io/lang/Charset.kt b/korge-core/src/korlibs/io/lang/Charset.kt index 02b7b7c14a..b44de1b224 100644 --- a/korge-core/src/korlibs/io/lang/Charset.kt +++ b/korge-core/src/korlibs/io/lang/Charset.kt @@ -210,7 +210,6 @@ open class SingleByteCharset(name: String, val conv: String) : BaseSingleByteCha object ISO_8859_1 : SingleByteCharset("ISO-8859-1", buildString { for (n in 0 until 256) append(n.toChar()) }) -@SharedImmutable expect val UTF8: Charset class UTF16Charset(val le: Boolean) : Charset("UTF-16-" + (if (le) "LE" else "BE")) { diff --git a/korge-core/src@darwin/korlibs/io/dynamic/DynApiNative.kt b/korge-core/src@darwin/korlibs/io/dynamic/DynApiNative.kt index acef1dc469..4406abdeb4 100644 --- a/korge-core/src@darwin/korlibs/io/dynamic/DynApiNative.kt +++ b/korge-core/src@darwin/korlibs/io/dynamic/DynApiNative.kt @@ -1,7 +1,7 @@ package korlibs.io.dynamic internal actual object DynamicInternal : DynApi { - override fun get(instance: Any?, key: String): Any? = throw UnsupportedOperationException("DynamicInternal.get") - override fun set(instance: Any?, key: String, value: Any?): Unit = throw UnsupportedOperationException("DynamicInternal.set") - override fun invoke(instance: Any?, key: String, args: Array): Any? = throw UnsupportedOperationException("DynamicInternal.invoke") + actual override fun get(instance: Any?, key: String): Any? = throw UnsupportedOperationException("DynamicInternal.get") + actual override fun set(instance: Any?, key: String, value: Any?): Unit = throw UnsupportedOperationException("DynamicInternal.set") + actual override fun invoke(instance: Any?, key: String, args: Array): Any? = throw UnsupportedOperationException("DynamicInternal.invoke") } diff --git a/korge-core/src@js/korlibs/io/dynamic/DynApiJs.kt b/korge-core/src@js/korlibs/io/dynamic/DynApiJs.kt index cf13d2924c..129bfe83ce 100644 --- a/korge-core/src@js/korlibs/io/dynamic/DynApiJs.kt +++ b/korge-core/src@js/korlibs/io/dynamic/DynApiJs.kt @@ -3,10 +3,10 @@ package korlibs.io.dynamic import korlibs.io.jsGlobalDynamic internal actual object DynamicInternal : DynApi { - override val global: Any get() = jsGlobalDynamic + override val global: Any? get() = jsGlobalDynamic - override fun get(instance: Any?, key: String): Any? = (instance.asDynamic())[key] - override fun set(instance: Any?, key: String, value: Any?) { (instance.asDynamic())[key] = value } - override fun invoke(instance: Any?, key: String, args: Array): Any? = + actual override fun get(instance: Any?, key: String): Any? = (instance.asDynamic())[key] + actual override fun set(instance: Any?, key: String, value: Any?) { (instance.asDynamic())[key] = value } + actual override fun invoke(instance: Any?, key: String, args: Array): Any? = (instance.asDynamic())[key].apply(instance, args) } diff --git a/korge-core/src@wasmJs/korlibs/io/dynamic/DynApiJs.kt b/korge-core/src@wasmJs/korlibs/io/dynamic/DynApiJs.kt index 936532819c..a0e97c2aa7 100644 --- a/korge-core/src@wasmJs/korlibs/io/dynamic/DynApiJs.kt +++ b/korge-core/src@wasmJs/korlibs/io/dynamic/DynApiJs.kt @@ -13,16 +13,16 @@ private external fun JsAny_set(obj: JsAny, key: String, value: JsAny?) private external fun JsAny_invoke(obj: JsAny, key: String, args: JsArray) internal actual object DynamicInternal : DynApi { - override val global: Any get() = jsGlobal + override val global: Any? get() = jsGlobal - override fun get(instance: Any?, key: String): Any? { + actual override fun get(instance: Any?, key: String): Any? { if (instance == null) return null return JsAny_get((instance as JsAny), key) } - override fun set(instance: Any?, key: String, value: Any?) { + actual override fun set(instance: Any?, key: String, value: Any?) { if (instance == null) return return JsAny_set((instance as JsAny), key, value as? JsAny?) } - override fun invoke(instance: Any?, key: String, args: Array): Any? = + actual override fun invoke(instance: Any?, key: String, args: Array): Any? = JsAny_invoke(instance as JsAny, key, jsArrayOf(*args.map { it as? JsAny? }.toTypedArray())) } diff --git a/korlibs-logger/src@darwin/korlibs/logger/Logger.darwin.kt b/korlibs-logger/src@darwin/korlibs/logger/Logger.darwin.kt index 0971332feb..e397a726c8 100644 --- a/korlibs-logger/src@darwin/korlibs/logger/Logger.darwin.kt +++ b/korlibs-logger/src@darwin/korlibs/logger/Logger.darwin.kt @@ -15,7 +15,7 @@ actual object Console : BaseConsole() { } actual object DefaultLogOutput : Logger.Output { - override fun output(logger: Logger, level: Logger.Level, msg: Any?) = Logger.ConsoleLogOutput.output(logger, level, msg) + actual override fun output(logger: Logger, level: Logger.Level, msg: Any?) = Logger.ConsoleLogOutput.output(logger, level, msg) } internal actual val miniEnvironmentVariables: Map by lazy { diff --git a/korlibs-logger/src@js/korlibs/logger/Logger.js.kt b/korlibs-logger/src@js/korlibs/logger/Logger.js.kt index 9a6fca43a0..9e86e261ec 100644 --- a/korlibs-logger/src@js/korlibs/logger/Logger.js.kt +++ b/korlibs-logger/src@js/korlibs/logger/Logger.js.kt @@ -16,7 +16,7 @@ actual object Console : BaseConsole() { } actual object DefaultLogOutput : Logger.Output { - override fun output(logger: Logger, level: Logger.Level, msg: Any?) = Logger.ConsoleLogOutput.output(logger, level, msg) + actual override fun output(logger: Logger, level: Logger.Level, msg: Any?) = Logger.ConsoleLogOutput.output(logger, level, msg) } private external val process: dynamic diff --git a/korlibs-logger/src@linux/korlibs/logger/Logger.linux.kt b/korlibs-logger/src@linux/korlibs/logger/Logger.linux.kt index cc158e6a3e..2b5226f9ae 100644 --- a/korlibs-logger/src@linux/korlibs/logger/Logger.linux.kt +++ b/korlibs-logger/src@linux/korlibs/logger/Logger.linux.kt @@ -7,7 +7,7 @@ import kotlinx.cinterop.* actual object Console : BaseConsole() actual object DefaultLogOutput : Logger.Output { - override fun output(logger: Logger, level: Logger.Level, msg: Any?) = Logger.ConsoleLogOutput.output(logger, level, msg) + actual override fun output(logger: Logger, level: Logger.Level, msg: Any?) = Logger.ConsoleLogOutput.output(logger, level, msg) } internal actual val miniEnvironmentVariables: Map by lazy { diff --git a/korlibs-logger/src@mingw/korlibs/logger/Logger.mingw.kt b/korlibs-logger/src@mingw/korlibs/logger/Logger.mingw.kt index 302da51cb6..0c91b534bf 100644 --- a/korlibs-logger/src@mingw/korlibs/logger/Logger.mingw.kt +++ b/korlibs-logger/src@mingw/korlibs/logger/Logger.mingw.kt @@ -8,7 +8,7 @@ import platform.windows.* actual object Console : BaseConsole() actual object DefaultLogOutput : Logger.Output { - override fun output(logger: Logger, level: Logger.Level, msg: Any?) = Logger.ConsoleLogOutput.output(logger, level, msg) + actual override fun output(logger: Logger, level: Logger.Level, msg: Any?) = Logger.ConsoleLogOutput.output(logger, level, msg) } internal actual val miniEnvironmentVariables: Map by lazy { getEnvs() } diff --git a/korlibs-logger/src@wasmJs/korlibs/logger/Logger.wasm.kt b/korlibs-logger/src@wasmJs/korlibs/logger/Logger.wasm.kt index d0daa20ded..5fe2c1d5d7 100644 --- a/korlibs-logger/src@wasmJs/korlibs/logger/Logger.wasm.kt +++ b/korlibs-logger/src@wasmJs/korlibs/logger/Logger.wasm.kt @@ -27,7 +27,7 @@ actual object Console : BaseConsole() { } actual object DefaultLogOutput : Logger.Output { - override fun output(logger: Logger, level: Logger.Level, msg: Any?) = Logger.ConsoleLogOutput.output(logger, level, msg) + actual override fun output(logger: Logger, level: Logger.Level, msg: Any?) = Logger.ConsoleLogOutput.output(logger, level, msg) } internal actual val miniEnvironmentVariables: Map by lazy { From e0a3511c4496fdefa7a88f9913f8a15668e3381b Mon Sep 17 00:00:00 2001 From: soywiz Date: Sun, 28 Jan 2024 00:55:39 +0100 Subject: [PATCH 3/7] Fixes android --- korlibs-logger/src@android/korlibs/logger/Logger.android.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/korlibs-logger/src@android/korlibs/logger/Logger.android.kt b/korlibs-logger/src@android/korlibs/logger/Logger.android.kt index c973614b63..f97aa944e0 100644 --- a/korlibs-logger/src@android/korlibs/logger/Logger.android.kt +++ b/korlibs-logger/src@android/korlibs/logger/Logger.android.kt @@ -36,7 +36,7 @@ actual object Console : BaseConsole() { } actual object DefaultLogOutput : Logger.Output { - override fun output(logger: Logger, level: Logger.Level, msg: Any?) { + actual override fun output(logger: Logger, level: Logger.Level, msg: Any?) { if (level == Logger.Level.NONE) return Log.println(when (level) { Logger.Level.NONE -> Log.VERBOSE From 33a0387f561aa1bc23ab17d4581462a7a075829a Mon Sep 17 00:00:00 2001 From: soywiz Date: Tue, 13 Feb 2024 16:19:39 +0100 Subject: [PATCH 4/7] Beta4 --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index fca76c144b..41348a206b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -15,7 +15,7 @@ jgit = "5.13.1.202206130422-r" #kotlin = "1.9.0" #kotlin = "1.9.10" -kotlin = "2.0.0-Beta3" +kotlin = "2.0.0-Beta4" kotlinx-coroutines = "1.8.0-RC" kotlinx-serialization = "1.6.2" kotlinx-atomicfu = "0.23.1" From 1c590c23d27fee3aa74062fb678f920b71bf9f04 Mon Sep 17 00:00:00 2001 From: soywiz Date: Wed, 14 Feb 2024 06:39:10 +0100 Subject: [PATCH 5/7] Duplicate code to circumvent new version issue --- .../korlibs/datastructure/BaseCollections.kt | 18 ++++++++++++++---- .../datastructure/_Datastructure_sync.kt | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/korlibs-datastructure/src/korlibs/datastructure/BaseCollections.kt b/korlibs-datastructure/src/korlibs/datastructure/BaseCollections.kt index b66836f7f6..3cb19ad86e 100644 --- a/korlibs-datastructure/src/korlibs/datastructure/BaseCollections.kt +++ b/korlibs-datastructure/src/korlibs/datastructure/BaseCollections.kt @@ -14,7 +14,7 @@ interface BaseMap : Map { override fun containsValue(value: V): Boolean = values.contains(value) } -interface BaseMutableList : BaseList, MutableList { +abstract class BaseMutableList : BaseList(), MutableList { override fun iterator(): MutableIterator = listIterator(0) override fun listIterator(): MutableListIterator = listIterator(0) override fun listIterator(index: Int): MutableListIterator = BaseMutableListIterator(this, index) @@ -49,7 +49,7 @@ interface BaseMutableList : BaseList, MutableList { } } -interface BaseList : List { +abstract class BaseList : List { override fun containsAll(elements: Collection): Boolean { val elementsSet = elements.toSet() for (n in 0 until size) if (this[n] in elementsSet) return true @@ -71,7 +71,7 @@ interface BaseList : List { } } -open class BaseSubList(val list: List, start: Int, end: Int) : BaseList { +open class BaseSubList(val list: List, start: Int, end: Int) : BaseList() { var start: Int = start ; protected set var end: Int = end ; protected set override val size: Int get() = end - start @@ -83,7 +83,17 @@ open class BaseSubList(val list: List, start: Int, end: Int) : BaseList override fun get(index: Int): T = list[checkIndex(index)] } -open class BaseSubMutableList(val mlist: MutableList, start: Int, end: Int) : BaseSubList(mlist, start, end), BaseMutableList { +open class BaseSubMutableList(val mlist: MutableList, start: Int, end: Int) : BaseMutableList() { + var start: Int = start ; protected set + var end: Int = end ; protected set + override val size: Int get() = end - start + fun checkIndex(index: Int): Int { + if (index < 0 || index >= size) throw IndexOutOfBoundsException() + return start + index + } + + override fun get(index: Int): T = mlist[checkIndex(index)] + override fun add(index: Int, element: T) { mlist.add(checkIndex(index), element) end++ diff --git a/korlibs-datastructure/src/korlibs/datastructure/_Datastructure_sync.kt b/korlibs-datastructure/src/korlibs/datastructure/_Datastructure_sync.kt index 39591b462e..bdeb47d02a 100644 --- a/korlibs-datastructure/src/korlibs/datastructure/_Datastructure_sync.kt +++ b/korlibs-datastructure/src/korlibs/datastructure/_Datastructure_sync.kt @@ -25,7 +25,7 @@ open class SynchronizedCollection( open class SynchronizedList( protected val base: MutableList, protected val lock: NonRecursiveLock = NonRecursiveLock() -) : BaseMutableList { +) : BaseMutableList() { override fun clear() = lock { base.clear() } override fun add(index: Int, element: T) { lock { base.add(index, element) } } override fun addAll(index: Int, elements: Collection): Boolean = lock { base.addAll(index, elements) } From 896673168996599a077eac00c24cd27d73fbdc28 Mon Sep 17 00:00:00 2001 From: soywiz Date: Wed, 14 Feb 2024 06:51:14 +0100 Subject: [PATCH 6/7] From now on, this is invalid: MutableCollection, List by children So if MutableList shouldn't be implemented, this is a problem that will force to duplicated code. But for now, let's circumvent it. --- korge/src/korlibs/korge/view/Container.kt | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/korge/src/korlibs/korge/view/Container.kt b/korge/src/korlibs/korge/view/Container.kt index 0881f0783b..b86a420f09 100644 --- a/korge/src/korlibs/korge/view/Container.kt +++ b/korge/src/korlibs/korge/view/Container.kt @@ -38,7 +38,7 @@ open class Container( /** * A collection with all the children [View]s. */ - val children: ContainerCollection = ContainerCollection(this, __children) + val children: ContainerCollection = ContainerCollection(this) @PublishedApi override val _children: List? get() = __children @@ -415,6 +415,14 @@ open class Container( if (parent.hasAncestor(child)) invalidOp("Can't addChild to an ancestor") } + fun addChildrenAt(views: Collection, index: Int) { + // @TODO: Optimize this + var nindex = index + for (v in views) { + addChildAt(v, nindex++) + } + } + /** * Adds the [view] [View] as a child at a specific [index]. * @@ -495,13 +503,22 @@ open class Container( /** * Allows to safely interact with the children of a [container] instance. */ -class ContainerCollection internal constructor(val container: Container, children: List) : MutableCollection, List by children { +class ContainerCollection internal constructor(val container: Container) : BaseMutableList() { override val size: Int get() = container.numChildren + override fun get(index: Int): View = container.getChildAt(index) + override fun removeAt(index: Int): View = this[index].also { container.removeChildAt(index) } + override fun set(index: Int, element: View): View { + val old = this[index] + container.replaceChild(old, element) + return old + } override fun contains(element: View): Boolean = element.parent === container override fun containsAll(elements: Collection): Boolean = elements.all { it.parent === container } override fun isEmpty(): Boolean = container.numChildren == 0 + override fun addAll(index: Int, elements: Collection): Boolean = elements.isNotEmpty().also { container.addChildrenAt(elements, index) } + override fun add(index: Int, element: View) = container.addChildAt(element, index) override fun add(element: View): Boolean { container.addChild(element) return true From 73b92f932a21736e939669c5970e50c7dff4dbdf Mon Sep 17 00:00:00 2001 From: soywiz Date: Fri, 22 Mar 2024 16:10:50 +0100 Subject: [PATCH 7/7] Try Kotlin 2.0.0-Beta5 --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 41348a206b..7c027aeab8 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -15,7 +15,7 @@ jgit = "5.13.1.202206130422-r" #kotlin = "1.9.0" #kotlin = "1.9.10" -kotlin = "2.0.0-Beta4" +kotlin = "2.0.0-Beta5" kotlinx-coroutines = "1.8.0-RC" kotlinx-serialization = "1.6.2" kotlinx-atomicfu = "0.23.1"