Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename moduleId onto more sense "playground" #777

Merged
merged 1 commit into from
Oct 22, 2024
Merged
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
7 changes: 3 additions & 4 deletions common/src/main/kotlin/component/KotlinEnvironment.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package component

import com.intellij.openapi.util.Disposer
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.parseCommandLineArguments
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
Expand Down Expand Up @@ -88,20 +87,20 @@ class KotlinEnvironment(

private val configuration = createConfiguration()
val jsConfiguration: CompilerConfiguration = configuration.copy().apply {
put(CommonConfigurationKeys.MODULE_NAME, "moduleId")
put(CommonConfigurationKeys.MODULE_NAME, "playground")
put(JSConfigurationKeys.MODULE_KIND, ModuleKind.PLAIN)
put(JSConfigurationKeys.LIBRARIES, JS_LIBRARIES)
}

val wasmConfiguration: CompilerConfiguration = configuration.copy().apply {
put(CommonConfigurationKeys.MODULE_NAME, "moduleId")
put(CommonConfigurationKeys.MODULE_NAME, "playground")
put(JSConfigurationKeys.LIBRARIES, WASM_LIBRARIES)
put(WasmConfigurationKeys.WASM_ENABLE_ARRAY_RANGE_CHECKS, false)
put(WasmConfigurationKeys.WASM_ENABLE_ASSERTS, false)
}

val composeWasmConfiguration: CompilerConfiguration = configuration.copy().apply {
put(CommonConfigurationKeys.MODULE_NAME, "moduleId")
put(CommonConfigurationKeys.MODULE_NAME, "playground")
put(JSConfigurationKeys.LIBRARIES, COMPOSE_WASM_LIBRARIES)
put(WasmConfigurationKeys.WASM_ENABLE_ARRAY_RANGE_CHECKS, false)
put(WasmConfigurationKeys.WASM_ENABLE_ASSERTS, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class KotlinToJSTranslator(
private val kotlinEnvironment: KotlinEnvironment,
) {
companion object {
private const val JS_IR_CODE_BUFFER = "moduleId.output?.buffer_1;\n"
private const val JS_IR_CODE_BUFFER = "playground.output?.buffer_1;\n"

private val JS_IR_OUTPUT_REWRITE = """
if (typeof get_output !== "undefined") {
Expand Down Expand Up @@ -87,7 +87,7 @@ class KotlinToJSTranslator(

fun doTranslateWithIr(files: List<KtFile>, arguments: List<String>): CompilationResult<String> =
usingTempDirectory { inputDir ->
val moduleName = "moduleId"
val moduleName = "playground"
usingTempDirectory { outputDir ->
val ioFiles = files.writeToIoFiles(inputDir)
val k2JSCompiler = K2JSCompiler()
Expand Down Expand Up @@ -138,7 +138,7 @@ class KotlinToJSTranslator(
compilerPluginOptions: List<String>,
): CompilationResult<WasmTranslationSuccessfulOutput> =
usingTempDirectory { inputDir ->
val moduleName = "moduleId"
val moduleName = "playground"
usingTempDirectory { outputDir ->
val ioFiles = files.writeToIoFiles(inputDir)
val k2JSCompiler = K2JSCompiler()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,11 @@ class TestProjectRunner {
Assertions.assertNotNull(result, "Test result should no be a null")

val tmpDir = createTempDirectory()
val jsMain = tmpDir.resolve("moduleId.mjs")
val jsMain = tmpDir.resolve("playground.mjs")
jsMain.writeText(result.jsInstantiated)
val jsUninstantiated = tmpDir.resolve("moduleId.uninstantiated.mjs")
val jsUninstantiated = tmpDir.resolve("playground.uninstantiated.mjs")
jsUninstantiated.writeText(result.jsCode!!)
val wasmMain = tmpDir.resolve("moduleId.wasm")
val wasmMain = tmpDir.resolve("playground.wasm")
wasmMain.writeBytes(result.wasm)

val wat = result.wat
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"jsCode":"//region block: polyfills\n(function () {\n if (typeof globalThis === 'object')\n return;\n Object.defineProperty(Object.prototype, '__magic__', {get: function () {\n return this;\n }, configurable: true});\n __magic__.globalThis = __magic__;\n delete Object.prototype.__magic__;\n}());\n//endregion\n(function (factory) {\n if (typeof define === 'function' && define.amd)\n define(['exports'], factory);\n else if (typeof exports === 'object')\n factory(module.exports);\n else\n globalThis.moduleId = factory(typeof moduleId === 'undefined' ? {} : moduleId);\n}(function (_) {\n 'use strict';\n //region block: pre-declaration\n initMetadataForObject(Unit, 'Unit');\n //endregion\n function implement(interfaces) {\n var maxSize = 1;\n var masks = [];\n var inductionVariable = 0;\n var last = interfaces.length;\n while (inductionVariable < last) {\n var i = interfaces[inductionVariable];\n inductionVariable = inductionVariable + 1 | 0;\n var currentSize = maxSize;\n var tmp0_elvis_lhs = i.prototype.$imask$;\n var imask = tmp0_elvis_lhs == null ? i.$imask$ : tmp0_elvis_lhs;\n if (!(imask == null)) {\n masks.push(imask);\n currentSize = imask.length;\n }\n var iid = i.$metadata$.iid;\n var tmp;\n if (iid == null) {\n tmp = null;\n } else {\n // Inline function 'kotlin.let' call\n // Inline function 'kotlin.js.implement.<anonymous>' call\n tmp = bitMaskWith(iid);\n }\n var iidImask = tmp;\n if (!(iidImask == null)) {\n masks.push(iidImask);\n currentSize = Math.max(currentSize, iidImask.length);\n }\n if (currentSize > maxSize) {\n maxSize = currentSize;\n }\n }\n return compositeBitMask(maxSize, masks);\n }\n function bitMaskWith(activeBit) {\n var numberIndex = activeBit >> 5;\n var intArray = new Int32Array(numberIndex + 1 | 0);\n var positionInNumber = activeBit & 31;\n var numberWithSettledBit = 1 << positionInNumber;\n intArray[numberIndex] = intArray[numberIndex] | numberWithSettledBit;\n return intArray;\n }\n function compositeBitMask(capacity, masks) {\n var tmp = 0;\n var tmp_0 = new Int32Array(capacity);\n while (tmp < capacity) {\n var tmp_1 = tmp;\n var result = 0;\n var inductionVariable = 0;\n var last = masks.length;\n while (inductionVariable < last) {\n var mask = masks[inductionVariable];\n inductionVariable = inductionVariable + 1 | 0;\n if (tmp_1 < mask.length) {\n result = result | mask[tmp_1];\n }\n }\n tmp_0[tmp_1] = result;\n tmp = tmp + 1 | 0;\n }\n return tmp_0;\n }\n function defineProp(obj, name, getter, setter) {\n return Object.defineProperty(obj, name, {configurable: true, get: getter, set: setter});\n }\n function objectCreate(proto) {\n proto = proto === VOID ? null : proto;\n return Object.create(proto);\n }\n function equals(obj1, obj2) {\n if (obj1 == null) {\n return obj2 == null;\n }\n if (obj2 == null) {\n return false;\n }\n if (typeof obj1 === 'object' && typeof obj1.equals === 'function') {\n return obj1.equals(obj2);\n }\n if (obj1 !== obj1) {\n return obj2 !== obj2;\n }\n if (typeof obj1 === 'number' && typeof obj2 === 'number') {\n var tmp;\n if (obj1 === obj2) {\n var tmp_0;\n if (obj1 !== 0) {\n tmp_0 = true;\n } else {\n // Inline function 'kotlin.js.asDynamic' call\n var tmp_1 = 1 / obj1;\n // Inline function 'kotlin.js.asDynamic' call\n tmp_0 = tmp_1 === 1 / obj2;\n }\n tmp = tmp_0;\n } else {\n tmp = false;\n }\n return tmp;\n }\n return obj1 === obj2;\n }\n function protoOf(constructor) {\n return constructor.prototype;\n }\n function createMetadata(kind, name, defaultConstructor, associatedObjectKey, associatedObjects, suspendArity) {\n var undef = VOID;\n var iid = kind === 'interface' ? generateInterfaceId() : VOID;\n return {kind: kind, simpleName: name, associatedObjectKey: associatedObjectKey, associatedObjects: associatedObjects, suspendArity: suspendArity, $kClass$: undef, defaultConstructor: defaultConstructor, iid: iid};\n }\n function generateInterfaceId() {\n if (globalInterfaceId === VOID) {\n globalInterfaceId = 0;\n }\n // Inline function 'kotlin.js.unsafeCast' call\n globalInterfaceId = globalInterfaceId + 1 | 0;\n // Inline function 'kotlin.js.unsafeCast' call\n return globalInterfaceId;\n }\n var globalInterfaceId;\n function initMetadataFor(kind, ctor, name, defaultConstructor, parent, interfaces, suspendArity, associatedObjectKey, associatedObjects) {\n if (!(parent == null)) {\n ctor.prototype = Object.create(parent.prototype);\n ctor.prototype.constructor = ctor;\n }\n var metadata = createMetadata(kind, name, defaultConstructor, associatedObjectKey, associatedObjects, suspendArity);\n ctor.$metadata$ = metadata;\n if (!(interfaces == null)) {\n var receiver = !equals(metadata.iid, VOID) ? ctor : ctor.prototype;\n receiver.$imask$ = implement(interfaces);\n }\n }\n function initMetadataForObject(ctor, name, defaultConstructor, parent, interfaces, suspendArity, associatedObjectKey, associatedObjects) {\n var kind = 'object';\n initMetadataFor(kind, ctor, name, defaultConstructor, parent, interfaces, suspendArity, associatedObjectKey, associatedObjects);\n }\n function initMetadataForCompanion(ctor, parent, interfaces, suspendArity) {\n initMetadataForObject(ctor, 'Companion', VOID, parent, interfaces, suspendArity, VOID, VOID);\n }\n function get_VOID() {\n _init_properties_void_kt__3zg9as();\n return VOID;\n }\n var VOID;\n var properties_initialized_void_kt_e4ret2;\n function _init_properties_void_kt__3zg9as() {\n if (!properties_initialized_void_kt_e4ret2) {\n properties_initialized_void_kt_e4ret2 = true;\n VOID = void 0;\n }\n }\n function Unit() {\n }\n var Unit_instance;\n function Unit_getInstance() {\n return Unit_instance;\n }\n function main() {\n alert('alert from Kotlin!');\n }\n function mainWrapper() {\n main();\n }\n //region block: init\n Unit_instance = new Unit();\n //endregion\nif (typeof get_output !== \"undefined\") {\n get_output();\n output = new BufferedOutput();\n _.output = get_output();\n}\n mainWrapper();\n return _;\n}));\nmoduleId.output?.buffer_1;\n\n","exception":null,"errors":{"File.kt":[]},"text":""}
{"jsCode":"//region block: polyfills\n(function () {\n if (typeof globalThis === 'object')\n return;\n Object.defineProperty(Object.prototype, '__magic__', {get: function () {\n return this;\n }, configurable: true});\n __magic__.globalThis = __magic__;\n delete Object.prototype.__magic__;\n}());\n//endregion\n(function (factory) {\n if (typeof define === 'function' && define.amd)\n define(['exports'], factory);\n else if (typeof exports === 'object')\n factory(module.exports);\n else\n globalThis.playground = factory(typeof playground === 'undefined' ? {} : playground);\n}(function (_) {\n 'use strict';\n //region block: pre-declaration\n initMetadataForObject(Unit, 'Unit');\n //endregion\n function implement(interfaces) {\n var maxSize = 1;\n var masks = [];\n var inductionVariable = 0;\n var last = interfaces.length;\n while (inductionVariable < last) {\n var i = interfaces[inductionVariable];\n inductionVariable = inductionVariable + 1 | 0;\n var currentSize = maxSize;\n var tmp0_elvis_lhs = i.prototype.$imask$;\n var imask = tmp0_elvis_lhs == null ? i.$imask$ : tmp0_elvis_lhs;\n if (!(imask == null)) {\n masks.push(imask);\n currentSize = imask.length;\n }\n var iid = i.$metadata$.iid;\n var tmp;\n if (iid == null) {\n tmp = null;\n } else {\n // Inline function 'kotlin.let' call\n // Inline function 'kotlin.js.implement.<anonymous>' call\n tmp = bitMaskWith(iid);\n }\n var iidImask = tmp;\n if (!(iidImask == null)) {\n masks.push(iidImask);\n currentSize = Math.max(currentSize, iidImask.length);\n }\n if (currentSize > maxSize) {\n maxSize = currentSize;\n }\n }\n return compositeBitMask(maxSize, masks);\n }\n function bitMaskWith(activeBit) {\n var numberIndex = activeBit >> 5;\n var intArray = new Int32Array(numberIndex + 1 | 0);\n var positionInNumber = activeBit & 31;\n var numberWithSettledBit = 1 << positionInNumber;\n intArray[numberIndex] = intArray[numberIndex] | numberWithSettledBit;\n return intArray;\n }\n function compositeBitMask(capacity, masks) {\n var tmp = 0;\n var tmp_0 = new Int32Array(capacity);\n while (tmp < capacity) {\n var tmp_1 = tmp;\n var result = 0;\n var inductionVariable = 0;\n var last = masks.length;\n while (inductionVariable < last) {\n var mask = masks[inductionVariable];\n inductionVariable = inductionVariable + 1 | 0;\n if (tmp_1 < mask.length) {\n result = result | mask[tmp_1];\n }\n }\n tmp_0[tmp_1] = result;\n tmp = tmp + 1 | 0;\n }\n return tmp_0;\n }\n function defineProp(obj, name, getter, setter) {\n return Object.defineProperty(obj, name, {configurable: true, get: getter, set: setter});\n }\n function objectCreate(proto) {\n proto = proto === VOID ? null : proto;\n return Object.create(proto);\n }\n function equals(obj1, obj2) {\n if (obj1 == null) {\n return obj2 == null;\n }\n if (obj2 == null) {\n return false;\n }\n if (typeof obj1 === 'object' && typeof obj1.equals === 'function') {\n return obj1.equals(obj2);\n }\n if (obj1 !== obj1) {\n return obj2 !== obj2;\n }\n if (typeof obj1 === 'number' && typeof obj2 === 'number') {\n var tmp;\n if (obj1 === obj2) {\n var tmp_0;\n if (obj1 !== 0) {\n tmp_0 = true;\n } else {\n // Inline function 'kotlin.js.asDynamic' call\n var tmp_1 = 1 / obj1;\n // Inline function 'kotlin.js.asDynamic' call\n tmp_0 = tmp_1 === 1 / obj2;\n }\n tmp = tmp_0;\n } else {\n tmp = false;\n }\n return tmp;\n }\n return obj1 === obj2;\n }\n function protoOf(constructor) {\n return constructor.prototype;\n }\n function createMetadata(kind, name, defaultConstructor, associatedObjectKey, associatedObjects, suspendArity) {\n var undef = VOID;\n var iid = kind === 'interface' ? generateInterfaceId() : VOID;\n return {kind: kind, simpleName: name, associatedObjectKey: associatedObjectKey, associatedObjects: associatedObjects, suspendArity: suspendArity, $kClass$: undef, defaultConstructor: defaultConstructor, iid: iid};\n }\n function generateInterfaceId() {\n if (globalInterfaceId === VOID) {\n globalInterfaceId = 0;\n }\n // Inline function 'kotlin.js.unsafeCast' call\n globalInterfaceId = globalInterfaceId + 1 | 0;\n // Inline function 'kotlin.js.unsafeCast' call\n return globalInterfaceId;\n }\n var globalInterfaceId;\n function initMetadataFor(kind, ctor, name, defaultConstructor, parent, interfaces, suspendArity, associatedObjectKey, associatedObjects) {\n if (!(parent == null)) {\n ctor.prototype = Object.create(parent.prototype);\n ctor.prototype.constructor = ctor;\n }\n var metadata = createMetadata(kind, name, defaultConstructor, associatedObjectKey, associatedObjects, suspendArity);\n ctor.$metadata$ = metadata;\n if (!(interfaces == null)) {\n var receiver = !equals(metadata.iid, VOID) ? ctor : ctor.prototype;\n receiver.$imask$ = implement(interfaces);\n }\n }\n function initMetadataForObject(ctor, name, defaultConstructor, parent, interfaces, suspendArity, associatedObjectKey, associatedObjects) {\n var kind = 'object';\n initMetadataFor(kind, ctor, name, defaultConstructor, parent, interfaces, suspendArity, associatedObjectKey, associatedObjects);\n }\n function initMetadataForCompanion(ctor, parent, interfaces, suspendArity) {\n initMetadataForObject(ctor, 'Companion', VOID, parent, interfaces, suspendArity, VOID, VOID);\n }\n function get_VOID() {\n _init_properties_void_kt__3zg9as();\n return VOID;\n }\n var VOID;\n var properties_initialized_void_kt_e4ret2;\n function _init_properties_void_kt__3zg9as() {\n if (!properties_initialized_void_kt_e4ret2) {\n properties_initialized_void_kt_e4ret2 = true;\n VOID = void 0;\n }\n }\n function Unit() {\n }\n var Unit_instance;\n function Unit_getInstance() {\n return Unit_instance;\n }\n function main() {\n alert('alert from Kotlin!');\n }\n function mainWrapper() {\n main();\n }\n //region block: init\n Unit_instance = new Unit();\n //endregion\nif (typeof get_output !== \"undefined\") {\n get_output();\n output = new BufferedOutput();\n _.output = get_output();\n}\n mainWrapper();\n return _;\n}));\nplayground.output?.buffer_1;\n\n","exception":null,"errors":{"File.kt":[]},"text":""}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only change is renaming moduleId -> playground

Loading
Loading