[WASM] Initial infrastructure
- New module ":compiler:backend.wasm"
- Initial compiler infra (driver, phaser, context)
- Subset of Wasm AST
- Skeleton of IR -> Wasm AST
- Wasm AST -> WAT transformer
- Testing infra
- SpiderMonkey jsshell tool
This commit is contained in:
@@ -13,6 +13,9 @@
|
||||
|
||||
package kotlin
|
||||
|
||||
import kotlin.wasm.internal.WasmInstruction
|
||||
import kotlin.wasm.internal.wasm_i32_compareTo
|
||||
|
||||
/**
|
||||
* 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`.
|
||||
@@ -21,26 +24,34 @@ public class Boolean private constructor() : Comparable<Boolean> {
|
||||
/**
|
||||
* Returns the inverse of this boolean.
|
||||
*/
|
||||
@WasmInstruction(WasmInstruction.I32_EQZ)
|
||||
public 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.
|
||||
*/
|
||||
@WasmInstruction(WasmInstruction.I32_AND)
|
||||
public 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.
|
||||
*/
|
||||
@WasmInstruction(WasmInstruction.I32_OR)
|
||||
public infix fun or(other: Boolean): Boolean
|
||||
|
||||
/**
|
||||
* Performs a logical `xor` operation between this Boolean and the [other] one.
|
||||
*/
|
||||
@WasmInstruction(WasmInstruction.I32_XOR)
|
||||
public infix fun xor(other: Boolean): Boolean
|
||||
|
||||
public override fun compareTo(other: Boolean): Int
|
||||
public override fun compareTo(other: Boolean): Int =
|
||||
wasm_i32_compareTo(this.asInt(), other.asInt())
|
||||
|
||||
@WasmInstruction(WasmInstruction.NOP)
|
||||
internal fun asInt(): Int
|
||||
|
||||
@SinceKotlin("1.3")
|
||||
companion object {}
|
||||
|
||||
@@ -3,16 +3,15 @@
|
||||
* 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"
|
||||
)
|
||||
@file:Suppress("OVERRIDE_BY_INLINE", "NOTHING_TO_INLINE")
|
||||
|
||||
package kotlin
|
||||
|
||||
import kotlin.wasm.internal.ExcludedFromCodegen
|
||||
import kotlin.wasm.internal.WasmInstruction
|
||||
import kotlin.wasm.internal.implementedAsIntrinsic
|
||||
import kotlin.wasm.internal.wasm_i32_compareTo
|
||||
|
||||
/**
|
||||
* Represents a 16-bit Unicode character.
|
||||
*
|
||||
@@ -25,39 +24,56 @@ public class Char private constructor() : Comparable<Char> {
|
||||
* 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.
|
||||
*/
|
||||
public override fun compareTo(other: Char): Int
|
||||
public override inline fun compareTo(other: Char): Int =
|
||||
wasm_i32_compareTo(this.toInt(), other.toInt())
|
||||
|
||||
/** Adds the other Int value to this value resulting a Char. */
|
||||
public operator fun plus(other: Int): Char
|
||||
public inline operator fun plus(other: Int): Char =
|
||||
(this.toInt() + other).toChar()
|
||||
|
||||
/** Subtracts the other Char value from this value resulting an Int. */
|
||||
public operator fun minus(other: Char): Int
|
||||
public inline operator fun minus(other: Char): Int =
|
||||
(this.toInt() - other.toInt())
|
||||
|
||||
/** Subtracts the other Int value from this value resulting a Char. */
|
||||
public operator fun minus(other: Int): Char
|
||||
public inline operator fun minus(other: Int): Char =
|
||||
(this.toInt() - other).toChar()
|
||||
|
||||
/** Increments this value. */
|
||||
public operator fun inc(): Char
|
||||
public inline operator fun inc(): Char =
|
||||
(this.toInt() + 1).toChar()
|
||||
|
||||
/** Decrements this value. */
|
||||
public operator fun dec(): Char
|
||||
public inline operator fun dec(): Char =
|
||||
(this.toInt() - 1).toChar()
|
||||
|
||||
// /** Creates a range from this value to the specified [other] value. */
|
||||
// public operator fun rangeTo(other: Char): CharRange
|
||||
|
||||
/** Returns the value of this character as a `Byte`. */
|
||||
public fun toByte(): Byte
|
||||
public inline fun toByte(): Byte =
|
||||
this.toInt().toByte()
|
||||
/** Returns the value of this character as a `Char`. */
|
||||
public fun toChar(): Char
|
||||
public inline fun toChar(): Char =
|
||||
this
|
||||
/** Returns the value of this character as a `Short`. */
|
||||
public fun toShort(): Short
|
||||
public inline fun toShort(): Short =
|
||||
this.toInt().toShort()
|
||||
/** Returns the value of this character as a `Int`. */
|
||||
public fun toInt(): Int
|
||||
@WasmInstruction(WasmInstruction.NOP)
|
||||
public fun toInt(): Int =
|
||||
implementedAsIntrinsic
|
||||
/** Returns the value of this character as a `Long`. */
|
||||
public fun toLong(): Long
|
||||
public inline fun toLong(): Long =
|
||||
this.toInt().toLong()
|
||||
/** Returns the value of this character as a `Float`. */
|
||||
public fun toFloat(): Float
|
||||
public inline fun toFloat(): Float =
|
||||
this.toInt().toFloat()
|
||||
/** Returns the value of this character as a `Double`. */
|
||||
public fun toDouble(): Double
|
||||
public inline fun toDouble(): Double =
|
||||
this.toInt().toDouble()
|
||||
|
||||
@ExcludedFromCodegen
|
||||
companion object {
|
||||
/**
|
||||
* The minimum value of a character code unit.
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"NON_MEMBER_FUNCTION_NO_BODY",
|
||||
"REIFIED_TYPE_PARAMETER_NO_INLINE"
|
||||
)
|
||||
@file:ExcludedFromCodegen
|
||||
@file:kotlin.wasm.internal.ExcludedFromCodegen
|
||||
|
||||
package kotlin
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -13,19 +13,25 @@
|
||||
|
||||
package kotlin
|
||||
|
||||
import kotlin.wasm.internal.ExcludedFromCodegen
|
||||
import kotlin.wasm.internal.WasmImport
|
||||
|
||||
/**
|
||||
* The `String` class represents character strings. All string literals in Kotlin programs, such as `"abc"`, are
|
||||
* implemented as instances of this class.
|
||||
*/
|
||||
public class String : Comparable<String>, CharSequence {
|
||||
@ExcludedFromCodegen
|
||||
companion object {}
|
||||
|
||||
/**
|
||||
* Returns a string obtained by concatenating this string with the string representation of the given [other] object.
|
||||
*/
|
||||
@WasmImport("runtime", "String_plus")
|
||||
public operator fun plus(other: Any?): String
|
||||
|
||||
public override val length: Int
|
||||
@WasmImport("runtime", "String_getLength") get
|
||||
|
||||
/**
|
||||
* Returns the character of this string at the specified [index].
|
||||
@@ -33,9 +39,20 @@ public class String : Comparable<String>, CharSequence {
|
||||
* If the [index] is out of bounds of this string, throws an [IndexOutOfBoundsException] except in Kotlin/JS
|
||||
* where the behavior is unspecified.
|
||||
*/
|
||||
@WasmImport("runtime", "String_getChar")
|
||||
public override fun get(index: Int): Char
|
||||
|
||||
@ExcludedFromCodegen
|
||||
public override fun subSequence(startIndex: Int, endIndex: Int): CharSequence
|
||||
|
||||
@WasmImport("runtime", "String_compareTo")
|
||||
public override fun compareTo(other: String): Int
|
||||
}
|
||||
|
||||
@ExcludedFromCodegen
|
||||
public override fun equals(other: Any?): Boolean
|
||||
|
||||
public override fun toString(): String = this
|
||||
|
||||
@ExcludedFromCodegen
|
||||
public override fun hashCode(): Int
|
||||
}
|
||||
Reference in New Issue
Block a user