From 8506a865b8b7599a2a99fe9865dd621d78dacc50 Mon Sep 17 00:00:00 2001 From: rompf Date: Thu, 11 Mar 2010 16:55:38 +0000 Subject: [PATCH] moved the continuations plugin into trunk. it is now part of the distributions under /plugins/continuations.jar which should make scalac load it by default. actual use however must be enabled by passing -P:continuations:enable as command line arg. supporting library code is in package scala.util.continuations and is compiled into scala-library.jar. review by rytz, cunei, odersky. git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@21140 5e8d7ff9-d8ef-0310-90f0-a4852d11357a --- build.xml | 157 +++++- .../scala/util/continuations/package.scala | 65 +++ .../selectivecps/CPSAnnotationChecker.scala | 448 ++++++++++++++++++ .../scala/tools/selectivecps/CPSUtils.scala | 131 +++++ .../selectivecps/SelectiveANFTransform.scala | 389 +++++++++++++++ .../selectivecps/SelectiveCPSPlugin.scala | 61 +++ .../selectivecps/SelectiveCPSTransform.scala | 250 ++++++++++ src/continuations/plugin/scalac-plugin.xml | 5 + test/files/continuations-neg/function0.check | 6 + test/files/continuations-neg/function0.scala | 16 + test/files/continuations-neg/function2.check | 6 + test/files/continuations-neg/function2.scala | 16 + test/files/continuations-neg/function3.check | 6 + test/files/continuations-neg/function3.scala | 15 + test/files/continuations-neg/infer0.check | 4 + test/files/continuations-neg/infer0.scala | 14 + test/files/continuations-neg/infer2.check | 4 + test/files/continuations-neg/infer2.scala | 19 + test/files/continuations-neg/t1929.check | 6 + test/files/continuations-neg/t1929.scala | 17 + test/files/continuations-neg/t2285.check | 6 + test/files/continuations-neg/t2285.scala | 11 + test/files/continuations-neg/t2949.check | 6 + test/files/continuations-neg/t2949.scala | 15 + test/files/continuations-run/basics.check | 2 + test/files/continuations-run/basics.scala | 23 + test/files/continuations-run/function1.check | 1 + test/files/continuations-run/function1.scala | 16 + test/files/continuations-run/function4.check | 1 + test/files/continuations-run/function4.scala | 15 + test/files/continuations-run/function5.check | 1 + test/files/continuations-run/function5.scala | 15 + test/files/continuations-run/ifelse0.check | 2 + test/files/continuations-run/ifelse0.scala | 18 + test/files/continuations-run/ifelse1.check | 4 + test/files/continuations-run/ifelse1.scala | 25 + test/files/continuations-run/ifelse2.check | 4 + test/files/continuations-run/ifelse2.scala | 16 + test/files/continuations-run/ifelse3.check | 2 + test/files/continuations-run/ifelse3.scala | 21 + test/files/continuations-run/infer1.scala | 33 ++ test/files/continuations-run/match0.check | 2 + test/files/continuations-run/match0.scala | 18 + test/files/continuations-run/match1.check | 2 + test/files/continuations-run/match1.scala | 18 + test/files/continuations-run/match2.check | 2 + test/files/continuations-run/match2.scala | 26 + test/files/continuations-run/t1807.check | 1 + test/files/continuations-run/t1807.scala | 14 + test/files/continuations-run/t1808.scala | 10 + test/files/continuations-run/t1820.scala | 14 + test/files/continuations-run/t1821.check | 4 + test/files/continuations-run/t1821.scala | 20 + test/files/continuations-run/while0.check | 1 + test/files/continuations-run/while0.scala | 22 + test/files/continuations-run/while1.check | 11 + test/files/continuations-run/while1.scala | 22 + test/files/continuations-run/while2.check | 19 + test/files/continuations-run/while2.scala | 23 + test/pending/continuations-run/example0.scala | 9 + test/pending/continuations-run/example1.scala | 9 + .../pending/continuations-run/example16.scala | 9 + test/pending/continuations-run/example2.scala | 9 + test/pending/continuations-run/example3.scala | 9 + test/pending/continuations-run/example4.scala | 9 + test/pending/continuations-run/example5.scala | 9 + test/pending/continuations-run/example6.scala | 9 + test/pending/continuations-run/example7.scala | 9 + test/pending/continuations-run/example8.scala | 9 + test/pending/continuations-run/example9.scala | 9 + test/pending/continuations-run/foreach.check | 4 + test/pending/continuations-run/foreach.scala | 33 ++ .../pending/continuations-run/function6.scala | 15 + test/pending/continuations-run/select-run.log | 20 + test/pending/continuations-run/select.check | 2 + test/pending/continuations-run/select.scala | 21 + test/pending/continuations-run/t2864.scala | 18 + test/pending/continuations-run/t2934.scala | 14 + 78 files changed, 2322 insertions(+), 5 deletions(-) create mode 100644 src/continuations/library/scala/util/continuations/package.scala create mode 100644 src/continuations/plugin/scala/tools/selectivecps/CPSAnnotationChecker.scala create mode 100644 src/continuations/plugin/scala/tools/selectivecps/CPSUtils.scala create mode 100644 src/continuations/plugin/scala/tools/selectivecps/SelectiveANFTransform.scala create mode 100644 src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSPlugin.scala create mode 100644 src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala create mode 100644 src/continuations/plugin/scalac-plugin.xml create mode 100644 test/files/continuations-neg/function0.check create mode 100644 test/files/continuations-neg/function0.scala create mode 100644 test/files/continuations-neg/function2.check create mode 100644 test/files/continuations-neg/function2.scala create mode 100644 test/files/continuations-neg/function3.check create mode 100644 test/files/continuations-neg/function3.scala create mode 100644 test/files/continuations-neg/infer0.check create mode 100644 test/files/continuations-neg/infer0.scala create mode 100644 test/files/continuations-neg/infer2.check create mode 100644 test/files/continuations-neg/infer2.scala create mode 100644 test/files/continuations-neg/t1929.check create mode 100644 test/files/continuations-neg/t1929.scala create mode 100644 test/files/continuations-neg/t2285.check create mode 100644 test/files/continuations-neg/t2285.scala create mode 100644 test/files/continuations-neg/t2949.check create mode 100644 test/files/continuations-neg/t2949.scala create mode 100755 test/files/continuations-run/basics.check create mode 100755 test/files/continuations-run/basics.scala create mode 100644 test/files/continuations-run/function1.check create mode 100644 test/files/continuations-run/function1.scala create mode 100644 test/files/continuations-run/function4.check create mode 100644 test/files/continuations-run/function4.scala create mode 100644 test/files/continuations-run/function5.check create mode 100644 test/files/continuations-run/function5.scala create mode 100644 test/files/continuations-run/ifelse0.check create mode 100644 test/files/continuations-run/ifelse0.scala create mode 100644 test/files/continuations-run/ifelse1.check create mode 100644 test/files/continuations-run/ifelse1.scala create mode 100644 test/files/continuations-run/ifelse2.check create mode 100644 test/files/continuations-run/ifelse2.scala create mode 100644 test/files/continuations-run/ifelse3.check create mode 100644 test/files/continuations-run/ifelse3.scala create mode 100644 test/files/continuations-run/infer1.scala create mode 100644 test/files/continuations-run/match0.check create mode 100644 test/files/continuations-run/match0.scala create mode 100644 test/files/continuations-run/match1.check create mode 100644 test/files/continuations-run/match1.scala create mode 100644 test/files/continuations-run/match2.check create mode 100644 test/files/continuations-run/match2.scala create mode 100644 test/files/continuations-run/t1807.check create mode 100644 test/files/continuations-run/t1807.scala create mode 100644 test/files/continuations-run/t1808.scala create mode 100644 test/files/continuations-run/t1820.scala create mode 100644 test/files/continuations-run/t1821.check create mode 100644 test/files/continuations-run/t1821.scala create mode 100644 test/files/continuations-run/while0.check create mode 100644 test/files/continuations-run/while0.scala create mode 100644 test/files/continuations-run/while1.check create mode 100644 test/files/continuations-run/while1.scala create mode 100644 test/files/continuations-run/while2.check create mode 100644 test/files/continuations-run/while2.scala create mode 100644 test/pending/continuations-run/example0.scala create mode 100644 test/pending/continuations-run/example1.scala create mode 100644 test/pending/continuations-run/example16.scala create mode 100644 test/pending/continuations-run/example2.scala create mode 100644 test/pending/continuations-run/example3.scala create mode 100644 test/pending/continuations-run/example4.scala create mode 100644 test/pending/continuations-run/example5.scala create mode 100644 test/pending/continuations-run/example6.scala create mode 100644 test/pending/continuations-run/example7.scala create mode 100644 test/pending/continuations-run/example8.scala create mode 100644 test/pending/continuations-run/example9.scala create mode 100644 test/pending/continuations-run/foreach.check create mode 100644 test/pending/continuations-run/foreach.scala create mode 100644 test/pending/continuations-run/function6.scala create mode 100644 test/pending/continuations-run/select-run.log create mode 100644 test/pending/continuations-run/select.check create mode 100644 test/pending/continuations-run/select.scala create mode 100644 test/pending/continuations-run/t2864.scala create mode 100644 test/pending/continuations-run/t2934.scala diff --git a/build.xml b/build.xml index 921f53620..0eb649fdd 100644 --- a/build.xml +++ b/build.xml @@ -370,7 +370,7 @@ LOCAL REFERENCE BUILD (LOCKER) - + @@ -447,6 +447,7 @@ QUICK BUILD (QUICK) + @@ -598,7 +599,62 @@ QUICK BUILD (QUICK) - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -802,7 +858,21 @@ PACKED QUICK BUILD (PACK) - + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1283,6 +1407,7 @@ DOCUMENTATION classpathref="pack.classpath"> + @@ -1390,6 +1515,7 @@ BOOTRAPING TEST AND TEST SUITE + @@ -1440,7 +1566,24 @@ BOOTRAPING TEST AND TEST SUITE - + + + + + + + + + + + + + + + + + continuations + scala.tools.selectivecps.SelectiveCPSPlugin + diff --git a/test/files/continuations-neg/function0.check b/test/files/continuations-neg/function0.check new file mode 100644 index 000000000..0a66763a0 --- /dev/null +++ b/test/files/continuations-neg/function0.check @@ -0,0 +1,6 @@ +function0.scala:11: error: type mismatch; + found : () => Int @scala.util.continuations.cpsParam[Int,Int] + required: () => Int + val g: () => Int = f + ^ +one error found diff --git a/test/files/continuations-neg/function0.scala b/test/files/continuations-neg/function0.scala new file mode 100644 index 000000000..6ef0d98b9 --- /dev/null +++ b/test/files/continuations-neg/function0.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 = f + + println(reset(g())) + } + +} \ No newline at end of file diff --git a/test/files/continuations-neg/function2.check b/test/files/continuations-neg/function2.check new file mode 100644 index 000000000..483305765 --- /dev/null +++ b/test/files/continuations-neg/function2.check @@ -0,0 +1,6 @@ +function2.scala:11: error: type mismatch; + found : () => Int + required: () => Int @util.continuations.package.cps[Int] + val g: () => Int @cps[Int] = f + ^ +one error found diff --git a/test/files/continuations-neg/function2.scala b/test/files/continuations-neg/function2.scala new file mode 100644 index 000000000..402c6dcad --- /dev/null +++ b/test/files/continuations-neg/function2.scala @@ -0,0 +1,16 @@ +// $Id$ + +import scala.util.continuations._ + + +object Test { + + def main(args: Array[String]): Any = { + + val f = () => 7 + val g: () => Int @cps[Int] = f + + println(reset(g())) + } + +} \ No newline at end of file diff --git a/test/files/continuations-neg/function3.check b/test/files/continuations-neg/function3.check new file mode 100644 index 000000000..4705ad9ed --- /dev/null +++ b/test/files/continuations-neg/function3.check @@ -0,0 +1,6 @@ +function3.scala:10: error: type mismatch; + found : Int @scala.util.continuations.cpsParam[Int,Int] + required: Int + val g: () => Int = () => shift { k: (Int=>Int) => k(7) } + ^ +one error found diff --git a/test/files/continuations-neg/function3.scala b/test/files/continuations-neg/function3.scala new file mode 100644 index 000000000..c4acc4c2e --- /dev/null +++ b/test/files/continuations-neg/function3.scala @@ -0,0 +1,15 @@ +// $Id$ + +import scala.util.continuations._ + + +object Test { + + def main(args: Array[String]): Any = { + + val g: () => Int = () => shift { k: (Int=>Int) => k(7) } + + println(reset(g())) + } + +} \ No newline at end of file diff --git a/test/files/continuations-neg/infer0.check b/test/files/continuations-neg/infer0.check new file mode 100644 index 000000000..1dd072ef0 --- /dev/null +++ b/test/files/continuations-neg/infer0.check @@ -0,0 +1,4 @@ +infer0.scala:11: error: cannot cps-transform expression 8: type arguments [Int(8),String,Int] do not conform to method shiftUnit's type parameter bounds [A,B,C >: B] + test(8) + ^ +one error found diff --git a/test/files/continuations-neg/infer0.scala b/test/files/continuations-neg/infer0.scala new file mode 100644 index 000000000..9cf69c5d3 --- /dev/null +++ b/test/files/continuations-neg/infer0.scala @@ -0,0 +1,14 @@ +// $Id$ + +import scala.util.continuations._ + + +object Test { + + def test(x: => Int @cpsParam[String,Int]) = 7 + + def main(args: Array[String]): Any = { + test(8) + } + +} \ No newline at end of file diff --git a/test/files/continuations-neg/infer2.check b/test/files/continuations-neg/infer2.check new file mode 100644 index 000000000..59eb670bc --- /dev/null +++ b/test/files/continuations-neg/infer2.check @@ -0,0 +1,4 @@ +infer2.scala:14: error: illegal answer type modification: scala.util.continuations.cpsParam[String,Int] andThen scala.util.continuations.cpsParam[String,Int] + test { sym(); sym() } + ^ +one error found diff --git a/test/files/continuations-neg/infer2.scala b/test/files/continuations-neg/infer2.scala new file mode 100644 index 000000000..eaffbc17f --- /dev/null +++ b/test/files/continuations-neg/infer2.scala @@ -0,0 +1,19 @@ +// $Id$ + +import scala.util.continuations._ + + +object Test { + + def test(x: => Int @cpsParam[String,Int]) = 7 + + def sym() = shift { k: (Int => String) => 9 } + + + def main(args: Array[String]): Any = { + test { sym(); sym() } + } + +} + + diff --git a/test/files/continuations-neg/t1929.check b/test/files/continuations-neg/t1929.check new file mode 100644 index 000000000..f42c3a1e1 --- /dev/null +++ b/test/files/continuations-neg/t1929.check @@ -0,0 +1,6 @@ +t1929.scala:8: error: type mismatch; + found : Int @scala.util.continuations.cpsParam[String,java.lang.String] @scala.util.continuations.cpsSynth + required: Int @scala.util.continuations.cpsParam[Int,java.lang.String] + reset { + ^ +one error found diff --git a/test/files/continuations-neg/t1929.scala b/test/files/continuations-neg/t1929.scala new file mode 100644 index 000000000..02eda9170 --- /dev/null +++ b/test/files/continuations-neg/t1929.scala @@ -0,0 +1,17 @@ +// $Id$ + +import scala.util.continuations._ + + +object Test { + def main(args : Array[String]) { + reset { + println("up") + val x = shift((k:Int=>String) => k(8) + k(2)) + println("down " + x) + val y = shift((k:Int=>String) => k(3)) + println("down2 " + y) + y + x + } + } +} \ No newline at end of file diff --git a/test/files/continuations-neg/t2285.check b/test/files/continuations-neg/t2285.check new file mode 100644 index 000000000..d5dff6a4f --- /dev/null +++ b/test/files/continuations-neg/t2285.check @@ -0,0 +1,6 @@ +t2285.scala:9: error: type mismatch; + found : Int @scala.util.continuations.cpsParam[String,String] @scala.util.continuations.cpsSynth + required: Int @scala.util.continuations.cpsParam[Int,String] + def foo() = reset { bar(); 7 } + ^ +one error found diff --git a/test/files/continuations-neg/t2285.scala b/test/files/continuations-neg/t2285.scala new file mode 100644 index 000000000..b906dc455 --- /dev/null +++ b/test/files/continuations-neg/t2285.scala @@ -0,0 +1,11 @@ +// $Id$ + +import scala.util.continuations._ + +object Test { + + def bar() = shift { k: (String => String) => k("1") } + + def foo() = reset { bar(); 7 } + +} diff --git a/test/files/continuations-neg/t2949.check b/test/files/continuations-neg/t2949.check new file mode 100644 index 000000000..dd9768807 --- /dev/null +++ b/test/files/continuations-neg/t2949.check @@ -0,0 +1,6 @@ +t2949.scala:13: error: type mismatch; + found : Int + required: ? @scala.util.continuations.cpsParam[List[?],Any] + x * y + ^ +one error found diff --git a/test/files/continuations-neg/t2949.scala b/test/files/continuations-neg/t2949.scala new file mode 100644 index 000000000..2d426a4d8 --- /dev/null +++ b/test/files/continuations-neg/t2949.scala @@ -0,0 +1,15 @@ +// $Id$ + +import scala.util.continuations._ + +object Test { + + def reflect[A,B](xs : List[A]) = shift{ xs.flatMap[B, List[B]] } + def reify[A, B](x : A @cpsParam[List[A], B]) = reset{ List(x) } + + def main(args: Array[String]): Unit = println(reify { + val x = reflect[Int, Int](List(1,2,3)) + val y = reflect[Int, Int](List(2,4,8)) + x * y + }) +} diff --git a/test/files/continuations-run/basics.check b/test/files/continuations-run/basics.check new file mode 100755 index 000000000..54c059fdc --- /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 000000000..b63710bc6 --- /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 000000000..7f8f011eb --- /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 000000000..fbd413ed9 --- /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 000000000..c7930257d --- /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 000000000..2ccd0b4ff --- /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 000000000..c7930257d --- /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 000000000..fe528e14e --- /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 000000000..f8bc79860 --- /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 000000000..2facab4b9 --- /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 000000000..86a3fbc0c --- /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 000000000..c624b84b7 --- /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 000000000..f97a95b08 --- /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 000000000..506acc4d0 --- /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 000000000..95b562c8e --- /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 000000000..54566a421 --- /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 000000000..10822508e --- /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 000000000..f8bc79860 --- /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 000000000..b65d343c0 --- /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 000000000..73053d3f4 --- /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 000000000..20671f26b --- /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 000000000..cbf91349c --- /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 000000000..8b0fb946d --- /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 000000000..56a6051ca --- /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 000000000..278b3a993 --- /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 000000000..125c7c1cd --- /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 000000000..893ddab6d --- /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 000000000..f7b76115d --- /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 000000000..0d5fb553b --- /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 000000000..d58c55a31 --- /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 000000000..46005a4a7 --- /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 000000000..3d5f0b9a4 --- /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 000000000..fd41ab36e --- /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 000000000..9fe515181 --- /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 000000000..63f9cb99f --- /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 diff --git a/test/pending/continuations-run/example0.scala b/test/pending/continuations-run/example0.scala new file mode 100644 index 000000000..de5ea54e9 --- /dev/null +++ b/test/pending/continuations-run/example0.scala @@ -0,0 +1,9 @@ +// $Id$ + +object Test { + + def main(args: Array[String]): Any = { + examples.continuations.Test0.main(args) + } + +} \ No newline at end of file diff --git a/test/pending/continuations-run/example1.scala b/test/pending/continuations-run/example1.scala new file mode 100644 index 000000000..e31d6af88 --- /dev/null +++ b/test/pending/continuations-run/example1.scala @@ -0,0 +1,9 @@ +// $Id$ + +object Test { + + def main(args: Array[String]): Any = { + examples.continuations.Test1.main(args) + } + +} \ No newline at end of file diff --git a/test/pending/continuations-run/example16.scala b/test/pending/continuations-run/example16.scala new file mode 100644 index 000000000..561f0ab0e --- /dev/null +++ b/test/pending/continuations-run/example16.scala @@ -0,0 +1,9 @@ +// $Id$ + +object Test { + + def main(args: Array[String]): Any = { + examples.continuations.Test16Printf.main(args) + } + +} \ No newline at end of file diff --git a/test/pending/continuations-run/example2.scala b/test/pending/continuations-run/example2.scala new file mode 100644 index 000000000..730f7cc63 --- /dev/null +++ b/test/pending/continuations-run/example2.scala @@ -0,0 +1,9 @@ +// $Id$ + +object Test { + + def main(args: Array[String]): Any = { + examples.continuations.Test2.main(args) + } + +} \ No newline at end of file diff --git a/test/pending/continuations-run/example3.scala b/test/pending/continuations-run/example3.scala new file mode 100644 index 000000000..41cf1cce0 --- /dev/null +++ b/test/pending/continuations-run/example3.scala @@ -0,0 +1,9 @@ +// $Id$ + +object Test { + + def main(args: Array[String]): Any = { + examples.continuations.Test3.main(args) + } + +} \ No newline at end of file diff --git a/test/pending/continuations-run/example4.scala b/test/pending/continuations-run/example4.scala new file mode 100644 index 000000000..adcc7aa90 --- /dev/null +++ b/test/pending/continuations-run/example4.scala @@ -0,0 +1,9 @@ +// $Id$ + +object Test { + + def main(args: Array[String]): Any = { + examples.continuations.Test4.main(args) + } + +} \ No newline at end of file diff --git a/test/pending/continuations-run/example5.scala b/test/pending/continuations-run/example5.scala new file mode 100644 index 000000000..241e8cd06 --- /dev/null +++ b/test/pending/continuations-run/example5.scala @@ -0,0 +1,9 @@ +// $Id$ + +object Test { + + def main(args: Array[String]): Any = { + examples.continuations.Test5.main(args) + } + +} \ No newline at end of file diff --git a/test/pending/continuations-run/example6.scala b/test/pending/continuations-run/example6.scala new file mode 100644 index 000000000..00f84fcd6 --- /dev/null +++ b/test/pending/continuations-run/example6.scala @@ -0,0 +1,9 @@ +// $Id$ + +object Test { + + def main(args: Array[String]): Any = { + examples.continuations.Test6.main(args) + } + +} \ No newline at end of file diff --git a/test/pending/continuations-run/example7.scala b/test/pending/continuations-run/example7.scala new file mode 100644 index 000000000..64abc6d9a --- /dev/null +++ b/test/pending/continuations-run/example7.scala @@ -0,0 +1,9 @@ +// $Id$ + +object Test { + + def main(args: Array[String]): Any = { + examples.continuations.Test7.main(args) + } + +} \ No newline at end of file diff --git a/test/pending/continuations-run/example8.scala b/test/pending/continuations-run/example8.scala new file mode 100644 index 000000000..a5f953d3f --- /dev/null +++ b/test/pending/continuations-run/example8.scala @@ -0,0 +1,9 @@ +// $Id$ + +object Test { + + def main(args: Array[String]): Any = { + examples.continuations.Test8.main(args) + } + +} \ No newline at end of file diff --git a/test/pending/continuations-run/example9.scala b/test/pending/continuations-run/example9.scala new file mode 100644 index 000000000..09d792c42 --- /dev/null +++ b/test/pending/continuations-run/example9.scala @@ -0,0 +1,9 @@ +// $Id$ + +object Test { + + def main(args: Array[String]): Any = { + examples.continuations.Test9Monads.main(args) + } + +} \ No newline at end of file diff --git a/test/pending/continuations-run/foreach.check b/test/pending/continuations-run/foreach.check new file mode 100644 index 000000000..9bab7a2ee --- /dev/null +++ b/test/pending/continuations-run/foreach.check @@ -0,0 +1,4 @@ +1 +2 +3 +enough is enough \ No newline at end of file diff --git a/test/pending/continuations-run/foreach.scala b/test/pending/continuations-run/foreach.scala new file mode 100644 index 000000000..76823e760 --- /dev/null +++ b/test/pending/continuations-run/foreach.scala @@ -0,0 +1,33 @@ +// $Id$ + +import scala.util.continuations._ + +import scala.util.continuations.Loops._ + +object Test { + + def main(args: Array[String]): Any = { + + + reset { + + val list = List(1,2,3,4,5) + + for (x <- list.suspendable) { + + shift { k: (Unit => Unit) => + println(x) + if (x < 3) + k() + else + println("enough is enough") + } + + } + + } + + + } + +} \ No newline at end of file diff --git a/test/pending/continuations-run/function6.scala b/test/pending/continuations-run/function6.scala new file mode 100644 index 000000000..727d46d9b --- /dev/null +++ b/test/pending/continuations-run/function6.scala @@ -0,0 +1,15 @@ +// $Id$ + +import scala.util.continuations._ + + +object Test { + + def main(args: Array[String]): Any = { + + val g: PartialFunction[Int, Int @cps[Int,Int]] = { case x => 7 } + + println(reset(g(2))) + } + +} \ No newline at end of file diff --git a/test/pending/continuations-run/select-run.log b/test/pending/continuations-run/select-run.log new file mode 100644 index 000000000..6faa868ce --- /dev/null +++ b/test/pending/continuations-run/select-run.log @@ -0,0 +1,20 @@ +8 +java.lang.ClassCastException: scala.util.continuations.ControlContext cannot be cast to java.lang.Integer + at scala.runtime.BoxesRunTime.unboxToInt(Unknown Source) + at Test$$anonfun$main$2.apply(select.scala:18) + at Test$$anonfun$main$2.apply(select.scala:18) + at scala.util.continuations.ControlContext$.reset(ControlContext.scala:65) + at Test$.main(select.scala:18) + at Test.main(select.scala) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:597) + at scala.tools.nsc.util.ScalaClassLoader$$anonfun$run$1.apply(ScalaClassLoader.scala:55) + at scala.tools.nsc.util.ScalaClassLoader$class.asContext(ScalaClassLoader.scala:22) + at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.asContext(ScalaClassLoader.scala:61) + at scala.tools.nsc.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:55) + at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:61) + at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:33) + at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:153) + at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala) diff --git a/test/pending/continuations-run/select.check b/test/pending/continuations-run/select.check new file mode 100644 index 000000000..620ce8421 --- /dev/null +++ b/test/pending/continuations-run/select.check @@ -0,0 +1,2 @@ +8 +8 \ No newline at end of file diff --git a/test/pending/continuations-run/select.scala b/test/pending/continuations-run/select.scala new file mode 100644 index 000000000..6012d1080 --- /dev/null +++ b/test/pending/continuations-run/select.scala @@ -0,0 +1,21 @@ +// $Id$ + +import scala.util.continuations._ + + +object Test { + + class Bla { + val x = 8 + } + + def bla = shift { k:(Bla=>Bla) => k(new Bla) } + + // TODO: check whether this also applies to a::shift { k => ... } + + def main(args: Array[String]) = { + println(reset(bla).x) + println(reset(bla.x)) + } + +} diff --git a/test/pending/continuations-run/t2864.scala b/test/pending/continuations-run/t2864.scala new file mode 100644 index 000000000..291e73933 --- /dev/null +++ b/test/pending/continuations-run/t2864.scala @@ -0,0 +1,18 @@ +// $Id$ + +import scala.util.continuations._ + + + +object Test { + + def double[B](n : Int)(k : Int => B) : B = k(n * 2) + + def main(args : Array[String]) { + reset { + val result1 = shift(double[Unit](100)) + val result2 = shift(double[Unit](result1)) + println(result2) + } + } +} \ No newline at end of file diff --git a/test/pending/continuations-run/t2934.scala b/test/pending/continuations-run/t2934.scala new file mode 100644 index 000000000..6089355bc --- /dev/null +++ b/test/pending/continuations-run/t2934.scala @@ -0,0 +1,14 @@ +// $Id$ + +import scala.util.continuations._ + + +object Test { + + def main(args : Array[String]) { + println(reset { + val x = shift(List(1,2,3).flatMap[Int, List[Int]]) + List(x + 2) + }) + } +} \ No newline at end of file