[K/Wasm] Allow to export unsigned numbers
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
// TARGET_BACKEND: WASM
|
||||
// FILE: externals.js
|
||||
function provideUByte() { return -1 }
|
||||
function provideNullableUByte(nullable) { return nullable ? null : - 1 }
|
||||
|
||||
function consumeUByte(x) { return x.toString() }
|
||||
function consumeNullableUByte(x) { return x == null ? null : x.toString() }
|
||||
|
||||
function provideUShort() { return -1 }
|
||||
function provideNullableUShort(nullable) { return nullable ? null : - 1 }
|
||||
|
||||
function consumeUShort(x) { return x.toString() }
|
||||
function consumeNullableUShort(x) { return x == null ? null : x.toString() }
|
||||
|
||||
function provideUInt() { return -1 }
|
||||
function provideNullableUInt(nullable) { return nullable ? null : - 1 }
|
||||
|
||||
function consumeUInt(x) { return x.toString() }
|
||||
function consumeNullableUInt(x) { return x == null ? null : x.toString() }
|
||||
|
||||
function provideULong() { return -1n }
|
||||
function provideNullableULong(nullable) { return nullable ? null : - 1n }
|
||||
|
||||
function consumeULong(x) { return x.toString() }
|
||||
function consumeNullableULong(x) { return x == null ? null : x.toString() }
|
||||
|
||||
function consumeUByteVararg(x) { return x.toString() }
|
||||
function consumeNullableUByteVararg(x) { return x == null ? null : x.toString() }
|
||||
|
||||
function consumeUShortVararg(x) { return x.toString() }
|
||||
function consumeNullableUShortVararg(x) { return x == null ? null : x.toString() }
|
||||
|
||||
function consumeUIntVararg(x) { return x.toString() }
|
||||
function consumeNullableUIntVararg(x) { return x == null ? null : x.toString() }
|
||||
|
||||
function consumeULongVararg(x) { return x.toString() }
|
||||
function consumeNullableULongVararg(x) { return x == null ? null : x.toString() }
|
||||
|
||||
// FILE: externals.kt
|
||||
external fun provideUByte(): UByte
|
||||
|
||||
external fun provideNullableUByte(nullable: Boolean): UByte?
|
||||
|
||||
external fun consumeUByte(x: UByte): String
|
||||
|
||||
external fun consumeNullableUByte(x: UByte?): String?
|
||||
|
||||
external fun provideUShort(): UShort
|
||||
|
||||
external fun provideNullableUShort(nullable: Boolean): UShort?
|
||||
|
||||
external fun consumeUShort(x: UShort): String
|
||||
|
||||
external fun consumeNullableUShort(x: UShort?): String?
|
||||
|
||||
external fun provideUInt(): UInt
|
||||
|
||||
external fun provideNullableUInt(nullable: Boolean): UInt?
|
||||
|
||||
external fun consumeUInt(x: UInt): String
|
||||
|
||||
external fun consumeNullableUInt(x: UInt?): String?
|
||||
|
||||
external fun provideULong(): ULong
|
||||
|
||||
external fun provideNullableULong(nullable: Boolean): ULong?
|
||||
|
||||
external fun consumeULong(x: ULong): String
|
||||
|
||||
external fun consumeNullableULong(x: ULong?): String?
|
||||
|
||||
external fun consumeUByteVararg(vararg shorts: UByte): String
|
||||
|
||||
external fun consumeNullableUByteVararg(vararg shorts: UByte?): String?
|
||||
|
||||
external fun consumeUShortVararg(vararg shorts: UShort): String
|
||||
|
||||
external fun consumeNullableUShortVararg(vararg shorts: UShort?): String?
|
||||
|
||||
external fun consumeUIntVararg(vararg ints: UInt): String
|
||||
|
||||
external fun consumeNullableUIntVararg(vararg ints: UInt?): String?
|
||||
|
||||
external fun consumeULongVararg(vararg ints: ULong): String
|
||||
|
||||
external fun consumeNullableULongVararg(vararg ints: ULong?): String?
|
||||
|
||||
fun box(): String {
|
||||
if (provideUByte() != UByte.MAX_VALUE) return "Fail 1"
|
||||
if (provideNullableUByte(false) != UByte.MAX_VALUE) return "Fail 2"
|
||||
if (provideNullableUByte(true) != null) return "Fail 3"
|
||||
|
||||
if (provideUShort() != UShort.MAX_VALUE) return "Fail 4"
|
||||
if (provideNullableUShort(false) != UShort.MAX_VALUE) return "Fail 5"
|
||||
if (provideNullableUShort(true) != null) return "Fail 6"
|
||||
|
||||
if (provideUInt() != UInt.MAX_VALUE) return "Fail 7"
|
||||
if (provideNullableUInt(false) != UInt.MAX_VALUE) return "Fail 8"
|
||||
if (provideNullableUInt(true) != null) return "Fail 9"
|
||||
|
||||
if (provideULong() != ULong.MAX_VALUE) return "Fail 10"
|
||||
if (provideNullableULong(false) != ULong.MAX_VALUE) return "Fail 11"
|
||||
if (provideNullableULong(true) != null) return "Fail 12"
|
||||
|
||||
if (consumeUByte(UByte.MAX_VALUE) != "255") return "Fail 13"
|
||||
if (consumeNullableUByte(UByte.MAX_VALUE) != "255") return "Fail 14"
|
||||
if (consumeNullableUByte(null) != null) return "Fail 15"
|
||||
|
||||
if (consumeUShort(UShort.MAX_VALUE) != "65535") return "Fail 16"
|
||||
if (consumeNullableUShort(UShort.MAX_VALUE) != "65535") return "Fail 17"
|
||||
if (consumeNullableUShort(null) != null) return "Fail 18"
|
||||
|
||||
if (consumeUInt(UInt.MAX_VALUE) != "4294967295") return "Fail 19"
|
||||
if (consumeNullableUInt(UInt.MAX_VALUE) != "4294967295") return "Fail 20"
|
||||
if (consumeNullableUInt(null) != null) return "Fail 21"
|
||||
|
||||
if (consumeULong(ULong.MAX_VALUE) != "18446744073709551615") return "Fail 22"
|
||||
if (consumeNullableULong(ULong.MAX_VALUE) != "18446744073709551615") return "Fail 23"
|
||||
if (consumeNullableULong(null) != null) return "Fail 24"
|
||||
|
||||
if (provideUShort() != UShort.MAX_VALUE) return "Fail 25"
|
||||
if (provideNullableUShort(false) != UShort.MAX_VALUE) return "Fail 26"
|
||||
if (provideNullableUShort(true) != null) return "Fail 27"
|
||||
|
||||
if (provideUInt() != UInt.MAX_VALUE) return "Fail 28"
|
||||
if (provideNullableUInt(false) != UInt.MAX_VALUE) return "Fail 29"
|
||||
if (provideNullableUInt(true) != null) return "Fail 30"
|
||||
|
||||
if (provideULong() != ULong.MAX_VALUE) return "Fail 31"
|
||||
if (provideNullableULong(false) != ULong.MAX_VALUE) return "Fail 32"
|
||||
if (provideNullableULong(true) != null) return "Fail 33"
|
||||
|
||||
if (consumeUByteVararg(UByte.MAX_VALUE) != "255") return "Fail 34"
|
||||
if (consumeNullableUByteVararg(UByte.MAX_VALUE) != "255") return "Fail 35"
|
||||
if (consumeNullableUByteVararg(null) != null) return "Fail 36"
|
||||
|
||||
if (consumeUShortVararg(UShort.MAX_VALUE) != "65535") return "Fail 37"
|
||||
if (consumeNullableUShortVararg(UShort.MAX_VALUE) != "65535") return "Fail 38"
|
||||
if (consumeNullableUShortVararg(null) != null) return "Fail 39"
|
||||
|
||||
if (consumeUIntVararg(UInt.MAX_VALUE) != "4294967295") return "Fail 40"
|
||||
if (consumeNullableUIntVararg(UInt.MAX_VALUE) != "4294967295") return "Fail 41"
|
||||
if (consumeNullableUIntVararg(null) != null) return "Fail 42"
|
||||
|
||||
if (consumeULongVararg(ULong.MAX_VALUE) != "18446744073709551615") return "Fail 43"
|
||||
if (consumeNullableULongVararg(ULong.MAX_VALUE) != "18446744073709551615") return "Fail 44"
|
||||
if (consumeNullableULongVararg(null) != null) return "Fail 45"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+183
-1
@@ -24,6 +24,54 @@ fun eiAsAny(ei: EI): JsReference<Any> = ei.toJsReference()
|
||||
@JsExport
|
||||
fun anyAsEI(any: JsReference<Any>): EI = any.get() as EI
|
||||
|
||||
@JsExport
|
||||
fun provideUByte(): UByte = UByte.MAX_VALUE
|
||||
|
||||
@JsExport
|
||||
fun provideNullableUByte(nullable: Boolean): UByte? = if (nullable) null else UByte.MAX_VALUE
|
||||
|
||||
@JsExport
|
||||
fun consumeUByte(x: UByte) = x.toString()
|
||||
|
||||
@JsExport
|
||||
fun consumeNullableUByte(x: UByte?) = x?.toString()
|
||||
|
||||
@JsExport
|
||||
fun provideUShort(): UShort = UShort.MAX_VALUE
|
||||
|
||||
@JsExport
|
||||
fun provideNullableUShort(nullable: Boolean): UShort? = if (nullable) null else UShort.MAX_VALUE
|
||||
|
||||
@JsExport
|
||||
fun consumeUShort(x: UShort) = x.toString()
|
||||
|
||||
@JsExport
|
||||
fun consumeNullableUShort(x: UShort?) = x?.toString()
|
||||
|
||||
@JsExport
|
||||
fun provideUInt(): UInt = UInt.MAX_VALUE
|
||||
|
||||
@JsExport
|
||||
fun provideNullableUInt(nullable: Boolean): UInt? = if (nullable) null else UInt.MAX_VALUE
|
||||
|
||||
@JsExport
|
||||
fun consumeUInt(x: UInt) = x.toString()
|
||||
|
||||
@JsExport
|
||||
fun consumeNullableUInt(x: UInt?) = x?.toString()
|
||||
|
||||
@JsExport
|
||||
fun provideULong(): ULong = ULong.MAX_VALUE
|
||||
|
||||
@JsExport
|
||||
fun provideNullableULong(nullable: Boolean): ULong? = if (nullable) null else ULong.MAX_VALUE
|
||||
|
||||
@JsExport
|
||||
fun consumeULong(x: ULong) = x.toString()
|
||||
|
||||
@JsExport
|
||||
fun consumeNullableULong(x: ULong?) = x?.toString()
|
||||
|
||||
fun box(): String = "OK"
|
||||
|
||||
// FILE: entry.mjs
|
||||
@@ -45,4 +93,138 @@ if (main.isEven(31) !== false || main.isEven(10) !== true) {
|
||||
|
||||
if (main.anyAsEI(main.eiAsAny({x:10})).x !== 10) {
|
||||
throw "Fail 4";
|
||||
}
|
||||
}
|
||||
|
||||
if (main.provideUByte() != 255) {
|
||||
throw "Fail 5";
|
||||
}
|
||||
if (main.provideUShort() != 65535) {
|
||||
throw "Fail 6";
|
||||
}
|
||||
if (main.provideUInt() != 4294967295) {
|
||||
throw "Fail 7";
|
||||
}
|
||||
if (main.provideULong() != 18446744073709551615n) {
|
||||
throw "Fail 8";
|
||||
}
|
||||
|
||||
if (main.provideNullableUByte(false) != 255) {
|
||||
throw "Fail 9";
|
||||
}
|
||||
if (main.provideNullableUByte(true) != null) {
|
||||
throw "Fail 10";
|
||||
}
|
||||
if (main.provideNullableUShort(false) != 65535) {
|
||||
throw "Fail 11";
|
||||
}
|
||||
if (main.provideNullableUShort(true) != null) {
|
||||
throw "Fail 12";
|
||||
}
|
||||
if (main.provideNullableUInt(false) != 4294967295) {
|
||||
throw "Fail 13";
|
||||
}
|
||||
if (main.provideNullableUInt(true) != null) {
|
||||
throw "Fail 14";
|
||||
}
|
||||
if (main.provideNullableULong(false) != 18446744073709551615n) {
|
||||
throw "Fail 15";
|
||||
}
|
||||
if (main.provideNullableULong(true) != null) {
|
||||
throw "Fail 16";
|
||||
}
|
||||
|
||||
if (main.consumeUByte(-1) != "255") {
|
||||
throw "Fail 17";
|
||||
}
|
||||
if (main.consumeNullableUByte(-1) != "255") {
|
||||
throw "Fail 18";
|
||||
}
|
||||
if (main.consumeNullableUByte(null) != null) {
|
||||
throw "Fail 19";
|
||||
}
|
||||
|
||||
if (main.consumeUShort(-1) != "65535") {
|
||||
throw "Fail 20";
|
||||
}
|
||||
if (main.consumeNullableUShort(-1) != "65535") {
|
||||
throw "Fail 21";
|
||||
}
|
||||
if (main.consumeNullableUShort(null) != null) {
|
||||
throw "Fail 22";
|
||||
}
|
||||
|
||||
if (main.consumeUInt(-1) != "4294967295") {
|
||||
throw "Fail 23";
|
||||
}
|
||||
if (main.consumeNullableUInt(-1) != "4294967295") {
|
||||
throw "Fail 24";
|
||||
}
|
||||
if (main.consumeNullableUInt(null) != null) {
|
||||
throw "Fail 25";
|
||||
}
|
||||
|
||||
if (main.consumeULong(-1n) != "18446744073709551615") {
|
||||
throw "Fail 26";
|
||||
}
|
||||
if (main.consumeNullableULong(-1n) != "18446744073709551615") {
|
||||
throw "Fail 27";
|
||||
}
|
||||
if (main.consumeNullableULong(null) != null) {
|
||||
throw "Fail 28";
|
||||
}
|
||||
|
||||
if (main.consumeUByte(255) != "255") {
|
||||
throw "Fail 29";
|
||||
}
|
||||
if (main.consumeNullableUByte(255) != "255") {
|
||||
throw "Fail 30";
|
||||
}
|
||||
|
||||
if (main.consumeUShort(65535) != "65535") {
|
||||
throw "Fail 31";
|
||||
}
|
||||
if (main.consumeNullableUShort(65535) != "65535") {
|
||||
throw "Fail 32";
|
||||
}
|
||||
|
||||
if (main.consumeUInt(4294967295) != "4294967295") {
|
||||
throw "Fail 33";
|
||||
}
|
||||
if (main.consumeNullableUInt(4294967295) != "4294967295") {
|
||||
throw "Fail 34";
|
||||
}
|
||||
|
||||
if (main.consumeULong(18446744073709551615n) != "18446744073709551615") {
|
||||
throw "Fail 35";
|
||||
}
|
||||
if (main.consumeNullableULong(18446744073709551615n) != "18446744073709551615") {
|
||||
throw "Fail 36";
|
||||
}
|
||||
|
||||
if (main.consumeUByte(256) != "0") {
|
||||
throw "Fail 37";
|
||||
}
|
||||
if (main.consumeNullableUByte(256) != "0") {
|
||||
throw "Fail 38";
|
||||
}
|
||||
|
||||
if (main.consumeUShort(65536) != "0") {
|
||||
throw "Fail 39";
|
||||
}
|
||||
if (main.consumeNullableUShort(65536) != "0") {
|
||||
throw "Fail 40";
|
||||
}
|
||||
|
||||
if (main.consumeUInt(4294967296) != "0") {
|
||||
throw "Fail 41";
|
||||
}
|
||||
if (main.consumeNullableUInt(4294967296) != "0") {
|
||||
throw "Fail 42";
|
||||
}
|
||||
|
||||
if (main.consumeULong(18446744073709551616n) != "0") {
|
||||
throw "Fail 43";
|
||||
}
|
||||
if (main.consumeNullableULong(18446744073709551616n) != "0") {
|
||||
throw "Fail 44";
|
||||
}
|
||||
|
||||
+24
-5
@@ -2,18 +2,37 @@
|
||||
|
||||
import kotlin.wasm.WasmExport
|
||||
|
||||
@WasmExport
|
||||
fun exportDefaultName(): Boolean = true
|
||||
|
||||
fun checkDefaultName(): Boolean = js("typeof wasmExports.exportDefaultName() !== 'object'")
|
||||
|
||||
@WasmExport("exportOverriddenName")
|
||||
fun exportWithName(): Boolean = true
|
||||
|
||||
@WasmExport
|
||||
fun exportDefaultName(): Boolean = true
|
||||
|
||||
@WasmExport
|
||||
fun provideUByte(): UByte = UByte.MAX_VALUE
|
||||
|
||||
@WasmExport
|
||||
fun provideUShort(): UShort = UShort.MAX_VALUE
|
||||
|
||||
@WasmExport
|
||||
fun provideUInt(): UInt = UInt.MAX_VALUE
|
||||
|
||||
@WasmExport
|
||||
fun provideULong(): ULong = ULong.MAX_VALUE
|
||||
|
||||
fun checkDefaultName(): Boolean = js("typeof wasmExports.exportDefaultName() !== 'object'")
|
||||
fun checkOverriddenName(): Boolean = js("typeof wasmExports.exportOverriddenName() !== 'object'")
|
||||
fun checkProvideUByte(): Boolean = js("wasmExports.provideUByte() === -1")
|
||||
fun checkProvideUShort(): Boolean = js("wasmExports.provideUShort() === -1")
|
||||
fun checkProvideUInt(): Boolean = js("wasmExports.provideUInt() === -1")
|
||||
fun checkProvideULong(): Boolean = js("wasmExports.provideULong() === -1n")
|
||||
|
||||
fun box(): String {
|
||||
if (!checkDefaultName()) return "checkDefaultName fail"
|
||||
if (!checkOverriddenName()) return "checkOverriddenName fail"
|
||||
if (!checkProvideUByte()) return "checkProvideUByte fail"
|
||||
if (!checkProvideUShort()) return "checkProvideUShort fail"
|
||||
if (!checkProvideUInt()) return "checkProvideUInt fail"
|
||||
if (!checkProvideULong()) return "checkProvideULong fail"
|
||||
return "OK"
|
||||
}
|
||||
@@ -20,6 +20,16 @@ export { sub as "" }
|
||||
export { sub as "\n \r \t" }
|
||||
export default sub;
|
||||
|
||||
// FILE: 3.mjs
|
||||
|
||||
export function provideUByte() { return -1 }
|
||||
|
||||
export function provideUShort() { return -1 }
|
||||
|
||||
export function provideUInt() { return -1 }
|
||||
|
||||
export function provideULong() { return -1n }
|
||||
|
||||
// FILE: wasmImport.kt
|
||||
import kotlin.wasm.WasmImport
|
||||
|
||||
@@ -50,6 +60,18 @@ external fun sub5(x: Float, y: Float): Float
|
||||
@WasmImport("./2.mjs", "default")
|
||||
external fun sub6(x: Float, y: Float): Float
|
||||
|
||||
@WasmImport("./3.mjs", "provideUByte")
|
||||
external fun provideUByte(): UByte
|
||||
|
||||
@WasmImport("./3.mjs", "provideUShort")
|
||||
external fun provideUShort(): UShort
|
||||
|
||||
@WasmImport("./3.mjs", "provideUInt")
|
||||
external fun provideUInt(): UInt
|
||||
|
||||
@WasmImport("./3.mjs", "provideULong")
|
||||
external fun provideULong(): ULong
|
||||
|
||||
fun box(): String {
|
||||
if (addImportRenamed(5, 6) != 11) return "Fail1"
|
||||
if (add(5, 6) != 11) return "Fail1"
|
||||
@@ -62,5 +84,10 @@ fun box(): String {
|
||||
if (sub5(5f, 6f) != -1f) return "Fail6"
|
||||
if (sub6(5f, 6f) != -1f) return "Fail7"
|
||||
|
||||
if (provideUByte() != UByte.MAX_VALUE) return "Fail9"
|
||||
if (provideUShort() != UShort.MAX_VALUE) return "Fail10"
|
||||
if (provideUInt() != UInt.MAX_VALUE) return "Fail11"
|
||||
if (provideULong() != ULong.MAX_VALUE) return "Fail12"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user