diff options
author | Tiark Rompf <tiark.rompf@epfl.ch> | 2010-03-11 16:55:38 +0000 |
---|---|---|
committer | Tiark Rompf <tiark.rompf@epfl.ch> | 2010-03-11 16:55:38 +0000 |
commit | f584d243487dcd1214291167707e2f53fef5ab5e (patch) | |
tree | af3e926d301193b259d27567470b4c483efbecbe /src/continuations/library | |
parent | 356540e284e9c9407151a44afdb9480d8eb137a1 (diff) | |
download | scala-f584d243487dcd1214291167707e2f53fef5ab5e.tar.gz scala-f584d243487dcd1214291167707e2f53fef5ab5e.tar.bz2 scala-f584d243487dcd1214291167707e2f53fef5ab5e.zip |
moved the continuations plugin into trunk.
Diffstat (limited to 'src/continuations/library')
-rw-r--r-- | src/continuations/library/scala/util/continuations/package.scala | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/continuations/library/scala/util/continuations/package.scala b/src/continuations/library/scala/util/continuations/package.scala new file mode 100644 index 0000000000..0d924565c1 --- /dev/null +++ b/src/continuations/library/scala/util/continuations/package.scala @@ -0,0 +1,65 @@ +// $Id$ + + +// TODO: scaladoc + +package scala.util + +package object continuations { + + type cps[A] = cpsParam[A,A] + + type suspendable = cps[Unit] + + + def shift[A,B,C](fun: (A => B) => C): A @cpsParam[B,C] = { + throw new NoSuchMethodException("this code has to be compiled with the Scala continuations plugin enabled") + } + + def reset[A,C](ctx: =>(A @cpsParam[A,C])): C = { + val ctxR = reify[A,A,C](ctx) + if (ctxR.isTrivial) + ctxR.getTrivialValue.asInstanceOf[C] + else + ctxR.foreach((x:A) => x) + } + + def reset0[A](ctx: =>(A @cpsParam[A,A])): A = reset(ctx) + + def run[A](ctx: =>(Any @cpsParam[Unit,A])): A = { + val ctxR = reify[Any,Unit,A](ctx) + if (ctxR.isTrivial) + ctxR.getTrivialValue.asInstanceOf[A] + else + ctxR.foreach((x:Any) => ()) + } + + + // methods below are primarily implementation details and are not + // needed frequently in client code + + def shiftUnit0[A,B](x: A): A @cpsParam[B,B] = { + shiftUnit[A,B,B](x) + } + + def shiftUnit[A,B,C>:B](x: A): A @cpsParam[B,C] = { + throw new NoSuchMethodException("this code has to be compiled with the Scala continuations plugin enabled") + } + + def reify[A,B,C](ctx: =>(A @cpsParam[B,C])): ControlContext[A,B,C] = { + throw new NoSuchMethodException("this code has to be compiled with the Scala continuations plugin enabled") + } + + def shiftUnitR[A,B](x: A): ControlContext[A,B,B] = { + new ControlContext(null, x) + } + + def shiftR[A,B,C](fun: (A => B) => C): ControlContext[A,B,C] = { + new ControlContext(fun, null.asInstanceOf[A]) + } + + def reifyR[A,B,C](ctx: => ControlContext[A,B,C]): ControlContext[A,B,C] = { + ctx + } + +} |