diff --git a/.idea/artifacts/kotlin_stdlib_py_js_1_6_255_SNAPSHOT.xml b/.idea/artifacts/kotlin_stdlib_py_js_1_6_255_SNAPSHOT.xml
new file mode 100644
index 0000000000000..e5b30548d8f8a
--- /dev/null
+++ b/.idea/artifacts/kotlin_stdlib_py_js_1_6_255_SNAPSHOT.xml
@@ -0,0 +1,8 @@
+
+
+ $PROJECT_DIR$/libraries/stdlib/py/build/libs
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/artifacts/kotlin_stdlib_py_minimal_for_test_js_1_6_255_SNAPSHOT.xml b/.idea/artifacts/kotlin_stdlib_py_minimal_for_test_js_1_6_255_SNAPSHOT.xml
new file mode 100644
index 0000000000000..e3fa53cb1955b
--- /dev/null
+++ b/.idea/artifacts/kotlin_stdlib_py_minimal_for_test_js_1_6_255_SNAPSHOT.xml
@@ -0,0 +1,6 @@
+
+
+ $PROJECT_DIR$/libraries/stdlib/py-minimal-for-test/build/libs
+
+
+
\ No newline at end of file
diff --git a/libraries/stdlib/py-minimal-for-test/build.gradle.kts b/libraries/stdlib/py-minimal-for-test/build.gradle.kts
new file mode 100644
index 0000000000000..7a8435a005231
--- /dev/null
+++ b/libraries/stdlib/py-minimal-for-test/build.gradle.kts
@@ -0,0 +1,140 @@
+import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
+
+plugins {
+ kotlin("multiplatform")
+}
+
+kotlin {
+ js(IR) {
+ nodejs()
+ }
+}
+
+val commonMainSources by task {
+ dependsOn(":kotlin-stdlib-py:commonMainSources")
+ from {
+ val fullCommonMainSources = tasks.getByPath(":kotlin-stdlib-py:commonMainSources")
+ exclude(
+ listOf(
+ "libraries/stdlib/unsigned/src/kotlin/UByteArray.kt",
+ "libraries/stdlib/unsigned/src/kotlin/UIntArray.kt",
+ "libraries/stdlib/unsigned/src/kotlin/ULongArray.kt",
+ "libraries/stdlib/unsigned/src/kotlin/UMath.kt",
+ "libraries/stdlib/unsigned/src/kotlin/UNumbers.kt",
+ "libraries/stdlib/unsigned/src/kotlin/UShortArray.kt",
+ "libraries/stdlib/unsigned/src/kotlin/UStrings.kt",
+ "libraries/stdlib/common/src/generated/_Arrays.kt",
+ "libraries/stdlib/common/src/generated/_Collections.kt",
+ "libraries/stdlib/common/src/generated/_Comparisons.kt",
+ "libraries/stdlib/common/src/generated/_Maps.kt",
+ "libraries/stdlib/common/src/generated/_OneToManyTitlecaseMappings.kt",
+ "libraries/stdlib/common/src/generated/_Sequences.kt",
+ "libraries/stdlib/common/src/generated/_Sets.kt",
+ "libraries/stdlib/common/src/generated/_Strings.kt",
+ "libraries/stdlib/common/src/generated/_UArrays.kt",
+ "libraries/stdlib/common/src/generated/_URanges.kt",
+ "libraries/stdlib/common/src/generated/_UCollections.kt",
+ "libraries/stdlib/common/src/generated/_UComparisons.kt",
+ "libraries/stdlib/common/src/generated/_USequences.kt",
+ "libraries/stdlib/common/src/kotlin/SequencesH.kt",
+ "libraries/stdlib/common/src/kotlin/TextH.kt",
+ "libraries/stdlib/common/src/kotlin/UMath.kt",
+ "libraries/stdlib/common/src/kotlin/collections/**",
+ "libraries/stdlib/common/src/kotlin/ioH.kt",
+ "libraries/stdlib/src/kotlin/collections/**",
+ "libraries/stdlib/src/kotlin/properties/Delegates.kt",
+ "libraries/stdlib/src/kotlin/random/URandom.kt",
+ "libraries/stdlib/src/kotlin/text/**",
+ "libraries/stdlib/src/kotlin/time/**",
+ "libraries/stdlib/src/kotlin/util/KotlinVersion.kt",
+ "libraries/stdlib/src/kotlin/util/Tuples.kt"
+ )
+ )
+ fullCommonMainSources.outputs.files.singleFile
+ }
+
+ into("$buildDir/commonMainSources")
+}
+
+val jsMainSources by task {
+ dependsOn(":kotlin-stdlib-py:jsMainSources")
+
+ from {
+ val fullJsMainSources = tasks.getByPath(":kotlin-stdlib-py:jsMainSources")
+ exclude(
+ listOf(
+ "libraries/stdlib/js/src/org.w3c/**",
+ "libraries/stdlib/js/src/kotlin/char.kt",
+ "libraries/stdlib/js/src/kotlin/collections.kt",
+ "libraries/stdlib/js/src/kotlin/collections/**",
+ "libraries/stdlib/js/src/kotlin/time/**",
+ "libraries/stdlib/js/src/kotlin/console.kt",
+ "libraries/stdlib/js/src/kotlin/coreDeprecated.kt",
+ "libraries/stdlib/js/src/kotlin/date.kt",
+ "libraries/stdlib/js/src/kotlin/grouping.kt",
+ "libraries/stdlib/js/src/kotlin/json.kt",
+ "libraries/stdlib/js/src/kotlin/promise.kt",
+ "libraries/stdlib/js/src/kotlin/regexp.kt",
+ "libraries/stdlib/js/src/kotlin/sequence.kt",
+ "libraries/stdlib/js/src/kotlin/throwableExtensions.kt",
+ "libraries/stdlib/js/src/kotlin/text/**",
+ "libraries/stdlib/js/src/kotlin/reflect/KTypeHelpers.kt",
+ "libraries/stdlib/js/src/kotlin/reflect/KTypeParameterImpl.kt",
+ "libraries/stdlib/js/src/kotlin/reflect/KTypeImpl.kt",
+ "libraries/stdlib/js/src/kotlin/dom/**",
+ "libraries/stdlib/js/src/kotlin/browser/**",
+ "libraries/stdlib/js/src/kotlinx/dom/**",
+ "libraries/stdlib/js/src/kotlinx/browser/**"
+ )
+ )
+ fullJsMainSources.outputs.files.singleFile
+ }
+
+ for (jsIrSrcDir in listOf("builtins", "runtime", "src")) {
+ from("$rootDir/libraries/stdlib/py/$jsIrSrcDir") {
+ exclude(
+ listOf(
+ "collectionsHacks.kt",
+ "generated/**",
+ "kotlin/text/**"
+ )
+ )
+ into("libraries/stdlib/py/$jsIrSrcDir")
+ }
+ }
+
+ from("$rootDir/libraries/stdlib/py-minimal-for-test/src")
+ into("$buildDir/jsMainSources")
+}
+
+kotlin {
+ sourceSets {
+ val commonMain by getting {
+ kotlin.srcDir(files(commonMainSources.map { it.destinationDir }))
+ }
+ val jsMain by getting {
+ kotlin.srcDir(files(jsMainSources.map { it.destinationDir }))
+ }
+ }
+}
+
+tasks.withType> {
+ kotlinOptions.freeCompilerArgs += listOf(
+ "-Xallow-kotlin-package",
+ "-Xopt-in=kotlin.ExperimentalMultiplatform",
+ "-Xopt-in=kotlin.contracts.ExperimentalContracts",
+ "-Xopt-in=kotlin.RequiresOptIn",
+ "-Xopt-in=kotlin.ExperimentalUnsignedTypes",
+ "-Xopt-in=kotlin.ExperimentalStdlibApi"
+ )
+}
+
+tasks {
+ compileKotlinMetadata {
+ enabled = false
+ }
+
+ named("compileKotlinJs", KotlinCompile::class) {
+ kotlinOptions.freeCompilerArgs += "-Xir-module-name=kotlin"
+ }
+}
diff --git a/libraries/stdlib/py-minimal-for-test/src/smallRuntimeCollections.kt b/libraries/stdlib/py-minimal-for-test/src/smallRuntimeCollections.kt
new file mode 100644
index 0000000000000..0c8a43cac63f9
--- /dev/null
+++ b/libraries/stdlib/py-minimal-for-test/src/smallRuntimeCollections.kt
@@ -0,0 +1,12 @@
+/*
+ * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+package kotlin.collections
+
+@SinceKotlin("1.4")
+@library("arrayEquals")
+public infix fun Array?.contentEquals(other: Array?): Boolean {
+ definedExternally
+}
\ No newline at end of file
diff --git a/libraries/stdlib/py-minimal-for-test/src/smallRuntimeMissingDeclarations.kt b/libraries/stdlib/py-minimal-for-test/src/smallRuntimeMissingDeclarations.kt
new file mode 100644
index 0000000000000..dc796d2dc964c
--- /dev/null
+++ b/libraries/stdlib/py-minimal-for-test/src/smallRuntimeMissingDeclarations.kt
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+package kotlin
+
+/**
+ * Returns `true` if this char sequence is empty (contains no characters).
+ */
+@kotlin.internal.InlineOnly
+public inline fun CharSequence.isEmpty(): Boolean = length == 0
+
+/**
+ * Accumulates value starting with [initial] value and applying [operation] from left to right to current accumulator value and each element.
+ */
+public inline fun Array.fold(initial: R, operation: (acc: R, T) -> R): R {
+ var accumulator = initial
+ for (element in this) accumulator = operation(accumulator, element)
+ return accumulator
+}
+
+
+public actual fun Throwable.stackTraceToString(): String = toString()
+
+public actual fun Throwable.printStackTrace() {
+ TODO("Not implemented in reduced runtime")
+}
+
+public actual fun Throwable.addSuppressed(exception: Throwable) {
+ TODO("Not implemented in reduced runtime")
+}
+
+public actual val Throwable.suppressedExceptions: List
+ get() = TODO("Not implemented in reduced runtime")
+
+/**
+ * Returns a string representation of this [Long] value in the specified [radix].
+ *
+ * @throws IllegalArgumentException when [radix] is not a valid radix for number to string conversion.
+ */
+@SinceKotlin("1.2")
+public fun Long.toString(radix: Int): String =
+ this.toStringImpl(checkRadix(radix))
+
+/**
+ * Checks whether the given [radix] is valid radix for string to number and number to string conversion.
+ */
+internal fun checkRadix(radix: Int): Int {
+ if (radix !in 2..36) {
+ throw IllegalArgumentException("radix $radix was not in valid range 2..36")
+ }
+ return radix
+}
\ No newline at end of file
diff --git a/libraries/stdlib/py-minimal-for-test/src/tests.kt b/libraries/stdlib/py-minimal-for-test/src/tests.kt
new file mode 100644
index 0000000000000..b4845b65ba941
--- /dev/null
+++ b/libraries/stdlib/py-minimal-for-test/src/tests.kt
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+package kotlin.test
+
+// This file plugs some declaration from "kotlin.test" library used in tests.
+
+fun assertEquals(a: T, b: T) {
+ if (a != b) throw Exception("")
+}
+
+fun assertTrue(x: Boolean) {
+ if (!x) throw Exception("")
+}
+
+fun assertFalse(x: Boolean) {
+ if (x) throw Exception("")
+}
+
+fun assertNotNull(actual: T?, message: String? = null): T {
+ if (actual == null) throw Exception("")
+ return actual
+}
+
+
diff --git a/libraries/stdlib/py/build.gradle.kts b/libraries/stdlib/py/build.gradle.kts
new file mode 100644
index 0000000000000..9f42393baa87e
--- /dev/null
+++ b/libraries/stdlib/py/build.gradle.kts
@@ -0,0 +1,169 @@
+import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
+
+plugins {
+ kotlin("multiplatform")
+}
+
+kotlin {
+ js(IR) {
+ nodejs {
+ testTask {
+ useMocha {
+ timeout = "10s"
+ }
+ }
+ }
+ }
+}
+
+val unimplementedNativeBuiltIns =
+ (file("$rootDir/core/builtins/native/kotlin/").list().toSortedSet() - file("$rootDir/libraries/stdlib/py/builtins/").list())
+ .map { "core/builtins/native/kotlin/$it" }
+
+// Required to compile native builtins with the rest of runtime
+val builtInsHeader = """@file:Suppress(
+ "NON_ABSTRACT_FUNCTION_WITH_NO_BODY",
+ "MUST_BE_INITIALIZED_OR_BE_ABSTRACT",
+ "EXTERNAL_TYPE_EXTENDS_NON_EXTERNAL_TYPE",
+ "PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED",
+ "WRONG_MODIFIER_TARGET",
+ "UNUSED_PARAMETER"
+)
+"""
+
+val commonMainSources by task {
+ dependsOn(":prepare:build.version:writeStdlibVersion")
+
+ val sources = listOf(
+ "libraries/stdlib/common/src/",
+ "libraries/stdlib/src/kotlin/",
+ "libraries/stdlib/unsigned/"
+ )
+
+ sources.forEach { path ->
+ from("$rootDir/$path") {
+ into(path.dropLastWhile { it != '/' })
+ }
+ }
+
+ into("$buildDir/commonMainSources")
+}
+
+val jsMainSources by task {
+ val sources = listOf(
+ "core/builtins/src/kotlin/",
+ "libraries/stdlib/js/src/",
+ "libraries/stdlib/js/runtime/"
+ ) + unimplementedNativeBuiltIns
+
+ val excluded = listOf(
+ // stdlib/js/src/generated is used exclusively for current `js-v1` backend.
+ "libraries/stdlib/js/src/generated/**",
+
+ // JS-specific optimized version of emptyArray() already defined
+ "core/builtins/src/kotlin/ArrayIntrinsics.kt"
+ )
+
+ sources.forEach { path ->
+ from("$rootDir/$path") {
+ into(path.dropLastWhile { it != '/' })
+ excluded.filter { it.startsWith(path) }.forEach {
+ exclude(it.substring(path.length))
+ }
+ }
+ }
+
+ into("$buildDir/jsMainSources")
+
+ val unimplementedNativeBuiltIns = unimplementedNativeBuiltIns
+ val buildDir = buildDir
+ val builtInsHeader = builtInsHeader
+ doLast {
+ unimplementedNativeBuiltIns.forEach { path ->
+ val file = File("$buildDir/jsMainSources/$path")
+ val sourceCode = builtInsHeader + file.readText()
+ file.writeText(sourceCode)
+ }
+ }
+}
+
+val commonTestSources by task {
+ val sources = listOf(
+ "libraries/stdlib/test/",
+ "libraries/stdlib/common/test/"
+ )
+
+ sources.forEach { path ->
+ from("$rootDir/$path") {
+ into(path.dropLastWhile { it != '/' })
+ }
+ }
+
+ into("$buildDir/commonTestSources")
+}
+
+val jsTestSources by task {
+ from("$rootDir/libraries/stdlib/js/test/")
+ into("$buildDir/jsTestSources")
+}
+
+kotlin {
+ sourceSets {
+ val commonMain by getting {
+ kotlin.srcDir(files(commonMainSources.map { it.destinationDir }))
+ }
+ val jsMain by getting {
+ kotlin.srcDir(files(jsMainSources.map { it.destinationDir }))
+ kotlin.srcDir("builtins")
+ kotlin.srcDir("runtime")
+ kotlin.srcDir("src")
+ }
+ val commonTest by getting {
+ dependencies {
+ api(project(":kotlin-test:kotlin-test-js-ir"))
+ }
+ kotlin.srcDir(files(commonTestSources.map { it.destinationDir }))
+ }
+ val jsTest by getting {
+ dependencies {
+ api(project(":kotlin-test:kotlin-test-js-ir"))
+ }
+ kotlin.srcDir(files(jsTestSources.map { it.destinationDir }))
+ }
+ }
+}
+
+tasks.withType>().configureEach {
+ kotlinOptions.freeCompilerArgs += listOf(
+ "-Xallow-kotlin-package",
+ "-Xopt-in=kotlin.ExperimentalMultiplatform",
+ "-Xopt-in=kotlin.contracts.ExperimentalContracts",
+ "-Xopt-in=kotlin.RequiresOptIn",
+ "-Xopt-in=kotlin.ExperimentalUnsignedTypes",
+ "-Xopt-in=kotlin.ExperimentalStdlibApi"
+ )
+}
+
+val compileKotlinJs by tasks.existing(KotlinCompile::class) {
+ kotlinOptions.freeCompilerArgs += "-Xir-module-name=kotlin"
+
+ if (!kotlinBuildProperties.disableWerror) {
+ kotlinOptions.allWarningsAsErrors = true
+ }
+}
+
+val compileTestKotlinJs by tasks.existing(KotlinCompile::class) {
+ val sources: FileCollection = kotlin.sourceSets["commonTest"].kotlin
+ doFirst {
+ // Note: common test sources are copied to the actual source directory by commonMainSources task,
+ // so can't do this at configuration time:
+ kotlinOptions.freeCompilerArgs += "-Xcommon-sources=${sources.joinToString(",")}"
+ }
+}
+
+val packFullRuntimeKLib by tasks.registering(Jar::class) {
+ dependsOn(compileKotlinJs)
+ from(buildDir.resolve("classes/kotlin/js/main"))
+ destinationDirectory.set(rootProject.buildDir.resolve("js-ir-runtime"))
+ archiveFileName.set("full-runtime.klib")
+}
diff --git a/libraries/stdlib/py/builtins/Arrays.kt b/libraries/stdlib/py/builtins/Arrays.kt
new file mode 100644
index 0000000000000..4b8df504cfa25
--- /dev/null
+++ b/libraries/stdlib/py/builtins/Arrays.kt
@@ -0,0 +1,224 @@
+/*
+ * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+@file:Suppress(
+ "NON_ABSTRACT_FUNCTION_WITH_NO_BODY",
+ "MUST_BE_INITIALIZED_OR_BE_ABSTRACT",
+ "EXTERNAL_TYPE_EXTENDS_NON_EXTERNAL_TYPE",
+ "PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED",
+ "WRONG_MODIFIER_TARGET",
+ "UNUSED_PARAMETER"
+)
+
+package kotlin
+
+/**
+ * An array of bytes. When targeting the JVM, instances of this class are represented as `byte[]`.
+ * @constructor Creates a new array of the specified [size], with all elements initialized to zero.
+ */
+class ByteArray(size: Int) {
+ /**
+ * Creates a new array of the specified [size], where each element is calculated by calling the specified
+ * [init] function.
+ *
+ * The function [init] is called for each array element sequentially starting from the first one.
+ * It should return the value for an array element given its index.
+ */
+ inline constructor(size: Int, init: (Int) -> Byte)
+
+ /** Returns the array element at the given [index]. This method can be called using the index operator. */
+ operator fun get(index: Int): Byte
+ /** Sets the element at the given [index] to the given [value]. This method can be called using the index operator. */
+ operator fun set(index: Int, value: Byte): Unit
+
+ /** Returns the number of elements in the array. */
+ val size: Int
+
+ /** Creates an iterator over the elements of the array. */
+ operator fun iterator(): ByteIterator
+}
+
+/**
+ * An array of chars. When targeting the JVM, instances of this class are represented as `char[]`.
+ * @constructor Creates a new array of the specified [size], with all elements initialized to null char (`\u0000').
+ */
+class CharArray(size: Int) {
+ /**
+ * Creates a new array of the specified [size], where each element is calculated by calling the specified
+ * [init] function.
+ *
+ * The function [init] is called for each array element sequentially starting from the first one.
+ * It should return the value for an array element given its index.
+ */
+ inline constructor(size: Int, init: (Int) -> Char)
+
+ /** Returns the array element at the given [index]. This method can be called using the index operator. */
+ operator fun get(index: Int): Char
+ /** Sets the element at the given [index] to the given [value]. This method can be called using the index operator. */
+ operator fun set(index: Int, value: Char): Unit
+
+ /** Returns the number of elements in the array. */
+ val size: Int
+
+ /** Creates an iterator over the elements of the array. */
+ operator fun iterator(): CharIterator
+}
+
+/**
+ * An array of shorts. When targeting the JVM, instances of this class are represented as `short[]`.
+ * @constructor Creates a new array of the specified [size], with all elements initialized to zero.
+ */
+class ShortArray(size: Int) {
+ /**
+ * Creates a new array of the specified [size], where each element is calculated by calling the specified
+ * [init] function.
+ *
+ * The function [init] is called for each array element sequentially starting from the first one.
+ * It should return the value for an array element given its index.
+ */
+ inline constructor(size: Int, init: (Int) -> Short)
+
+ /** Returns the array element at the given [index]. This method can be called using the index operator. */
+ operator fun get(index: Int): Short
+ /** Sets the element at the given [index] to the given [value]. This method can be called using the index operator. */
+ operator fun set(index: Int, value: Short): Unit
+
+ /** Returns the number of elements in the array. */
+ val size: Int
+
+ /** Creates an iterator over the elements of the array. */
+ operator fun iterator(): ShortIterator
+}
+
+/**
+ * An array of ints. When targeting the JVM, instances of this class are represented as `int[]`.
+ * @constructor Creates a new array of the specified [size], with all elements initialized to zero.
+ */
+class IntArray(size: Int) {
+ /**
+ * Creates a new array of the specified [size], where each element is calculated by calling the specified
+ * [init] function.
+ *
+ * The function [init] is called for each array element sequentially starting from the first one.
+ * It should return the value for an array element given its index.
+ */
+ inline constructor(size: Int, init: (Int) -> Int)
+
+ /** Returns the array element at the given [index]. This method can be called using the index operator. */
+ operator fun get(index: Int): Int
+ /** Sets the element at the given [index] to the given [value]. This method can be called using the index operator. */
+ operator fun set(index: Int, value: Int): Unit
+
+ /** Returns the number of elements in the array. */
+ val size: Int
+
+ /** Creates an iterator over the elements of the array. */
+ operator fun iterator(): IntIterator
+}
+
+/**
+ * An array of longs. When targeting the JVM, instances of this class are represented as `long[]`.
+ * @constructor Creates a new array of the specified [size], with all elements initialized to zero.
+ */
+class LongArray(size: Int) {
+ /**
+ * Creates a new array of the specified [size], where each element is calculated by calling the specified
+ * [init] function.
+ *
+ * The function [init] is called for each array element sequentially starting from the first one.
+ * It should return the value for an array element given its index.
+ */
+ inline constructor(size: Int, init: (Int) -> Long)
+
+ /** Returns the array element at the given [index]. This method can be called using the index operator. */
+ operator fun get(index: Int): Long
+ /** Sets the element at the given [index] to the given [value]. This method can be called using the index operator. */
+ operator fun set(index: Int, value: Long): Unit
+
+ /** Returns the number of elements in the array. */
+ val size: Int
+
+ /** Creates an iterator over the elements of the array. */
+ operator fun iterator(): LongIterator
+}
+
+/**
+ * An array of floats. When targeting the JVM, instances of this class are represented as `float[]`.
+ * @constructor Creates a new array of the specified [size], with all elements initialized to zero.
+ */
+class FloatArray(size: Int) {
+ /**
+ * Creates a new array of the specified [size], where each element is calculated by calling the specified
+ * [init] function.
+ *
+ * The function [init] is called for each array element sequentially starting from the first one.
+ * It should return the value for an array element given its index.
+ */
+ inline constructor(size: Int, init: (Int) -> Float)
+
+ /** Returns the array element at the given [index]. This method can be called using the index operator. */
+ operator fun get(index: Int): Float
+ /** Sets the element at the given [index] to the given [value]. This method can be called using the index operator. */
+ operator fun set(index: Int, value: Float): Unit
+
+ /** Returns the number of elements in the array. */
+ val size: Int
+
+ /** Creates an iterator over the elements of the array. */
+ operator fun iterator(): FloatIterator
+}
+
+/**
+ * An array of doubles. When targeting the JVM, instances of this class are represented as `double[]`.
+ * @constructor Creates a new array of the specified [size], with all elements initialized to zero.
+ */
+class DoubleArray(size: Int) {
+ /**
+ * Creates a new array of the specified [size], where each element is calculated by calling the specified
+ * [init] function.
+ *
+ * The function [init] is called for each array element sequentially starting from the first one.
+ * It should return the value for an array element given its index.
+ */
+ inline constructor(size: Int, init: (Int) -> Double)
+
+ /** Returns the array element at the given [index]. This method can be called using the index operator. */
+ operator fun get(index: Int): Double
+ /** Sets the element at the given [index] to the given [value]. This method can be called using the index operator. */
+ operator fun set(index: Int, value: Double): Unit
+
+ /** Returns the number of elements in the array. */
+ val size: Int
+
+ /** Creates an iterator over the elements of the array. */
+ operator fun iterator(): DoubleIterator
+}
+
+/**
+ * An array of booleans. When targeting the JVM, instances of this class are represented as `boolean[]`.
+ * @constructor Creates a new array of the specified [size], with all elements initialized to `false`.
+ */
+class BooleanArray(size: Int) {
+ /**
+ * Creates a new array of the specified [size], where each element is calculated by calling the specified
+ * [init] function.
+ *
+ * The function [init] is called for each array element sequentially starting from the first one.
+ * It should return the value for an array element given its index.
+ */
+ inline constructor(size: Int, init: (Int) -> Boolean)
+
+ /** Returns the array element at the given [index]. This method can be called using the index operator. */
+ operator fun get(index: Int): Boolean
+ /** Sets the element at the given [index] to the given [value]. This method can be called using the index operator. */
+ operator fun set(index: Int, value: Boolean): Unit
+
+ /** Returns the number of elements in the array. */
+ val size: Int
+
+ /** Creates an iterator over the elements of the array. */
+ operator fun iterator(): BooleanIterator
+}
+
diff --git a/libraries/stdlib/py/builtins/Boolean.kt b/libraries/stdlib/py/builtins/Boolean.kt
new file mode 100644
index 0000000000000..2778cb74a7f39
--- /dev/null
+++ b/libraries/stdlib/py/builtins/Boolean.kt
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+@file:Suppress("NON_ABSTRACT_FUNCTION_WITH_NO_BODY", "UNUSED_PARAMETER")
+
+package kotlin
+
+/**
+ * Represents a value which is either `true` or `false`. On the JVM, non-nullable values of this type are
+ * represented as values of the primitive type `boolean`.
+ */
+class Boolean private constructor() : Comparable {
+ /**
+ * Returns the inverse of this boolean.
+ */
+ operator fun not(): Boolean
+
+ /**
+ * Performs a logical `and` operation between this Boolean and the [other] one. Unlike the `&&` operator,
+ * this function does not perform short-circuit evaluation. Both `this` and [other] will always be evaluated.
+ */
+ infix fun and(other: Boolean): Boolean
+
+ /**
+ * Performs a logical `or` operation between this Boolean and the [other] one. Unlike the `||` operator,
+ * this function does not perform short-circuit evaluation. Both `this` and [other] will always be evaluated.
+ */
+ infix fun or(other: Boolean): Boolean
+
+ /**
+ * Performs a logical `xor` operation between this Boolean and the [other] one.
+ */
+ infix fun xor(other: Boolean): Boolean
+
+ override fun compareTo(other: Boolean): Int
+
+
+ override fun equals(other: Any?): Boolean
+
+ override fun hashCode(): Int
+
+ override fun toString(): String
+
+ @SinceKotlin("1.3")
+ companion object
+}
diff --git a/libraries/stdlib/py/builtins/Char.kt b/libraries/stdlib/py/builtins/Char.kt
new file mode 100644
index 0000000000000..8a9602a40a4ba
--- /dev/null
+++ b/libraries/stdlib/py/builtins/Char.kt
@@ -0,0 +1,152 @@
+/*
+ * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+package kotlin
+
+/**
+ * Represents a 16-bit Unicode character.
+ * On the JVM, non-nullable values of this type are represented as values of the primitive type `char`.
+ */
+// TODO: KT-35100
+//public inline class Char internal constructor (val value: Int) : Comparable {
+class Char
+@SinceKotlin("1.5")
+@WasExperimental(ExperimentalStdlibApi::class)
+constructor(code: UShort) : Comparable {
+ private val value: Int = code.toInt()
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ override fun compareTo(other: Char): Int = value - other.value
+
+ /** Adds the other Int value to this value resulting a Char. */
+ operator fun plus(other: Int): Char = (value + other).toChar()
+
+ /** Subtracts the other Char value from this value resulting an Int. */
+ operator fun minus(other: Char): Int = value - other.value
+ /** Subtracts the other Int value from this value resulting a Char. */
+ operator fun minus(other: Int): Char = (value - other).toChar()
+
+ /**
+ * Returns this value incremented by one.
+ *
+ * @sample samples.misc.Builtins.inc
+ */
+ operator fun inc(): Char = (value + 1).toChar()
+
+ /**
+ * Returns this value decremented by one.
+ *
+ * @sample samples.misc.Builtins.dec
+ */
+ operator fun dec(): Char = (value - 1).toChar()
+
+ /** Creates a range from this value to the specified [other] value. */
+ operator fun rangeTo(other: Char): CharRange = CharRange(this, other)
+
+ /** Returns the value of this character as a `Byte`. */
+ @Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code.toByte()"))
+ @DeprecatedSinceKotlin(warningSince = "1.5")
+ fun toByte(): Byte = value.toByte()
+ /** Returns the value of this character as a `Char`. */
+ fun toChar(): Char = this
+ /** Returns the value of this character as a `Short`. */
+ @Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code.toShort()"))
+ @DeprecatedSinceKotlin(warningSince = "1.5")
+ fun toShort(): Short = value.toShort()
+ /** Returns the value of this character as a `Int`. */
+ @Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code"))
+ @DeprecatedSinceKotlin(warningSince = "1.5")
+ fun toInt(): Int = value
+ /** Returns the value of this character as a `Long`. */
+ @Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code.toLong()"))
+ @DeprecatedSinceKotlin(warningSince = "1.5")
+ fun toLong(): Long = value.toLong()
+ /** Returns the value of this character as a `Float`. */
+ @Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code.toFloat()"))
+ @DeprecatedSinceKotlin(warningSince = "1.5")
+ fun toFloat(): Float = value.toFloat()
+ /** Returns the value of this character as a `Double`. */
+ @Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code.toDouble()"))
+ @DeprecatedSinceKotlin(warningSince = "1.5")
+ fun toDouble(): Double = value.toDouble()
+
+ override fun equals(other: Any?): Boolean {
+ @Suppress("IMPLICIT_BOXING_IN_IDENTITY_EQUALS")
+ if (other === this) return true
+ if (other !is Char) return false
+
+ return this.value == other.value
+ }
+
+ override fun hashCode(): Int = value
+
+ // TODO implicit usages of toString and valueOf must be covered in DCE
+ @Suppress("JS_NAME_PROHIBITED_FOR_OVERRIDE")
+ @JsName("toString")
+ override fun toString(): String {
+ return js("String").fromCharCode(value).unsafeCast()
+ }
+
+ companion object {
+ /**
+ * The minimum value of a character code unit.
+ */
+ @SinceKotlin("1.3")
+ const val MIN_VALUE: Char = '\u0000'
+
+ /**
+ * The maximum value of a character code unit.
+ */
+ @SinceKotlin("1.3")
+ const val MAX_VALUE: Char = '\uFFFF'
+
+ /**
+ * The minimum value of a Unicode high-surrogate code unit.
+ */
+ const val MIN_HIGH_SURROGATE: Char = '\uD800'
+
+ /**
+ * The maximum value of a Unicode high-surrogate code unit.
+ */
+ const val MAX_HIGH_SURROGATE: Char = '\uDBFF'
+
+ /**
+ * The minimum value of a Unicode low-surrogate code unit.
+ */
+ const val MIN_LOW_SURROGATE: Char = '\uDC00'
+
+ /**
+ * The maximum value of a Unicode low-surrogate code unit.
+ */
+ const val MAX_LOW_SURROGATE: Char = '\uDFFF'
+
+ /**
+ * The minimum value of a Unicode surrogate code unit.
+ */
+ const val MIN_SURROGATE: Char = MIN_HIGH_SURROGATE
+
+ /**
+ * The maximum value of a Unicode surrogate code unit.
+ */
+ const val MAX_SURROGATE: Char = MAX_LOW_SURROGATE
+
+ /**
+ * The number of bytes used to represent a Char in a binary form.
+ */
+ @SinceKotlin("1.3")
+ const val SIZE_BYTES: Int = 2
+
+ /**
+ * The number of bits used to represent a Char in a binary form.
+ */
+ @SinceKotlin("1.3")
+ const val SIZE_BITS: Int = 16
+ }
+
+}
\ No newline at end of file
diff --git a/libraries/stdlib/py/builtins/Collections.kt b/libraries/stdlib/py/builtins/Collections.kt
new file mode 100644
index 0000000000000..afcb73205d4ec
--- /dev/null
+++ b/libraries/stdlib/py/builtins/Collections.kt
@@ -0,0 +1,435 @@
+/*
+ * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+@file:Suppress(
+ "NON_ABSTRACT_FUNCTION_WITH_NO_BODY",
+ "MUST_BE_INITIALIZED_OR_BE_ABSTRACT",
+ "EXTERNAL_TYPE_EXTENDS_NON_EXTERNAL_TYPE",
+ "PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED",
+ "WRONG_MODIFIER_TARGET"
+)
+/*
+ * Copyright 2010-2015 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package kotlin.collections
+
+/**
+ * Classes that inherit from this interface can be represented as a sequence of elements that can
+ * be iterated over.
+ * @param T the type of element being iterated over. The iterator is covariant in its element type.
+ */
+interface Iterable {
+ /**
+ * Returns an iterator over the elements of this object.
+ */
+ operator fun iterator(): Iterator
+}
+
+/**
+ * Classes that inherit from this interface can be represented as a sequence of elements that can
+ * be iterated over and that supports removing elements during iteration.
+ * @param T the type of element being iterated over. The mutable iterator is invariant in its element type.
+ */
+interface MutableIterable : Iterable {
+ /**
+ * Returns an iterator over the elements of this sequence that supports removing elements during iteration.
+ */
+ override fun iterator(): MutableIterator
+}
+
+/**
+ * A generic collection of elements. Methods in this interface support only read-only access to the collection;
+ * read/write access is supported through the [MutableCollection] interface.
+ * @param E the type of elements contained in the collection. The collection is covariant in its element type.
+ */
+interface Collection : Iterable {
+ // Query Operations
+ /**
+ * Returns the size of the collection.
+ */
+ val size: Int
+
+ /**
+ * Returns `true` if the collection is empty (contains no elements), `false` otherwise.
+ */
+ fun isEmpty(): Boolean
+
+ /**
+ * Checks if the specified element is contained in this collection.
+ */
+ operator fun contains(element: @UnsafeVariance E): Boolean
+
+ override fun iterator(): Iterator
+
+ // Bulk Operations
+ /**
+ * Checks if all elements in the specified collection are contained in this collection.
+ */
+ fun containsAll(elements: Collection<@UnsafeVariance E>): Boolean
+}
+
+/**
+ * A generic collection of elements that supports adding and removing elements.
+ *
+ * @param E the type of elements contained in the collection. The mutable collection is invariant in its element type.
+ */
+interface MutableCollection : Collection, MutableIterable {
+ // Query Operations
+ override fun iterator(): MutableIterator
+
+ // Modification Operations
+ /**
+ * Adds the specified element to the collection.
+ *
+ * @return `true` if the element has been added, `false` if the collection does not support duplicates
+ * and the element is already contained in the collection.
+ */
+ fun add(element: E): Boolean
+
+ /**
+ * Removes a single instance of the specified element from this
+ * collection, if it is present.
+ *
+ * @return `true` if the element has been successfully removed; `false` if it was not present in the collection.
+ */
+ fun remove(element: E): Boolean
+
+ // Bulk Modification Operations
+ /**
+ * Adds all of the elements of the specified collection to this collection.
+ *
+ * @return `true` if any of the specified elements was added to the collection, `false` if the collection was not modified.
+ */
+ fun addAll(elements: Collection): Boolean
+
+ /**
+ * Removes all of this collection's elements that are also contained in the specified collection.
+ *
+ * @return `true` if any of the specified elements was removed from the collection, `false` if the collection was not modified.
+ */
+ fun removeAll(elements: Collection): Boolean
+
+ /**
+ * Retains only the elements in this collection that are contained in the specified collection.
+ *
+ * @return `true` if any element was removed from the collection, `false` if the collection was not modified.
+ */
+ fun retainAll(elements: Collection): Boolean
+
+ /**
+ * Removes all elements from this collection.
+ */
+ fun clear(): Unit
+}
+
+/**
+ * A generic ordered collection of elements. Methods in this interface support only read-only access to the list;
+ * read/write access is supported through the [MutableList] interface.
+ * @param E the type of elements contained in the list. The list is covariant in its element type.
+ */
+interface List : Collection {
+ // Query Operations
+
+ override val size: Int
+ override fun isEmpty(): Boolean
+ override fun contains(element: @UnsafeVariance E): Boolean
+ override fun iterator(): Iterator
+
+ // Bulk Operations
+ override fun containsAll(elements: Collection<@UnsafeVariance E>): Boolean
+
+ // Positional Access Operations
+ /**
+ * Returns the element at the specified index in the list.
+ */
+ operator fun get(index: Int): E
+
+ // Search Operations
+ /**
+ * Returns the index of the first occurrence of the specified element in the list, or -1 if the specified
+ * element is not contained in the list.
+ */
+ fun indexOf(element: @UnsafeVariance E): Int
+
+ /**
+ * Returns the index of the last occurrence of the specified element in the list, or -1 if the specified
+ * element is not contained in the list.
+ */
+ fun lastIndexOf(element: @UnsafeVariance E): Int
+
+ // List Iterators
+ /**
+ * Returns a list iterator over the elements in this list (in proper sequence).
+ */
+ fun listIterator(): ListIterator
+
+ /**
+ * Returns a list iterator over the elements in this list (in proper sequence), starting at the specified [index].
+ */
+ fun listIterator(index: Int): ListIterator
+
+ // View
+ /**
+ * Returns a view of the portion of this list between the specified [fromIndex] (inclusive) and [toIndex] (exclusive).
+ * The returned list is backed by this list, so non-structural changes in the returned list are reflected in this list, and vice-versa.
+ *
+ * Structural changes in the base list make the behavior of the view undefined.
+ */
+ fun subList(fromIndex: Int, toIndex: Int): List
+}
+
+/**
+ * A generic ordered collection of elements that supports adding and removing elements.
+ * @param E the type of elements contained in the list. The mutable list is invariant in its element type.
+ */
+interface MutableList : List, MutableCollection {
+ // Modification Operations
+ /**
+ * Adds the specified element to the end of this list.
+ *
+ * @return `true` because the list is always modified as the result of this operation.
+ */
+ override fun add(element: E): Boolean
+
+ override fun remove(element: E): Boolean
+
+ // Bulk Modification Operations
+ /**
+ * Adds all of the elements of the specified collection to the end of this list.
+ *
+ * The elements are appended in the order they appear in the [elements] collection.
+ *
+ * @return `true` if the list was changed as the result of the operation.
+ */
+ override fun addAll(elements: Collection): Boolean
+
+ /**
+ * Inserts all of the elements of the specified collection [elements] into this list at the specified [index].
+ *
+ * @return `true` if the list was changed as the result of the operation.
+ */
+ fun addAll(index: Int, elements: Collection): Boolean
+
+ override fun removeAll(elements: Collection): Boolean
+ override fun retainAll(elements: Collection): Boolean
+ override fun clear(): Unit
+
+ // Positional Access Operations
+ /**
+ * Replaces the element at the specified position in this list with the specified element.
+ *
+ * @return the element previously at the specified position.
+ */
+ operator fun set(index: Int, element: E): E
+
+ /**
+ * Inserts an element into the list at the specified [index].
+ */
+ fun add(index: Int, element: E): Unit
+
+ /**
+ * Removes an element at the specified [index] from the list.
+ *
+ * @return the element that has been removed.
+ */
+ fun removeAt(index: Int): E
+
+ // List Iterators
+ override fun listIterator(): MutableListIterator
+
+ override fun listIterator(index: Int): MutableListIterator
+
+ // View
+ override fun subList(fromIndex: Int, toIndex: Int): MutableList
+}
+
+/**
+ * A generic unordered collection of elements that does not support duplicate elements.
+ * Methods in this interface support only read-only access to the set;
+ * read/write access is supported through the [MutableSet] interface.
+ * @param E the type of elements contained in the set. The set is covariant in its element type.
+ */
+interface Set : Collection {
+ // Query Operations
+
+ override val size: Int
+ override fun isEmpty(): Boolean
+ override fun contains(element: @UnsafeVariance E): Boolean
+ override fun iterator(): Iterator
+
+ // Bulk Operations
+ override fun containsAll(elements: Collection<@UnsafeVariance E>): Boolean
+}
+
+/**
+ * A generic unordered collection of elements that does not support duplicate elements, and supports
+ * adding and removing elements.
+ * @param E the type of elements contained in the set. The mutable set is invariant in its element type.
+ */
+interface MutableSet : Set, MutableCollection {
+ // Query Operations
+ override fun iterator(): MutableIterator
+
+ // Modification Operations
+
+ /**
+ * Adds the specified element to the set.
+ *
+ * @return `true` if the element has been added, `false` if the element is already contained in the set.
+ */
+ override fun add(element: E): Boolean
+
+ override fun remove(element: E): Boolean
+
+ // Bulk Modification Operations
+
+ override fun addAll(elements: Collection): Boolean
+ override fun removeAll(elements: Collection): Boolean
+ override fun retainAll(elements: Collection): Boolean
+ override fun clear(): Unit
+}
+
+/**
+ * A collection that holds pairs of objects (keys and values) and supports efficiently retrieving
+ * the value corresponding to each key. Map keys are unique; the map holds only one value for each key.
+ * Methods in this interface support only read-only access to the map; read-write access is supported through
+ * the [MutableMap] interface.
+ * @param K the type of map keys. The map is invariant in its key type, as it
+ * can accept key as a parameter (of [containsKey] for example) and return it in [keys] set.
+ * @param V the type of map values. The map is covariant in its value type.
+ */
+interface Map {
+ // Query Operations
+ /**
+ * Returns the number of key/value pairs in the map.
+ */
+ val size: Int
+
+ /**
+ * Returns `true` if the map is empty (contains no elements), `false` otherwise.
+ */
+ fun isEmpty(): Boolean
+
+ /**
+ * Returns `true` if the map contains the specified [key].
+ */
+ fun containsKey(key: K): Boolean
+
+ /**
+ * Returns `true` if the map maps one or more keys to the specified [value].
+ */
+ fun containsValue(value: @UnsafeVariance V): Boolean
+
+ /**
+ * Returns the value corresponding to the given [key], or `null` if such a key is not present in the map.
+ */
+ operator fun get(key: K): V?
+
+ // Views
+ /**
+ * Returns a read-only [Set] of all keys in this map.
+ */
+ val keys: Set
+
+ /**
+ * Returns a read-only [Collection] of all values in this map. Note that this collection may contain duplicate values.
+ */
+ val values: Collection
+
+ /**
+ * Returns a read-only [Set] of all key/value pairs in this map.
+ */
+ val entries: Set>
+
+ /**
+ * Represents a key/value pair held by a [Map].
+ */
+ interface Entry {
+ /**
+ * Returns the key of this key/value pair.
+ */
+ val key: K
+
+ /**
+ * Returns the value of this key/value pair.
+ */
+ val value: V
+ }
+}
+
+/**
+ * A modifiable collection that holds pairs of objects (keys and values) and supports efficiently retrieving
+ * the value corresponding to each key. Map keys are unique; the map holds only one value for each key.
+ * @param K the type of map keys. The map is invariant in its key type.
+ * @param V the type of map values. The mutable map is invariant in its value type.
+ */
+interface MutableMap : Map {
+ // Modification Operations
+ /**
+ * Associates the specified [value] with the specified [key] in the map.
+ *
+ * @return the previous value associated with the key, or `null` if the key was not present in the map.
+ */
+ fun put(key: K, value: V): V?
+
+ /**
+ * Removes the specified key and its corresponding value from this map.
+ *
+ * @return the previous value associated with the key, or `null` if the key was not present in the map.
+ */
+ fun remove(key: K): V?
+
+ // Bulk Modification Operations
+ /**
+ * Updates this map with key/value pairs from the specified map [from].
+ */
+ fun putAll(from: Map): Unit
+
+ /**
+ * Removes all elements from this map.
+ */
+ fun clear(): Unit
+
+ // Views
+ /**
+ * Returns a [MutableSet] of all keys in this map.
+ */
+ override val keys: MutableSet
+
+ /**
+ * Returns a [MutableCollection] of all values in this map. Note that this collection may contain duplicate values.
+ */
+ override val values: MutableCollection
+
+ /**
+ * Returns a [MutableSet] of all key/value pairs in this map.
+ */
+ override val entries: MutableSet>
+
+ /**
+ * Represents a key/value pair held by a [MutableMap].
+ */
+ interface MutableEntry : Map.Entry {
+ /**
+ * Changes the value associated with the key of this entry.
+ *
+ * @return the previous value corresponding to the key.
+ */
+ fun setValue(newValue: V): V
+ }
+}
diff --git a/libraries/stdlib/py/builtins/Enum.kt b/libraries/stdlib/py/builtins/Enum.kt
new file mode 100644
index 0000000000000..823df9fdfeac2
--- /dev/null
+++ b/libraries/stdlib/py/builtins/Enum.kt
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+package kotlin
+
+abstract class Enum>(val name: String, val ordinal: Int) : Comparable {
+
+ final override fun compareTo(other: E) = ordinal.compareTo(other.ordinal)
+
+ final override fun equals(other: Any?) = this === other
+
+ final override fun hashCode(): Int = identityHashCode(this)
+
+ override fun toString() = name
+
+ companion object
+}
\ No newline at end of file
diff --git a/libraries/stdlib/py/builtins/Library.kt b/libraries/stdlib/py/builtins/Library.kt
new file mode 100644
index 0000000000000..4bfa628a50576
--- /dev/null
+++ b/libraries/stdlib/py/builtins/Library.kt
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+@file:Suppress("NOTHING_TO_INLINE")
+
+package kotlin
+
+/**
+ * Returns a string representation of the object. Can be called with a null receiver, in which case
+ * it returns the string "null".
+ */
+fun Any?.toString(): String = this?.toString() ?: "null"
+
+
+/**
+ * Concatenates this string with the string representation of the given [other] object. If either the receiver
+ * or the [other] object are null, they are represented as the string "null".
+ */
+operator fun String?.plus(other: Any?): String =
+ (this?.toString() ?: "null").plus(other?.toString() ?: "null")
+
+/**
+ * Returns an array of objects of the given type with the given [size], initialized with null values.
+ */
+inline fun arrayOfNulls(size: Int): Array = fillArrayVal(Array(size), null)
+
+/**
+ * Returns an array containing the specified elements.
+ */
+inline fun arrayOf(vararg elements: T): Array = elements.unsafeCast>()
+
+/**
+ * Returns an array containing the specified [Double] numbers.
+ */
+inline fun doubleArrayOf(vararg elements: Double): DoubleArray = elements
+
+/**
+ * Returns an array containing the specified [Float] numbers.
+ */
+inline fun floatArrayOf(vararg elements: Float): FloatArray = elements
+
+/**
+ * Returns an array containing the specified [Long] numbers.
+ */
+inline fun longArrayOf(vararg elements: Long): LongArray = elements
+
+/**
+ * Returns an array containing the specified [Int] numbers.
+ */
+inline fun intArrayOf(vararg elements: Int): IntArray = elements
+
+/**
+ * Returns an array containing the specified characters.
+ */
+inline fun charArrayOf(vararg elements: Char): CharArray = elements
+
+/**
+ * Returns an array containing the specified [Short] numbers.
+ */
+inline fun shortArrayOf(vararg elements: Short): ShortArray = elements
+
+/**
+ * Returns an array containing the specified [Byte] numbers.
+ */
+inline fun byteArrayOf(vararg elements: Byte): ByteArray = elements
+
+/**
+ * Returns an array containing the specified boolean values.
+ */
+inline fun booleanArrayOf(vararg elements: Boolean): BooleanArray = elements
+
+// Use non-inline calls to enumValuesIntrinsic and enumValueOfIntrinsic calls in order
+// for compiler to replace them with method calls of concrete enum classes after inlining.
+// TODO: Figure out better solution (Inline hacks? Dynamic calls to stable mangled names?)
+
+/**
+ * Returns an array containing enum T entries.
+ */
+@SinceKotlin("1.1")
+inline fun > enumValues(): Array = enumValuesIntrinsic()
+
+/**
+ * Returns an enum entry with specified name.
+ */
+@SinceKotlin("1.1")
+inline fun > enumValueOf(name: String): T = enumValueOfIntrinsic(name)
\ No newline at end of file
diff --git a/libraries/stdlib/py/builtins/Primitives.kt b/libraries/stdlib/py/builtins/Primitives.kt
new file mode 100644
index 0000000000000..7ef495bbd2340
--- /dev/null
+++ b/libraries/stdlib/py/builtins/Primitives.kt
@@ -0,0 +1,1310 @@
+/*
+ * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+// Auto-generated file. DO NOT EDIT!
+@file:Suppress("NON_ABSTRACT_FUNCTION_WITH_NO_BODY", "UNUSED_PARAMETER")
+
+package kotlin
+
+/**
+ * Represents a 8-bit signed integer.
+ * On the JVM, non-nullable values of this type are represented as values of the primitive type `byte`.
+ */
+class Byte private constructor() : Number(), Comparable {
+ companion object {
+ /**
+ * A constant holding the minimum value an instance of Byte can have.
+ */
+ const val MIN_VALUE: Byte = -128
+
+ /**
+ * A constant holding the maximum value an instance of Byte can have.
+ */
+ const val MAX_VALUE: Byte = 127
+
+ /**
+ * The number of bytes used to represent an instance of Byte in a binary form.
+ */
+ @SinceKotlin("1.3")
+ const val SIZE_BYTES: Int = 1
+
+ /**
+ * The number of bits used to represent an instance of Byte in a binary form.
+ */
+ @SinceKotlin("1.3")
+ const val SIZE_BITS: Int = 8
+ }
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ override operator fun compareTo(other: Byte): Int
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ operator fun compareTo(other: Short): Int
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ operator fun compareTo(other: Int): Int
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ operator fun compareTo(other: Long): Int
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ operator fun compareTo(other: Float): Int
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ operator fun compareTo(other: Double): Int
+
+ /** Adds the other value to this value. */
+ operator fun plus(other: Byte): Int
+ /** Adds the other value to this value. */
+ operator fun plus(other: Short): Int
+ /** Adds the other value to this value. */
+ operator fun plus(other: Int): Int
+ /** Adds the other value to this value. */
+ operator fun plus(other: Long): Long
+ /** Adds the other value to this value. */
+ operator fun plus(other: Float): Float
+ /** Adds the other value to this value. */
+ operator fun plus(other: Double): Double
+
+ /** Subtracts the other value from this value. */
+ operator fun minus(other: Byte): Int
+ /** Subtracts the other value from this value. */
+ operator fun minus(other: Short): Int
+ /** Subtracts the other value from this value. */
+ operator fun minus(other: Int): Int
+ /** Subtracts the other value from this value. */
+ operator fun minus(other: Long): Long
+ /** Subtracts the other value from this value. */
+ operator fun minus(other: Float): Float
+ /** Subtracts the other value from this value. */
+ operator fun minus(other: Double): Double
+
+ /** Multiplies this value by the other value. */
+ operator fun times(other: Byte): Int
+ /** Multiplies this value by the other value. */
+ operator fun times(other: Short): Int
+ /** Multiplies this value by the other value. */
+ operator fun times(other: Int): Int
+ /** Multiplies this value by the other value. */
+ operator fun times(other: Long): Long
+ /** Multiplies this value by the other value. */
+ operator fun times(other: Float): Float
+ /** Multiplies this value by the other value. */
+ operator fun times(other: Double): Double
+
+ /** Divides this value by the other value, truncating the result to an integer that is closer to zero. */
+ operator fun div(other: Byte): Int
+ /** Divides this value by the other value, truncating the result to an integer that is closer to zero. */
+ operator fun div(other: Short): Int
+ /** Divides this value by the other value, truncating the result to an integer that is closer to zero. */
+ operator fun div(other: Int): Int
+ /** Divides this value by the other value, truncating the result to an integer that is closer to zero. */
+ operator fun div(other: Long): Long
+ /** Divides this value by the other value. */
+ operator fun div(other: Float): Float
+ /** Divides this value by the other value. */
+ operator fun div(other: Double): Double
+
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ operator fun rem(other: Byte): Int
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ operator fun rem(other: Short): Int
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ operator fun rem(other: Int): Int
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ operator fun rem(other: Long): Long
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ operator fun rem(other: Float): Float
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ operator fun rem(other: Double): Double
+
+ /**
+ * Returns this value incremented by one.
+ *
+ * @sample samples.misc.Builtins.inc
+ */
+ operator fun inc(): Byte
+
+ /**
+ * Returns this value decremented by one.
+ *
+ * @sample samples.misc.Builtins.dec
+ */
+ operator fun dec(): Byte
+
+ /** Returns this value. */
+ operator fun unaryPlus(): Int
+ /** Returns the negative of this value. */
+ operator fun unaryMinus(): Int
+
+ /** Creates a range from this value to the specified [other] value. */
+ operator fun rangeTo(other: Byte): IntRange
+ /** Creates a range from this value to the specified [other] value. */
+ operator fun rangeTo(other: Short): IntRange
+ /** Creates a range from this value to the specified [other] value. */
+ operator fun rangeTo(other: Int): IntRange
+ /** Creates a range from this value to the specified [other] value. */
+ operator fun rangeTo(other: Long): LongRange
+
+ /** Returns this value. */
+ override fun toByte(): Byte
+ /**
+ * Converts this [Byte] value to [Char].
+ *
+ * If this value is non-negative, the resulting `Char` code is equal to this value.
+ *
+ * The least significant 8 bits of the resulting `Char` code are the same as the bits of this `Byte` value,
+ * whereas the most significant 8 bits are filled with the sign bit of this value.
+ */
+ @Deprecated("Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", ReplaceWith("this.toInt().toChar()"))
+ @DeprecatedSinceKotlin(warningSince = "1.5")
+ override fun toChar(): Char
+ /**
+ * Converts this [Byte] value to [Short].
+ *
+ * The resulting `Short` value represents the same numerical value as this `Byte`.
+ *
+ * The least significant 8 bits of the resulting `Short` value are the same as the bits of this `Byte` value,
+ * whereas the most significant 8 bits are filled with the sign bit of this value.
+ */
+ override fun toShort(): Short
+ /**
+ * Converts this [Byte] value to [Int].
+ *
+ * The resulting `Int` value represents the same numerical value as this `Byte`.
+ *
+ * The least significant 8 bits of the resulting `Int` value are the same as the bits of this `Byte` value,
+ * whereas the most significant 24 bits are filled with the sign bit of this value.
+ */
+ override fun toInt(): Int
+ /**
+ * Converts this [Byte] value to [Long].
+ *
+ * The resulting `Long` value represents the same numerical value as this `Byte`.
+ *
+ * The least significant 8 bits of the resulting `Long` value are the same as the bits of this `Byte` value,
+ * whereas the most significant 56 bits are filled with the sign bit of this value.
+ */
+ override fun toLong(): Long
+ /**
+ * Converts this [Byte] value to [Float].
+ *
+ * The resulting `Float` value represents the same numerical value as this `Byte`.
+ */
+ override fun toFloat(): Float
+ /**
+ * Converts this [Byte] value to [Double].
+ *
+ * The resulting `Double` value represents the same numerical value as this `Byte`.
+ */
+ override fun toDouble(): Double
+
+ override fun equals(other: Any?): Boolean
+ override fun hashCode(): Int
+ override fun toString(): String
+}
+
+/**
+ * Represents a 16-bit signed integer.
+ * On the JVM, non-nullable values of this type are represented as values of the primitive type `short`.
+ */
+class Short private constructor() : Number(), Comparable {
+ companion object {
+ /**
+ * A constant holding the minimum value an instance of Short can have.
+ */
+ const val MIN_VALUE: Short = -32768
+
+ /**
+ * A constant holding the maximum value an instance of Short can have.
+ */
+ const val MAX_VALUE: Short = 32767
+
+ /**
+ * The number of bytes used to represent an instance of Short in a binary form.
+ */
+ @SinceKotlin("1.3")
+ const val SIZE_BYTES: Int = 2
+
+ /**
+ * The number of bits used to represent an instance of Short in a binary form.
+ */
+ @SinceKotlin("1.3")
+ const val SIZE_BITS: Int = 16
+ }
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ operator fun compareTo(other: Byte): Int
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ override operator fun compareTo(other: Short): Int
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ operator fun compareTo(other: Int): Int
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ operator fun compareTo(other: Long): Int
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ operator fun compareTo(other: Float): Int
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ operator fun compareTo(other: Double): Int
+
+ /** Adds the other value to this value. */
+ operator fun plus(other: Byte): Int
+ /** Adds the other value to this value. */
+ operator fun plus(other: Short): Int
+ /** Adds the other value to this value. */
+ operator fun plus(other: Int): Int
+ /** Adds the other value to this value. */
+ operator fun plus(other: Long): Long
+ /** Adds the other value to this value. */
+ operator fun plus(other: Float): Float
+ /** Adds the other value to this value. */
+ operator fun plus(other: Double): Double
+
+ /** Subtracts the other value from this value. */
+ operator fun minus(other: Byte): Int
+ /** Subtracts the other value from this value. */
+ operator fun minus(other: Short): Int
+ /** Subtracts the other value from this value. */
+ operator fun minus(other: Int): Int
+ /** Subtracts the other value from this value. */
+ operator fun minus(other: Long): Long
+ /** Subtracts the other value from this value. */
+ operator fun minus(other: Float): Float
+ /** Subtracts the other value from this value. */
+ operator fun minus(other: Double): Double
+
+ /** Multiplies this value by the other value. */
+ operator fun times(other: Byte): Int
+ /** Multiplies this value by the other value. */
+ operator fun times(other: Short): Int
+ /** Multiplies this value by the other value. */
+ operator fun times(other: Int): Int
+ /** Multiplies this value by the other value. */
+ operator fun times(other: Long): Long
+ /** Multiplies this value by the other value. */
+ operator fun times(other: Float): Float
+ /** Multiplies this value by the other value. */
+ operator fun times(other: Double): Double
+
+ /** Divides this value by the other value, truncating the result to an integer that is closer to zero. */
+ operator fun div(other: Byte): Int
+ /** Divides this value by the other value, truncating the result to an integer that is closer to zero. */
+ operator fun div(other: Short): Int
+ /** Divides this value by the other value, truncating the result to an integer that is closer to zero. */
+ operator fun div(other: Int): Int
+ /** Divides this value by the other value, truncating the result to an integer that is closer to zero. */
+ operator fun div(other: Long): Long
+ /** Divides this value by the other value. */
+ operator fun div(other: Float): Float
+ /** Divides this value by the other value. */
+ operator fun div(other: Double): Double
+
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ operator fun rem(other: Byte): Int
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ operator fun rem(other: Short): Int
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ operator fun rem(other: Int): Int
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ operator fun rem(other: Long): Long
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ operator fun rem(other: Float): Float
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ operator fun rem(other: Double): Double
+
+ /**
+ * Returns this value incremented by one.
+ *
+ * @sample samples.misc.Builtins.inc
+ */
+ operator fun inc(): Short
+
+ /**
+ * Returns this value decremented by one.
+ *
+ * @sample samples.misc.Builtins.dec
+ */
+ operator fun dec(): Short
+
+ /** Returns this value. */
+ operator fun unaryPlus(): Int
+ /** Returns the negative of this value. */
+ operator fun unaryMinus(): Int
+
+ /** Creates a range from this value to the specified [other] value. */
+ operator fun rangeTo(other: Byte): IntRange
+ /** Creates a range from this value to the specified [other] value. */
+ operator fun rangeTo(other: Short): IntRange
+ /** Creates a range from this value to the specified [other] value. */
+ operator fun rangeTo(other: Int): IntRange
+ /** Creates a range from this value to the specified [other] value. */
+ operator fun rangeTo(other: Long): LongRange
+
+ /**
+ * Converts this [Short] value to [Byte].
+ *
+ * If this value is in [Byte.MIN_VALUE]..[Byte.MAX_VALUE], the resulting `Byte` value represents
+ * the same numerical value as this `Short`.
+ *
+ * The resulting `Byte` value is represented by the least significant 8 bits of this `Short` value.
+ */
+ override fun toByte(): Byte
+ /**
+ * Converts this [Short] value to [Char].
+ *
+ * The resulting `Char` code is equal to this value reinterpreted as an unsigned number,
+ * i.e. it has the same binary representation as this `Short`.
+ */
+ @Deprecated("Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", ReplaceWith("this.toInt().toChar()"))
+ override fun toChar(): Char
+ /** Returns this value. */
+ override fun toShort(): Short
+ /**
+ * Converts this [Short] value to [Int].
+ *
+ * The resulting `Int` value represents the same numerical value as this `Short`.
+ *
+ * The least significant 16 bits of the resulting `Int` value are the same as the bits of this `Short` value,
+ * whereas the most significant 16 bits are filled with the sign bit of this value.
+ */
+ override fun toInt(): Int
+ /**
+ * Converts this [Short] value to [Long].
+ *
+ * The resulting `Long` value represents the same numerical value as this `Short`.
+ *
+ * The least significant 16 bits of the resulting `Long` value are the same as the bits of this `Short` value,
+ * whereas the most significant 48 bits are filled with the sign bit of this value.
+ */
+ override fun toLong(): Long
+ /**
+ * Converts this [Short] value to [Float].
+ *
+ * The resulting `Float` value represents the same numerical value as this `Short`.
+ */
+ override fun toFloat(): Float
+ /**
+ * Converts this [Short] value to [Double].
+ *
+ * The resulting `Double` value represents the same numerical value as this `Short`.
+ */
+ override fun toDouble(): Double
+
+ override fun equals(other: Any?): Boolean
+ override fun hashCode(): Int
+ override fun toString(): String
+}
+
+/**
+ * Represents a 32-bit signed integer.
+ * On the JVM, non-nullable values of this type are represented as values of the primitive type `int`.
+ */
+class Int private constructor() : Number(), Comparable {
+ companion object {
+ /**
+ * A constant holding the minimum value an instance of Int can have.
+ */
+ const val MIN_VALUE: Int = -2147483648
+
+ /**
+ * A constant holding the maximum value an instance of Int can have.
+ */
+ const val MAX_VALUE: Int = 2147483647
+
+ /**
+ * The number of bytes used to represent an instance of Int in a binary form.
+ */
+ @SinceKotlin("1.3")
+ const val SIZE_BYTES: Int = 4
+
+ /**
+ * The number of bits used to represent an instance of Int in a binary form.
+ */
+ @SinceKotlin("1.3")
+ const val SIZE_BITS: Int = 32
+ }
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ operator fun compareTo(other: Byte): Int
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ operator fun compareTo(other: Short): Int
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ override operator fun compareTo(other: Int): Int
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ operator fun compareTo(other: Long): Int
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ operator fun compareTo(other: Float): Int
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ operator fun compareTo(other: Double): Int
+
+ /** Adds the other value to this value. */
+ operator fun plus(other: Byte): Int
+ /** Adds the other value to this value. */
+ operator fun plus(other: Short): Int
+ /** Adds the other value to this value. */
+ operator fun plus(other: Int): Int
+ /** Adds the other value to this value. */
+ operator fun plus(other: Long): Long
+ /** Adds the other value to this value. */
+ operator fun plus(other: Float): Float
+ /** Adds the other value to this value. */
+ operator fun plus(other: Double): Double
+
+ /** Subtracts the other value from this value. */
+ operator fun minus(other: Byte): Int
+ /** Subtracts the other value from this value. */
+ operator fun minus(other: Short): Int
+ /** Subtracts the other value from this value. */
+ operator fun minus(other: Int): Int
+ /** Subtracts the other value from this value. */
+ operator fun minus(other: Long): Long
+ /** Subtracts the other value from this value. */
+ operator fun minus(other: Float): Float
+ /** Subtracts the other value from this value. */
+ operator fun minus(other: Double): Double
+
+ /** Multiplies this value by the other value. */
+ operator fun times(other: Byte): Int
+ /** Multiplies this value by the other value. */
+ operator fun times(other: Short): Int
+ /** Multiplies this value by the other value. */
+ operator fun times(other: Int): Int
+ /** Multiplies this value by the other value. */
+ operator fun times(other: Long): Long
+ /** Multiplies this value by the other value. */
+ operator fun times(other: Float): Float
+ /** Multiplies this value by the other value. */
+ operator fun times(other: Double): Double
+
+ /** Divides this value by the other value, truncating the result to an integer that is closer to zero. */
+ operator fun div(other: Byte): Int
+ /** Divides this value by the other value, truncating the result to an integer that is closer to zero. */
+ operator fun div(other: Short): Int
+ /** Divides this value by the other value, truncating the result to an integer that is closer to zero. */
+ operator fun div(other: Int): Int
+ /** Divides this value by the other value, truncating the result to an integer that is closer to zero. */
+ operator fun div(other: Long): Long
+ /** Divides this value by the other value. */
+ operator fun div(other: Float): Float
+ /** Divides this value by the other value. */
+ operator fun div(other: Double): Double
+
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ operator fun rem(other: Byte): Int
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ operator fun rem(other: Short): Int
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ operator fun rem(other: Int): Int
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ operator fun rem(other: Long): Long
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ operator fun rem(other: Float): Float
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ operator fun rem(other: Double): Double
+
+ /**
+ * Returns this value incremented by one.
+ *
+ * @sample samples.misc.Builtins.inc
+ */
+ operator fun inc(): Int
+
+ /**
+ * Returns this value decremented by one.
+ *
+ * @sample samples.misc.Builtins.dec
+ */
+ operator fun dec(): Int
+
+ /** Returns this value. */
+ operator fun unaryPlus(): Int
+ /** Returns the negative of this value. */
+ operator fun unaryMinus(): Int
+
+ /** Creates a range from this value to the specified [other] value. */
+ operator fun rangeTo(other: Byte): IntRange
+ /** Creates a range from this value to the specified [other] value. */
+ operator fun rangeTo(other: Short): IntRange
+ /** Creates a range from this value to the specified [other] value. */
+ operator fun rangeTo(other: Int): IntRange
+ /** Creates a range from this value to the specified [other] value. */
+ operator fun rangeTo(other: Long): LongRange
+
+ /**
+ * Shifts this value left by the [bitCount] number of bits.
+ *
+ * Note that only the five lowest-order bits of the [bitCount] are used as the shift distance.
+ * The shift distance actually used is therefore always in the range `0..31`.
+ */
+ infix fun shl(bitCount: Int): Int
+
+ /**
+ * Shifts this value right by the [bitCount] number of bits, filling the leftmost bits with copies of the sign bit.
+ *
+ * Note that only the five lowest-order bits of the [bitCount] are used as the shift distance.
+ * The shift distance actually used is therefore always in the range `0..31`.
+ */
+ infix fun shr(bitCount: Int): Int
+
+ /**
+ * Shifts this value right by the [bitCount] number of bits, filling the leftmost bits with zeros.
+ *
+ * Note that only the five lowest-order bits of the [bitCount] are used as the shift distance.
+ * The shift distance actually used is therefore always in the range `0..31`.
+ */
+ infix fun ushr(bitCount: Int): Int
+
+ /** Performs a bitwise AND operation between the two values. */
+ infix fun and(other: Int): Int
+ /** Performs a bitwise OR operation between the two values. */
+ infix fun or(other: Int): Int
+ /** Performs a bitwise XOR operation between the two values. */
+ infix fun xor(other: Int): Int
+ /** Inverts the bits in this value. */
+ fun inv(): Int
+
+ /**
+ * Converts this [Int] value to [Byte].
+ *
+ * If this value is in [Byte.MIN_VALUE]..[Byte.MAX_VALUE], the resulting `Byte` value represents
+ * the same numerical value as this `Int`.
+ *
+ * The resulting `Byte` value is represented by the least significant 8 bits of this `Int` value.
+ */
+ override fun toByte(): Byte
+ /**
+ * Converts this [Int] value to [Char].
+ *
+ * If this value is in the range of `Char` codes `Char.MIN_VALUE..Char.MAX_VALUE`,
+ * the resulting `Char` code is equal to this value.
+ *
+ * The resulting `Char` code is represented by the least significant 16 bits of this `Int` value.
+ */
+ override fun toChar(): Char
+ /**
+ * Converts this [Int] value to [Short].
+ *
+ * If this value is in [Short.MIN_VALUE]..[Short.MAX_VALUE], the resulting `Short` value represents
+ * the same numerical value as this `Int`.
+ *
+ * The resulting `Short` value is represented by the least significant 16 bits of this `Int` value.
+ */
+ override fun toShort(): Short
+ /** Returns this value. */
+ override fun toInt(): Int
+ /**
+ * Converts this [Int] value to [Long].
+ *
+ * The resulting `Long` value represents the same numerical value as this `Int`.
+ *
+ * The least significant 32 bits of the resulting `Long` value are the same as the bits of this `Int` value,
+ * whereas the most significant 32 bits are filled with the sign bit of this value.
+ */
+ override fun toLong(): Long
+ /**
+ * Converts this [Int] value to [Float].
+ *
+ * The resulting value is the closest `Float` to this `Int` value.
+ * In case when this `Int` value is exactly between two `Float`s,
+ * the one with zero at least significant bit of mantissa is selected.
+ */
+ override fun toFloat(): Float
+ /**
+ * Converts this [Int] value to [Double].
+ *
+ * The resulting `Double` value represents the same numerical value as this `Int`.
+ */
+ override fun toDouble(): Double
+
+ override fun equals(other: Any?): Boolean
+ override fun hashCode(): Int
+ override fun toString(): String
+}
+
+/**
+ * Represents a single-precision 32-bit IEEE 754 floating point number.
+ * On the JVM, non-nullable values of this type are represented as values of the primitive type `float`.
+ */
+class Float private constructor() : Number(), Comparable {
+ @Suppress("DIVISION_BY_ZERO")
+ companion object {
+ /**
+ * A constant holding the smallest *positive* nonzero value of Float.
+ */
+ const val MIN_VALUE: Float = 1.4E-45F
+
+ /**
+ * A constant holding the largest positive finite value of Float.
+ */
+ const val MAX_VALUE: Float = 3.4028235E38F
+
+ /**
+ * A constant holding the positive infinity value of Float.
+ */
+ const val POSITIVE_INFINITY: Float = 1.0F/0.0F
+
+ /**
+ * A constant holding the negative infinity value of Float.
+ */
+ const val NEGATIVE_INFINITY: Float = -1.0F/0.0F
+
+ /**
+ * A constant holding the "not a number" value of Float.
+ */
+ const val NaN: Float = -(0.0F/0.0F)
+
+ /**
+ * The number of bytes used to represent an instance of Float in a binary form.
+ */
+ @SinceKotlin("1.4")
+ const val SIZE_BYTES: Int = 4
+
+ /**
+ * The number of bits used to represent an instance of Float in a binary form.
+ */
+ @SinceKotlin("1.4")
+ const val SIZE_BITS: Int = 32
+ }
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ operator fun compareTo(other: Byte): Int
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ operator fun compareTo(other: Short): Int
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ operator fun compareTo(other: Int): Int
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ operator fun compareTo(other: Long): Int
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ override operator fun compareTo(other: Float): Int
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ operator fun compareTo(other: Double): Int
+
+ /** Adds the other value to this value. */
+ operator fun plus(other: Byte): Float
+ /** Adds the other value to this value. */
+ operator fun plus(other: Short): Float
+ /** Adds the other value to this value. */
+ operator fun plus(other: Int): Float
+ /** Adds the other value to this value. */
+ operator fun plus(other: Long): Float
+ /** Adds the other value to this value. */
+ operator fun plus(other: Float): Float
+ /** Adds the other value to this value. */
+ operator fun plus(other: Double): Double
+
+ /** Subtracts the other value from this value. */
+ operator fun minus(other: Byte): Float
+ /** Subtracts the other value from this value. */
+ operator fun minus(other: Short): Float
+ /** Subtracts the other value from this value. */
+ operator fun minus(other: Int): Float
+ /** Subtracts the other value from this value. */
+ operator fun minus(other: Long): Float
+ /** Subtracts the other value from this value. */
+ operator fun minus(other: Float): Float
+ /** Subtracts the other value from this value. */
+ operator fun minus(other: Double): Double
+
+ /** Multiplies this value by the other value. */
+ operator fun times(other: Byte): Float
+ /** Multiplies this value by the other value. */
+ operator fun times(other: Short): Float
+ /** Multiplies this value by the other value. */
+ operator fun times(other: Int): Float
+ /** Multiplies this value by the other value. */
+ operator fun times(other: Long): Float
+ /** Multiplies this value by the other value. */
+ operator fun times(other: Float): Float
+ /** Multiplies this value by the other value. */
+ operator fun times(other: Double): Double
+
+ /** Divides this value by the other value. */
+ operator fun div(other: Byte): Float
+ /** Divides this value by the other value. */
+ operator fun div(other: Short): Float
+ /** Divides this value by the other value. */
+ operator fun div(other: Int): Float
+ /** Divides this value by the other value. */
+ operator fun div(other: Long): Float
+ /** Divides this value by the other value. */
+ operator fun div(other: Float): Float
+ /** Divides this value by the other value. */
+ operator fun div(other: Double): Double
+
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ operator fun rem(other: Byte): Float
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ operator fun rem(other: Short): Float
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ operator fun rem(other: Int): Float
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ operator fun rem(other: Long): Float
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ operator fun rem(other: Float): Float
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ operator fun rem(other: Double): Double
+
+ /**
+ * Returns this value incremented by one.
+ *
+ * @sample samples.misc.Builtins.inc
+ */
+ operator fun inc(): Float
+
+ /**
+ * Returns this value decremented by one.
+ *
+ * @sample samples.misc.Builtins.dec
+ */
+ operator fun dec(): Float
+
+ /** Returns this value. */
+ operator fun unaryPlus(): Float
+ /** Returns the negative of this value. */
+ operator fun unaryMinus(): Float
+
+
+ /**
+ * Converts this [Float] value to [Byte].
+ *
+ * The resulting `Byte` value is equal to `this.toInt().toByte()`.
+ */
+ @Deprecated("Unclear conversion. To achieve the same result convert to Int explicitly and then to Byte.", ReplaceWith("toInt().toByte()"))
+ @DeprecatedSinceKotlin(warningSince = "1.3", errorSince = "1.5")
+ override fun toByte(): Byte
+ /**
+ * Converts this [Float] value to [Char].
+ *
+ * The resulting `Char` value is equal to `this.toInt().toChar()`.
+ */
+ @Deprecated("Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", ReplaceWith("this.toInt().toChar()"))
+ @DeprecatedSinceKotlin(warningSince = "1.5")
+ override fun toChar(): Char
+ /**
+ * Converts this [Float] value to [Short].
+ *
+ * The resulting `Short` value is equal to `this.toInt().toShort()`.
+ */
+ @Deprecated("Unclear conversion. To achieve the same result convert to Int explicitly and then to Short.", ReplaceWith("toInt().toShort()"))
+ @DeprecatedSinceKotlin(warningSince = "1.3", errorSince = "1.5")
+ override fun toShort(): Short
+ /**
+ * Converts this [Float] value to [Int].
+ *
+ * The fractional part, if any, is rounded down towards zero.
+ * Returns zero if this `Float` value is `NaN`, [Int.MIN_VALUE] if it's less than `Int.MIN_VALUE`,
+ * [Int.MAX_VALUE] if it's bigger than `Int.MAX_VALUE`.
+ */
+ override fun toInt(): Int
+ /**
+ * Converts this [Float] value to [Long].
+ *
+ * The fractional part, if any, is rounded down towards zero.
+ * Returns zero if this `Float` value is `NaN`, [Long.MIN_VALUE] if it's less than `Long.MIN_VALUE`,
+ * [Long.MAX_VALUE] if it's bigger than `Long.MAX_VALUE`.
+ */
+ override fun toLong(): Long
+ /** Returns this value. */
+ override fun toFloat(): Float
+ /**
+ * Converts this [Float] value to [Double].
+ *
+ * The resulting `Double` value represents the same numerical value as this `Float`.
+ */
+ override fun toDouble(): Double
+
+ override fun equals(other: Any?): Boolean
+ override fun hashCode(): Int
+ override fun toString(): String
+}
+
+/**
+ * Represents a double-precision 64-bit IEEE 754 floating point number.
+ * On the JVM, non-nullable values of this type are represented as values of the primitive type `double`.
+ */
+class Double private constructor() : Number(), Comparable {
+ @Suppress("DIVISION_BY_ZERO")
+ companion object {
+ /**
+ * A constant holding the smallest *positive* nonzero value of Double.
+ */
+ const val MIN_VALUE: Double = 4.9E-324
+
+ /**
+ * A constant holding the largest positive finite value of Double.
+ */
+ const val MAX_VALUE: Double = 1.7976931348623157E308
+
+ /**
+ * A constant holding the positive infinity value of Double.
+ */
+ const val POSITIVE_INFINITY: Double = 1.0/0.0
+
+ /**
+ * A constant holding the negative infinity value of Double.
+ */
+ const val NEGATIVE_INFINITY: Double = -1.0/0.0
+
+ /**
+ * A constant holding the "not a number" value of Double.
+ */
+ const val NaN: Double = -(0.0/0.0)
+
+ /**
+ * The number of bytes used to represent an instance of Double in a binary form.
+ */
+ @SinceKotlin("1.4")
+ const val SIZE_BYTES: Int = 8
+
+ /**
+ * The number of bits used to represent an instance of Double in a binary form.
+ */
+ @SinceKotlin("1.4")
+ const val SIZE_BITS: Int = 64
+ }
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ operator fun compareTo(other: Byte): Int
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ operator fun compareTo(other: Short): Int
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ operator fun compareTo(other: Int): Int
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ operator fun compareTo(other: Long): Int
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ operator fun compareTo(other: Float): Int
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ override operator fun compareTo(other: Double): Int
+
+ /** Adds the other value to this value. */
+ operator fun plus(other: Byte): Double
+ /** Adds the other value to this value. */
+ operator fun plus(other: Short): Double
+ /** Adds the other value to this value. */
+ operator fun plus(other: Int): Double
+ /** Adds the other value to this value. */
+ operator fun plus(other: Long): Double
+ /** Adds the other value to this value. */
+ operator fun plus(other: Float): Double
+ /** Adds the other value to this value. */
+ operator fun plus(other: Double): Double
+
+ /** Subtracts the other value from this value. */
+ operator fun minus(other: Byte): Double
+ /** Subtracts the other value from this value. */
+ operator fun minus(other: Short): Double
+ /** Subtracts the other value from this value. */
+ operator fun minus(other: Int): Double
+ /** Subtracts the other value from this value. */
+ operator fun minus(other: Long): Double
+ /** Subtracts the other value from this value. */
+ operator fun minus(other: Float): Double
+ /** Subtracts the other value from this value. */
+ operator fun minus(other: Double): Double
+
+ /** Multiplies this value by the other value. */
+ operator fun times(other: Byte): Double
+ /** Multiplies this value by the other value. */
+ operator fun times(other: Short): Double
+ /** Multiplies this value by the other value. */
+ operator fun times(other: Int): Double
+ /** Multiplies this value by the other value. */
+ operator fun times(other: Long): Double
+ /** Multiplies this value by the other value. */
+ operator fun times(other: Float): Double
+ /** Multiplies this value by the other value. */
+ operator fun times(other: Double): Double
+
+ /** Divides this value by the other value. */
+ operator fun div(other: Byte): Double
+ /** Divides this value by the other value. */
+ operator fun div(other: Short): Double
+ /** Divides this value by the other value. */
+ operator fun div(other: Int): Double
+ /** Divides this value by the other value. */
+ operator fun div(other: Long): Double
+ /** Divides this value by the other value. */
+ operator fun div(other: Float): Double
+ /** Divides this value by the other value. */
+ operator fun div(other: Double): Double
+
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ operator fun rem(other: Byte): Double
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ operator fun rem(other: Short): Double
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ operator fun rem(other: Int): Double
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ operator fun rem(other: Long): Double
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ operator fun rem(other: Float): Double
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ operator fun rem(other: Double): Double
+
+ /**
+ * Returns this value incremented by one.
+ *
+ * @sample samples.misc.Builtins.inc
+ */
+ operator fun inc(): Double
+
+ /**
+ * Returns this value decremented by one.
+ *
+ * @sample samples.misc.Builtins.dec
+ */
+ operator fun dec(): Double
+
+ /** Returns this value. */
+ operator fun unaryPlus(): Double
+ /** Returns the negative of this value. */
+ operator fun unaryMinus(): Double
+
+
+ /**
+ * Converts this [Double] value to [Byte].
+ *
+ * The resulting `Byte` value is equal to `this.toInt().toByte()`.
+ */
+ @Deprecated("Unclear conversion. To achieve the same result convert to Int explicitly and then to Byte.", ReplaceWith("toInt().toByte()"))
+ @DeprecatedSinceKotlin(warningSince = "1.3", errorSince = "1.5")
+ override fun toByte(): Byte
+ /**
+ * Converts this [Double] value to [Char].
+ *
+ * The resulting `Char` value is equal to `this.toInt().toChar()`.
+ */
+ @Deprecated("Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", ReplaceWith("this.toInt().toChar()"))
+ @DeprecatedSinceKotlin(warningSince = "1.5")
+ override fun toChar(): Char
+ /**
+ * Converts this [Double] value to [Short].
+ *
+ * The resulting `Short` value is equal to `this.toInt().toShort()`.
+ */
+ @Deprecated("Unclear conversion. To achieve the same result convert to Int explicitly and then to Short.", ReplaceWith("toInt().toShort()"))
+ @DeprecatedSinceKotlin(warningSince = "1.3", errorSince = "1.5")
+ override fun toShort(): Short
+ /**
+ * Converts this [Double] value to [Int].
+ *
+ * The fractional part, if any, is rounded down towards zero.
+ * Returns zero if this `Double` value is `NaN`, [Int.MIN_VALUE] if it's less than `Int.MIN_VALUE`,
+ * [Int.MAX_VALUE] if it's bigger than `Int.MAX_VALUE`.
+ */
+ override fun toInt(): Int
+ /**
+ * Converts this [Double] value to [Long].
+ *
+ * The fractional part, if any, is rounded down towards zero.
+ * Returns zero if this `Double` value is `NaN`, [Long.MIN_VALUE] if it's less than `Long.MIN_VALUE`,
+ * [Long.MAX_VALUE] if it's bigger than `Long.MAX_VALUE`.
+ */
+ override fun toLong(): Long
+ /**
+ * Converts this [Double] value to [Float].
+ *
+ * The resulting value is the closest `Float` to this `Double` value.
+ * In case when this `Double` value is exactly between two `Float`s,
+ * the one with zero at least significant bit of mantissa is selected.
+ */
+ override fun toFloat(): Float
+ /** Returns this value. */
+ override fun toDouble(): Double
+
+ override fun equals(other: Any?): Boolean
+ override fun hashCode(): Int
+ override fun toString(): String
+}
+
diff --git a/libraries/stdlib/py/builtins/String.kt b/libraries/stdlib/py/builtins/String.kt
new file mode 100644
index 0000000000000..b552e8d972960
--- /dev/null
+++ b/libraries/stdlib/py/builtins/String.kt
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+@file:Suppress("NON_ABSTRACT_FUNCTION_WITH_NO_BODY", "MUST_BE_INITIALIZED_OR_BE_ABSTRACT", "UNUSED_PARAMETER")
+
+package kotlin
+
+/**
+ * The `String` class represents character strings. All string literals in Kotlin programs, such as `"abc"`, are
+ * implemented as instances of this class.
+ */
+class String : Comparable, CharSequence {
+ companion object;
+
+ /**
+ * Returns a string obtained by concatenating this string with the string representation of the given [other] object.
+ */
+ operator fun plus(other: Any?): String
+
+ override val length: Int
+
+ /**
+ * Returns the character of this string at the specified [index].
+ *
+ * If the [index] is out of bounds of this string, throws an [IndexOutOfBoundsException] except in Kotlin/JS
+ * where the behavior is unspecified.
+ */
+ override fun get(index: Int): Char
+
+ override fun subSequence(startIndex: Int, endIndex: Int): CharSequence
+
+ override fun compareTo(other: String): Int
+
+ override fun equals(other: Any?): Boolean
+
+ override fun hashCode(): Int
+
+ override fun toString(): String
+}
diff --git a/libraries/stdlib/py/builtins/Throwable.kt b/libraries/stdlib/py/builtins/Throwable.kt
new file mode 100644
index 0000000000000..a5341b5e121a3
--- /dev/null
+++ b/libraries/stdlib/py/builtins/Throwable.kt
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+package kotlin
+
+/**
+ * The base class for all errors and exceptions. Only instances of this class can be thrown or caught.
+ *
+ * @param message the detail message string.
+ * @param cause the cause of this throwable.
+ */
+@JsName("Error")
+open external class Throwable {
+ open val message: String?
+ open val cause: Throwable?
+
+ constructor(message: String?, cause: Throwable?)
+ constructor(message: String?)
+ constructor(cause: Throwable?)
+ constructor()
+
+ // TODO: add specialized version to runtime
+// public override fun equals(other: Any?): Boolean
+// public override fun hashCode(): Int
+ override fun toString(): String
+}
\ No newline at end of file
diff --git a/libraries/stdlib/py/runtime/DefaultConstructorMarker.kt b/libraries/stdlib/py/runtime/DefaultConstructorMarker.kt
new file mode 100644
index 0000000000000..85d6e3483bed6
--- /dev/null
+++ b/libraries/stdlib/py/runtime/DefaultConstructorMarker.kt
@@ -0,0 +1,8 @@
+/*
+ * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+package kotlin.js
+
+internal object DefaultConstructorMarker
\ No newline at end of file
diff --git a/libraries/stdlib/py/runtime/JsError.kt b/libraries/stdlib/py/runtime/JsError.kt
new file mode 100644
index 0000000000000..e3e516decc15f
--- /dev/null
+++ b/libraries/stdlib/py/runtime/JsError.kt
@@ -0,0 +1,7 @@
+/*
+ * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+@JsName("Error")
+internal open external class JsError(message: String) : Throwable
\ No newline at end of file
diff --git a/libraries/stdlib/py/runtime/arrays.kt b/libraries/stdlib/py/runtime/arrays.kt
new file mode 100644
index 0000000000000..11f2ac129e42c
--- /dev/null
+++ b/libraries/stdlib/py/runtime/arrays.kt
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+package kotlin.js
+
+import withType
+
+@PublishedApi
+internal external fun Array(size: Int): Array
+
+@PublishedApi
+internal fun fillArrayVal(array: Array, initValue: T): Array {
+ for (i in 0..array.size - 1) {
+ array[i] = initValue
+ }
+ return array
+}
+
+internal inline fun arrayWithFun(size: Int, init: (Int) -> T) = fillArrayFun(Array(size), init)
+
+internal inline fun fillArrayFun(array: dynamic, init: (Int) -> T): Array {
+ val result = array.unsafeCast>()
+ var i = 0
+ while (i != result.size) {
+ result[i] = init(i)
+ ++i
+ }
+ return result
+}
+
+internal fun booleanArray(size: Int): BooleanArray = withType("BooleanArray", fillArrayVal(Array(size), false)).unsafeCast()
+
+internal fun booleanArrayOf(arr: Array): BooleanArray = withType("BooleanArray", arr.asDynamic().slice()).unsafeCast()
+
+//internal fun charArray(size: Int): CharArray = withType("CharArray", fillArrayVal(Array(size), 0)).unsafeCast()
+internal fun charArray(size: Int): CharArray = withType("CharArray", fillArrayVal(Array(size), Char(0))).unsafeCast()
+
+internal fun charArrayOf(arr: Array): CharArray = withType("CharArray", arr.asDynamic().slice()).unsafeCast()
+
+internal fun longArray(size: Int): LongArray = withType("LongArray", fillArrayVal(Array(size), 0L)).unsafeCast()
+
+internal fun longArrayOf(arr: Array): LongArray = withType("LongArray", arr.asDynamic().slice()).unsafeCast()
+
+internal fun arrayIterator(array: Array) = object : Iterator {
+ var index = 0
+ override fun hasNext() = index != array.size
+ override fun next() = if (index != array.size) array[index++] else throw NoSuchElementException("$index")
+}
+
+internal fun booleanArrayIterator(array: BooleanArray) = object : BooleanIterator() {
+ var index = 0
+ override fun hasNext() = index != array.size
+ override fun nextBoolean() = if (index != array.size) array[index++] else throw NoSuchElementException("$index")
+}
+
+internal fun byteArrayIterator(array: ByteArray) = object : ByteIterator() {
+ var index = 0
+ override fun hasNext() = index != array.size
+ override fun nextByte() = if (index != array.size) array[index++] else throw NoSuchElementException("$index")
+}
+
+internal fun shortArrayIterator(array: ShortArray) = object : ShortIterator() {
+ var index = 0
+ override fun hasNext() = index != array.size
+ override fun nextShort() = if (index != array.size) array[index++] else throw NoSuchElementException("$index")
+}
+
+internal fun charArrayIterator(array: CharArray) = object : CharIterator() {
+ var index = 0
+ override fun hasNext() = index != array.size
+ override fun nextChar() = if (index != array.size) array[index++] else throw NoSuchElementException("$index")
+}
+
+internal fun intArrayIterator(array: IntArray) = object : IntIterator() {
+ var index = 0
+ override fun hasNext() = index != array.size
+ override fun nextInt() = if (index != array.size) array[index++] else throw NoSuchElementException("$index")
+}
+
+internal fun floatArrayIterator(array: FloatArray) = object : FloatIterator() {
+ var index = 0
+ override fun hasNext() = index != array.size
+ override fun nextFloat() = if (index != array.size) array[index++] else throw NoSuchElementException("$index")
+}
+
+internal fun doubleArrayIterator(array: DoubleArray) = object : DoubleIterator() {
+ var index = 0
+ override fun hasNext() = index != array.size
+ override fun nextDouble() = if (index != array.size) array[index++] else throw NoSuchElementException("$index")
+}
+
+internal fun longArrayIterator(array: LongArray) = object : LongIterator() {
+ var index = 0
+ override fun hasNext() = index != array.size
+ override fun nextLong() = if (index != array.size) array[index++] else throw NoSuchElementException("$index")
+}
diff --git a/libraries/stdlib/py/runtime/bitUtils.kt b/libraries/stdlib/py/runtime/bitUtils.kt
new file mode 100644
index 0000000000000..25af2ae812bee
--- /dev/null
+++ b/libraries/stdlib/py/runtime/bitUtils.kt
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+package kotlin.js
+
+// TODO use declarations from stdlib
+private external class ArrayBuffer(size: Int)
+private external class Float64Array(buffer: ArrayBuffer)
+private external class Float32Array(buffer: ArrayBuffer)
+private external class Int32Array(buffer: ArrayBuffer)
+
+private val buf = ArrayBuffer(8)
+// TODO use one DataView instead of bunch of typed views.
+private val bufFloat64 = Float64Array(buf).unsafeCast()
+private val bufFloat32 = Float32Array(buf).unsafeCast()
+private val bufInt32 = Int32Array(buf).unsafeCast()
+
+private val lowIndex = run {
+ bufFloat64[0] = -1.0 // bff00000_00000000
+ if (bufInt32[0] != 0) 1 else 0
+}
+private val highIndex = 1 - lowIndex
+
+internal fun doubleToRawBits(value: Double): Long {
+ bufFloat64[0] = value
+ return Long(bufInt32[lowIndex], bufInt32[highIndex])
+}
+
+@PublishedApi
+internal fun doubleFromBits(value: Long): Double {
+ bufInt32[lowIndex] = value.low
+ bufInt32[highIndex] = value.high
+ return bufFloat64[0]
+}
+
+internal fun floatToRawBits(value: Float): Int {
+ bufFloat32[0] = value
+ return bufInt32[0]
+}
+
+@PublishedApi
+internal fun floatFromBits(value: Int): Float {
+ bufInt32[0] = value
+ return bufFloat32[0]
+}
+
+// returns zero value for number with positive sign bit and non-zero value for number with negative sign bit.
+internal fun doubleSignBit(value: Double): Int {
+ bufFloat64[0] = value
+ return bufInt32[highIndex] and Int.MIN_VALUE
+}
+
+internal fun getNumberHashCode(obj: Double): Int {
+ @Suppress("DEPRECATED_IDENTITY_EQUALS")
+ if (jsBitwiseOr(obj, 0).unsafeCast() === obj) {
+ return obj.toInt()
+ }
+
+ bufFloat64[0] = obj
+ return bufInt32[highIndex] * 31 + bufInt32[lowIndex]
+}
diff --git a/libraries/stdlib/py/runtime/booleanInExternalHelpers.kt b/libraries/stdlib/py/runtime/booleanInExternalHelpers.kt
new file mode 100644
index 0000000000000..0877025e6537c
--- /dev/null
+++ b/libraries/stdlib/py/runtime/booleanInExternalHelpers.kt
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+package kotlin.js
+
+import JsError
+
+@JsName("Boolean")
+internal external fun nativeBoolean(obj: Any?): Boolean
+
+internal fun booleanInExternalLog(name: String, obj: dynamic) {
+ if (jsTypeOf(obj) != "boolean") {
+ console.asDynamic().error("Boolean expected for '$name', but actual:", obj)
+ }
+}
+
+internal fun booleanInExternalException(name: String, obj: dynamic) {
+ if (jsTypeOf(obj) != "boolean") {
+ throw JsError("Boolean expected for '$name', but actual: $obj")
+ }
+}
\ No newline at end of file
diff --git a/libraries/stdlib/py/runtime/charSequence.kt b/libraries/stdlib/py/runtime/charSequence.kt
new file mode 100644
index 0000000000000..f0766e33e1b1d
--- /dev/null
+++ b/libraries/stdlib/py/runtime/charSequence.kt
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+package kotlin.js
+
+internal annotation class DoNotIntrinsify
+
+@PublishedApi
+@DoNotIntrinsify
+internal fun charSequenceGet(a: CharSequence, index: Int): Char {
+ return if (isString(a)) {
+ Char(a.asDynamic().charCodeAt(index).unsafeCast())
+ } else {
+ a[index]
+ }
+}
+
+@PublishedApi
+@DoNotIntrinsify
+internal fun charSequenceLength(a: CharSequence): Int {
+ return if (isString(a)) {
+ a.asDynamic().length.unsafeCast()
+ } else {
+ a.length
+ }
+}
+
+@PublishedApi
+@DoNotIntrinsify
+internal fun charSequenceSubSequence(a: CharSequence, startIndex: Int, endIndex: Int): CharSequence {
+ return if (isString(a)) {
+ a.asDynamic().substring(startIndex, endIndex).unsafeCast()
+ } else {
+ a.subSequence(startIndex, endIndex)
+ }
+}
+
+// Keeping this function as separate non-inline to intrincify `is` operator
+internal fun isString(a: CharSequence) = a is String
diff --git a/libraries/stdlib/py/runtime/collectionsHacks.kt b/libraries/stdlib/py/runtime/collectionsHacks.kt
new file mode 100644
index 0000000000000..4b1310ffac8d5
--- /dev/null
+++ b/libraries/stdlib/py/runtime/collectionsHacks.kt
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+package kotlin.collections
+
+import kotlin.Array
+import kotlin.Boolean
+import kotlin.Int
+import kotlin.UByteArray
+import kotlin.UIntArray
+import kotlin.ULongArray
+import kotlin.UShortArray
+import kotlin.js.*
+
+internal fun arrayToString(array: Array<*>) = array.joinToString(", ", "[", "]") { toString(it) }
+
+internal fun Array?.contentDeepHashCodeInternal(): Int {
+ if (this == null) return 0
+ var result = 1
+ for (element in this) {
+ val elementHash = when {
+ element == null -> 0
+ isArrayish(element) -> (element.unsafeCast>()).contentDeepHashCodeInternal()
+
+ element is UByteArray -> element.contentHashCode()
+ element is UShortArray -> element.contentHashCode()
+ element is UIntArray -> element.contentHashCode()
+ element is ULongArray -> element.contentHashCode()
+
+ else -> element.hashCode()
+ }
+
+ result = 31 * result + elementHash
+ }
+ return result
+}
+
+internal fun T.contentEqualsInternal(other: T): Boolean {
+ val a = this.asDynamic()
+ val b = other.asDynamic()
+
+ if (a === b) return true
+
+ if (a == null || b == null || !isArrayish(b) || a.length != b.length) return false
+
+ for (i in 0 until a.length) {
+ if (!equals(a[i], b[i])) {
+ return false
+ }
+ }
+ return true
+}
+
+internal fun T.contentHashCodeInternal(): Int {
+ val a = this.asDynamic()
+ if (a == null) return 0
+
+ var result = 1
+
+ for (i in 0 until a.length) {
+ result = result * 31 + hashCode(a[i])
+ }
+
+ return result
+}
\ No newline at end of file
diff --git a/libraries/stdlib/py/runtime/compareTo.kt b/libraries/stdlib/py/runtime/compareTo.kt
new file mode 100644
index 0000000000000..7a6aa4ced3b98
--- /dev/null
+++ b/libraries/stdlib/py/runtime/compareTo.kt
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+package kotlin.js
+
+
+// Adopted from misc.js
+
+internal fun compareTo(a: dynamic, b: dynamic): Int = when (jsTypeOf(a)) {
+ "number" -> when {
+ jsTypeOf(b) == "number" ->
+ doubleCompareTo(a, b)
+ b is Long ->
+ doubleCompareTo(a, b.toDouble())
+ else ->
+ primitiveCompareTo(a, b)
+ }
+
+ "string", "boolean" -> primitiveCompareTo(a, b)
+
+ else -> compareToDoNotIntrinsicify(a, b)
+}
+
+@DoNotIntrinsify
+private fun > compareToDoNotIntrinsicify(a: Comparable, b: T) =
+ a.compareTo(b)
+
+internal fun primitiveCompareTo(a: dynamic, b: dynamic): Int =
+ when {
+ a < b -> -1
+ a > b -> 1
+ else -> 0
+ }
+
+internal fun doubleCompareTo(a: dynamic, b: dynamic): Int =
+ when {
+ a < b -> -1
+ a > b -> 1
+
+ a === b -> {
+ if (a !== 0)
+ 0
+ else {
+ val ia = 1.asDynamic() / a
+ if (ia === 1.asDynamic() / b) {
+ 0
+ } else if (ia < 0) {
+ -1
+ } else {
+ 1
+ }
+ }
+ }
+
+ a !== a ->
+ if (b !== b) 0 else 1
+
+ else -> -1
+ }
\ No newline at end of file
diff --git a/libraries/stdlib/py/runtime/constructFunction.kt b/libraries/stdlib/py/runtime/constructFunction.kt
new file mode 100644
index 0000000000000..2cc0c373257f7
--- /dev/null
+++ b/libraries/stdlib/py/runtime/constructFunction.kt
@@ -0,0 +1,13 @@
+/*
+ * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+package kotlin.js
+
+/**
+ * @param CT is return type of calling constructor (uses in DCE)
+ */
+internal fun construct(constructorType: dynamic, resultType: dynamic, vararg args: Any?): Any {
+ return js("Reflect").construct(constructorType, args, resultType)
+}
diff --git a/libraries/stdlib/py/runtime/coreRuntime.kt b/libraries/stdlib/py/runtime/coreRuntime.kt
new file mode 100644
index 0000000000000..d1684c9074bf1
--- /dev/null
+++ b/libraries/stdlib/py/runtime/coreRuntime.kt
@@ -0,0 +1,141 @@
+/*
+ * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+package kotlin.js
+
+internal fun equals(obj1: dynamic, obj2: dynamic): Boolean {
+ if (obj1 == null) {
+ return obj2 == null
+ }
+ if (obj2 == null) {
+ return false
+ }
+
+ if (jsTypeOf(obj1) == "object" && jsTypeOf(obj1.equals) == "function") {
+ return (obj1.equals)(obj2)
+ }
+
+ if (obj1 !== obj1) {
+ return obj2 !== obj2
+ }
+
+ if (jsTypeOf(obj1) == "number" && jsTypeOf(obj2) == "number") {
+ return obj1 === obj2 && (obj1 !== 0 || 1.asDynamic() / obj1 === 1.asDynamic() / obj2)
+ }
+ return obj1 === obj2
+}
+
+internal fun toString(o: dynamic): String = when {
+ o == null -> "null"
+ isArrayish(o) -> "[...]"
+
+ else -> (o.toString)().unsafeCast()
+}
+
+internal fun anyToString(o: dynamic): String = js("Object").prototype.toString.call(o)
+
+private fun hasOwnPrototypeProperty(o: Any, name: String): Boolean {
+ return JsObject.getPrototypeOf(o).hasOwnProperty(name).unsafeCast()
+}
+
+internal fun hashCode(obj: dynamic): Int {
+ if (obj == null)
+ return 0
+
+ return when (jsTypeOf(obj)) {
+ "object" -> if ("function" === jsTypeOf(obj.hashCode)) (obj.hashCode)() else getObjectHashCode(obj)
+ "function" -> getObjectHashCode(obj)
+ "number" -> getNumberHashCode(obj)
+ "boolean" -> if(obj.unsafeCast()) 1 else 0
+ else -> getStringHashCode(js("String")(obj))
+ }
+}
+
+private const val POW_2_32 = 4294967296.0
+private const val OBJECT_HASH_CODE_PROPERTY_NAME = "kotlinHashCodeValue$"
+
+internal fun getObjectHashCode(obj: dynamic): Int {
+ if (!jsIn(OBJECT_HASH_CODE_PROPERTY_NAME, obj)) {
+ var hash = jsBitwiseOr(js("Math").random() * POW_2_32, 0) // Make 32-bit singed integer.
+ var descriptor = js("new Object()")
+ descriptor.value = hash
+ descriptor.enumerable = false
+ js("Object").defineProperty(obj, OBJECT_HASH_CODE_PROPERTY_NAME, descriptor)
+ }
+ return obj[OBJECT_HASH_CODE_PROPERTY_NAME].unsafeCast()
+}
+
+internal fun getStringHashCode(str: String): Int {
+ var hash = 0
+ val length: Int = str.length // TODO: Implement WString.length
+ for (i in 0..length-1) {
+ val code: Int = str.asDynamic().charCodeAt(i)
+ hash = hash * 31 + code
+ }
+ return hash
+}
+
+internal fun identityHashCode(obj: Any?): Int = getObjectHashCode(obj)
+
+internal fun captureStack(instance: Throwable, constructorFunction: Any) {
+ if (js("Error").captureStackTrace != null) {
+ js("Error").captureStackTrace(instance, constructorFunction)
+ } else {
+ instance.asDynamic().stack = js("new Error()").stack
+ }
+}
+
+internal fun newThrowable(message: String?, cause: Throwable?): Throwable {
+ val throwable = js("new Error()")
+ throwable.message = if (isUndefined(message)) {
+ if (isUndefined(cause)) message else cause?.toString() ?: undefined
+ } else message ?: undefined
+ throwable.cause = cause
+ throwable.name = "Throwable"
+ return throwable.unsafeCast()
+}
+
+internal fun extendThrowable(this_: dynamic, message: String?, cause: Throwable?) {
+ js("Error").call(this_)
+ setPropertiesToThrowableInstance(this_, message, cause)
+}
+
+internal fun setPropertiesToThrowableInstance(this_: dynamic, message: String?, cause: Throwable?) {
+ if (!hasOwnPrototypeProperty(this_, "message")) {
+ @Suppress("IfThenToElvis")
+ this_.message = if (message == null) {
+ @Suppress("SENSELESS_COMPARISON")
+ if (message !== null) {
+ // undefined
+ cause?.toString() ?: undefined
+ } else {
+ // real null
+ undefined
+ }
+ } else message
+ }
+ if (!hasOwnPrototypeProperty(this_, "cause")) {
+ this_.cause = cause
+ }
+ this_.name = JsObject.getPrototypeOf(this_).constructor.name
+}
+
+@JsName("Object")
+internal external class JsObject {
+ companion object {
+ fun getPrototypeOf(obj: Any?): dynamic
+ }
+}
+
+// Note: once some error-compilation design happened consider to distinguish a special exception for error-code.
+internal fun errorCode(description: String): Nothing {
+ throw IllegalStateException(description)
+}
+
+@Suppress("SENSELESS_COMPARISON")
+internal fun isUndefined(value: dynamic): Boolean = value === undefined
+
+internal fun boxIntrinsic(@Suppress("UNUSED_PARAMETER") x: T): R = error("Should be lowered")
+internal fun unboxIntrinsic(@Suppress("UNUSED_PARAMETER") x: T): R = error("Should be lowered")
diff --git a/libraries/stdlib/py/runtime/coroutineInternalJS.kt b/libraries/stdlib/py/runtime/coroutineInternalJS.kt
new file mode 100644
index 0000000000000..48bb3af52336f
--- /dev/null
+++ b/libraries/stdlib/py/runtime/coroutineInternalJS.kt
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+
+package kotlin.js
+
+import kotlin.coroutines.Continuation
+import kotlin.coroutines.ContinuationInterceptor
+import kotlin.coroutines.CoroutineContext
+
+
+@PublishedApi
+internal fun getContinuation(): Continuation { throw Exception("Implemented as intrinsic") }
+// Do we really need this intrinsic in JS?
+
+@PublishedApi
+internal suspend fun returnIfSuspended(@Suppress("UNUSED_PARAMETER") argument: Any?): T {
+ throw Exception("Implemented as intrinsic")
+}
+
+@PublishedApi
+internal fun interceptContinuationIfNeeded(
+ context: CoroutineContext,
+ continuation: Continuation
+) = context[ContinuationInterceptor]?.interceptContinuation(continuation) ?: continuation
+
+
+@SinceKotlin("1.2")
+@PublishedApi
+internal suspend fun getCoroutineContext(): CoroutineContext = getContinuation().context
+
+// TODO: remove `JS` suffix oncec `NameGenerator` is implemented
+@PublishedApi
+internal suspend fun suspendCoroutineUninterceptedOrReturnJS(block: (Continuation) -> Any?): T =
+ returnIfSuspended(block(getContinuation()))
+
+
diff --git a/libraries/stdlib/py/runtime/dceUtils.kt b/libraries/stdlib/py/runtime/dceUtils.kt
new file mode 100644
index 0000000000000..70e29301ffa65
--- /dev/null
+++ b/libraries/stdlib/py/runtime/dceUtils.kt
@@ -0,0 +1,16 @@
+/*
+ * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+package kotlin.js
+
+import JsError
+
+internal fun unreachableDeclarationLog() {
+ console.asDynamic().trace("Unreachable declaration")
+}
+
+internal fun unreachableDeclarationException() {
+ throw JsError("Unreachable declaration")
+}
\ No newline at end of file
diff --git a/libraries/stdlib/py/runtime/hacks.kt b/libraries/stdlib/py/runtime/hacks.kt
new file mode 100644
index 0000000000000..48272f514d750
--- /dev/null
+++ b/libraries/stdlib/py/runtime/hacks.kt
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+package kotlin
+
+@PublishedApi
+internal fun throwUninitializedPropertyAccessException(name: String): Nothing =
+ throw UninitializedPropertyAccessException("lateinit property $name has not been initialized")
+
+@PublishedApi
+internal fun throwKotlinNothingValueException(): Nothing =
+ throw KotlinNothingValueException()
+
+internal fun noWhenBranchMatchedException(): Nothing = throw NoWhenBranchMatchedException()
+
+internal fun THROW_ISE(): Nothing {
+ throw IllegalStateException()
+}
+
+internal fun THROW_CCE(): Nothing {
+ throw ClassCastException()
+}
+
+internal fun THROW_NPE(): Nothing {
+ throw NullPointerException()
+}
+
+internal fun THROW_IAE(msg: String): Nothing {
+ throw IllegalArgumentException(msg)
+}
+
+internal fun ensureNotNull(v: T?): T = if (v == null) THROW_NPE() else v
\ No newline at end of file
diff --git a/libraries/stdlib/py/runtime/jsIntrinsics.kt b/libraries/stdlib/py/runtime/jsIntrinsics.kt
new file mode 100644
index 0000000000000..62937340ad5bb
--- /dev/null
+++ b/libraries/stdlib/py/runtime/jsIntrinsics.kt
@@ -0,0 +1,207 @@
+/*
+ * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+@file:Suppress("NON_MEMBER_FUNCTION_NO_BODY", "UNUSED_PARAMETER", "unused")
+
+package kotlin.js
+
+@RequiresOptIn(message = "Here be dragons! This is a compiler intrinsic, proceed with care!")
+@Retention(AnnotationRetention.BINARY)
+@Target(AnnotationTarget.FUNCTION)
+internal annotation class JsIntrinsic
+
+@JsIntrinsic
+internal fun jsEqeq(a: Any?, b: Any?): Boolean
+
+@JsIntrinsic
+internal fun jsNotEq(a: Any?, b: Any?): Boolean
+
+@JsIntrinsic
+internal fun jsEqeqeq(a: Any?, b: Any?): Boolean
+
+@JsIntrinsic
+internal fun jsNotEqeq(a: Any?, b: Any?): Boolean
+
+@JsIntrinsic
+internal fun jsGt(a: Any?, b: Any?): Boolean
+
+@JsIntrinsic
+internal fun jsGtEq(a: Any?, b: Any?): Boolean
+
+@JsIntrinsic
+internal fun jsLt(a: Any?, b: Any?): Boolean
+
+@JsIntrinsic
+internal fun jsLtEq(a: Any?, b: Any?): Boolean
+
+@JsIntrinsic
+internal fun jsNot(a: Any?): Boolean
+
+@JsIntrinsic
+internal fun jsUnaryPlus(a: Any?): Any?
+
+@JsIntrinsic
+internal fun jsUnaryMinus(a: Any?): Any?
+
+@JsIntrinsic
+internal fun jsPrefixInc(a: Any?): Any?
+
+@JsIntrinsic
+internal fun jsPostfixInc(a: Any?): Any?
+
+@JsIntrinsic
+internal fun jsPrefixDec(a: Any?): Any?
+
+@JsIntrinsic
+internal fun jsPostfixDec(a: Any?): Any?
+
+@JsIntrinsic
+internal fun jsPlus(a: Any?, b: Any?): Any?
+
+@JsIntrinsic
+internal fun jsMinus(a: Any?, b: Any?): Any?
+
+@JsIntrinsic
+internal fun jsMult(a: Any?, b: Any?): Any?
+
+@JsIntrinsic
+internal fun jsDiv(a: Any?, b: Any?): Any?
+
+@JsIntrinsic
+internal fun jsMod(a: Any?, b: Any?): Any?
+
+@JsIntrinsic
+internal fun jsPlusAssign(a: Any?, b: Any?): Any?
+
+@JsIntrinsic
+internal fun jsMinusAssign(a: Any?, b: Any?): Any?
+
+@JsIntrinsic
+internal fun jsMultAssign(a: Any?, b: Any?): Any?
+
+@JsIntrinsic
+internal fun jsDivAssign(a: Any?, b: Any?): Any?
+
+@JsIntrinsic
+internal fun jsModAssign(a: Any?, b: Any?): Any?
+
+@JsIntrinsic
+internal fun jsAnd(a: Any?, b: Any?): Any?
+
+@JsIntrinsic
+internal fun jsOr(a: Any?, b: Any?): Any?
+
+@JsIntrinsic
+internal fun jsBitAnd(a: Any?, b: Any?): Int
+
+@JsIntrinsic
+internal fun jsBitOr(a: Any?, b: Any?): Int
+
+@JsIntrinsic
+internal fun jsBitXor(a: Any?, b: Any?): Int
+
+@JsIntrinsic
+internal fun jsBitNot(a: Any?): Int
+
+@JsIntrinsic
+internal fun jsBitShiftR(a: Any?, b: Any?): Int
+
+@JsIntrinsic
+internal fun jsBitShiftRU(a: Any?, b: Any?): Int
+
+@JsIntrinsic
+internal fun jsBitShiftL(a: Any?, b: Any?): Int
+
+@JsIntrinsic
+internal fun jsInstanceOfIntrinsic(a: Any?, b: Any?): Boolean
+
+@JsIntrinsic
+internal fun jsNewTarget(a: Any?): Any?
+
+@JsIntrinsic
+internal fun emptyObject(a: Any?): Any?
+
+@JsIntrinsic
+internal fun openInitializerBox(a: Any?, b: Any?): Any?
+
+@JsIntrinsic
+internal fun jsArrayLength(a: Any?): Any?
+
+@JsIntrinsic
+internal fun jsArrayGet(a: Any?, b: Any?): Any?
+
+@JsIntrinsic
+internal fun jsArraySet(a: Any?, b: Any?, c: Any?): Any?
+
+@JsIntrinsic
+internal fun arrayLiteral(a: Any?): Any?
+
+@JsIntrinsic
+internal fun int8Array(a: Any?): Any?
+
+@JsIntrinsic
+internal fun int16Array(a: Any?): Any?
+
+@JsIntrinsic
+internal fun int32Array(a: Any?): Any?
+
+@JsIntrinsic
+internal fun float32Array(a: Any?): Any?
+
+@JsIntrinsic
+internal fun float64Array(a: Any?): Any?
+
+@JsIntrinsic
+internal fun int8ArrayOf(a: Any?): Any?
+
+@JsIntrinsic
+internal fun int16ArrayOf(a: Any?): Any?
+
+@JsIntrinsic
+internal fun int32ArrayOf(a: Any?): Any?
+
+@JsIntrinsic
+internal fun float32ArrayOf(a: Any?): Any?
+
+@JsIntrinsic
+internal fun float64ArrayOf(a: Any?): Any?
+
+@JsIntrinsic
+internal fun objectCreate(): T
+
+@JsIntrinsic
+internal fun sharedBoxCreate(v: T?): dynamic
+
+@JsIntrinsic
+internal fun sharedBoxRead(box: dynamic): T?
+
+@JsIntrinsic
+internal fun sharedBoxWrite(box: dynamic, nv: T?)
+
+@JsIntrinsic
+internal fun jsUndefined(): Nothing?
+
+@JsIntrinsic
+internal fun DefaultType(): T
+
+@JsIntrinsic
+internal fun jsBind(receiver: Any?, target: Any?): Any?
+
+@JsIntrinsic
+internal fun slice(a: A): A
+
+@JsIntrinsic
+internal fun unreachable(): Nothing
+
+@JsIntrinsic
+@Suppress("REIFIED_TYPE_PARAMETER_NO_INLINE") // TODO: mark `inline` and skip in inliner
+internal fun jsClassIntrinsic(): JsClass
+
+// Returns true if the specified property is in the specified object or its prototype chain.
+@JsIntrinsic
+internal fun jsInIntrinsic(lhs: Any?, rhs: Any): Boolean
+
+@JsIntrinsic
+internal fun jsDelete(e: Any?)
\ No newline at end of file
diff --git a/libraries/stdlib/py/runtime/kotlinHacks.kt b/libraries/stdlib/py/runtime/kotlinHacks.kt
new file mode 100644
index 0000000000000..ceb39f289373b
--- /dev/null
+++ b/libraries/stdlib/py/runtime/kotlinHacks.kt
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+
+// File is a copy of stdlib/js/src/kotlin/kotlin.kt
+// TODO: Compile arrayPlusCollection
+// TODO: implement a copy of jsIsType for both JS backends
+
+@file:Suppress("UNUSED_PARAMETER", "NOTHING_TO_INLINE")
+
+package kotlin
+
+/**
+ * Returns an empty array of the specified type [T].
+ */
+inline fun emptyArray(): Array = js("[]")
+
+/**
+ * Creates a new instance of the [Lazy] that uses the specified initialization function [initializer].
+ */
+actual fun lazy(initializer: () -> T): Lazy = UnsafeLazyImpl(initializer)
+
+/**
+ * Creates a new instance of the [Lazy] that uses the specified initialization function [initializer].
+ *
+ * The [mode] parameter is ignored. */
+actual fun lazy(mode: LazyThreadSafetyMode, initializer: () -> T): Lazy = UnsafeLazyImpl(initializer)
+
+/**
+ * Creates a new instance of the [Lazy] that uses the specified initialization function [initializer].
+ *
+ * The [lock] parameter is ignored.
+ */
+actual fun lazy(lock: Any?, initializer: () -> T): Lazy = UnsafeLazyImpl(initializer)
+
+
+internal fun fillFrom(src: dynamic, dst: dynamic): dynamic {
+ val srcLen: Int = src.length
+ val dstLen: Int = dst.length
+ var index: Int = 0
+ val arr = dst.unsafeCast>()
+ while (index < srcLen && index < dstLen) arr[index] = src[index++]
+ return dst
+}
+
+
+internal fun arrayCopyResize(source: dynamic, newSize: Int, defaultValue: Any?): dynamic {
+ val result = source.slice(0, newSize).unsafeCast>()
+ copyArrayType(source, result)
+ var index: Int = source.length
+ if (newSize > index) {
+ result.asDynamic().length = newSize
+ while (index < newSize) result[index++] = defaultValue
+ }
+ return result
+}
+
+internal fun arrayPlusCollection(array: dynamic, collection: Collection): dynamic {
+ val result = array.slice().unsafeCast>()
+ result.asDynamic().length = result.size + collection.size
+ copyArrayType(array, result)
+ var index: Int = array.length
+ for (element in collection) result[index++] = element
+ return result
+}
+
+internal inline fun copyArrayType(from: dynamic, to: dynamic) {
+ if (from.`$type$` !== undefined) {
+ to.`$type$` = from.`$type$`
+ }
+}
diff --git a/libraries/stdlib/py/runtime/kotlinJsHacks.kt b/libraries/stdlib/py/runtime/kotlinJsHacks.kt
new file mode 100644
index 0000000000000..c4d6699ffb6c7
--- /dev/null
+++ b/libraries/stdlib/py/runtime/kotlinJsHacks.kt
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+package kotlin.js
+
+@PublishedApi
+internal fun > enumValuesIntrinsic(): Array =
+ throw IllegalStateException("Should be replaced by compiler")
+
+@PublishedApi
+internal fun > enumValueOfIntrinsic(@Suppress("UNUSED_PARAMETER") name: String): T =
+ throw IllegalStateException("Should be replaced by compiler")
+
+@PublishedApi
+internal fun safePropertyGet(self: dynamic, getterName: String, propName: String): dynamic {
+ val getter = self[getterName]
+ return if (getter != null) getter.call(self) else self[propName]
+}
+
+@PublishedApi
+internal fun safePropertySet(self: dynamic, setterName: String, propName: String, value: dynamic) {
+ val setter = self[setterName]
+ if (setter != null) setter.call(self, value) else self[propName] = value
+}
+
+/**
+ * Implements annotated function in JavaScript.
+ * [code] string must contain JS expression that evaluates to JS function with signature that matches annotated kotlin function
+ *
+ * For example, a function that adds two Doubles:
+ *
+ * @JsFun("(x, y) => x + y")
+ * fun jsAdd(x: Double, y: Double): Double =
+ * error("...")
+ *
+ * Code gets inserted as is without syntax verification.
+ */
+@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER)
+internal annotation class JsFun(val code: String)
\ No newline at end of file
diff --git a/libraries/stdlib/py/runtime/long.kt b/libraries/stdlib/py/runtime/long.kt
new file mode 100644
index 0000000000000..0f4f45c891747
--- /dev/null
+++ b/libraries/stdlib/py/runtime/long.kt
@@ -0,0 +1,291 @@
+/*
+ * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+@file:Suppress("NOTHING_TO_INLINE")
+
+package kotlin
+
+/**
+ * Represents a 64-bit signed integer.
+ */
+class Long internal constructor(
+ internal val low: Int,
+ internal val high: Int
+) : Number(), Comparable {
+
+ companion object {
+ /**
+ * A constant holding the minimum value an instance of Long can have.
+ */
+ const val MIN_VALUE: Long = -9223372036854775807L - 1L
+
+ /**
+ * A constant holding the maximum value an instance of Long can have.
+ */
+ const val MAX_VALUE: Long = 9223372036854775807L
+
+ /**
+ * The number of bytes used to represent an instance of Long in a binary form.
+ */
+ @SinceKotlin("1.3")
+ const val SIZE_BYTES: Int = 8
+
+ /**
+ * The number of bits used to represent an instance of Long in a binary form.
+ */
+ @SinceKotlin("1.3")
+ const val SIZE_BITS: Int = 64
+ }
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ inline operator fun compareTo(other: Byte): Int = compareTo(other.toLong())
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ inline operator fun compareTo(other: Short): Int = compareTo(other.toLong())
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ inline operator fun compareTo(other: Int): Int = compareTo(other.toLong())
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ override operator fun compareTo(other: Long): Int = compare(other)
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ inline operator fun compareTo(other: Float): Int = toFloat().compareTo(other)
+
+ /**
+ * Compares this value with the specified value for order.
+ * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
+ * or a positive number if it's greater than other.
+ */
+ inline operator fun compareTo(other: Double): Int = toDouble().compareTo(other)
+
+ /** Adds the other value to this value. */
+ inline operator fun plus(other: Byte): Long = plus(other.toLong())
+
+ /** Adds the other value to this value. */
+ inline operator fun plus(other: Short): Long = plus(other.toLong())
+
+ /** Adds the other value to this value. */
+ inline operator fun plus(other: Int): Long = plus(other.toLong())
+
+ /** Adds the other value to this value. */
+ operator fun plus(other: Long): Long = add(other)
+
+ /** Adds the other value to this value. */
+ inline operator fun plus(other: Float): Float = toFloat() + other
+
+ /** Adds the other value to this value. */
+ inline operator fun plus(other: Double): Double = toDouble() + other
+
+ /** Subtracts the other value from this value. */
+ inline operator fun minus(other: Byte): Long = minus(other.toLong())
+
+ /** Subtracts the other value from this value. */
+ inline operator fun minus(other: Short): Long = minus(other.toLong())
+
+ /** Subtracts the other value from this value. */
+ inline operator fun minus(other: Int): Long = minus(other.toLong())
+
+ /** Subtracts the other value from this value. */
+ operator fun minus(other: Long): Long = subtract(other)
+
+ /** Subtracts the other value from this value. */
+ inline operator fun minus(other: Float): Float = toFloat() - other
+
+ /** Subtracts the other value from this value. */
+ inline operator fun minus(other: Double): Double = toDouble() - other
+
+ /** Multiplies this value by the other value. */
+ inline operator fun times(other: Byte): Long = times(other.toLong())
+
+ /** Multiplies this value by the other value. */
+ inline operator fun times(other: Short): Long = times(other.toLong())
+
+ /** Multiplies this value by the other value. */
+ inline operator fun times(other: Int): Long = times(other.toLong())
+
+ /** Multiplies this value by the other value. */
+ operator fun times(other: Long): Long = multiply(other)
+
+ /** Multiplies this value by the other value. */
+ inline operator fun times(other: Float): Float = toFloat() * other
+
+ /** Multiplies this value by the other value. */
+ inline operator fun times(other: Double): Double = toDouble() * other
+
+ /** Divides this value by the other value, truncating the result to an integer that is closer to zero. */
+ inline operator fun div(other: Byte): Long = div(other.toLong())
+
+ /** Divides this value by the other value, truncating the result to an integer that is closer to zero. */
+ inline operator fun div(other: Short): Long = div(other.toLong())
+
+ /** Divides this value by the other value, truncating the result to an integer that is closer to zero. */
+ inline operator fun div(other: Int): Long = div(other.toLong())
+
+ /** Divides this value by the other value, truncating the result to an integer that is closer to zero. */
+ operator fun div(other: Long): Long = divide(other)
+
+ /** Divides this value by the other value. */
+ inline operator fun div(other: Float): Float = toFloat() / other
+
+ /** Divides this value by the other value. */
+ inline operator fun div(other: Double): Double = toDouble() / other
+
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ inline operator fun rem(other: Byte): Long = rem(other.toLong())
+
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ inline operator fun rem(other: Short): Long = rem(other.toLong())
+
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ inline operator fun rem(other: Int): Long = rem(other.toLong())
+
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ operator fun rem(other: Long): Long = modulo(other)
+
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ inline operator fun rem(other: Float): Float = toFloat() % other
+
+ /**
+ * Calculates the remainder of truncating division of this value by the other value.
+ *
+ * The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
+ */
+ @SinceKotlin("1.1")
+ inline operator fun rem(other: Double): Double = toDouble() % other
+
+ /**
+ * Returns this value incremented by one.
+ *
+ * @sample samples.misc.Builtins.inc
+ */
+ operator fun inc(): Long = this + 1L
+
+ /**
+ * Returns this value decremented by one.
+ *
+ * @sample samples.misc.Builtins.dec
+ */
+ operator fun dec(): Long = this - 1L
+
+ /** Returns this value. */
+ inline operator fun unaryPlus(): Long = this
+
+ /** Returns the negative of this value. */
+ operator fun unaryMinus(): Long = inv() + 1L
+
+ /** Creates a range from this value to the specified [other] value. */
+ operator fun rangeTo(other: Byte): LongRange = rangeTo(other.toLong())
+
+ /** Creates a range from this value to the specified [other] value. */
+ operator fun rangeTo(other: Short): LongRange = rangeTo(other.toLong())
+
+ /** Creates a range from this value to the specified [other] value. */
+ operator fun rangeTo(other: Int): LongRange = rangeTo(other.toLong())
+
+ /** Creates a range from this value to the specified [other] value. */
+ operator fun rangeTo(other: Long): LongRange = LongRange(this, other)
+
+ /**
+ * Shifts this value left by the [bitCount] number of bits.
+ *
+ * Note that only the six lowest-order bits of the [bitCount] are used as the shift distance.
+ * The shift distance actually used is therefore always in the range `0..63`.
+ */
+ infix fun shl(bitCount: Int): Long = shiftLeft(bitCount)
+
+ /**
+ * Shifts this value right by the [bitCount] number of bits, filling the leftmost bits with copies of the sign bit.
+ *
+ * Note that only the six lowest-order bits of the [bitCount] are used as the shift distance.
+ * The shift distance actually used is therefore always in the range `0..63`.
+ */
+ infix fun shr(bitCount: Int): Long = shiftRight(bitCount)
+
+ /**
+ * Shifts this value right by the [bitCount] number of bits, filling the leftmost bits with zeros.
+ *
+ * Note that only the six lowest-order bits of the [bitCount] are used as the shift distance.
+ * The shift distance actually used is therefore always in the range `0..63`.
+ */
+ infix fun ushr(bitCount: Int): Long = shiftRightUnsigned(bitCount)
+
+ /** Performs a bitwise AND operation between the two values. */
+ infix fun and(other: Long): Long = Long(low and other.low, high and other.high)
+
+ /** Performs a bitwise OR operation between the two values. */
+ infix fun or(other: Long): Long = Long(low or other.low, high or other.high)
+
+ /** Performs a bitwise XOR operation between the two values. */
+ infix fun xor(other: Long): Long = Long(low xor other.low, high xor other.high)
+
+ /** Inverts the bits in this value. */
+ fun inv(): Long = Long(low.inv(), high.inv())
+
+ override fun toByte(): Byte = low.toByte()
+ @Deprecated("Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", ReplaceWith("this.toInt().toChar()"))
+ @DeprecatedSinceKotlin(warningSince = "1.5")
+ override fun toChar(): Char = low.toChar()
+ override fun toShort(): Short = low.toShort()
+ override fun toInt(): Int = low
+ override fun toLong(): Long = this
+ override fun toFloat(): Float = toDouble().toFloat()
+ override fun toDouble(): Double = toNumber()
+
+ // This method is used by `toString()`
+ @JsName("valueOf")
+ internal fun valueOf() = toDouble()
+
+ override fun equals(other: Any?): Boolean = other is Long && equalsLong(other)
+
+ override fun hashCode(): Int = hashCode(this)
+
+ override fun toString(): String = this.toStringImpl(radix = 10)
+}
\ No newline at end of file
diff --git a/libraries/stdlib/py/runtime/longjs.kt b/libraries/stdlib/py/runtime/longjs.kt
new file mode 100644
index 0000000000000..7d251e6cdee78
--- /dev/null
+++ b/libraries/stdlib/py/runtime/longjs.kt
@@ -0,0 +1,388 @@
+/*
+ * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+// Copyright 2009 The Closure Library Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS-IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+
+package kotlin
+
+internal fun Long.toNumber() = high * TWO_PWR_32_DBL_ + getLowBitsUnsigned()
+
+internal fun Long.getLowBitsUnsigned() = if (low >= 0) low.toDouble() else TWO_PWR_32_DBL_ + low
+
+internal fun hashCode(l: Long) = l.low xor l.high
+
+internal fun Long.toStringImpl(radix: Int): String {
+ if (radix < 2 || 36 < radix) {
+ throw Exception("radix out of range: $radix")
+ }
+
+ if (isZero()) {
+ return "0"
+ }
+
+ if (isNegative()) {
+ if (equalsLong(MIN_VALUE)) {
+ // We need to change the Long value before it can be negated, so we remove
+ // the bottom-most digit in this base and then recurse to do the rest.
+ val radixLong = fromInt(radix)
+ val div = div(radixLong)
+ val rem = div.multiply(radixLong).subtract(this).toInt()
+ // Using rem.asDynamic() to break dependency on "kotlin.text" package
+ return div.toStringImpl(radix) + rem.asDynamic().toString(radix).unsafeCast()
+ } else {
+ return "-${negate().toStringImpl(radix)}"
+ }
+ }
+
+ // Do several (6) digits each time through the loop, so as to
+ // minimize the calls to the very expensive emulated div.
+ val radixToPower = fromNumber(JsMath.pow(radix.toDouble(), 6.0))
+
+ var rem = this
+ var result = ""
+ while (true) {
+ val remDiv = rem.div(radixToPower)
+ val intval = rem.subtract(remDiv.multiply(radixToPower)).toInt()
+ var digits = intval.asDynamic().toString(radix).unsafeCast()
+
+ rem = remDiv
+ if (rem.isZero()) {
+ return digits + result
+ } else {
+ while (digits.length < 6) {
+ digits = "0" + digits
+ }
+ result = digits + result
+ }
+ }
+}
+
+internal fun Long.negate() = unaryMinus()
+
+internal fun Long.isZero() = high == 0 && low == 0
+
+internal fun Long.isNegative() = high < 0
+
+internal fun Long.isOdd() = low and 1 == 1
+
+internal fun Long.equalsLong(other: Long) = high == other.high && low == other.low
+
+internal fun Long.lessThan(other: Long) = compare(other) < 0
+
+internal fun Long.lessThanOrEqual(other: Long) = compare(other) <= 0
+
+internal fun Long.greaterThan(other: Long) = compare(other) > 0
+
+internal fun Long.greaterThanOrEqual(other: Long) = compare(other) >= 0
+
+internal fun Long.compare(other: Long): Int {
+ if (equalsLong(other)) {
+ return 0
+ }
+
+ val thisNeg = isNegative()
+ val otherNeg = other.isNegative()
+
+ return when {
+ thisNeg && !otherNeg -> -1
+ !thisNeg && otherNeg -> 1
+ // at this point, the signs are the same, so subtraction will not overflow
+ subtract(other).isNegative() -> -1
+ else -> 1
+ }
+}
+
+internal fun Long.add(other: Long): Long {
+ // Divide each number into 4 chunks of 16 bits, and then sum the chunks.
+
+ val a48 = high ushr 16
+ val a32 = high and 0xFFFF
+ val a16 = low ushr 16
+ val a00 = low and 0xFFFF
+
+ val b48 = other.high ushr 16
+ val b32 = other.high and 0xFFFF
+ val b16 = other.low ushr 16
+ val b00 = other.low and 0xFFFF
+
+ var c48 = 0
+ var c32 = 0
+ var c16 = 0
+ var c00 = 0
+ c00 += a00 + b00
+ c16 += c00 ushr 16
+ c00 = c00 and 0xFFFF
+ c16 += a16 + b16
+ c32 += c16 ushr 16
+ c16 = c16 and 0xFFFF
+ c32 += a32 + b32
+ c48 += c32 ushr 16
+ c32 = c32 and 0xFFFF
+ c48 += a48 + b48
+ c48 = c48 and 0xFFFF
+ return Long((c16 shl 16) or c00, (c48 shl 16) or c32)
+}
+
+internal fun Long.subtract(other: Long) = add(other.unaryMinus())
+
+internal fun Long.multiply(other: Long): Long {
+ if (isZero()) {
+ return ZERO
+ } else if (other.isZero()) {
+ return ZERO
+ }
+
+ if (equalsLong(MIN_VALUE)) {
+ return if (other.isOdd()) MIN_VALUE else ZERO
+ } else if (other.equalsLong(MIN_VALUE)) {
+ return if (isOdd()) MIN_VALUE else ZERO
+ }
+
+ if (isNegative()) {
+ return if (other.isNegative()) {
+ negate().multiply(other.negate())
+ } else {
+ negate().multiply(other).negate()
+ }
+ } else if (other.isNegative()) {
+ return multiply(other.negate()).negate()
+ }
+
+ // If both longs are small, use float multiplication
+ if (lessThan(TWO_PWR_24_) && other.lessThan(TWO_PWR_24_)) {
+ return fromNumber(toNumber() * other.toNumber())
+ }
+
+ // Divide each long into 4 chunks of 16 bits, and then add up 4x4 products.
+ // We can skip products that would overflow.
+
+ val a48 = high ushr 16
+ val a32 = high and 0xFFFF
+ val a16 = low ushr 16
+ val a00 = low and 0xFFFF
+
+ val b48 = other.high ushr 16
+ val b32 = other.high and 0xFFFF
+ val b16 = other.low ushr 16
+ val b00 = other.low and 0xFFFF
+
+ var c48 = 0
+ var c32 = 0
+ var c16 = 0
+ var c00 = 0
+ c00 += a00 * b00
+ c16 += c00 ushr 16
+ c00 = c00 and 0xFFFF
+ c16 += a16 * b00
+ c32 += c16 ushr 16
+ c16 = c16 and 0xFFFF
+ c16 += a00 * b16
+ c32 += c16 ushr 16
+ c16 = c16 and 0xFFFF
+ c32 += a32 * b00
+ c48 += c32 ushr 16
+ c32 = c32 and 0xFFFF
+ c32 += a16 * b16
+ c48 += c32 ushr 16
+ c32 = c32 and 0xFFFF
+ c32 += a00 * b32
+ c48 += c32 ushr 16
+ c32 = c32 and 0xFFFF
+ c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48
+ c48 = c48 and 0xFFFF
+ return Long(c16 shl 16 or c00, c48 shl 16 or c32)
+}
+
+internal fun Long.divide(other: Long): Long {
+ if (other.isZero()) {
+ throw Exception("division by zero")
+ } else if (isZero()) {
+ return ZERO
+ }
+
+ if (equalsLong(MIN_VALUE)) {
+ if (other.equalsLong(ONE) || other.equalsLong(NEG_ONE)) {
+ return MIN_VALUE // recall that -MIN_VALUE == MIN_VALUE
+ } else if (other.equalsLong(MIN_VALUE)) {
+ return ONE
+ } else {
+ // At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|.
+ val halfThis = shiftRight(1)
+ val approx = halfThis.div(other).shiftLeft(1)
+ if (approx.equalsLong(ZERO)) {
+ return if (other.isNegative()) ONE else NEG_ONE
+ } else {
+ val rem = subtract(other.multiply(approx))
+ return approx.add(rem.div(other))
+ }
+ }
+ } else if (other.equalsLong(MIN_VALUE)) {
+ return ZERO
+ }
+
+ if (isNegative()) {
+ return if (other.isNegative()) {
+ negate().div(other.negate())
+ } else {
+ negate().div(other).negate()
+ }
+ } else if (other.isNegative()) {
+ return div(other.negate()).negate()
+ }
+
+ // Repeat the following until the remainder is less than other: find a
+ // floating-point that approximates remainder / other *from below*, add this
+ // into the result, and subtract it from the remainder. It is critical that
+ // the approximate value is less than or equal to the real value so that the
+ // remainder never becomes negative.
+ var res = ZERO
+ var rem = this
+ while (rem.greaterThanOrEqual(other)) {
+ // Approximate the result of division. This may be a little greater or
+ // smaller than the actual value.
+ val approxDouble = rem.toNumber() / other.toNumber()
+ var approx2 = JsMath.max(1.0, JsMath.floor(approxDouble))
+
+ // We will tweak the approximate result by changing it in the 48-th digit or
+ // the smallest non-fractional digit, whichever is larger.
+ val log2 = JsMath.ceil(JsMath.log(approx2) / JsMath.LN2)
+ val delta = if (log2 <= 48) 1.0 else JsMath.pow(2.0, log2 - 48)
+
+ // Decrease the approximation until it is smaller than the remainder. Note
+ // that if it is too large, the product overflows and is negative.
+ var approxRes = fromNumber(approx2)
+ var approxRem = approxRes.multiply(other)
+ while (approxRem.isNegative() || approxRem.greaterThan(rem)) {
+ approx2 -= delta
+ approxRes = fromNumber(approx2)
+ approxRem = approxRes.multiply(other)
+ }
+
+ // We know the answer can't be zero... and actually, zero would cause
+ // infinite recursion since we would make no progress.
+ if (approxRes.isZero()) {
+ approxRes = ONE
+ }
+
+ res = res.add(approxRes)
+ rem = rem.subtract(approxRem)
+ }
+ return res
+}
+
+internal fun Long.modulo(other: Long) = subtract(div(other).multiply(other))
+
+internal fun Long.shiftLeft(numBits: Int): Long {
+ @Suppress("NAME_SHADOWING")
+ val numBits = numBits and 63
+ if (numBits == 0) {
+ return this
+ } else {
+ if (numBits < 32) {
+ return Long(low shl numBits, (high shl numBits) or (low ushr (32 - numBits)))
+ } else {
+ return Long(0, low shl (numBits - 32))
+ }
+ }
+}
+
+internal fun Long.shiftRight(numBits: Int): Long {
+ @Suppress("NAME_SHADOWING")
+ val numBits = numBits and 63
+ if (numBits == 0) {
+ return this
+ } else {
+ if (numBits < 32) {
+ return Long((low ushr numBits) or (high shl (32 - numBits)), high shr numBits)
+ } else {
+ return Long(high shr (numBits - 32), if (high >= 0) 0 else -1)
+ }
+ }
+}
+
+internal fun Long.shiftRightUnsigned(numBits: Int): Long {
+ @Suppress("NAME_SHADOWING")
+ val numBits = numBits and 63
+ if (numBits == 0) {
+ return this
+ } else {
+ if (numBits < 32) {
+ return Long((low ushr numBits) or (high shl (32 - numBits)), high ushr numBits)
+ } else return if (numBits == 32) {
+ Long(high, 0)
+ } else {
+ Long(high ushr (numBits - 32), 0)
+ }
+ }
+}
+
+/**
+ * Returns a Long representing the given (32-bit) integer value.
+ * @param {number} value The 32-bit integer in question.
+ * @return {!Kotlin.Long} The corresponding Long value.
+ */
+// TODO: cache
+internal fun fromInt(value: Int) = Long(value, if (value < 0) -1 else 0)
+
+/**
+ * Converts this [Double] value to [Long].
+ * The fractional part, if any, is rounded down towards zero.
+ * Returns zero if this `Double` value is `NaN`, [Long.MIN_VALUE] if it's less than `Long.MIN_VALUE`,
+ * [Long.MAX_VALUE] if it's bigger than `Long.MAX_VALUE`.
+ */
+internal fun fromNumber(value: Double): Long {
+ if (value.isNaN()) {
+ return ZERO
+ } else if (value <= -TWO_PWR_63_DBL_) {
+ return MIN_VALUE
+ } else if (value + 1 >= TWO_PWR_63_DBL_) {
+ return MAX_VALUE
+ } else if (value < 0) {
+ return fromNumber(-value).negate()
+ } else {
+ val twoPwr32 = TWO_PWR_32_DBL_
+ return Long(
+ jsBitwiseOr(value.rem(twoPwr32), 0),
+ jsBitwiseOr(value / twoPwr32, 0)
+ )
+ }
+}
+
+private const val TWO_PWR_16_DBL_ = (1 shl 16).toDouble()
+
+private const val TWO_PWR_24_DBL_ = (1 shl 24).toDouble()
+
+//private val TWO_PWR_32_DBL_ = TWO_PWR_16_DBL_ * TWO_PWR_16_DBL_
+private const val TWO_PWR_32_DBL_ = (1 shl 16).toDouble() * (1 shl 16).toDouble()
+
+//private val TWO_PWR_64_DBL_ = TWO_PWR_32_DBL_ * TWO_PWR_32_DBL_
+private const val TWO_PWR_64_DBL_ = ((1 shl 16).toDouble() * (1 shl 16).toDouble()) * ((1 shl 16).toDouble() * (1 shl 16).toDouble())
+
+//private val TWO_PWR_63_DBL_ = TWO_PWR_64_DBL_ / 2
+private const val TWO_PWR_63_DBL_ = (((1 shl 16).toDouble() * (1 shl 16).toDouble()) * ((1 shl 16).toDouble() * (1 shl 16).toDouble())) / 2
+
+private val ZERO = fromInt(0)
+
+private val ONE = fromInt(1)
+
+private val NEG_ONE = fromInt(-1)
+
+private val MAX_VALUE = Long(-1, -1 ushr 1)
+
+private val MIN_VALUE = Long(0, 1 shl 31)
+
+private val TWO_PWR_24_ = fromInt(1 shl 24)
+
+
diff --git a/libraries/stdlib/py/runtime/misc.kt b/libraries/stdlib/py/runtime/misc.kt
new file mode 100644
index 0000000000000..3eb9122d156e7
--- /dev/null
+++ b/libraries/stdlib/py/runtime/misc.kt
@@ -0,0 +1,13 @@
+/*
+ * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
+ * that can be found in the license/LICENSE.txt file.
+ */
+
+package kotlin.js
+
+// TODO: Polyfill
+internal fun imul(a_local: Int, b_local: Int): Int {
+ val lhs = jsBitwiseAnd(a_local, js("0xffff0000")).toDouble() * jsBitwiseAnd(b_local, 0xffff).toDouble()
+ val rhs = jsBitwiseAnd(a_local, 0xffff).toDouble() * b_local.toDouble()
+ return jsBitwiseOr(lhs + rhs, 0)
+}
diff --git a/libraries/stdlib/py/runtime/noPackageHacks.kt b/libraries/stdlib/py/runtime/noPackageHacks.kt
new file mode 100644
index 0000000000000..b89e5f180a273
--- /dev/null
+++ b/libraries/stdlib/py/runtime/noPackageHacks.kt
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+/** Concat regular Array's and TypedArray's into an Array.
+ */
+@PublishedApi
+internal fun arrayConcat(vararg args: T): T {
+ val len = args.size
+ val typed = js("Array(len)").unsafeCast>()
+ for (i in 0 .. (len - 1)) {
+ val arr = args[i]
+ if (arr !is Array<*>) {
+ typed[i] = js("[]").slice.call(arr)
+ } else {
+ typed[i] = arr
+ }
+ }
+ return js("[]").concat.apply(js("[]"), typed)
+}
+
+/** Concat primitive arrays. Main use: prepare vararg arguments.
+ */
+@PublishedApi
+internal fun primitiveArrayConcat(vararg args: T): T {
+ var size_local = 0
+ for (i in 0 .. (args.size - 1)) {
+ size_local += args[i].unsafeCast>().size
+ }
+ val a = args[0]
+ val result = js("new a.constructor(size_local)").unsafeCast>()
+ if (a.asDynamic().`$type$` != null) {
+ withType(a.asDynamic().`$type$`, result)
+ }
+
+ size_local = 0
+ for (i in 0 .. (args.size - 1)) {
+ val arr = args[i].unsafeCast>()
+ for (j in 0 .. (arr.size - 1)) {
+ result[size_local++] = arr[j]
+ }
+ }
+ return result.unsafeCast()
+}
+
+internal fun taggedArrayCopy(array: dynamic): T {
+ val res = array.slice()
+ res.`$type$` = array.`$type$`
+ return res.unsafeCast()
+}
+
+@PublishedApi
+@Suppress("NOTHING_TO_INLINE")
+internal inline fun withType(type: String, array: dynamic): dynamic {
+ array.`$type$` = type
+ return array
+}
diff --git a/libraries/stdlib/py/runtime/numberConversion.kt b/libraries/stdlib/py/runtime/numberConversion.kt
new file mode 100644
index 0000000000000..6d8878684b6eb
--- /dev/null
+++ b/libraries/stdlib/py/runtime/numberConversion.kt
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+package kotlin.js
+
+internal fun numberToByte(a: dynamic): Byte = toByte(numberToInt(a))
+
+internal fun numberToDouble(@Suppress("UNUSED_PARAMETER") a: dynamic): Double = js("+a").unsafeCast()
+
+internal fun numberToInt(a: dynamic): Int = if (a is Long) a.toInt() else doubleToInt(a)
+
+internal fun numberToShort(a: dynamic): Short = toShort(numberToInt(a))
+
+// << and >> shifts are used to preserve sign of the number
+internal fun toByte(@Suppress("UNUSED_PARAMETER") a: dynamic): Byte = js("a << 24 >> 24").unsafeCast()
+internal fun toShort(@Suppress("UNUSED_PARAMETER") a: dynamic): Short = js("a << 16 >> 16").unsafeCast()
+
+internal fun numberToLong(a: dynamic): Long = if (a is Long) a else fromNumber(a)
+
+internal fun toLong(a: dynamic): Long = fromInt(a)
+
+internal fun doubleToInt(a: Double): Int = when {
+ a > 2147483647 -> 2147483647
+ a < -2147483648 -> -2147483648
+ else -> jsBitwiseOr(a, 0)
+}
+
+internal fun numberToChar(a: dynamic) = Char(numberToInt(a).toUShort())
\ No newline at end of file
diff --git a/libraries/stdlib/py/runtime/rangeTo.kt b/libraries/stdlib/py/runtime/rangeTo.kt
new file mode 100644
index 0000000000000..e197fdb36d8db
--- /dev/null
+++ b/libraries/stdlib/py/runtime/rangeTo.kt
@@ -0,0 +1,15 @@
+/*
+ * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+package kotlin.js
+
+// Creates IntRange for {Byte, Short, Int}.rangeTo(x: {Byte, Short, Int})
+internal fun numberRangeToNumber(start: dynamic, endInclusive: dynamic) =
+ IntRange(start, endInclusive)
+
+// Create LongRange for {Byte, Short, Int}.rangeTo(x: Long)
+// Long.rangeTo(x: *) should be implemented in Long class
+internal fun numberRangeToLong(start: dynamic, endInclusive: dynamic) =
+ LongRange(numberToLong(start), endInclusive)
diff --git a/libraries/stdlib/py/runtime/reflectRuntime.kt b/libraries/stdlib/py/runtime/reflectRuntime.kt
new file mode 100644
index 0000000000000..9b8fb4b76f96e
--- /dev/null
+++ b/libraries/stdlib/py/runtime/reflectRuntime.kt
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+package kotlin.js
+
+import kotlin.reflect.KProperty
+
+internal fun getPropertyCallableRef(name: String, paramCount: Int, type: dynamic, getter: dynamic, setter: dynamic): KProperty<*> {
+ getter.get = getter
+ getter.set = setter
+ getter.callableName = name
+ return getPropertyRefClass(getter, getKPropMetadata(paramCount, setter, type)).unsafeCast>()
+}
+
+internal fun getLocalDelegateReference(name: String, type: dynamic, mutable: Boolean, lambda: dynamic): KProperty<*> {
+ return getPropertyCallableRef(name, 0, type, lambda, if (mutable) lambda else null)
+}
+
+private fun getPropertyRefClass(obj: dynamic, metadata: dynamic): dynamic {
+ obj.`$metadata$` = metadata
+ obj.constructor = obj
+ return obj
+}
+
+private fun getKPropMetadata(paramCount: Int, setter: Any?, type: dynamic): dynamic {
+ val mdata = propertyRefClassMetadataCache[paramCount][if (setter == null) 0 else 1]
+ if (mdata.interfaces.length == 0) {
+ mdata.interfaces.push(type)
+ }
+
+ return mdata
+}
+
+@Suppress("NOTHING_TO_INLINE")
+private inline fun metadataObject(): dynamic = js("{ kind: 'class', interfaces: [] }")
+
+private val propertyRefClassMetadataCache: Array> = arrayOf>(
+ // immutable , mutable
+ arrayOf(metadataObject(), metadataObject()), // 0
+ arrayOf(metadataObject(), metadataObject()), // 1
+ arrayOf(metadataObject(), metadataObject()) // 2
+)
+
diff --git a/libraries/stdlib/py/runtime/typeCheckUtils.kt b/libraries/stdlib/py/runtime/typeCheckUtils.kt
new file mode 100644
index 0000000000000..614e2fdb5c896
--- /dev/null
+++ b/libraries/stdlib/py/runtime/typeCheckUtils.kt
@@ -0,0 +1,189 @@
+/*
+ * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+package kotlin.js
+
+private external interface Metadata {
+ val interfaces: Array
+ val suspendArity: Array?
+}
+
+private external interface Ctor {
+ val `$metadata$`: Metadata?
+ val prototype: Ctor?
+}
+
+private fun isInterfaceImpl(ctor: Ctor, iface: dynamic): Boolean {
+ if (ctor === iface) return true
+
+ val metadata = ctor.`$metadata$`
+ if (metadata != null) {
+ val interfaces = metadata.interfaces
+ for (i in interfaces) {
+ if (isInterfaceImpl(i, iface)) {
+ return true
+ }
+ }
+ }
+
+ val superPrototype = if (ctor.prototype != null) js("Object").getPrototypeOf(ctor.prototype) else null
+ val superConstructor: Ctor? = if (superPrototype != null) superPrototype.constructor else null
+ return superConstructor != null && isInterfaceImpl(superConstructor, iface)
+}
+
+internal fun isInterface(obj: dynamic, iface: dynamic): Boolean {
+ val ctor = obj.constructor ?: return false
+
+ return isInterfaceImpl(ctor, iface)
+}
+
+/*
+
+internal interface ClassMetadata {
+ val simpleName: String
+ val interfaces: Array
+}
+
+// TODO: replace `isInterface` with the following
+public fun isInterface(ctor: dynamic, IType: dynamic): Boolean {
+ if (ctor === IType) return true
+
+ val metadata = ctor.`$metadata$`.unsafeCast()
+
+ if (metadata !== null) {
+ val interfaces = metadata.interfaces
+ for (i in interfaces) {
+ if (isInterface(i, IType)) {
+ return true
+ }
+ }
+ }
+
+ var superPrototype = ctor.prototype
+ if (superPrototype !== null) {
+ superPrototype = js("Object.getPrototypeOf(superPrototype)")
+ }
+
+ val superConstructor = if (superPrototype !== null) {
+ superPrototype.constructor
+ } else null
+
+ return superConstructor != null && isInterface(superConstructor, IType)
+}
+*/
+
+internal fun isSuspendFunction(obj: dynamic, arity: Int): Boolean {
+ if (jsTypeOf(obj) == "function") {
+ @Suppress("DEPRECATED_IDENTITY_EQUALS")
+ return obj.`$arity`.unsafeCast() === arity
+ }
+
+ if (jsTypeOf(obj) == "object" && jsIn("${'$'}metadata${'$'}", obj.constructor)) {
+ @Suppress("IMPLICIT_BOXING_IN_IDENTITY_EQUALS")
+ return obj.constructor.unsafeCast().`$metadata$`?.suspendArity?.let {
+ var result = false
+ for (item in it) {
+ if (arity == item) {
+ result = true
+ break
+ }
+ }
+ return result
+ } ?: false
+ }
+
+ return false
+}
+
+internal fun isObject(obj: dynamic): Boolean {
+ val objTypeOf = jsTypeOf(obj)
+
+ return when (objTypeOf) {
+ "string" -> true
+ "number" -> true
+ "boolean" -> true
+ "function" -> true
+ else -> jsInstanceOf(obj, js("Object"))
+ }
+}
+
+private fun isJsArray(obj: Any): Boolean {
+ return js("Array").isArray(obj).unsafeCast()
+}
+
+internal fun isArray(obj: Any): Boolean {
+ return isJsArray(obj) && !(obj.asDynamic().`$type$`)
+}
+
+internal fun isArrayish(o: dynamic) =
+ isJsArray(o) || js("ArrayBuffer").isView(o).unsafeCast()
+
+
+internal fun isChar(@Suppress("UNUSED_PARAMETER") c: Any): Boolean {
+ error("isChar is not implemented")
+}
+
+// TODO: Distinguish Boolean/Byte and Short/Char
+internal fun isBooleanArray(a: dynamic): Boolean = isJsArray(a) && a.`$type$` === "BooleanArray"
+internal fun isByteArray(a: dynamic): Boolean = jsInstanceOf(a, js("Int8Array"))
+internal fun isShortArray(a: dynamic): Boolean = jsInstanceOf(a, js("Int16Array"))
+internal fun isCharArray(a: dynamic): Boolean = isJsArray(a) && a.`$type$` === "CharArray"
+internal fun isIntArray(a: dynamic): Boolean = jsInstanceOf(a, js("Int32Array"))
+internal fun isFloatArray(a: dynamic): Boolean = jsInstanceOf(a, js("Float32Array"))
+internal fun isDoubleArray(a: dynamic): Boolean = jsInstanceOf(a, js("Float64Array"))
+internal fun isLongArray(a: dynamic): Boolean = isJsArray(a) && a.`$type$` === "LongArray"
+
+
+internal fun jsGetPrototypeOf(jsClass: dynamic) = js("Object").getPrototypeOf(jsClass)
+
+internal fun jsIsType(obj: dynamic, jsClass: dynamic): Boolean {
+ if (jsClass === js("Object")) {
+ return isObject(obj)
+ }
+
+ if (obj == null || jsClass == null || (jsTypeOf(obj) != "object" && jsTypeOf(obj) != "function")) {
+ return false
+ }
+
+ if (jsTypeOf(jsClass) == "function" && jsInstanceOf(obj, jsClass)) {
+ return true
+ }
+
+ var proto = jsGetPrototypeOf(jsClass)
+ var constructor = proto?.constructor
+ if (constructor != null && jsIn("${'$'}metadata${'$'}", constructor)) {
+ var metadata = constructor.`$metadata$`
+ if (metadata.kind === "object") {
+ return obj === jsClass
+ }
+ }
+
+ var klassMetadata = jsClass.`$metadata$`
+
+ // In WebKit (JavaScriptCore) for some interfaces from DOM typeof returns "object", nevertheless they can be used in RHS of instanceof
+ if (klassMetadata == null) {
+ return jsInstanceOf(obj, jsClass)
+ }
+
+ if (klassMetadata.kind === "interface" && obj.constructor != null) {
+ return isInterfaceImpl(obj.constructor, jsClass)
+ }
+
+ return false
+}
+
+internal fun isNumber(a: dynamic) = jsTypeOf(a) == "number" || a is Long
+
+internal fun isComparable(value: dynamic): Boolean {
+ var type = jsTypeOf(value)
+
+ return type == "string" ||
+ type == "boolean" ||
+ isNumber(value) ||
+ isInterface(value, Comparable::class.js)
+}
+
+internal fun isCharSequence(value: dynamic): Boolean =
+ jsTypeOf(value) == "string" || isInterface(value, CharSequence::class.js)
diff --git a/libraries/stdlib/py/src/generated/.gitattributes b/libraries/stdlib/py/src/generated/.gitattributes
new file mode 100644
index 0000000000000..d0496f1a2665d
--- /dev/null
+++ b/libraries/stdlib/py/src/generated/.gitattributes
@@ -0,0 +1 @@
+*.kt eol=lf
diff --git a/libraries/stdlib/py/src/generated/_ArraysJs.kt b/libraries/stdlib/py/src/generated/_ArraysJs.kt
new file mode 100644
index 0000000000000..c76f0f6b00223
--- /dev/null
+++ b/libraries/stdlib/py/src/generated/_ArraysJs.kt
@@ -0,0 +1,2188 @@
+/*
+ * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+package kotlin.collections
+
+//
+// NOTE: THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
+// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
+//
+
+import primitiveArrayConcat
+import withType
+
+/**
+ * Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
+ *
+ * @sample samples.collections.Collections.Elements.elementAt
+ */
+actual fun Array.elementAt(index: Int): T {
+ return elementAtOrElse(index) { throw IndexOutOfBoundsException("index: $index, size: $size}") }
+}
+
+/**
+ * Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
+ *
+ * @sample samples.collections.Collections.Elements.elementAt
+ */
+actual fun ByteArray.elementAt(index: Int): Byte {
+ return elementAtOrElse(index) { throw IndexOutOfBoundsException("index: $index, size: $size}") }
+}
+
+/**
+ * Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
+ *
+ * @sample samples.collections.Collections.Elements.elementAt
+ */
+actual fun ShortArray.elementAt(index: Int): Short {
+ return elementAtOrElse(index) { throw IndexOutOfBoundsException("index: $index, size: $size}") }
+}
+
+/**
+ * Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
+ *
+ * @sample samples.collections.Collections.Elements.elementAt
+ */
+actual fun IntArray.elementAt(index: Int): Int {
+ return elementAtOrElse(index) { throw IndexOutOfBoundsException("index: $index, size: $size}") }
+}
+
+/**
+ * Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
+ *
+ * @sample samples.collections.Collections.Elements.elementAt
+ */
+actual fun LongArray.elementAt(index: Int): Long {
+ return elementAtOrElse(index) { throw IndexOutOfBoundsException("index: $index, size: $size}") }
+}
+
+/**
+ * Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
+ *
+ * @sample samples.collections.Collections.Elements.elementAt
+ */
+actual fun FloatArray.elementAt(index: Int): Float {
+ return elementAtOrElse(index) { throw IndexOutOfBoundsException("index: $index, size: $size}") }
+}
+
+/**
+ * Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
+ *
+ * @sample samples.collections.Collections.Elements.elementAt
+ */
+actual fun DoubleArray.elementAt(index: Int): Double {
+ return elementAtOrElse(index) { throw IndexOutOfBoundsException("index: $index, size: $size}") }
+}
+
+/**
+ * Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
+ *
+ * @sample samples.collections.Collections.Elements.elementAt
+ */
+actual fun BooleanArray.elementAt(index: Int): Boolean {
+ return elementAtOrElse(index) { throw IndexOutOfBoundsException("index: $index, size: $size}") }
+}
+
+/**
+ * Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
+ *
+ * @sample samples.collections.Collections.Elements.elementAt
+ */
+actual fun CharArray.elementAt(index: Int): Char {
+ return elementAtOrElse(index) { throw IndexOutOfBoundsException("index: $index, size: $size}") }
+}
+
+/**
+ * Returns a [List] that wraps the original array.
+ */
+actual fun Array.asList(): List {
+ return ArrayList(this.unsafeCast>())
+}
+
+/**
+ * Returns a [List] that wraps the original array.
+ */
+@kotlin.internal.InlineOnly
+actual inline fun ByteArray.asList(): List {
+ return this.unsafeCast>().asList()
+}
+
+/**
+ * Returns a [List] that wraps the original array.
+ */
+@kotlin.internal.InlineOnly
+actual inline fun ShortArray.asList(): List {
+ return this.unsafeCast>().asList()
+}
+
+/**
+ * Returns a [List] that wraps the original array.
+ */
+@kotlin.internal.InlineOnly
+actual inline fun IntArray.asList(): List {
+ return this.unsafeCast>().asList()
+}
+
+/**
+ * Returns a [List] that wraps the original array.
+ */
+@kotlin.internal.InlineOnly
+actual inline fun LongArray.asList(): List {
+ return this.unsafeCast>().asList()
+}
+
+/**
+ * Returns a [List] that wraps the original array.
+ */
+@kotlin.internal.InlineOnly
+actual inline fun FloatArray.asList(): List {
+ return this.unsafeCast>().asList()
+}
+
+/**
+ * Returns a [List] that wraps the original array.
+ */
+@kotlin.internal.InlineOnly
+actual inline fun DoubleArray.asList(): List {
+ return this.unsafeCast>().asList()
+}
+
+/**
+ * Returns a [List] that wraps the original array.
+ */
+@kotlin.internal.InlineOnly
+actual inline fun BooleanArray.asList(): List {
+ return this.unsafeCast>().asList()
+}
+
+/**
+ * Returns a [List] that wraps the original array.
+ */
+actual fun CharArray.asList(): List {
+ return object : AbstractList(), RandomAccess {
+ override val size: Int get() = this@asList.size
+ override fun isEmpty(): Boolean = this@asList.isEmpty()
+ override fun contains(element: Char): Boolean = this@asList.contains(element)
+ override fun get(index: Int): Char {
+ AbstractList.checkElementIndex(index, size)
+ return this@asList[index]
+ }
+ override fun indexOf(element: Char): Int {
+ @Suppress("USELESS_CAST")
+ if ((element as Any?) !is Char) return -1
+ return this@asList.indexOf(element)
+ }
+ override fun lastIndexOf(element: Char): Int {
+ @Suppress("USELESS_CAST")
+ if ((element as Any?) !is Char) return -1
+ return this@asList.lastIndexOf(element)
+ }
+ }
+}
+
+/**
+ * Returns `true` if the two specified arrays are *deeply* equal to one another,
+ * i.e. contain the same number of the same elements in the same order.
+ *
+ * If two corresponding elements are nested arrays, they are also compared deeply.
+ * If any of arrays contains itself on any nesting level the behavior is undefined.
+ *
+ * The elements of other types are compared for equality with the [equals][Any.equals] function.
+ * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
+ */
+@SinceKotlin("1.1")
+@kotlin.internal.LowPriorityInOverloadResolution
+actual infix fun Array.contentDeepEquals(other: Array): Boolean {
+ return this.contentDeepEquals(other)
+}
+
+/**
+ * Returns `true` if the two specified arrays are *deeply* equal to one another,
+ * i.e. contain the same number of the same elements in the same order.
+ *
+ * The specified arrays are also considered deeply equal if both are `null`.
+ *
+ * If two corresponding elements are nested arrays, they are also compared deeply.
+ * If any of arrays contains itself on any nesting level the behavior is undefined.
+ *
+ * The elements of other types are compared for equality with the [equals][Any.equals] function.
+ * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
+ */
+@SinceKotlin("1.4")
+actual infix fun Array?.contentDeepEquals(other: Array?): Boolean {
+ return contentDeepEqualsImpl(other)
+}
+
+/**
+ * Returns a hash code based on the contents of this array as if it is [List].
+ * Nested arrays are treated as lists too.
+ *
+ * If any of arrays contains itself on any nesting level the behavior is undefined.
+ */
+@SinceKotlin("1.1")
+@kotlin.internal.LowPriorityInOverloadResolution
+actual fun Array.contentDeepHashCode(): Int {
+ return this.contentDeepHashCode()
+}
+
+/**
+ * Returns a hash code based on the contents of this array as if it is [List].
+ * Nested arrays are treated as lists too.
+ *
+ * If any of arrays contains itself on any nesting level the behavior is undefined.
+ */
+@SinceKotlin("1.4")
+actual fun Array?.contentDeepHashCode(): Int {
+ return contentDeepHashCodeInternal()
+}
+
+/**
+ * Returns a string representation of the contents of this array as if it is a [List].
+ * Nested arrays are treated as lists too.
+ *
+ * If any of arrays contains itself on any nesting level that reference
+ * is rendered as `"[...]"` to prevent recursion.
+ *
+ * @sample samples.collections.Arrays.ContentOperations.contentDeepToString
+ */
+@SinceKotlin("1.1")
+@kotlin.internal.LowPriorityInOverloadResolution
+actual fun Array.contentDeepToString(): String {
+ return this.contentDeepToString()
+}
+
+/**
+ * Returns a string representation of the contents of this array as if it is a [List].
+ * Nested arrays are treated as lists too.
+ *
+ * If any of arrays contains itself on any nesting level that reference
+ * is rendered as `"[...]"` to prevent recursion.
+ *
+ * @sample samples.collections.Arrays.ContentOperations.contentDeepToString
+ */
+@SinceKotlin("1.4")
+actual fun Array?.contentDeepToString(): String {
+ return contentDeepToStringImpl()
+}
+
+/**
+ * Returns `true` if the two specified arrays are *structurally* equal to one another,
+ * i.e. contain the same number of the same elements in the same order.
+ *
+ * The elements are compared for equality with the [equals][Any.equals] function.
+ * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
+ */
+@Deprecated("Use Kotlin compiler 1.4 to avoid deprecation warning.")
+@SinceKotlin("1.1")
+@DeprecatedSinceKotlin(hiddenSince = "1.4")
+actual infix fun Array.contentEquals(other: Array): Boolean {
+ return this.contentEquals(other)
+}
+
+/**
+ * Returns `true` if the two specified arrays are *structurally* equal to one another,
+ * i.e. contain the same number of the same elements in the same order.
+ *
+ * The elements are compared for equality with the [equals][Any.equals] function.
+ * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
+ */
+@Deprecated("Use Kotlin compiler 1.4 to avoid deprecation warning.")
+@SinceKotlin("1.1")
+@DeprecatedSinceKotlin(hiddenSince = "1.4")
+actual infix fun ByteArray.contentEquals(other: ByteArray): Boolean {
+ return this.contentEquals(other)
+}
+
+/**
+ * Returns `true` if the two specified arrays are *structurally* equal to one another,
+ * i.e. contain the same number of the same elements in the same order.
+ *
+ * The elements are compared for equality with the [equals][Any.equals] function.
+ * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
+ */
+@Deprecated("Use Kotlin compiler 1.4 to avoid deprecation warning.")
+@SinceKotlin("1.1")
+@DeprecatedSinceKotlin(hiddenSince = "1.4")
+actual infix fun ShortArray.contentEquals(other: ShortArray): Boolean {
+ return this.contentEquals(other)
+}
+
+/**
+ * Returns `true` if the two specified arrays are *structurally* equal to one another,
+ * i.e. contain the same number of the same elements in the same order.
+ *
+ * The elements are compared for equality with the [equals][Any.equals] function.
+ * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
+ */
+@Deprecated("Use Kotlin compiler 1.4 to avoid deprecation warning.")
+@SinceKotlin("1.1")
+@DeprecatedSinceKotlin(hiddenSince = "1.4")
+actual infix fun IntArray.contentEquals(other: IntArray): Boolean {
+ return this.contentEquals(other)
+}
+
+/**
+ * Returns `true` if the two specified arrays are *structurally* equal to one another,
+ * i.e. contain the same number of the same elements in the same order.
+ *
+ * The elements are compared for equality with the [equals][Any.equals] function.
+ * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
+ */
+@Deprecated("Use Kotlin compiler 1.4 to avoid deprecation warning.")
+@SinceKotlin("1.1")
+@DeprecatedSinceKotlin(hiddenSince = "1.4")
+actual infix fun LongArray.contentEquals(other: LongArray): Boolean {
+ return this.contentEquals(other)
+}
+
+/**
+ * Returns `true` if the two specified arrays are *structurally* equal to one another,
+ * i.e. contain the same number of the same elements in the same order.
+ *
+ * The elements are compared for equality with the [equals][Any.equals] function.
+ * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
+ */
+@Deprecated("Use Kotlin compiler 1.4 to avoid deprecation warning.")
+@SinceKotlin("1.1")
+@DeprecatedSinceKotlin(hiddenSince = "1.4")
+actual infix fun FloatArray.contentEquals(other: FloatArray): Boolean {
+ return this.contentEquals(other)
+}
+
+/**
+ * Returns `true` if the two specified arrays are *structurally* equal to one another,
+ * i.e. contain the same number of the same elements in the same order.
+ *
+ * The elements are compared for equality with the [equals][Any.equals] function.
+ * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
+ */
+@Deprecated("Use Kotlin compiler 1.4 to avoid deprecation warning.")
+@SinceKotlin("1.1")
+@DeprecatedSinceKotlin(hiddenSince = "1.4")
+actual infix fun DoubleArray.contentEquals(other: DoubleArray): Boolean {
+ return this.contentEquals(other)
+}
+
+/**
+ * Returns `true` if the two specified arrays are *structurally* equal to one another,
+ * i.e. contain the same number of the same elements in the same order.
+ *
+ * The elements are compared for equality with the [equals][Any.equals] function.
+ * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
+ */
+@Deprecated("Use Kotlin compiler 1.4 to avoid deprecation warning.")
+@SinceKotlin("1.1")
+@DeprecatedSinceKotlin(hiddenSince = "1.4")
+actual infix fun BooleanArray.contentEquals(other: BooleanArray): Boolean {
+ return this.contentEquals(other)
+}
+
+/**
+ * Returns `true` if the two specified arrays are *structurally* equal to one another,
+ * i.e. contain the same number of the same elements in the same order.
+ *
+ * The elements are compared for equality with the [equals][Any.equals] function.
+ * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
+ */
+@Deprecated("Use Kotlin compiler 1.4 to avoid deprecation warning.")
+@SinceKotlin("1.1")
+@DeprecatedSinceKotlin(hiddenSince = "1.4")
+actual infix fun CharArray.contentEquals(other: CharArray): Boolean {
+ return this.contentEquals(other)
+}
+
+/**
+ * Returns `true` if the two specified arrays are *structurally* equal to one another,
+ * i.e. contain the same number of the same elements in the same order.
+ *
+ * The elements are compared for equality with the [equals][Any.equals] function.
+ * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
+ */
+@SinceKotlin("1.4")
+actual infix fun Array?.contentEquals(other: Array?): Boolean {
+ return contentEqualsInternal(other)
+}
+
+/**
+ * Returns `true` if the two specified arrays are *structurally* equal to one another,
+ * i.e. contain the same number of the same elements in the same order.
+ *
+ * The elements are compared for equality with the [equals][Any.equals] function.
+ * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
+ */
+@SinceKotlin("1.4")
+actual infix fun ByteArray?.contentEquals(other: ByteArray?): Boolean {
+ return contentEqualsInternal(other)
+}
+
+/**
+ * Returns `true` if the two specified arrays are *structurally* equal to one another,
+ * i.e. contain the same number of the same elements in the same order.
+ *
+ * The elements are compared for equality with the [equals][Any.equals] function.
+ * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
+ */
+@SinceKotlin("1.4")
+actual infix fun ShortArray?.contentEquals(other: ShortArray?): Boolean {
+ return contentEqualsInternal(other)
+}
+
+/**
+ * Returns `true` if the two specified arrays are *structurally* equal to one another,
+ * i.e. contain the same number of the same elements in the same order.
+ *
+ * The elements are compared for equality with the [equals][Any.equals] function.
+ * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
+ */
+@SinceKotlin("1.4")
+actual infix fun IntArray?.contentEquals(other: IntArray?): Boolean {
+ return contentEqualsInternal(other)
+}
+
+/**
+ * Returns `true` if the two specified arrays are *structurally* equal to one another,
+ * i.e. contain the same number of the same elements in the same order.
+ *
+ * The elements are compared for equality with the [equals][Any.equals] function.
+ * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
+ */
+@SinceKotlin("1.4")
+actual infix fun LongArray?.contentEquals(other: LongArray?): Boolean {
+ return contentEqualsInternal(other)
+}
+
+/**
+ * Returns `true` if the two specified arrays are *structurally* equal to one another,
+ * i.e. contain the same number of the same elements in the same order.
+ *
+ * The elements are compared for equality with the [equals][Any.equals] function.
+ * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
+ */
+@SinceKotlin("1.4")
+actual infix fun FloatArray?.contentEquals(other: FloatArray?): Boolean {
+ return contentEqualsInternal(other)
+}
+
+/**
+ * Returns `true` if the two specified arrays are *structurally* equal to one another,
+ * i.e. contain the same number of the same elements in the same order.
+ *
+ * The elements are compared for equality with the [equals][Any.equals] function.
+ * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
+ */
+@SinceKotlin("1.4")
+actual infix fun DoubleArray?.contentEquals(other: DoubleArray?): Boolean {
+ return contentEqualsInternal(other)
+}
+
+/**
+ * Returns `true` if the two specified arrays are *structurally* equal to one another,
+ * i.e. contain the same number of the same elements in the same order.
+ *
+ * The elements are compared for equality with the [equals][Any.equals] function.
+ * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
+ */
+@SinceKotlin("1.4")
+actual infix fun BooleanArray?.contentEquals(other: BooleanArray?): Boolean {
+ return contentEqualsInternal(other)
+}
+
+/**
+ * Returns `true` if the two specified arrays are *structurally* equal to one another,
+ * i.e. contain the same number of the same elements in the same order.
+ *
+ * The elements are compared for equality with the [equals][Any.equals] function.
+ * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
+ */
+@SinceKotlin("1.4")
+actual infix fun CharArray?.contentEquals(other: CharArray?): Boolean {
+ return contentEqualsInternal(other)
+}
+
+/**
+ * Returns a hash code based on the contents of this array as if it is [List].
+ */
+@Deprecated("Use Kotlin compiler 1.4 to avoid deprecation warning.")
+@SinceKotlin("1.1")
+@DeprecatedSinceKotlin(hiddenSince = "1.4")
+actual fun Array.contentHashCode(): Int {
+ return this.contentHashCode()
+}
+
+/**
+ * Returns a hash code based on the contents of this array as if it is [List].
+ */
+@Deprecated("Use Kotlin compiler 1.4 to avoid deprecation warning.")
+@SinceKotlin("1.1")
+@DeprecatedSinceKotlin(hiddenSince = "1.4")
+actual fun ByteArray.contentHashCode(): Int {
+ return this.contentHashCode()
+}
+
+/**
+ * Returns a hash code based on the contents of this array as if it is [List].
+ */
+@Deprecated("Use Kotlin compiler 1.4 to avoid deprecation warning.")
+@SinceKotlin("1.1")
+@DeprecatedSinceKotlin(hiddenSince = "1.4")
+actual fun ShortArray.contentHashCode(): Int {
+ return this.contentHashCode()
+}
+
+/**
+ * Returns a hash code based on the contents of this array as if it is [List].
+ */
+@Deprecated("Use Kotlin compiler 1.4 to avoid deprecation warning.")
+@SinceKotlin("1.1")
+@DeprecatedSinceKotlin(hiddenSince = "1.4")
+actual fun IntArray.contentHashCode(): Int {
+ return this.contentHashCode()
+}
+
+/**
+ * Returns a hash code based on the contents of this array as if it is [List].
+ */
+@Deprecated("Use Kotlin compiler 1.4 to avoid deprecation warning.")
+@SinceKotlin("1.1")
+@DeprecatedSinceKotlin(hiddenSince = "1.4")
+actual fun LongArray.contentHashCode(): Int {
+ return this.contentHashCode()
+}
+
+/**
+ * Returns a hash code based on the contents of this array as if it is [List].
+ */
+@Deprecated("Use Kotlin compiler 1.4 to avoid deprecation warning.")
+@SinceKotlin("1.1")
+@DeprecatedSinceKotlin(hiddenSince = "1.4")
+actual fun FloatArray.contentHashCode(): Int {
+ return this.contentHashCode()
+}
+
+/**
+ * Returns a hash code based on the contents of this array as if it is [List].
+ */
+@Deprecated("Use Kotlin compiler 1.4 to avoid deprecation warning.")
+@SinceKotlin("1.1")
+@DeprecatedSinceKotlin(hiddenSince = "1.4")
+actual fun DoubleArray.contentHashCode(): Int {
+ return this.contentHashCode()
+}
+
+/**
+ * Returns a hash code based on the contents of this array as if it is [List].
+ */
+@Deprecated("Use Kotlin compiler 1.4 to avoid deprecation warning.")
+@SinceKotlin("1.1")
+@DeprecatedSinceKotlin(hiddenSince = "1.4")
+actual fun BooleanArray.contentHashCode(): Int {
+ return this.contentHashCode()
+}
+
+/**
+ * Returns a hash code based on the contents of this array as if it is [List].
+ */
+@Deprecated("Use Kotlin compiler 1.4 to avoid deprecation warning.")
+@SinceKotlin("1.1")
+@DeprecatedSinceKotlin(hiddenSince = "1.4")
+actual fun CharArray.contentHashCode(): Int {
+ return this.contentHashCode()
+}
+
+/**
+ * Returns a hash code based on the contents of this array as if it is [List].
+ */
+@SinceKotlin("1.4")
+actual fun Array?.contentHashCode(): Int {
+ return contentHashCodeInternal()
+}
+
+/**
+ * Returns a hash code based on the contents of this array as if it is [List].
+ */
+@SinceKotlin("1.4")
+actual fun ByteArray?.contentHashCode(): Int {
+ return contentHashCodeInternal()
+}
+
+/**
+ * Returns a hash code based on the contents of this array as if it is [List].
+ */
+@SinceKotlin("1.4")
+actual fun ShortArray?.contentHashCode(): Int {
+ return contentHashCodeInternal()
+}
+
+/**
+ * Returns a hash code based on the contents of this array as if it is [List].
+ */
+@SinceKotlin("1.4")
+actual fun IntArray?.contentHashCode(): Int {
+ return contentHashCodeInternal()
+}
+
+/**
+ * Returns a hash code based on the contents of this array as if it is [List].
+ */
+@SinceKotlin("1.4")
+actual fun LongArray?.contentHashCode(): Int {
+ return contentHashCodeInternal()
+}
+
+/**
+ * Returns a hash code based on the contents of this array as if it is [List].
+ */
+@SinceKotlin("1.4")
+actual fun FloatArray?.contentHashCode(): Int {
+ return contentHashCodeInternal()
+}
+
+/**
+ * Returns a hash code based on the contents of this array as if it is [List].
+ */
+@SinceKotlin("1.4")
+actual fun DoubleArray?.contentHashCode(): Int {
+ return contentHashCodeInternal()
+}
+
+/**
+ * Returns a hash code based on the contents of this array as if it is [List].
+ */
+@SinceKotlin("1.4")
+actual fun BooleanArray?.contentHashCode(): Int {
+ return contentHashCodeInternal()
+}
+
+/**
+ * Returns a hash code based on the contents of this array as if it is [List].
+ */
+@SinceKotlin("1.4")
+actual fun CharArray?.contentHashCode(): Int {
+ return contentHashCodeInternal()
+}
+
+/**
+ * Returns a string representation of the contents of the specified array as if it is [List].
+ *
+ * @sample samples.collections.Arrays.ContentOperations.contentToString
+ */
+@Deprecated("Use Kotlin compiler 1.4 to avoid deprecation warning.")
+@SinceKotlin("1.1")
+@DeprecatedSinceKotlin(hiddenSince = "1.4")
+actual fun