JS: transform coroutines before serializing AST to binary format

This commit is contained in:
Alexey Andreev
2017-02-27 20:08:09 +03:00
parent 02ca374dc9
commit 22f24d13b9
9 changed files with 95 additions and 27 deletions
+36
View File
@@ -0,0 +1,36 @@
// FILE: a.kt
// WITH_RUNTIME
import kotlin.coroutines.experimental.*
import kotlin.coroutines.experimental.intrinsics.*
suspend fun suspendThere(v: String): String = suspendCoroutineOrReturn { x ->
x.resume(v)
COROUTINE_SUSPENDED
}
suspend fun suspendHere(): String = suspendThere("O") + suspendThere("K")
// FILE: b.kt
// RECOMPILE
import kotlin.coroutines.experimental.*
import kotlin.coroutines.experimental.intrinsics.*
fun builder(c: suspend () -> Unit) {
c.startCoroutine(object : Continuation<Unit> {
override val context = EmptyCoroutineContext
override fun resume(result: Unit) {}
override fun resumeWithException(exception: Throwable) {}
})
}
fun box(): String {
var result = ""
builder {
result = suspendHere()
}
return result
}