Added some tests on coroutines
This commit is contained in:
@@ -796,6 +796,112 @@ task lateinit_notInitialized(type: RunKonanTest) {
|
||||
source = "codegen/lateinit/notInitialized.kt"
|
||||
}
|
||||
|
||||
task coroutines_simple(type: RunKonanTest) {
|
||||
goldValue = "42\n"
|
||||
source = "codegen/coroutines/simple.kt"
|
||||
}
|
||||
|
||||
task coroutines_withReceiver(type: RunKonanTest) {
|
||||
goldValue = "42\n"
|
||||
source = "codegen/coroutines/withReceiver.kt"
|
||||
}
|
||||
|
||||
task coroutines_correctOrder1(type: RunKonanTest) {
|
||||
goldValue = "f1\ns1\nf2\n160\n"
|
||||
source = "codegen/coroutines/correctOrder1.kt"
|
||||
}
|
||||
|
||||
task coroutines_controlFlow_if1(type: RunKonanTest) {
|
||||
goldValue = "f1\ns1\nf3\n84\n"
|
||||
source = "codegen/coroutines/controlFlow_if1.kt"
|
||||
}
|
||||
|
||||
task coroutines_controlFlow_if2(type: RunKonanTest) {
|
||||
goldValue = "f1\ns1\nf2\n43\n"
|
||||
source = "codegen/coroutines/controlFlow_if2.kt"
|
||||
}
|
||||
|
||||
// Enable after finally blocks lowering.
|
||||
|
||||
task coroutines_controlFlow_finally1(type: RunKonanTest) {
|
||||
disabled = true
|
||||
goldValue = "f1\ns1\n117\n"
|
||||
source = "codegen/coroutines/controlFlow_finally1.kt"
|
||||
}
|
||||
|
||||
task coroutines_controlFlow_finally2(type: RunKonanTest) {
|
||||
disabled = true
|
||||
goldValue = "f1\ns1\n117\n"
|
||||
source = "codegen/coroutines/controlFlow_finally2.kt"
|
||||
}
|
||||
|
||||
task coroutines_controlFlow_finally3(type: RunKonanTest) {
|
||||
disabled = true
|
||||
goldValue = "f1\ns1\n117\n"
|
||||
source = "codegen/coroutines/controlFlow_finally3.kt"
|
||||
}
|
||||
|
||||
task coroutines_controlFlow_finally4(type: RunKonanTest) {
|
||||
disabled = true
|
||||
goldValue = "s1\nfinally\n117\n"
|
||||
source = "codegen/coroutines/controlFlow_finally4.kt"
|
||||
}
|
||||
|
||||
task coroutines_controlFlow_inline1(type: RunKonanTest) {
|
||||
goldValue = "42\n"
|
||||
source = "codegen/coroutines/controlFlow_inline1.kt"
|
||||
}
|
||||
|
||||
task coroutines_controlFlow_inline2(type: RunKonanTest) {
|
||||
goldValue = "s1\n42\n"
|
||||
source = "codegen/coroutines/controlFlow_inline2.kt"
|
||||
}
|
||||
|
||||
task coroutines_controlFlow_inline3(type: RunKonanTest) {
|
||||
goldValue = "f1\ns1\n42\n"
|
||||
source = "codegen/coroutines/controlFlow_inline3.kt"
|
||||
}
|
||||
|
||||
task coroutines_controlFlow_tryCatch1(type: RunKonanTest) {
|
||||
goldValue = "s1\n42\n"
|
||||
source = "codegen/coroutines/controlFlow_tryCatch1.kt"
|
||||
}
|
||||
|
||||
task coroutines_controlFlow_tryCatch2(type: RunKonanTest) {
|
||||
goldValue = "s1\n42\n"
|
||||
source = "codegen/coroutines/controlFlow_tryCatch2.kt"
|
||||
}
|
||||
|
||||
task coroutines_controlFlow_tryCatch3(type: RunKonanTest) {
|
||||
goldValue = "s2\nf2\n1\n"
|
||||
source = "codegen/coroutines/controlFlow_tryCatch3.kt"
|
||||
}
|
||||
|
||||
task coroutines_controlFlow_tryCatch4(type: RunKonanTest) {
|
||||
goldValue = "s2\nf2\n1\n"
|
||||
source = "codegen/coroutines/controlFlow_tryCatch4.kt"
|
||||
}
|
||||
|
||||
task coroutines_controlFlow_tryCatch5(type: RunKonanTest) {
|
||||
goldValue = "s2\ns1\nError\n42\n"
|
||||
source = "codegen/coroutines/controlFlow_tryCatch5.kt"
|
||||
}
|
||||
|
||||
task coroutines_controlFlow_while1(type: RunKonanTest) {
|
||||
goldValue = "s3\ns3\ns3\ns3\n3\n"
|
||||
source = "codegen/coroutines/controlFlow_while1.kt"
|
||||
}
|
||||
|
||||
task coroutines_controlFlow_while2(type: RunKonanTest) {
|
||||
goldValue = "s3\ns3\ns3\n3\n"
|
||||
source = "codegen/coroutines/controlFlow_while2.kt"
|
||||
}
|
||||
|
||||
task coroutines_returnsUnit1(type: RunKonanTest) {
|
||||
goldValue = "117\ns1\n0\n"
|
||||
source = "codegen/coroutines/returnsUnit1.kt"
|
||||
}
|
||||
|
||||
task AbstractMutableCollection(type: RunKonanTest) {
|
||||
expectedExitStatus = 0
|
||||
source = "runtime/collections/AbstractMutableCollection.kt"
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import kotlin.coroutines.experimental.*
|
||||
import kotlin.coroutines.experimental.intrinsics.*
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resume(value: Any?) {}
|
||||
override fun resumeWithException(exception: Throwable) { throw exception }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineOrReturn { x ->
|
||||
println("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
println("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
println("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
fun f3(x: Int, y: Int): Int {
|
||||
println("f3")
|
||||
return x + y
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
result = try {
|
||||
f1()
|
||||
} catch (t: Throwable) {
|
||||
f2()
|
||||
} finally {
|
||||
s1()
|
||||
}
|
||||
}
|
||||
|
||||
println(result)
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import kotlin.coroutines.experimental.*
|
||||
import kotlin.coroutines.experimental.intrinsics.*
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resume(value: Any?) {}
|
||||
override fun resumeWithException(exception: Throwable) { throw exception }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineOrReturn { x ->
|
||||
println("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
println("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
println("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
fun f3(x: Int, y: Int): Int {
|
||||
println("f3")
|
||||
return x + y
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
val x = try {
|
||||
f1()
|
||||
} catch (t: Throwable) {
|
||||
f2()
|
||||
} finally {
|
||||
s1()
|
||||
}
|
||||
result = x
|
||||
}
|
||||
|
||||
println(result)
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import kotlin.coroutines.experimental.*
|
||||
import kotlin.coroutines.experimental.intrinsics.*
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resume(value: Any?) {}
|
||||
override fun resumeWithException(exception: Throwable) { throw exception }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineOrReturn { x ->
|
||||
println("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
println("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
println("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
fun f3(x: Int, y: Int): Int {
|
||||
println("f3")
|
||||
return x + y
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
try {
|
||||
result = f1()
|
||||
} catch (t: Throwable) {
|
||||
result = f2()
|
||||
} finally {
|
||||
s1()
|
||||
}
|
||||
}
|
||||
|
||||
println(result)
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import kotlin.coroutines.experimental.*
|
||||
import kotlin.coroutines.experimental.intrinsics.*
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resume(value: Any?) {}
|
||||
override fun resumeWithException(exception: Throwable) { throw exception }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineOrReturn { x ->
|
||||
println("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
println("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
println("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
fun f3(x: Int, y: Int): Int {
|
||||
println("f3")
|
||||
return x + y
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
try {
|
||||
result = s1()
|
||||
} catch (t: Throwable) {
|
||||
result = f2()
|
||||
} finally {
|
||||
println("finally")
|
||||
}
|
||||
}
|
||||
|
||||
println(result)
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import kotlin.coroutines.experimental.*
|
||||
import kotlin.coroutines.experimental.intrinsics.*
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resume(value: Any?) {}
|
||||
override fun resumeWithException(exception: Throwable) { throw exception }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineOrReturn { x ->
|
||||
println("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
println("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
println("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
fun f3(x: Int, y: Int): Int {
|
||||
println("f3")
|
||||
return x + y
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
result = f3(if (f1() > 100) s1() else f2(), 42)
|
||||
}
|
||||
|
||||
println(result)
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import kotlin.coroutines.experimental.*
|
||||
import kotlin.coroutines.experimental.intrinsics.*
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resume(value: Any?) {}
|
||||
override fun resumeWithException(exception: Throwable) { throw exception }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineOrReturn { x ->
|
||||
println("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
println("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
println("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
fun f3(x: Int, y: Int): Int {
|
||||
println("f3")
|
||||
return x + y
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
if (f1() > 100)
|
||||
result = s1() + f2()
|
||||
else
|
||||
result = 42
|
||||
}
|
||||
|
||||
println(result)
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import kotlin.coroutines.experimental.*
|
||||
import kotlin.coroutines.experimental.intrinsics.*
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resume(value: Any?) {}
|
||||
override fun resumeWithException(exception: Throwable) { throw exception }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineOrReturn { x ->
|
||||
println("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
inline suspend fun inline_s2(): Int {
|
||||
return 42
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
result = inline_s2()
|
||||
}
|
||||
|
||||
println(result)
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import kotlin.coroutines.experimental.*
|
||||
import kotlin.coroutines.experimental.intrinsics.*
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resume(value: Any?) {}
|
||||
override fun resumeWithException(exception: Throwable) { throw exception }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineOrReturn { x ->
|
||||
println("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
inline suspend fun inline_s2(): Int {
|
||||
var x = s1()
|
||||
return x
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
result = inline_s2()
|
||||
}
|
||||
|
||||
println(result)
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import kotlin.coroutines.experimental.*
|
||||
import kotlin.coroutines.experimental.intrinsics.*
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resume(value: Any?) {}
|
||||
override fun resumeWithException(exception: Throwable) { throw exception }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineOrReturn { x ->
|
||||
println("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
println("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
println("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
inline suspend fun inline_s2(): Int {
|
||||
var x = 0
|
||||
if (f1() > 0)
|
||||
x = s1()
|
||||
else x = f2()
|
||||
return x
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
result = inline_s2()
|
||||
}
|
||||
|
||||
println(result)
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import kotlin.coroutines.experimental.*
|
||||
import kotlin.coroutines.experimental.intrinsics.*
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resume(value: Any?) {}
|
||||
override fun resumeWithException(exception: Throwable) { throw exception }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineOrReturn { x ->
|
||||
println("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
println("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
println("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
fun f3(x: Int, y: Int): Int {
|
||||
println("f3")
|
||||
return x + y
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
val x = try {
|
||||
s1()
|
||||
} catch (t: Throwable) {
|
||||
f2()
|
||||
}
|
||||
result = x
|
||||
}
|
||||
|
||||
println(result)
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import kotlin.coroutines.experimental.*
|
||||
import kotlin.coroutines.experimental.intrinsics.*
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resume(value: Any?) {}
|
||||
override fun resumeWithException(exception: Throwable) { throw exception }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineOrReturn { x ->
|
||||
println("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
println("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
println("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
fun f3(x: Int, y: Int): Int {
|
||||
println("f3")
|
||||
return x + y
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
result = try {
|
||||
s1()
|
||||
} catch (t: Throwable) {
|
||||
f2()
|
||||
}
|
||||
}
|
||||
|
||||
println(result)
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import kotlin.coroutines.experimental.*
|
||||
import kotlin.coroutines.experimental.intrinsics.*
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resume(value: Any?) {}
|
||||
override fun resumeWithException(exception: Throwable) { throw exception }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineOrReturn { x ->
|
||||
println("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
suspend fun s2(): Int = suspendCoroutineOrReturn { x ->
|
||||
println("s2")
|
||||
x.resumeWithException(Error())
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
println("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
println("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
fun f3(x: Int, y: Int): Int {
|
||||
println("f3")
|
||||
return x + y
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
result = try {
|
||||
s2()
|
||||
} catch (t: Throwable) {
|
||||
f2()
|
||||
}
|
||||
}
|
||||
|
||||
println(result)
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import kotlin.coroutines.experimental.*
|
||||
import kotlin.coroutines.experimental.intrinsics.*
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resume(value: Any?) {}
|
||||
override fun resumeWithException(exception: Throwable) { throw exception }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineOrReturn { x ->
|
||||
println("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
suspend fun s2(): Int = suspendCoroutineOrReturn { x ->
|
||||
println("s2")
|
||||
x.resumeWithException(Error())
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
println("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
println("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
fun f3(x: Int, y: Int): Int {
|
||||
println("f3")
|
||||
return x + y
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
val x = try {
|
||||
s2()
|
||||
} catch (t: Throwable) {
|
||||
f2()
|
||||
}
|
||||
result = x
|
||||
}
|
||||
|
||||
println(result)
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import kotlin.coroutines.experimental.*
|
||||
import kotlin.coroutines.experimental.intrinsics.*
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resume(value: Any?) {}
|
||||
override fun resumeWithException(exception: Throwable) { throw exception }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineOrReturn { x ->
|
||||
println("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
suspend fun s2(): Int = suspendCoroutineOrReturn { x ->
|
||||
println("s2")
|
||||
x.resumeWithException(Error("Error"))
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
println("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
println("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
fun f3(x: Int, y: Int): Int {
|
||||
println("f3")
|
||||
return x + y
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
result = try {
|
||||
s2()
|
||||
} catch (t: Throwable) {
|
||||
val x = s1()
|
||||
println(t.message)
|
||||
x
|
||||
}
|
||||
}
|
||||
|
||||
println(result)
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import kotlin.coroutines.experimental.*
|
||||
import kotlin.coroutines.experimental.intrinsics.*
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resume(value: Any?) {}
|
||||
override fun resumeWithException(exception: Throwable) { throw exception }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineOrReturn { x ->
|
||||
println("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
suspend fun s2(): Int = suspendCoroutineOrReturn { x ->
|
||||
println("s2")
|
||||
x.resumeWithException(Error("Error"))
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
suspend fun s3(value: Int): Int = suspendCoroutineOrReturn { x ->
|
||||
println("s3")
|
||||
x.resume(value)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
println("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
println("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
fun f3(x: Int, y: Int): Int {
|
||||
println("f3")
|
||||
return x + y
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
while (s3(result) < 3)
|
||||
++result
|
||||
}
|
||||
|
||||
println(result)
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import kotlin.coroutines.experimental.*
|
||||
import kotlin.coroutines.experimental.intrinsics.*
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resume(value: Any?) {}
|
||||
override fun resumeWithException(exception: Throwable) { throw exception }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineOrReturn { x ->
|
||||
println("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
suspend fun s2(): Int = suspendCoroutineOrReturn { x ->
|
||||
println("s2")
|
||||
x.resumeWithException(Error("Error"))
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
suspend fun s3(value: Int): Int = suspendCoroutineOrReturn { x ->
|
||||
println("s3")
|
||||
x.resume(value)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
println("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
println("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
fun f3(x: Int, y: Int): Int {
|
||||
println("f3")
|
||||
return x + y
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
while (result < 3)
|
||||
result = s3(result) + 1
|
||||
}
|
||||
|
||||
println(result)
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import kotlin.coroutines.experimental.*
|
||||
import kotlin.coroutines.experimental.intrinsics.*
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resume(value: Any?) {}
|
||||
override fun resumeWithException(exception: Throwable) { throw exception }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineOrReturn { x ->
|
||||
println("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
println("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
println("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
result = f1() + s1() + f2()
|
||||
}
|
||||
|
||||
println(result)
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import kotlin.coroutines.experimental.*
|
||||
import kotlin.coroutines.experimental.intrinsics.*
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resume(value: Any?) {}
|
||||
override fun resumeWithException(exception: Throwable) { throw exception }
|
||||
}
|
||||
|
||||
suspend fun s1(): Unit = suspendCoroutineOrReturn { x ->
|
||||
println("s1")
|
||||
x.resume(Unit)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
inline suspend fun inline_s2(x: Int): Unit {
|
||||
println(x)
|
||||
s1()
|
||||
}
|
||||
|
||||
suspend fun s3(x: Int) {
|
||||
inline_s2(x)
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
s3(117)
|
||||
}
|
||||
|
||||
println(result)
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import kotlin.coroutines.experimental.*
|
||||
import kotlin.coroutines.experimental.intrinsics.*
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resume(value: Any?) {}
|
||||
override fun resumeWithException(exception: Throwable) { throw exception }
|
||||
}
|
||||
|
||||
suspend fun suspendHere(): Int = suspendCoroutineOrReturn { x ->
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
result = suspendHere()
|
||||
}
|
||||
|
||||
println(result)
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import kotlin.coroutines.experimental.*
|
||||
import kotlin.coroutines.experimental.intrinsics.*
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resume(value: Any?) {}
|
||||
override fun resumeWithException(exception: Throwable) { throw exception }
|
||||
}
|
||||
|
||||
class Controller {
|
||||
suspend fun suspendHere(): Int = suspendCoroutineOrReturn { x ->
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
}
|
||||
|
||||
fun builder(c: suspend Controller.() -> Unit) {
|
||||
c.startCoroutine(Controller(), EmptyContinuation)
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
result = suspendHere()
|
||||
}
|
||||
|
||||
println(result)
|
||||
}
|
||||
Reference in New Issue
Block a user