[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:
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
|
||||
fun equals1(a: Double, b: Double) = a.equals(b)
|
||||
|
||||
fun box(): String {
|
||||
if ((-0.0).equals(0.0)) return "fail 0"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
public fun box() : String {
|
||||
if ( 0 == 0 ) { // Does not crash if either this...
|
||||
if ( 0 == 0 ) { // ...or this is changed to if ( true )
|
||||
// Does not crash if the following is uncommented.
|
||||
//println("foo")
|
||||
}
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fun box(): String {
|
||||
if (1F != 1.toFloat()) return "fail 1"
|
||||
if (1.0F != 1.0.toFloat()) return "fail 2"
|
||||
if (1e1F != 1e1.toFloat()) return "fail 3"
|
||||
if (1.0e1F != 1.0e1.toFloat()) return "fail 4"
|
||||
if (1e-1F != 1e-1.toFloat()) return "fail 5"
|
||||
if (1.0e-1F != 1.0e-1.toFloat()) return "fail 6"
|
||||
|
||||
if (1f != 1.toFloat()) return "fail 7"
|
||||
if (1.0f != 1.0.toFloat()) return "fail 8"
|
||||
if (1e1f != 1e1.toFloat()) return "fail 9"
|
||||
if (1.0e1f != 1.0e1.toFloat()) return "fail 10"
|
||||
if (1e-1f != 1e-1.toFloat()) return "fail 11"
|
||||
if (1.0e-1f != 1.0e-1.toFloat()) return "fail 12"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
fun box(): String {
|
||||
if (1L != 1.toLong()) return "fail 1"
|
||||
if (0x1L != 0x1.toLong()) return "fail 2"
|
||||
if (0X1L != 0X1.toLong()) return "fail 3"
|
||||
if (0b1L != 0b1.toLong()) return "fail 4"
|
||||
if (0B1L != 0B1.toLong()) return "fail 5"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
fun foo(b: Boolean): String {
|
||||
return if (b) {
|
||||
"OK"
|
||||
} else if (false) {
|
||||
"fail: reached unreachable code at line 5"
|
||||
} else if (true) {
|
||||
"fail: reached unexpected code at line 7"
|
||||
} else if (true) {
|
||||
"fail: reached unreachable code at line 9"
|
||||
} else if (b) {
|
||||
"fail: reached unreachable code at line 11"
|
||||
} else {
|
||||
"fail: reached unreachable code at line 13"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return foo(true)
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
fun foo(b: Boolean): String {
|
||||
return if (b) {
|
||||
"fail: reached unexpected code at line 3"
|
||||
} else if (false) {
|
||||
"fail: reached unreachable code at line 5"
|
||||
} else if (true) {
|
||||
"OK"
|
||||
} else if (true) {
|
||||
"fail: reached unreachable code at line 9"
|
||||
} else if (b) {
|
||||
"fail: reached unreachable code at line 11"
|
||||
} else {
|
||||
"fail: reached unreachable code at line 13"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return foo(false)
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
fun box(): String {
|
||||
if (1 != 0) {
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
val Int.foo: String
|
||||
get() = "OK"
|
||||
|
||||
fun box(): String {
|
||||
return 1.foo
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fun box(): String {
|
||||
fun rmrf(i: Int) {
|
||||
if (i > 0) rmrf(i - 1)
|
||||
}
|
||||
rmrf(5)
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
// !LANGUAGE: +ProperIeee754Comparisons +NewInference
|
||||
|
||||
fun box(): String {
|
||||
if (-0.0 < 0.0) return "Fail 1"
|
||||
if (-0.0 < 0) return "Fail 2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
fun foo(x: String): String {
|
||||
fun bar(y: String) = x + y
|
||||
return bar("K")
|
||||
}
|
||||
|
||||
fun box() = foo("O")
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
fun foo(x: String): String {
|
||||
fun bar(y: String): String {
|
||||
fun qux(z: String): String =
|
||||
x + y + z
|
||||
return qux("")
|
||||
}
|
||||
return bar("K")
|
||||
}
|
||||
|
||||
fun box(): String =
|
||||
foo("O")
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
fun String.foo(): String {
|
||||
fun bar(y: String) = this + y
|
||||
return bar("K")
|
||||
}
|
||||
|
||||
fun box() = "O".foo()
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
val Int.getter: Int
|
||||
get() {
|
||||
return this@getter
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val i = 1
|
||||
if (i.getter != 1) return "getter failed"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
fun box(): String {
|
||||
if (!(1 < 2)) {
|
||||
return "fail"
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
@Target(AnnotationTarget.EXPRESSION)
|
||||
@Retention(AnnotationRetention.SOURCE)
|
||||
annotation class Annotation
|
||||
|
||||
fun box(): String {
|
||||
var v = 0
|
||||
@Annotation v += 1 + 2
|
||||
if (v != 3) return "fail1"
|
||||
|
||||
@Annotation v = 4
|
||||
if (v != 4) return "fail2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
infix fun Int.rem(other: Int) = 10
|
||||
infix operator fun Int.minus(other: Int): Int = 20
|
||||
|
||||
fun box(): String {
|
||||
val a = 5 rem 2
|
||||
if (a != 10) return "fail 1"
|
||||
|
||||
val b = 5 minus 3
|
||||
if (b != 20) return "fail 2"
|
||||
|
||||
val a1 = 5.rem(2)
|
||||
if (a1 != 1) return "fail 3"
|
||||
|
||||
val b2 = 5.minus(3)
|
||||
if (b2 != 2) return "fail 4"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
fun box(): String {
|
||||
if (1 != 0) {
|
||||
1
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
fun byteArg(b: Byte) {}
|
||||
fun charArg(c: Char) {}
|
||||
fun shortArg(s: Short) {}
|
||||
|
||||
fun box(): String {
|
||||
var b = 42.toByte()
|
||||
b++
|
||||
++b
|
||||
byteArg(b)
|
||||
|
||||
var c = 'x'
|
||||
c++
|
||||
++c
|
||||
charArg(c)
|
||||
|
||||
var s = 239.toShort()
|
||||
s++
|
||||
++s
|
||||
shortArg(s)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
fun box(): String {
|
||||
!true
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fun box(): String {
|
||||
if (1 >= 1.9) return "Fail #1"
|
||||
if (1.compareTo(1.1) >= 0) return "Fail #2"
|
||||
if (1.9 <= 1) return "Fail #3"
|
||||
if (1.1.compareTo(1) <= 0) return "Fail #4"
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
fun box(): String {
|
||||
val i: Int = 10000
|
||||
if (!(i === i)) return "Fail int ==="
|
||||
if (i !== i) return "Fail int !=="
|
||||
|
||||
val j: Long = 123L
|
||||
if (!(j === j)) return "Fail long ==="
|
||||
if (j !== j) return "Fail long !=="
|
||||
|
||||
val d: Double = 3.14
|
||||
if (!(d === d)) return "Fail double ==="
|
||||
if (d !== d) return "Fail double !=="
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
fun box(): String {
|
||||
if (3.compareTo(2) != 1) return "Fail #1"
|
||||
if (5.toByte().compareTo(10.toLong()) >= 0) return "Fail #2"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package demo
|
||||
|
||||
fun box() : String {
|
||||
var res : Boolean = true
|
||||
res = (res and false)
|
||||
res = (res or false)
|
||||
res = (res xor false)
|
||||
res = (true and false)
|
||||
res = (true or false)
|
||||
res = (true xor false)
|
||||
res = (!true)
|
||||
res = (true && false)
|
||||
res = (true || false)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fun box() : String {
|
||||
var a : Int = -1
|
||||
if((+a) != -1) return "fail 1"
|
||||
a = 1
|
||||
if((+a) != 1) return "fail 2"
|
||||
if((+-1) != -1) return "fail 3"
|
||||
if((-+a) != -1) return "fail 4"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// MODULE: lib
|
||||
// FILE: lib.kt
|
||||
@PublishedApi
|
||||
internal fun published() = "OK"
|
||||
|
||||
inline fun test() = published()
|
||||
|
||||
// MODULE: main(lib)
|
||||
// FILE: main.kt
|
||||
fun box() = test()
|
||||
@@ -0,0 +1,17 @@
|
||||
fun box(): String {
|
||||
val a1: Byte = -1
|
||||
val a2: Short = -1
|
||||
val a3: Int = -1
|
||||
val a4: Long = -1
|
||||
val a5: Double = -1.0
|
||||
val a6: Float = -1f
|
||||
|
||||
if (a1 != (-1).toByte()) return "fail 1"
|
||||
if (a2 != (-1).toShort()) return "fail 2"
|
||||
if (a3 != -1) return "fail 3"
|
||||
if (a4 != -1L) return "fail 4"
|
||||
if (a5 != -1.0) return "fail 5"
|
||||
if (a6 != -1f) return "fail 6"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fun box(): String {
|
||||
val x = 3
|
||||
when (x) {
|
||||
1 -> {}
|
||||
2 -> {}
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user