Add a common JVM/JS lowering for Array(size, function)

and remove the hack from JVM_IR codegen that replaces this call with
hardcoded inline function bytecode.
This commit is contained in:
pyos
2019-04-12 17:03:09 +02:00
committed by max-kammerer
parent f4bb1354c9
commit 4a29e3cfcf
14 changed files with 227 additions and 286 deletions
+6 -11
View File
@@ -41,6 +41,12 @@ public class ByteArray(size: Int) {
* @constructor Creates a new array of the specified [size], with all elements initialized to null char (`\u0000').
*/
public class CharArray(size: Int) {
/**
* Creates a new array of the specified [size], where each element is calculated by calling the specified
* [init] function. The [init] function returns an array element given its index.
*/
public inline constructor(size: Int, init: (Int) -> Char)
/** Returns the array element at the given [index]. This method can be called using the index operator. */
public 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. */
@@ -53,17 +59,6 @@ public class CharArray(size: Int) {
public operator fun iterator(): CharIterator
}
@kotlin.internal.InlineOnly
public inline fun CharArray(size: Int, init: (Int) -> Char): CharArray {
val result = CharArray(size)
var i = 0
while (i != result.size) {
result[i] = init(i)
++i
}
return result
}
/**
* 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.