summaryrefslogtreecommitdiff
path: root/src/continuations
diff options
context:
space:
mode:
authorTiark Rompf <tiark.rompf@epfl.ch>2010-03-11 20:36:43 +0000
committerTiark Rompf <tiark.rompf@epfl.ch>2010-03-11 20:36:43 +0000
commit32e1da60a1ae55675b07e031bef89c7e28832d02 (patch)
tree2eda8e5001ad86e07d0d05bd1e4adfc543dd4f3e /src/continuations
parent83520220541c0ff8e3c9f9efde10f90b963e679f (diff)
downloadscala-32e1da60a1ae55675b07e031bef89c7e28832d02.tar.gz
scala-32e1da60a1ae55675b07e031bef89c7e28832d02.tar.bz2
scala-32e1da60a1ae55675b07e031bef89c7e28832d02.zip
added missing file from last commit. no review.
Diffstat (limited to 'src/continuations')
-rw-r--r--src/continuations/library/scala/util/continuations/ControlContext.scala60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/continuations/library/scala/util/continuations/ControlContext.scala b/src/continuations/library/scala/util/continuations/ControlContext.scala
new file mode 100644
index 0000000000..709d2d2b02
--- /dev/null
+++ b/src/continuations/library/scala/util/continuations/ControlContext.scala
@@ -0,0 +1,60 @@
+// $Id$
+
+package scala.util.continuations
+
+
+class cpsParam[-B,+C] extends StaticAnnotation with TypeConstraint
+
+private class cpsSym[B] extends Annotation // implementation detail
+
+private class cpsSynth extends Annotation // implementation detail
+
+private class cpsPlus extends StaticAnnotation with TypeConstraint // implementation detail
+private class cpsMinus extends Annotation // implementation detail
+
+
+
+@serializable final class ControlContext[+A,-B,+C](val fun: (A => B) => C, val x: A) {
+
+ final def map[A1](f: (A => A1)): ControlContext[A1,B,C] = {
+ if (fun eq null)
+ new ControlContext(null, f(x))
+ else
+ new ControlContext((k:(A1 => B)) => fun((x:A) => k(f(x))), null.asInstanceOf[A1])
+ }
+
+ /*
+ final def flatMap[A1,B1<:B](f: (A => ControlContext[A1,B1,B])): ControlContext[A1,B1,C] = {
+ new ControlContext((k:(A1 => B1)) => fun((x:A) => f(x).fun(k)))
+ }
+ */
+
+ // it would be nice if @inline would turn the trivial path into a tail call.
+ // unfortunately it doesn't, so we do it ourselves in SelectiveCPSTransform
+
+ /*@inline*/ final def flatMap[A1,B1,C1<:B](f: (A => ControlContext[A1,B1,C1])): ControlContext[A1,B1,C] = {
+ if (fun eq null)
+ f(x).asInstanceOf[ControlContext[A1,B1,C]]
+ else
+ new ControlContext({ k:(A1 => B1) =>
+ fun { (x:A) =>
+ val ctxR = f(x)
+ val res: C1 = ctxR.foreach(k)
+ res
+ }
+ }, null.asInstanceOf[A1])
+ }
+
+ final def foreach(f: (A => B)) = {
+ if (fun eq null)
+ f(x).asInstanceOf[C]
+ else
+ fun(f)
+ }
+
+ final def isTrivial = fun eq null
+ final def getTrivialValue = x.asInstanceOf[A]
+
+ // need filter or other functions?
+
+}