[Wasm][Stdlib] Reuse K/N collections and StringBuilder

This commit is contained in:
Svyatoslav Kuzmich
2021-09-22 19:44:14 +03:00
parent 6ad6bca503
commit ab9a23cbfa
286 changed files with 1099 additions and 1409 deletions
+6 -3
View File
@@ -20,14 +20,16 @@ val builtInsSources by task<Sync> {
val excluded = listOf(
// JS-specific optimized version of emptyArray() already defined
"core/builtins/src/kotlin/ArrayIntrinsics.kt"
"ArrayIntrinsics.kt",
// Included with K/N collections
"Collections.kt", "Iterator.kt", "Iterators.kt"
)
sources.forEach { path ->
from("$rootDir/$path") {
into(path.dropLastWhile { it != '/' })
excluded.filter { it.startsWith(path) }.forEach {
exclude(it.substring(path.length))
excluded.forEach {
exclude(it)
}
}
}
@@ -58,6 +60,7 @@ kotlin {
sourceSets {
val jsMain by getting {
kotlin.srcDirs("builtins", "internal", "runtime", "src", "stubs")
kotlin.srcDirs("../native-wasm/")
kotlin.srcDirs(files(builtInsSources.map { it.destinationDir }))
}
@@ -324,3 +324,9 @@ public external fun wasm_i32_clz(a: Int): Int
@WasmOp(WasmOp.I64_CLZ)
public external fun wasm_i64_clz(a: Long): Long
@WasmOp(WasmOp.I64_POPCNT)
public external fun wasm_i64_popcnt(a: Long): Long
@WasmOp(WasmOp.I64_CTZ)
public external fun wasm_i64_ctz(a: Long): Long
@@ -93,3 +93,8 @@ public actual open class UninitializedPropertyAccessException actual constructor
actual constructor(cause: Throwable?) : this(null, cause)
}
public open class OutOfMemoryError : Error {
constructor() : super()
constructor(message: String?) : super(message)
}
@@ -1,32 +0,0 @@
/*
* 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.collections
/**
* Provides a skeletal implementation of the [MutableCollection] interface.
*
* @param E the type of elements contained in the collection. The collection is invariant on its element type.
*/
@SinceKotlin("1.3")
public actual abstract class AbstractMutableCollection<E> : MutableCollection<E> {
actual protected constructor()
actual abstract override val size: Int
actual abstract override fun iterator(): MutableIterator<E>
actual abstract override fun add(element: E): Boolean
actual override fun isEmpty(): Boolean = TODO("Wasm stdlib: AbstractMutableCollection")
actual override fun contains(element: @UnsafeVariance E): Boolean = TODO("Wasm stdlib: AbstractMutableCollection")
actual override fun containsAll(elements: Collection<@UnsafeVariance E>): Boolean = TODO("Wasm stdlib: AbstractMutableCollection")
actual override fun addAll(elements: Collection<E>): Boolean = TODO("Wasm stdlib: AbstractMutableCollection")
actual override fun remove(element: E): Boolean = TODO("Wasm stdlib: AbstractMutableCollection")
actual override fun removeAll(elements: Collection<E>): Boolean = TODO("Wasm stdlib: AbstractMutableCollection")
actual override fun retainAll(elements: Collection<E>): Boolean = TODO("Wasm stdlib: AbstractMutableCollection")
actual override fun clear(): Unit = TODO("Wasm stdlib: AbstractMutableCollection")
}
@@ -1,45 +0,0 @@
/*
* 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.collections
/**
* Provides a skeletal implementation of the [MutableList] interface.
*
* @param E the type of elements contained in the list. The list is invariant on its element type.
*/
public actual abstract class AbstractMutableList<E> : MutableList<E> {
actual protected constructor()
// From List
actual override fun isEmpty(): Boolean = TODO("Wasm stdlib: AbstractMutableList")
actual override fun contains(element: @UnsafeVariance E): Boolean = TODO("Wasm stdlib: AbstractMutableList")
actual override fun containsAll(elements: Collection<@UnsafeVariance E>): Boolean = TODO("Wasm stdlib: AbstractMutableList")
actual override fun indexOf(element: @UnsafeVariance E): Int = TODO("Wasm stdlib: AbstractMutableList")
actual override fun lastIndexOf(element: @UnsafeVariance E): Int = TODO("Wasm stdlib: AbstractMutableList")
// From MutableCollection
actual override fun iterator(): MutableIterator<E> = TODO("Wasm stdlib: AbstractMutableList")
// From MutableList
/**
* Adds the specified element to the end of this list.
*
* @return `true` because the list is always modified as the result of this operation.
*/
actual override fun add(element: E): Boolean = TODO("Wasm stdlib: AbstractMutableList")
actual override fun remove(element: E): Boolean = TODO("Wasm stdlib: AbstractMutableList")
actual override fun addAll(elements: Collection<E>): Boolean = TODO("Wasm stdlib: AbstractMutableList")
actual override fun addAll(index: Int, elements: Collection<E>): Boolean = TODO("Wasm stdlib: AbstractMutableList")
actual override fun removeAll(elements: Collection<E>): Boolean = TODO("Wasm stdlib: AbstractMutableList")
actual override fun retainAll(elements: Collection<E>): Boolean = TODO("Wasm stdlib: AbstractMutableList")
actual override fun clear() { TODO("Wasm stdlib: AbstractMutableList") }
actual override fun listIterator(): MutableListIterator<E> = TODO("Wasm stdlib: AbstractMutableList")
actual override fun listIterator(index: Int): MutableListIterator<E> = TODO("Wasm stdlib: AbstractMutableList")
actual override fun subList(fromIndex: Int, toIndex: Int): MutableList<E> = TODO("Wasm stdlib: AbstractMutableList")
}
@@ -1,42 +0,0 @@
/*
* 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.collections
/**
* Provides a skeletal implementation of the [MutableMap] interface.
*
* The implementor is required to implement [entries] property, which should return mutable set of map entries, and [put] function.
*
* @param K the type of map keys. The map is invariant on its key type.
* @param V the type of map values. The map is invariant on its value type.
*/
@SinceKotlin("1.3")
public actual abstract class AbstractMutableMap<K, V> : MutableMap<K, V> {
actual protected constructor()
/**
* Associates the specified [value] with the specified [key] in the map.
*
* This method is redeclared as abstract, because it's not implemented in the base class,
* so it must be always overridden in the concrete mutable collection implementation.
*
* @return the previous value associated with the key, or `null` if the key was not present in the map.
*/
abstract actual override fun put(key: K, value: V): V?
abstract actual override val entries: MutableSet<MutableMap.MutableEntry<K, V>>
actual override val keys: MutableSet<K> = TODO("Wasm stdlib: AbstractMutableMap")
actual override val size: Int = TODO("Wasm stdlib: AbstractMutableMap")
actual override val values: MutableCollection<V> = TODO("Wasm stdlib: AbstractMutableMap")
actual override fun clear() { TODO("Wasm stdlib: AbstractMutableMap") }
actual override fun containsKey(key: K): Boolean = TODO("Wasm stdlib: AbstractMutableMap")
actual override fun containsValue(value: V): Boolean = TODO("Wasm stdlib: AbstractMutableMap")
actual override fun get(key: K): V? = TODO("Wasm stdlib: AbstractMutableMap")
actual override fun isEmpty(): Boolean = TODO("Wasm stdlib: AbstractMutableMap")
actual override fun putAll(from: Map<out K, V>) { TODO("Wasm stdlib: AbstractMutableMap") }
actual override fun remove(key: K): V? = TODO("Wasm stdlib: AbstractMutableMap")
}
@@ -1,31 +0,0 @@
/*
* 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.collections
/**
* Provides a skeletal implementation of the [MutableSet] interface.
*
* @param E the type of elements contained in the set. The set is invariant on its element type.
*/
@SinceKotlin("1.3")
public actual abstract class AbstractMutableSet<E> : MutableSet<E> {
actual protected constructor()
actual abstract override val size: Int
actual abstract override fun iterator(): MutableIterator<E>
actual abstract override fun add(element: E): Boolean
actual override fun isEmpty(): Boolean = TODO("Wasm stdlib: AbstractMutableSet")
actual override fun contains(element: @UnsafeVariance E): Boolean = TODO("Wasm stdlib: AbstractMutableSet")
actual override fun containsAll(elements: Collection<@UnsafeVariance E>): Boolean = TODO("Wasm stdlib: AbstractMutableSet")
actual override fun addAll(elements: Collection<E>): Boolean = TODO("Wasm stdlib: AbstractMutableSet")
actual override fun remove(element: E): Boolean = TODO("Wasm stdlib: AbstractMutableSet")
actual override fun removeAll(elements: Collection<E>): Boolean = TODO("Wasm stdlib: AbstractMutableSet")
actual override fun retainAll(elements: Collection<E>): Boolean = TODO("Wasm stdlib: AbstractMutableSet")
actual override fun clear() { TODO("Wasm stdlib: AbstractMutableSet") }
}
@@ -1,45 +0,0 @@
/*
* 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.collections
actual open class ArrayList<E> : MutableList<E>, RandomAccess {
actual constructor() { TODO("Wasm stdlib: ArrayList") }
actual constructor(initialCapacity: Int) { TODO("Wasm stdlib: ArrayList") }
actual constructor(elements: Collection<E>) { TODO("Wasm stdlib: ArrayList") }
actual fun trimToSize() { TODO("Wasm stdlib: ArrayList") }
actual fun ensureCapacity(minCapacity: Int) { TODO("Wasm stdlib: ArrayList") }
// From List
actual override val size: Int = TODO("Wasm stdlib: ArrayList")
actual override fun isEmpty(): Boolean = TODO("Wasm stdlib: ArrayList")
actual override fun contains(element: @UnsafeVariance E): Boolean = TODO("Wasm stdlib: ArrayList")
actual override fun containsAll(elements: Collection<@UnsafeVariance E>): Boolean = TODO("Wasm stdlib: ArrayList")
actual override operator fun get(index: Int): E = TODO("Wasm stdlib: ArrayList")
actual override fun indexOf(element: @UnsafeVariance E): Int = TODO("Wasm stdlib: ArrayList")
actual override fun lastIndexOf(element: @UnsafeVariance E): Int = TODO("Wasm stdlib: ArrayList")
// From MutableCollection
actual override fun iterator(): MutableIterator<E> = TODO("Wasm stdlib: ArrayList")
// From MutableList
actual override fun add(element: E): Boolean = TODO("Wasm stdlib: ArrayList")
actual override fun remove(element: E): Boolean = TODO("Wasm stdlib: ArrayList")
actual override fun addAll(elements: Collection<E>): Boolean = TODO("Wasm stdlib: ArrayList")
actual override fun addAll(index: Int, elements: Collection<E>): Boolean = TODO("Wasm stdlib: ArrayList")
actual override fun removeAll(elements: Collection<E>): Boolean = TODO("Wasm stdlib: ArrayList")
actual override fun retainAll(elements: Collection<E>): Boolean = TODO("Wasm stdlib: ArrayList")
actual override fun clear() { TODO("Wasm stdlib: ArrayList") }
actual override operator fun set(index: Int, element: E): E = TODO("Wasm stdlib: ArrayList")
actual override fun add(index: Int, element: E) { TODO("Wasm stdlib: ArrayList") }
actual override fun removeAt(index: Int): E = TODO("Wasm stdlib: ArrayList")
actual override fun listIterator(): MutableListIterator<E> = TODO("Wasm stdlib: ArrayList")
actual override fun listIterator(index: Int): MutableListIterator<E> = TODO("Wasm stdlib: ArrayList")
actual override fun subList(fromIndex: Int, toIndex: Int): MutableList<E> = TODO("Wasm stdlib: ArrayList")
}
@@ -1,105 +0,0 @@
/*
* 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.collections
import kotlin.internal.PureReifiable
// Array Utils copied from K/N
internal fun checkCopyOfRangeArguments(fromIndex: Int, toIndex: Int, size: Int) {
if (toIndex > size)
throw IndexOutOfBoundsException("toIndex ($toIndex) is greater than size ($size).")
if (fromIndex > toIndex)
throw IllegalArgumentException("fromIndex ($fromIndex) is greater than toIndex ($toIndex).")
}
// TODO: internal
/**
* Returns a string representation of the contents of the subarray of the specified array as if it is [List].
*/
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline fun <T> Array<out T>.subarrayContentToString(offset: Int, length: Int): String {
val sb = StringBuilder(2 + length * 3)
sb.append("[")
var i = 0
while (i < length) {
if (i > 0) sb.append(", ")
sb.append(this[offset + i])
i++
}
sb.append("]")
return sb.toString()
}
/**
* 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")
@UseExperimental(ExperimentalUnsignedTypes::class)
internal fun <T> Array<out T>?.contentDeepHashCodeImpl(): Int {
if (this == null) return 0
var result = 1
for (element in this) {
val elementHash = when (element) {
null -> 0
is Array<*> -> element.contentDeepHashCode()
is ByteArray -> element.contentHashCode()
is ShortArray -> element.contentHashCode()
is IntArray -> element.contentHashCode()
is LongArray -> element.contentHashCode()
is FloatArray -> element.contentHashCode()
is DoubleArray -> element.contentHashCode()
is CharArray -> element.contentHashCode()
is BooleanArray -> element.contentHashCode()
is UByteArray -> element.contentHashCode()
is UShortArray -> element.contentHashCode()
is UIntArray -> element.contentHashCode()
is ULongArray -> element.contentHashCode()
else -> element.hashCode()
}
result = 31 * result + elementHash
}
return result
}
@Suppress("UNCHECKED_CAST")
internal actual fun <T> arrayOfNulls(reference: Array<T>, size: Int): Array<T> = arrayOfNulls<Any>(size) as Array<T>
internal actual fun copyToArrayImpl(collection: Collection<*>): Array<Any?> {
val array = Array<Any?>(collection.size)
val iterator = collection.iterator()
var index = 0
while (iterator.hasNext())
array[index++] = iterator.next()
return array
}
@Suppress("UNCHECKED_CAST")
internal actual fun <T> copyToArrayImpl(collection: Collection<*>, array: Array<T>): Array<T> {
if (array.size < collection.size)
return copyToArrayImpl(collection) as Array<T>
val iterator = collection.iterator()
var index = 0
while (iterator.hasNext()) {
array[index++] = iterator.next() as T
}
if (index < array.size) {
return array.copyOf(index) as Array<T>
}
return array
}
@@ -1,107 +0,0 @@
/*
* 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.collections
actual interface RandomAccess
/** Returns the array if it's not `null`, or an empty array otherwise. */
actual inline fun <reified T> Array<out T>?.orEmpty(): Array<out T> = this ?: emptyArray<T>()
public actual inline fun <reified T> Collection<T>.toTypedArray(): Array<T> {
val result = arrayOfNulls<T>(size)
var index = 0
for (element in this) result[index++] = element
@Suppress("UNCHECKED_CAST")
return result as Array<T>
}
@SinceKotlin("1.2")
actual fun <T> MutableList<T>.fill(value: T): Unit = TODO("Wasm stdlib: Collections")
@SinceKotlin("1.2")
actual fun <T> MutableList<T>.shuffle(): Unit = TODO("Wasm stdlib: Collections")
@SinceKotlin("1.2")
actual fun <T> Iterable<T>.shuffled(): List<T> = TODO("Wasm stdlib: Collections")
actual fun <T : Comparable<T>> MutableList<T>.sort(): Unit = TODO("Wasm stdlib: Collections")
actual fun <T> MutableList<T>.sortWith(comparator: Comparator<in T>): Unit = TODO("Wasm stdlib: Collections")
// from Grouping.kt
public actual fun <T, K> Grouping<T, K>.eachCount(): Map<K, Int> = TODO("Wasm stdlib: Collections")
// public actual inline fun <T, K> Grouping<T, K>.eachSumOf(valueSelector: (T) -> Int): Map<K, Int>
internal actual fun <K, V> Map<K, V>.toSingletonMapOrSelf(): Map<K, V> = TODO("Wasm stdlib: Collections")
internal actual fun <K, V> Map<out K, V>.toSingletonMap(): Map<K, V> = TODO("Wasm stdlib: Collections")
internal actual fun <T> Array<out T>.copyToArrayOfAny(isVarargs: Boolean): Array<out Any?> = TODO("Wasm stdlib: Collections")
@PublishedApi
@SinceKotlin("1.3")
internal actual fun checkIndexOverflow(index: Int): Int = TODO("Wasm stdlib: Collections")
@PublishedApi
@SinceKotlin("1.3")
internal actual fun checkCountOverflow(count: Int): Int = TODO("Wasm stdlib: Collections")
@PublishedApi
@SinceKotlin("1.3")
@kotlin.internal.InlineOnly
internal actual inline fun <E> buildListInternal(builderAction: MutableList<E>.() -> Unit): List<E> {
return TODO("Wasm stdlib: Collections")
}
@PublishedApi
@SinceKotlin("1.3")
@kotlin.internal.InlineOnly
internal actual inline fun <E> buildListInternal(capacity: Int, builderAction: MutableList<E>.() -> Unit): List<E> {
checkBuilderCapacity(capacity)
return TODO("Wasm stdlib: Collections")
}
/**
* Returns an immutable set containing only the specified object [element].
*/
public fun <T> setOf(element: T): Set<T> = hashSetOf(element)
@PublishedApi
@SinceKotlin("1.3")
@kotlin.internal.InlineOnly
internal actual inline fun <E> buildSetInternal(builderAction: MutableSet<E>.() -> Unit): Set<E> {
return TODO("Wasm stdlib: Collections")
}
@PublishedApi
@SinceKotlin("1.3")
@kotlin.internal.InlineOnly
internal actual inline fun <E> buildSetInternal(capacity: Int, builderAction: MutableSet<E>.() -> Unit): Set<E> {
return TODO("Wasm stdlib: Collections")
}
/**
* Returns an immutable map, mapping only the specified key to the
* specified value.
*/
public fun <K, V> mapOf(pair: Pair<K, V>): Map<K, V> = hashMapOf(pair)
@PublishedApi
@SinceKotlin("1.3")
@kotlin.internal.InlineOnly
internal actual inline fun <K, V> buildMapInternal(builderAction: MutableMap<K, V>.() -> Unit): Map<K, V> {
return TODO("Wasm stdlib: Collections")
}
@PublishedApi
@SinceKotlin("1.3")
@kotlin.internal.InlineOnly
internal actual inline fun <K, V> buildMapInternal(capacity: Int, builderAction: MutableMap<K, V>.() -> Unit): Map<K, V> {
return TODO("Wasm stdlib: Collections")
}
internal actual fun brittleContainsOptimizationEnabled(): Boolean = false
@@ -1,31 +0,0 @@
/*
* 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.collections
actual open class HashMap<K, V> : MutableMap<K, V> {
actual constructor() { TODO("Wasm stdlib: HashMap") }
actual constructor(initialCapacity: Int) { TODO("Wasm stdlib: HashMap") }
actual constructor(initialCapacity: Int, loadFactor: Float) { TODO("Wasm stdlib: HashMap") }
actual constructor(original: Map<out K, V>) { TODO("Wasm stdlib: HashMap") }
// From Map
actual override val size: Int = TODO("Wasm stdlib: HashMap")
actual override fun isEmpty(): Boolean = TODO("Wasm stdlib: HashMap")
actual override fun containsKey(key: K): Boolean = TODO("Wasm stdlib: HashMap")
actual override fun containsValue(value: @UnsafeVariance V): Boolean = TODO("Wasm stdlib: HashMap")
actual override operator fun get(key: K): V? = TODO("Wasm stdlib: HashMap")
// From MutableMap
actual override fun put(key: K, value: V): V? = TODO("Wasm stdlib: HashMap")
actual override fun remove(key: K): V? = TODO("Wasm stdlib: HashMap")
actual override fun putAll(from: Map<out K, V>) { TODO("Wasm stdlib: HashMap") }
actual override fun clear() { TODO("Wasm stdlib: HashMap") }
actual override val keys: MutableSet<K> = TODO("Wasm stdlib: HashMap")
actual override val values: MutableCollection<V> = TODO("Wasm stdlib: HashMap")
actual override val entries: MutableSet<MutableMap.MutableEntry<K, V>> = TODO("Wasm stdlib: HashMap")
}
@@ -1,32 +0,0 @@
/*
* 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.collections
actual open class HashSet<E> : MutableSet<E> {
actual constructor() { TODO("Wasm stdlib: HashSet") }
actual constructor(initialCapacity: Int) { TODO("Wasm stdlib: HashSet") }
actual constructor(initialCapacity: Int, loadFactor: Float) { TODO("Wasm stdlib: HashSet") }
actual constructor(elements: Collection<E>) { TODO("Wasm stdlib: HashSet") }
// From Set
actual override val size: Int = TODO("Wasm stdlib: HashSet")
actual override fun isEmpty(): Boolean = TODO("Wasm stdlib: HashSet")
actual override fun contains(element: @UnsafeVariance E): Boolean = TODO("Wasm stdlib: HashSet")
actual override fun containsAll(elements: Collection<@UnsafeVariance E>): Boolean = TODO("Wasm stdlib: HashSet")
// From MutableSet
actual override fun iterator(): MutableIterator<E> = TODO("Wasm stdlib: HashSet")
actual override fun add(element: E): Boolean = TODO("Wasm stdlib: HashSet")
actual override fun remove(element: E): Boolean = TODO("Wasm stdlib: HashSet")
actual override fun addAll(elements: Collection<E>): Boolean = TODO("Wasm stdlib: HashSet")
actual override fun removeAll(elements: Collection<E>): Boolean = TODO("Wasm stdlib: HashSet")
actual override fun retainAll(elements: Collection<E>): Boolean = TODO("Wasm stdlib: HashSet")
actual override fun clear() { TODO("Wasm stdlib: HashSet") }
}
fun <E> arrayOfUninitializedElements(size: Int): Array<E> = @Suppress("UNCHECKED_CAST") Array<Any?>(size) as Array<E>
@@ -0,0 +1,28 @@
/*
* 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
/**
* Returns an array of objects of the given type with the given [size], initialized with _uninitialized_ values.
* Attempts to read _uninitialized_ values from this array work in implementation-dependent manner,
* either throwing exception or returning some kind of implementation-specific default value.
*/
@PublishedApi
internal inline fun <E> arrayOfUninitializedElements(size: Int): Array<E> {
require(size >= 0) { "capacity must be non-negative." }
@Suppress("TYPE_PARAMETER_AS_REIFIED")
return Array<E>(size)
}
internal fun <E> Array<E>.resetRange(fromIndex: Int, toIndex: Int) {
@Suppress("UNCHECKED_CAST")
this.fill(null as E, fromIndex, toIndex)
}
internal fun <E> Array<E>.resetAt(index: Int) {
@Suppress("UNCHECKED_CAST")
(this as Array<Any?>)[index] = null
}
@@ -1,31 +0,0 @@
/*
* 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.collections
actual open class LinkedHashMap<K, V> : MutableMap<K, V> {
actual constructor() { TODO("Wasm stdlib: LinkedHashMap") }
actual constructor(initialCapacity: Int) { TODO("Wasm stdlib: LinkedHashMap") }
actual constructor(initialCapacity: Int, loadFactor: Float) { TODO("Wasm stdlib: LinkedHashMap") }
actual constructor(original: Map<out K, V>) { TODO("Wasm stdlib: LinkedHashMap") }
// From Map
actual override val size: Int = TODO("Wasm stdlib: LinkedHashMap")
actual override fun isEmpty(): Boolean = TODO("Wasm stdlib: LinkedHashMap")
actual override fun containsKey(key: K): Boolean = TODO("Wasm stdlib: LinkedHashMap")
actual override fun containsValue(value: V): Boolean = TODO("Wasm stdlib: LinkedHashMap")
actual override fun get(key: K): V? = TODO("Wasm stdlib: LinkedHashMap")
// From MutableMap
actual override fun put(key: K, value: V): V? = TODO("Wasm stdlib: LinkedHashMap")
actual override fun remove(key: K): V? = TODO("Wasm stdlib: LinkedHashMap")
actual override fun putAll(from: Map<out K, V>) { TODO("Wasm stdlib: LinkedHashMap") }
actual override fun clear() { TODO("Wasm stdlib: LinkedHashMap") }
actual override val keys: MutableSet<K> = TODO("Wasm stdlib: LinkedHashMap")
actual override val values: MutableCollection<V> = TODO("Wasm stdlib: LinkedHashMap")
actual override val entries: MutableSet<MutableMap.MutableEntry<K, V>> = TODO("Wasm stdlib: LinkedHashMap")
}
@@ -1,30 +0,0 @@
/*
* 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.collections
actual open class LinkedHashSet<E> : MutableSet<E> {
actual constructor() { TODO("Wasm stdlib: LinkedHashSet") }
actual constructor(initialCapacity: Int) { TODO("Wasm stdlib: LinkedHashSet") }
actual constructor(initialCapacity: Int, loadFactor: Float) { TODO("Wasm stdlib: LinkedHashSet") }
actual constructor(elements: Collection<E>) { TODO("Wasm stdlib: LinkedHashSet") }
// From Set
actual override val size: Int = TODO("Wasm stdlib: LinkedHashSet")
actual override fun isEmpty(): Boolean = TODO("Wasm stdlib: LinkedHashSet")
actual override fun contains(element: @UnsafeVariance E): Boolean = TODO("Wasm stdlib: LinkedHashSet")
actual override fun containsAll(elements: Collection<@UnsafeVariance E>): Boolean = TODO("Wasm stdlib: LinkedHashSet")
// From MutableSet
actual override fun iterator(): MutableIterator<E> = TODO("Wasm stdlib: LinkedHashSet")
actual override fun add(element: E): Boolean = TODO("Wasm stdlib: LinkedHashSet")
actual override fun remove(element: E): Boolean = TODO("Wasm stdlib: LinkedHashSet")
actual override fun addAll(elements: Collection<E>): Boolean = TODO("Wasm stdlib: LinkedHashSet")
actual override fun removeAll(elements: Collection<E>): Boolean = TODO("Wasm stdlib: LinkedHashSet")
actual override fun retainAll(elements: Collection<E>): Boolean = TODO("Wasm stdlib: LinkedHashSet")
actual override fun clear() { TODO("Wasm stdlib: LinkedHashSet") }
}
@@ -1,19 +0,0 @@
/*
* 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.collections
/**
* Calculate the initial capacity of a map.
*/
@PublishedApi
internal actual fun mapCapacity(expectedSize: Int): Int = TODO("Wasm stdlib: Maps")
/**
* Checks a collection builder function capacity argument.
*/
@SinceKotlin("1.3")
@PublishedApi
internal fun checkBuilderCapacity(capacity: Int) { TODO("Wasm stdlib: Maps") }
@@ -1,387 +1,34 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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.text
/**
* A mutable sequence of characters.
*
* String builder can be used to efficiently perform multiple string manipulation operations.
*/
actual class StringBuilder : Appendable, CharSequence {
/** Constructs an empty string builder. */
actual constructor() { TODO("Wasm stdlib: StringBuilder") }
/** Constructs an empty string builder with the specified initial [capacity]. */
actual constructor(capacity: Int) { TODO("Wasm stdlib: StringBuilder") }
/** Constructs a string builder that contains the same characters as the specified [content] char sequence. */
actual constructor(content: CharSequence) { TODO("Wasm stdlib: StringBuilder") }
/** Constructs a string builder that contains the same characters as the specified [content] string. */
@SinceKotlin("1.3")
// @ExperimentalStdlibApi
actual constructor(content: String) { TODO("Wasm stdlib: StringBuilder") }
actual override val length: Int = TODO("Wasm stdlib: StringBuilder")
actual override operator fun get(index: Int): Char = TODO("Wasm stdlib: StringBuilder")
actual override fun subSequence(startIndex: Int, endIndex: Int): CharSequence = TODO("Wasm stdlib: StringBuilder")
actual override fun append(value: Char): StringBuilder = TODO("Wasm stdlib: StringBuilder")
actual override fun append(value: CharSequence?): StringBuilder = TODO("Wasm stdlib: StringBuilder")
actual override fun append(value: CharSequence?, startIndex: Int, endIndex: Int): StringBuilder = TODO("Wasm stdlib: StringBuilder")
/**
* Reverses the contents of this string builder and returns this instance.
*
* Surrogate pairs included in this string builder are treated as single characters.
* Therefore, the order of the high-low surrogates is never reversed.
*
* Note that the reverse operation may produce new surrogate pairs that were unpaired low-surrogates and high-surrogates before the operation.
* For example, reversing `"\uDC00\uD800"` produces `"\uD800\uDC00"` which is a valid surrogate pair.
*/
actual fun reverse(): StringBuilder = TODO("Wasm stdlib: StringBuilder")
/**
* Appends the string representation of the specified object [value] to this string builder and returns this instance.
*
* The overall effect is exactly as if the [value] were converted to a string by the `value.toString()` method,
* and then that string was appended to this string builder.
*/
actual fun append(value: Any?): StringBuilder = TODO("Wasm stdlib: StringBuilder")
/**
* Appends the string representation of the specified boolean [value] to this string builder and returns this instance.
*
* The overall effect is exactly as if the [value] were converted to a string by the `value.toString()` method,
* and then that string was appended to this string builder.
*/
@SinceKotlin("1.3")
// @ExperimentalStdlibApi
actual fun append(value: Boolean): StringBuilder = TODO("Wasm stdlib: StringBuilder")
/**
* Appends characters in the specified character array [value] to this string builder and returns this instance.
*
* Characters are appended in order, starting at the index 0.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
actual fun append(value: CharArray): StringBuilder = TODO("Wasm stdlib: StringBuilder")
/**
* Appends the specified string [value] to this string builder and returns this instance.
*/
@SinceKotlin("1.3")
// @ExperimentalStdlibApi
actual fun append(value: String?): StringBuilder = TODO("Wasm stdlib: StringBuilder")
/**
* Returns the current capacity of this string builder.
*
* The capacity is the maximum length this string builder can have before an allocation occurs.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
actual fun capacity(): Int = TODO("Wasm stdlib: StringBuilder")
/**
* Ensures that the capacity of this string builder is at least equal to the specified [minimumCapacity].
*
* If the current capacity is less than the [minimumCapacity], a new backing storage is allocated with greater capacity.
* Otherwise, this method takes no action and simply returns.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
actual fun ensureCapacity(minimumCapacity: Int) { TODO("Wasm stdlib: StringBuilder") }
/**
* Returns the index within this string builder of the first occurrence of the specified [string].
*
* Returns `-1` if the specified [string] does not occur in this string builder.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
actual fun indexOf(string: String): Int = TODO("Wasm stdlib: StringBuilder")
/**
* Returns the index within this string builder of the first occurrence of the specified [string],
* starting at the specified [startIndex].
*
* Returns `-1` if the specified [string] does not occur in this string builder starting at the specified [startIndex].
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
actual fun indexOf(string: String, startIndex: Int): Int = TODO("Wasm stdlib: StringBuilder")
/**
* Returns the index within this string builder of the last occurrence of the specified [string].
* The last occurrence of empty string `""` is considered to be at the index equal to `this.length`.
*
* Returns `-1` if the specified [string] does not occur in this string builder.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
actual fun lastIndexOf(string: String): Int = TODO("Wasm stdlib: StringBuilder")
/**
* Returns the index within this string builder of the last occurrence of the specified [string],
* starting from the specified [startIndex] toward the beginning.
*
* Returns `-1` if the specified [string] does not occur in this string builder starting at the specified [startIndex].
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
actual fun lastIndexOf(string: String, startIndex: Int): Int = TODO("Wasm stdlib: StringBuilder")
/**
* Inserts the string representation of the specified boolean [value] into this string builder at the specified [index] and returns this instance.
*
* The overall effect is exactly as if the [value] were converted to a string by the `value.toString()` method,
* and then that string was inserted into this string builder at the specified [index].
*
* @throws IndexOutOfBoundsException if [index] is less than zero or greater than the length of this string builder.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
actual fun insert(index: Int, value: Boolean): StringBuilder = TODO("Wasm stdlib: StringBuilder")
/**
* Inserts the specified character [value] into this string builder at the specified [index] and returns this instance.
*
* @throws IndexOutOfBoundsException if [index] is less than zero or greater than the length of this string builder.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
actual fun insert(index: Int, value: Char): StringBuilder = TODO("Wasm stdlib: StringBuilder")
/**
* Inserts characters in the specified character array [value] into this string builder at the specified [index] and returns this instance.
*
* The inserted characters go in same order as in the [value] character array, starting at [index].
*
* @throws IndexOutOfBoundsException if [index] is less than zero or greater than the length of this string builder.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
actual fun insert(index: Int, value: CharArray): StringBuilder = TODO("Wasm stdlib: StringBuilder")
/**
* Inserts characters in the specified character sequence [value] into this string builder at the specified [index] and returns this instance.
*
* The inserted characters go in the same order as in the [value] character sequence, starting at [index].
*
* @param index the position in this string builder to insert at.
* @param value the character sequence from which characters are inserted. If [value] is `null`, then the four characters `"null"` are inserted.
*
* @throws IndexOutOfBoundsException if [index] is less than zero or greater than the length of this string builder.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
actual fun insert(index: Int, value: CharSequence?): StringBuilder = TODO("Wasm stdlib: StringBuilder")
/**
* Inserts the string representation of the specified object [value] into this string builder at the specified [index] and returns this instance.
*
* The overall effect is exactly as if the [value] were converted to a string by the `value.toString()` method,
* and then that string was inserted into this string builder at the specified [index].
*
* @throws IndexOutOfBoundsException if [index] is less than zero or greater than the length of this string builder.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
actual fun insert(index: Int, value: Any?): StringBuilder = TODO("Wasm stdlib: StringBuilder")
/**
* Inserts the string [value] into this string builder at the specified [index] and returns this instance.
*
* @throws IndexOutOfBoundsException if [index] is less than zero or greater than the length of this string builder.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
actual fun insert(index: Int, value: String?): StringBuilder = TODO("Wasm stdlib: StringBuilder")
/**
* Sets the length of this string builder to the specified [newLength].
*
* If the [newLength] is less than the current length, it is changed to the specified [newLength].
* Otherwise, null characters '\u0000' are appended to this string builder until its length is less than the [newLength].
*
* Note that in Kotlin/JS [set] operator function has non-constant execution time complexity.
* Therefore, increasing length of this string builder and then updating each character by index may slow down your program.
*
* @throws IndexOutOfBoundsException or [IllegalArgumentException] if [newLength] is less than zero.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
actual fun setLength(newLength: Int) { TODO("Wasm stdlib: StringBuilder") }
/**
* Returns a new [String] that contains characters in this string builder at [startIndex] (inclusive) and up to the [length] (exclusive).
*
* @throws IndexOutOfBoundsException if [startIndex] is less than zero or greater than the length of this string builder.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
actual fun substring(startIndex: Int): String = TODO("Wasm stdlib: StringBuilder")
/**
* Returns a new [String] that contains characters in this string builder at [startIndex] (inclusive) and up to the [endIndex] (exclusive).
*
* @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this string builder indices or when `startIndex > endIndex`.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
actual fun substring(startIndex: Int, endIndex: Int): String = TODO("Wasm stdlib: StringBuilder")
/**
* Attempts to reduce storage used for this string builder.
*
* If the backing storage of this string builder is larger than necessary to hold its current contents,
* then it may be resized to become more space efficient.
* Calling this method may, but is not required to, affect the value of the [capacity] property.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
actual fun trimToSize() { TODO("Wasm stdlib: StringBuilder") }
internal fun insertString(array: CharArray, distIndex: Int, value: String, sourceIndex: Int, count: Int): Int {
var arrayIdx = distIndex
var stringIdx = sourceIndex
repeat(count) {
array[arrayIdx++] = value[stringIdx++]
}
return count
}
internal fun unsafeStringFromCharArray(array: CharArray, start: Int, size: Int): String =
kotlin.String(array.copyOfRange(start, start + size))
/**
* Clears the content of this string builder making it empty and returns this instance.
*
* @sample samples.text.Strings.clearStringBuilder
*/
@SinceKotlin("1.3")
public actual fun StringBuilder.clear(): StringBuilder = TODO("Wasm stdlib: StringBuilder")
internal fun insertInt(array: CharArray, start: Int, value: Int): Int {
val valueString = value.toString()
val length = valueString.length
insertString(array, start, valueString, 0, length)
return length
}
/**
* Sets the character at the specified [index] to the specified [value].
*
* @throws IndexOutOfBoundsException if [index] is out of bounds of this string builder.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
public actual operator fun StringBuilder.set(index: Int, value: Char) { TODO("Wasm stdlib: StringBuilder") }
/**
* Replaces characters in the specified range of this string builder with characters in the specified string [value] and returns this instance.
*
* @param startIndex the beginning (inclusive) of the range to replace.
* @param endIndex the end (exclusive) of the range to replace.
* @param value the string to replace with.
*
* @throws IndexOutOfBoundsException or [IllegalArgumentException] if [startIndex] is less than zero, greater than the length of this string builder, or `startIndex > endIndex`.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
public actual fun StringBuilder.setRange(startIndex: Int, endIndex: Int, value: String): StringBuilder = TODO("Wasm stdlib: StringBuilder")
/**
* Removes the character at the specified [index] from this string builder and returns this instance.
*
* If the `Char` at the specified [index] is part of a supplementary code point, this method does not remove the entire supplementary character.
*
* @param index the index of `Char` to remove.
*
* @throws IndexOutOfBoundsException if [index] is out of bounds of this string builder.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
public actual fun StringBuilder.deleteAt(index: Int): StringBuilder = TODO("Wasm stdlib: StringBuilder")
/**
* Removes characters in the specified range from this string builder and returns this instance.
*
* @param startIndex the beginning (inclusive) of the range to remove.
* @param endIndex the end (exclusive) of the range to remove.
*
* @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] is out of range of this string builder indices or when `startIndex > endIndex`.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
public actual fun StringBuilder.deleteRange(startIndex: Int, endIndex: Int): StringBuilder = TODO("Wasm stdlib: StringBuilder")
/**
* Copies characters from this string builder into the [destination] character array.
*
* @param destination the array to copy to.
* @param destinationOffset the position in the array to copy to, 0 by default.
* @param startIndex the beginning (inclusive) of the range to copy, 0 by default.
* @param endIndex the end (exclusive) of the range to copy, length of this string builder by default.
*
* @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this string builder indices or when `startIndex > endIndex`.
* @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationOffset],
* or when that index is out of the [destination] array indices range.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
public actual fun StringBuilder.toCharArray(destination: CharArray, destinationOffset: Int, startIndex: Int, endIndex: Int) { TODO("Wasm stdlib: StringBuilder") }
/**
* Appends characters in a subarray of the specified character array [value] to this string builder and returns this instance.
*
* Characters are appended in order, starting at specified [startIndex].
*
* @param value the array from which characters are appended.
* @param startIndex the beginning (inclusive) of the subarray to append.
* @param endIndex the end (exclusive) of the subarray to append.
*
* @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of the [value] array indices or when `startIndex > endIndex`.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
public actual fun StringBuilder.appendRange(value: CharArray, startIndex: Int, endIndex: Int): StringBuilder = TODO("Wasm stdlib: StringBuilder")
/**
* Appends a subsequence of the specified character sequence [value] to this string builder and returns this instance.
*
* @param value the character sequence from which a subsequence is appended. If [value] is `null`,
* then characters are appended as if [value] contained the four characters `"null"`.
* @param startIndex the beginning (inclusive) of the subsequence to append.
* @param endIndex the end (exclusive) of the subsequence to append.
*
* @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of the [value] character sequence indices or when `startIndex > endIndex`.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
public actual fun StringBuilder.appendRange(value: CharSequence, startIndex: Int, endIndex: Int): StringBuilder = TODO("Wasm stdlib: StringBuilder")
/**
* Inserts characters in a subarray of the specified character array [value] into this string builder at the specified [index] and returns this instance.
*
* The inserted characters go in same order as in the [value] array, starting at [index].
*
* @param index the position in this string builder to insert at.
* @param value the array from which characters are inserted.
* @param startIndex the beginning (inclusive) of the subarray to insert.
* @param endIndex the end (exclusive) of the subarray to insert.
*
* @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of the [value] array indices or when `startIndex > endIndex`.
* @throws IndexOutOfBoundsException if [index] is less than zero or greater than the length of this string builder.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
public actual fun StringBuilder.insertRange(index: Int, value: CharArray, startIndex: Int, endIndex: Int): StringBuilder = TODO("Wasm stdlib: StringBuilder")
/**
* Inserts characters in a subsequence of the specified character sequence [value] into this string builder at the specified [index] and returns this instance.
*
* The inserted characters go in the same order as in the [value] character sequence, starting at [index].
*
* @param index the position in this string builder to insert at.
* @param value the character sequence from which a subsequence is inserted. If [value] is `null`,
* then characters will be inserted as if [value] contained the four characters `"null"`.
* @param startIndex the beginning (inclusive) of the subsequence to insert.
* @param endIndex the end (exclusive) of the subsequence to insert.
*
* @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of the [value] character sequence indices or when `startIndex > endIndex`.
* @throws IndexOutOfBoundsException if [index] is less than zero or greater than the length of this string builder.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
public actual fun StringBuilder.insertRange(index: Int, value: CharSequence, startIndex: Int, endIndex: Int): StringBuilder = TODO("Wasm stdlib: StringBuilder")
internal fun checkBoundsIndexes(startIndex: Int, endIndex: Int, size: Int) {
if (startIndex < 0 || endIndex > size) {
throw IndexOutOfBoundsException("startIndex: $startIndex, endIndex: $endIndex, size: $size")
}
if (startIndex > endIndex) {
throw IllegalArgumentException("startIndex: $startIndex > endIndex: $endIndex")
}
}
@@ -10,39 +10,37 @@ import kotlin.wasm.internal.*
/**
* Counts the number of set bits in the binary representation of this [Int] number.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
public actual fun Int.countOneBits(): Int = TODO("Wasm stdlib: Numbers")
@WasmOp(WasmOp.I32_POPCNT)
public actual fun Int.countOneBits(): Int =
implementedAsIntrinsic
/**
* Counts the number of consecutive most significant bits that are zero in the binary representation of this [Int] number.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
public actual fun Int.countLeadingZeroBits(): Int = wasm_i32_clz(this)
@WasmOp(WasmOp.I32_CLZ)
public actual fun Int.countLeadingZeroBits(): Int =
implementedAsIntrinsic
/**
* Counts the number of consecutive least significant bits that are zero in the binary representation of this [Int] number.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
public actual fun Int.countTrailingZeroBits(): Int = TODO("Wasm stdlib: Numbers")
@WasmOp(WasmOp.I32_CTZ)
public actual fun Int.countTrailingZeroBits(): Int =
implementedAsIntrinsic
/**
* Returns a number having a single bit set in the position of the most significant set bit of this [Int] number,
* or zero, if this number is zero.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
public actual fun Int.takeHighestOneBit(): Int = TODO("Wasm stdlib: Numbers")
public actual fun Int.takeHighestOneBit(): Int =
if (this == 0) 0 else 1.shl(32 - 1 - countLeadingZeroBits())
/**
* Returns a number having a single bit set in the position of the least significant set bit of this [Int] number,
* or zero, if this number is zero.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
public actual fun Int.takeLowestOneBit(): Int = TODO("Wasm stdlib: Numbers")
public actual fun Int.takeLowestOneBit(): Int =
this and -this
/**
* Rotates the binary representation of this [Int] number left by the specified [bitCount] number of bits.
@@ -54,9 +52,9 @@ public actual fun Int.takeLowestOneBit(): Int = TODO("Wasm stdlib: Numbers")
* Rotating by a multiple of [Int.SIZE_BITS] (32) returns the same number, or more generally
* `number.rotateLeft(n) == number.rotateLeft(n % 32)`
*/
@SinceKotlin("1.6")
@WasExperimental(ExperimentalStdlibApi::class)
public actual fun Int.rotateLeft(bitCount: Int): Int = TODO("Wasm stdlib: Numbers")
@ExperimentalStdlibApi
public actual fun Int.rotateLeft(bitCount: Int): Int =
shl(bitCount) or ushr(32 - bitCount)
/**
@@ -69,47 +67,42 @@ public actual fun Int.rotateLeft(bitCount: Int): Int = TODO("Wasm stdlib: Number
* Rotating by a multiple of [Int.SIZE_BITS] (32) returns the same number, or more generally
* `number.rotateRight(n) == number.rotateRight(n % 32)`
*/
@SinceKotlin("1.6")
@WasExperimental(ExperimentalStdlibApi::class)
public actual fun Int.rotateRight(bitCount: Int): Int = TODO("Wasm stdlib: Numbers")
@ExperimentalStdlibApi
public actual fun Int.rotateRight(bitCount: Int): Int =
shl(32 - bitCount) or ushr(bitCount)
/**
* Counts the number of set bits in the binary representation of this [Long] number.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
public actual fun Long.countOneBits(): Int = TODO("Wasm stdlib: Numbers")
public actual inline fun Long.countOneBits(): Int =
wasm_i64_popcnt(this).toInt()
/**
* Counts the number of consecutive most significant bits that are zero in the binary representation of this [Long] number.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
public actual fun Long.countLeadingZeroBits(): Int = wasm_i64_clz(this).toInt()
/**
* Counts the number of consecutive least significant bits that are zero in the binary representation of this [Long] number.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
public actual fun Long.countTrailingZeroBits(): Int = TODO("Wasm stdlib: Numbers")
public actual inline fun Long.countTrailingZeroBits(): Int =
wasm_i64_ctz(this).toInt()
/**
* Returns a number having a single bit set in the position of the most significant set bit of this [Long] number,
* or zero, if this number is zero.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
public actual fun Long.takeHighestOneBit(): Long = TODO("Wasm stdlib: Numbers")
public actual fun Long.takeHighestOneBit(): Long =
if (this == 0L) 0L else 1L.shl(64 - 1 - countLeadingZeroBits())
/**
* Returns a number having a single bit set in the position of the least significant set bit of this [Long] number,
* or zero, if this number is zero.
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
public actual fun Long.takeLowestOneBit(): Long = TODO("Wasm stdlib: Numbers")
public actual fun Long.takeLowestOneBit(): Long =
this and -this
/**
* Rotates the binary representation of this [Long] number left by the specified [bitCount] number of bits.
@@ -121,9 +114,9 @@ public actual fun Long.takeLowestOneBit(): Long = TODO("Wasm stdlib: Numbers")
* Rotating by a multiple of [Long.SIZE_BITS] (64) returns the same number, or more generally
* `number.rotateLeft(n) == number.rotateLeft(n % 64)`
*/
@SinceKotlin("1.6")
@WasExperimental(ExperimentalStdlibApi::class)
public actual fun Long.rotateLeft(bitCount: Int): Long = TODO("Wasm stdlib: Numbers")
@ExperimentalStdlibApi
public actual fun Long.rotateLeft(bitCount: Int): Long =
shl(bitCount) or ushr(64 - bitCount)
/**
* Rotates the binary representation of this [Long] number right by the specified [bitCount] number of bits.
@@ -135,6 +128,7 @@ public actual fun Long.rotateLeft(bitCount: Int): Long = TODO("Wasm stdlib: Numb
* Rotating by a multiple of [Long.SIZE_BITS] (64) returns the same number, or more generally
* `number.rotateRight(n) == number.rotateRight(n % 64)`
*/
@SinceKotlin("1.6")
@WasExperimental(ExperimentalStdlibApi::class)
public actual fun Long.rotateRight(bitCount: Int): Long = TODO("Wasm stdlib: Numbers")
@ExperimentalStdlibApi
@kotlin.internal.InlineOnly
public actual inline fun Long.rotateRight(bitCount: Int): Long =
shl(64 - bitCount) or ushr(bitCount)
@@ -0,0 +1,11 @@
/*
* 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.native.concurrent
// Only for compatibility with shared K/N stdlib code
internal val Any?.isFrozen
inline get() = false
@@ -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.native.internal
// Only for compatibility with shared K/N stdlib code
internal interface KonanSet<out E> : Set<E> {
fun getElement(element: @UnsafeVariance E): E?
}
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.SOURCE)
internal annotation class CanBePrecreated