summaryrefslogtreecommitdiff
path: root/test/files/continuations-run
diff options
context:
space:
mode:
authorTiark Rompf <tiark.rompf@epfl.ch>2010-03-11 16:55:38 +0000
committerTiark Rompf <tiark.rompf@epfl.ch>2010-03-11 16:55:38 +0000
commitf584d243487dcd1214291167707e2f53fef5ab5e (patch)
treeaf3e926d301193b259d27567470b4c483efbecbe /test/files/continuations-run
parent356540e284e9c9407151a44afdb9480d8eb137a1 (diff)
downloadscala-f584d243487dcd1214291167707e2f53fef5ab5e.tar.gz
scala-f584d243487dcd1214291167707e2f53fef5ab5e.tar.bz2
scala-f584d243487dcd1214291167707e2f53fef5ab5e.zip
moved the continuations plugin into trunk.
Diffstat (limited to 'test/files/continuations-run')
-rwxr-xr-xtest/files/continuations-run/basics.check2
-rwxr-xr-xtest/files/continuations-run/basics.scala23
-rw-r--r--test/files/continuations-run/function1.check1
-rw-r--r--test/files/continuations-run/function1.scala16
-rw-r--r--test/files/continuations-run/function4.check1
-rw-r--r--test/files/continuations-run/function4.scala15
-rw-r--r--test/files/continuations-run/function5.check1
-rw-r--r--test/files/continuations-run/function5.scala15
-rw-r--r--test/files/continuations-run/ifelse0.check2
-rw-r--r--test/files/continuations-run/ifelse0.scala18
-rw-r--r--test/files/continuations-run/ifelse1.check4
-rw-r--r--test/files/continuations-run/ifelse1.scala25
-rw-r--r--test/files/continuations-run/ifelse2.check4
-rw-r--r--test/files/continuations-run/ifelse2.scala16
-rw-r--r--test/files/continuations-run/ifelse3.check2
-rw-r--r--test/files/continuations-run/ifelse3.scala21
-rw-r--r--test/files/continuations-run/infer1.scala33
-rw-r--r--test/files/continuations-run/match0.check2
-rw-r--r--test/files/continuations-run/match0.scala18
-rw-r--r--test/files/continuations-run/match1.check2
-rw-r--r--test/files/continuations-run/match1.scala18
-rw-r--r--test/files/continuations-run/match2.check2
-rw-r--r--test/files/continuations-run/match2.scala26
-rw-r--r--test/files/continuations-run/t1807.check1
-rw-r--r--test/files/continuations-run/t1807.scala14
-rw-r--r--test/files/continuations-run/t1808.scala10
-rw-r--r--test/files/continuations-run/t1820.scala14
-rw-r--r--test/files/continuations-run/t1821.check4
-rw-r--r--test/files/continuations-run/t1821.scala20
-rw-r--r--test/files/continuations-run/while0.check1
-rw-r--r--test/files/continuations-run/while0.scala22
-rw-r--r--test/files/continuations-run/while1.check11
-rw-r--r--test/files/continuations-run/while1.scala22
-rw-r--r--test/files/continuations-run/while2.check19
-rw-r--r--test/files/continuations-run/while2.scala23
35 files changed, 428 insertions, 0 deletions
diff --git a/test/files/continuations-run/basics.check b/test/files/continuations-run/basics.check
new file mode 100755
index 0000000000..54c059fdcb
--- /dev/null
+++ b/test/files/continuations-run/basics.check
@@ -0,0 +1,2 @@
+28
+28 \ No newline at end of file
diff --git a/test/files/continuations-run/basics.scala b/test/files/continuations-run/basics.scala
new file mode 100755
index 0000000000..9df209b11c
--- /dev/null
+++ b/test/files/continuations-run/basics.scala
@@ -0,0 +1,23 @@
+// $Id$
+
+import scala.util.continuations._
+
+
+object Test {
+
+ def m0() = {
+ shift((k:Int => Int) => k(k(7))) * 2
+ }
+
+ def m1() = {
+ 2 * shift((k:Int => Int) => k(k(7)))
+ }
+
+ def main(args: Array[String]) = {
+
+ println(reset(m0()))
+ println(reset(m1()))
+
+ }
+
+}
diff --git a/test/files/continuations-run/function1.check b/test/files/continuations-run/function1.check
new file mode 100644
index 0000000000..7f8f011eb7
--- /dev/null
+++ b/test/files/continuations-run/function1.check
@@ -0,0 +1 @@
+7
diff --git a/test/files/continuations-run/function1.scala b/test/files/continuations-run/function1.scala
new file mode 100644
index 0000000000..3b39722e3a
--- /dev/null
+++ b/test/files/continuations-run/function1.scala
@@ -0,0 +1,16 @@
+// $Id$
+
+import scala.util.continuations._
+
+
+object Test {
+
+ def main(args: Array[String]): Any = {
+
+ val f = () => shift { k: (Int=>Int) => k(7) }
+ val g: () => Int @cps[Int] = f
+
+ println(reset(g()))
+ }
+
+} \ No newline at end of file
diff --git a/test/files/continuations-run/function4.check b/test/files/continuations-run/function4.check
new file mode 100644
index 0000000000..c7930257df
--- /dev/null
+++ b/test/files/continuations-run/function4.check
@@ -0,0 +1 @@
+7 \ No newline at end of file
diff --git a/test/files/continuations-run/function4.scala b/test/files/continuations-run/function4.scala
new file mode 100644
index 0000000000..b73eedb02c
--- /dev/null
+++ b/test/files/continuations-run/function4.scala
@@ -0,0 +1,15 @@
+// $Id$
+
+import scala.util.continuations._
+
+
+object Test {
+
+ def main(args: Array[String]): Any = {
+
+ val g: () => Int @cps[Int] = () => shift { k: (Int=>Int) => k(7) }
+
+ println(reset(g()))
+ }
+
+} \ No newline at end of file
diff --git a/test/files/continuations-run/function5.check b/test/files/continuations-run/function5.check
new file mode 100644
index 0000000000..c7930257df
--- /dev/null
+++ b/test/files/continuations-run/function5.check
@@ -0,0 +1 @@
+7 \ No newline at end of file
diff --git a/test/files/continuations-run/function5.scala b/test/files/continuations-run/function5.scala
new file mode 100644
index 0000000000..a689ccf243
--- /dev/null
+++ b/test/files/continuations-run/function5.scala
@@ -0,0 +1,15 @@
+// $Id$
+
+import scala.util.continuations._
+
+
+object Test {
+
+ def main(args: Array[String]): Any = {
+
+ val g: () => Int @cps[Int] = () => 7
+
+ println(reset(g()))
+ }
+
+} \ No newline at end of file
diff --git a/test/files/continuations-run/ifelse0.check b/test/files/continuations-run/ifelse0.check
new file mode 100644
index 0000000000..f8bc79860d
--- /dev/null
+++ b/test/files/continuations-run/ifelse0.check
@@ -0,0 +1,2 @@
+10
+9 \ No newline at end of file
diff --git a/test/files/continuations-run/ifelse0.scala b/test/files/continuations-run/ifelse0.scala
new file mode 100644
index 0000000000..e34b86ee84
--- /dev/null
+++ b/test/files/continuations-run/ifelse0.scala
@@ -0,0 +1,18 @@
+// $Id$
+
+import scala.util.continuations._
+
+
+object Test {
+
+ def test(x:Int) = if (x <= 7)
+ shift { k: (Int=>Int) => k(k(k(x))) }
+ else
+ shift { k: (Int=>Int) => k(x) }
+
+ def main(args: Array[String]): Any = {
+ println(reset(1 + test(7)))
+ println(reset(1 + test(8)))
+ }
+
+} \ No newline at end of file
diff --git a/test/files/continuations-run/ifelse1.check b/test/files/continuations-run/ifelse1.check
new file mode 100644
index 0000000000..86a3fbc0c1
--- /dev/null
+++ b/test/files/continuations-run/ifelse1.check
@@ -0,0 +1,4 @@
+10
+9
+8
+11 \ No newline at end of file
diff --git a/test/files/continuations-run/ifelse1.scala b/test/files/continuations-run/ifelse1.scala
new file mode 100644
index 0000000000..2ccc1ed730
--- /dev/null
+++ b/test/files/continuations-run/ifelse1.scala
@@ -0,0 +1,25 @@
+// $Id$
+
+import scala.util.continuations._
+
+
+object Test {
+
+ def test1(x:Int) = if (x <= 7)
+ shift { k: (Int=>Int) => k(k(k(x))) }
+ else
+ x
+
+ def test2(x:Int) = if (x <= 7)
+ x
+ else
+ shift { k: (Int=>Int) => k(k(k(x))) }
+
+ def main(args: Array[String]): Any = {
+ println(reset(1 + test1(7)))
+ println(reset(1 + test1(8)))
+ println(reset(1 + test2(7)))
+ println(reset(1 + test2(8)))
+ }
+
+} \ No newline at end of file
diff --git a/test/files/continuations-run/ifelse2.check b/test/files/continuations-run/ifelse2.check
new file mode 100644
index 0000000000..f97a95b08d
--- /dev/null
+++ b/test/files/continuations-run/ifelse2.check
@@ -0,0 +1,4 @@
+abort
+()
+alive
+()
diff --git a/test/files/continuations-run/ifelse2.scala b/test/files/continuations-run/ifelse2.scala
new file mode 100644
index 0000000000..536e350190
--- /dev/null
+++ b/test/files/continuations-run/ifelse2.scala
@@ -0,0 +1,16 @@
+// $Id$
+
+import scala.util.continuations._
+
+
+object Test {
+
+ def test(x:Int) = if (x <= 7)
+ shift { k: (Unit=>Unit) => println("abort") }
+
+ def main(args: Array[String]): Any = {
+ println(reset{ test(7); println("alive") })
+ println(reset{ test(8); println("alive") })
+ }
+
+} \ No newline at end of file
diff --git a/test/files/continuations-run/ifelse3.check b/test/files/continuations-run/ifelse3.check
new file mode 100644
index 0000000000..95b562c8e6
--- /dev/null
+++ b/test/files/continuations-run/ifelse3.check
@@ -0,0 +1,2 @@
+6
+9
diff --git a/test/files/continuations-run/ifelse3.scala b/test/files/continuations-run/ifelse3.scala
new file mode 100644
index 0000000000..5dbd079d1c
--- /dev/null
+++ b/test/files/continuations-run/ifelse3.scala
@@ -0,0 +1,21 @@
+// $Id$
+
+import scala.util.continuations._
+
+
+object Test {
+
+ def util(x: Boolean) = shift { k: (Boolean=>Int) => k(x) }
+
+ def test(x:Int) = if (util(x <= 7))
+ x - 1
+ else
+ x + 1
+
+
+ def main(args: Array[String]): Any = {
+ println(reset(test(7)))
+ println(reset(test(8)))
+ }
+
+} \ No newline at end of file
diff --git a/test/files/continuations-run/infer1.scala b/test/files/continuations-run/infer1.scala
new file mode 100644
index 0000000000..a6c6c07215
--- /dev/null
+++ b/test/files/continuations-run/infer1.scala
@@ -0,0 +1,33 @@
+// $Id$
+
+import scala.util.continuations._
+
+
+object Test {
+
+ def test(x: => Int @cpsParam[String,Int]) = 7
+
+ def test2() = {
+ val x = shift { k: (Int => String) => 9 }
+ x
+ }
+
+ def test3(x: => Int @cpsParam[Int,Int]) = 7
+
+
+ def util() = shift { k: (String => String) => "7" }
+
+ def main(args: Array[String]): Any = {
+ test { shift { k: (Int => String) => 9 } }
+ test { shift { k: (Int => String) => 9 }; 2 }
+// test { shift { k: (Int => String) => 9 }; util() } <-- doesn't work
+ test { shift { k: (Int => String) => 9 }; util(); 2 }
+
+
+ test { shift { k: (Int => String) => 9 }; { test3(0); 2 } }
+
+ test3 { { test3(0); 2 } }
+
+ }
+
+} \ No newline at end of file
diff --git a/test/files/continuations-run/match0.check b/test/files/continuations-run/match0.check
new file mode 100644
index 0000000000..f8bc79860d
--- /dev/null
+++ b/test/files/continuations-run/match0.check
@@ -0,0 +1,2 @@
+10
+9 \ No newline at end of file
diff --git a/test/files/continuations-run/match0.scala b/test/files/continuations-run/match0.scala
new file mode 100644
index 0000000000..bd36238d7f
--- /dev/null
+++ b/test/files/continuations-run/match0.scala
@@ -0,0 +1,18 @@
+// $Id$
+
+import scala.util.continuations._
+
+
+object Test {
+
+ def test(x:Int) = x match {
+ case 7 => shift { k: (Int=>Int) => k(k(k(x))) }
+ case 8 => shift { k: (Int=>Int) => k(x) }
+ }
+
+ def main(args: Array[String]): Any = {
+ println(reset(1 + test(7)))
+ println(reset(1 + test(8)))
+ }
+
+} \ No newline at end of file
diff --git a/test/files/continuations-run/match1.check b/test/files/continuations-run/match1.check
new file mode 100644
index 0000000000..73053d3f4f
--- /dev/null
+++ b/test/files/continuations-run/match1.check
@@ -0,0 +1,2 @@
+10
+9
diff --git a/test/files/continuations-run/match1.scala b/test/files/continuations-run/match1.scala
new file mode 100644
index 0000000000..ea4e219666
--- /dev/null
+++ b/test/files/continuations-run/match1.scala
@@ -0,0 +1,18 @@
+// $Id$
+
+import scala.util.continuations._
+
+
+object Test {
+
+ def test(x:Int) = x match {
+ case 7 => shift { k: (Int=>Int) => k(k(k(x))) }
+ case _ => x
+ }
+
+ def main(args: Array[String]): Any = {
+ println(reset(1 + test(7)))
+ println(reset(1 + test(8)))
+ }
+
+} \ No newline at end of file
diff --git a/test/files/continuations-run/match2.check b/test/files/continuations-run/match2.check
new file mode 100644
index 0000000000..cbf91349cc
--- /dev/null
+++ b/test/files/continuations-run/match2.check
@@ -0,0 +1,2 @@
+B
+B
diff --git a/test/files/continuations-run/match2.scala b/test/files/continuations-run/match2.scala
new file mode 100644
index 0000000000..8d4f04870f
--- /dev/null
+++ b/test/files/continuations-run/match2.scala
@@ -0,0 +1,26 @@
+// $Id$
+
+import scala.util.continuations._
+
+
+object Test {
+
+ def test1() = {
+ val (a, b) = shift { k: (((String,String)) => String) => k("A","B") }
+ b
+ }
+
+ case class Elem[T,U](a: T, b: U)
+
+ def test2() = {
+ val Elem(a,b) = shift { k: (Elem[String,String] => String) => k(Elem("A","B")) }
+ b
+ }
+
+
+ def main(args: Array[String]): Any = {
+ println(reset(test1()))
+ println(reset(test2()))
+ }
+
+} \ No newline at end of file
diff --git a/test/files/continuations-run/t1807.check b/test/files/continuations-run/t1807.check
new file mode 100644
index 0000000000..56a6051ca2
--- /dev/null
+++ b/test/files/continuations-run/t1807.check
@@ -0,0 +1 @@
+1 \ No newline at end of file
diff --git a/test/files/continuations-run/t1807.scala b/test/files/continuations-run/t1807.scala
new file mode 100644
index 0000000000..278b3a9936
--- /dev/null
+++ b/test/files/continuations-run/t1807.scala
@@ -0,0 +1,14 @@
+// $Id$
+
+import scala.util.continuations._
+
+
+object Test {
+ def main(args: Array[String]): Unit = {
+ val z = reset {
+ val f: (() => Int @cps[Int]) = () => 1
+ f()
+ }
+ println(z)
+ }
+} \ No newline at end of file
diff --git a/test/files/continuations-run/t1808.scala b/test/files/continuations-run/t1808.scala
new file mode 100644
index 0000000000..125c7c1cdf
--- /dev/null
+++ b/test/files/continuations-run/t1808.scala
@@ -0,0 +1,10 @@
+// $Id$
+
+import scala.util.continuations._
+
+
+object Test {
+ def main(args: Array[String]): Unit = {
+ reset0 { 0 }
+ }
+} \ No newline at end of file
diff --git a/test/files/continuations-run/t1820.scala b/test/files/continuations-run/t1820.scala
new file mode 100644
index 0000000000..893ddab6d1
--- /dev/null
+++ b/test/files/continuations-run/t1820.scala
@@ -0,0 +1,14 @@
+// $Id$
+
+import scala.util.continuations._
+
+
+object Test {
+ def shifted: Unit @suspendable = shift { (k: Unit => Unit) => () }
+ def test1(b: => Boolean) = {
+ reset {
+ if (b) shifted
+ }
+ }
+ def main(args: Array[String]) = test1(true)
+} \ No newline at end of file
diff --git a/test/files/continuations-run/t1821.check b/test/files/continuations-run/t1821.check
new file mode 100644
index 0000000000..f7b76115db
--- /dev/null
+++ b/test/files/continuations-run/t1821.check
@@ -0,0 +1,4 @@
+()
+()
+()
+() \ No newline at end of file
diff --git a/test/files/continuations-run/t1821.scala b/test/files/continuations-run/t1821.scala
new file mode 100644
index 0000000000..0d5fb553be
--- /dev/null
+++ b/test/files/continuations-run/t1821.scala
@@ -0,0 +1,20 @@
+// $Id$
+
+import scala.util.continuations._
+
+
+object Test {
+ def suspended[A](x: A): A @suspendable = x
+ def test1[A](x: A): A @suspendable = suspended(x) match { case x => x }
+ def test2[A](x: List[A]): A @suspendable = suspended(x) match { case List(x) => x }
+
+ def test3[A](x: A): A @suspendable = x match { case x => x }
+ def test4[A](x: List[A]): A @suspendable = x match { case List(x) => x }
+
+ def main(args: Array[String]) = {
+ println(reset(test1()))
+ println(reset(test2(List(()))))
+ println(reset(test3()))
+ println(reset(test4(List(()))))
+ }
+} \ No newline at end of file
diff --git a/test/files/continuations-run/while0.check b/test/files/continuations-run/while0.check
new file mode 100644
index 0000000000..d58c55a31d
--- /dev/null
+++ b/test/files/continuations-run/while0.check
@@ -0,0 +1 @@
+9000
diff --git a/test/files/continuations-run/while0.scala b/test/files/continuations-run/while0.scala
new file mode 100644
index 0000000000..9735f9d2c3
--- /dev/null
+++ b/test/files/continuations-run/while0.scala
@@ -0,0 +1,22 @@
+// $Id$
+
+import scala.util.continuations._
+
+
+object Test {
+
+ def foo(): Int @cps[Unit] = 2
+
+ def test(): Unit @cps[Unit] = {
+ var x = 0
+ while (x < 9000) { // pick number large enough to require tail-call opt
+ x += foo()
+ }
+ println(x)
+ }
+
+ def main(args: Array[String]): Any = {
+ reset(test())
+ }
+
+} \ No newline at end of file
diff --git a/test/files/continuations-run/while1.check b/test/files/continuations-run/while1.check
new file mode 100644
index 0000000000..3d5f0b9a46
--- /dev/null
+++ b/test/files/continuations-run/while1.check
@@ -0,0 +1,11 @@
+up
+up
+up
+up
+up
+10
+down
+down
+down
+down
+down
diff --git a/test/files/continuations-run/while1.scala b/test/files/continuations-run/while1.scala
new file mode 100644
index 0000000000..fb5dc0079a
--- /dev/null
+++ b/test/files/continuations-run/while1.scala
@@ -0,0 +1,22 @@
+// $Id$
+
+import scala.util.continuations._
+
+
+object Test {
+
+ def foo(): Int @cps[Unit] = shift { k => println("up"); k(2); println("down") }
+
+ def test(): Unit @cps[Unit] = {
+ var x = 0
+ while (x < 9) {
+ x += foo()
+ }
+ println(x)
+ }
+
+ def main(args: Array[String]): Any = {
+ reset(test())
+ }
+
+} \ No newline at end of file
diff --git a/test/files/continuations-run/while2.check b/test/files/continuations-run/while2.check
new file mode 100644
index 0000000000..9fe515181b
--- /dev/null
+++ b/test/files/continuations-run/while2.check
@@ -0,0 +1,19 @@
+up
+up
+up
+up
+up
+up
+up
+up
+up
+9000
+down
+down
+down
+down
+down
+down
+down
+down
+down
diff --git a/test/files/continuations-run/while2.scala b/test/files/continuations-run/while2.scala
new file mode 100644
index 0000000000..f36288929e
--- /dev/null
+++ b/test/files/continuations-run/while2.scala
@@ -0,0 +1,23 @@
+// $Id$
+
+import scala.util.continuations._
+
+
+object Test {
+
+ def foo1(): Int @cps[Unit] = 2
+ def foo2(): Int @cps[Unit] = shift { k => println("up"); k(2); println("down") }
+
+ def test(): Unit @cps[Unit] = {
+ var x = 0
+ while (x < 9000) { // pick number large enough to require tail-call opt
+ x += (if (x % 1000 != 0) foo1() else foo2())
+ }
+ println(x)
+ }
+
+ def main(args: Array[String]): Any = {
+ reset(test())
+ }
+
+} \ No newline at end of file