From b792b509cd891b42c88406fcf88176f35e057f37 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Fri, 14 Feb 2014 23:25:52 +0100 Subject: cleans up FutureSystem --- src/main/scala/scala/async/internal/AsyncId.scala | 14 ++++++-------- .../scala/scala/async/internal/AsyncMacro.scala | 4 ++-- .../scala/scala/async/internal/ExprBuilder.scala | 2 +- .../scala/scala/async/internal/FutureSystem.scala | 21 +++++++++------------ 4 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/main/scala/scala/async/internal/AsyncId.scala b/src/main/scala/scala/async/internal/AsyncId.scala index f9d8c0b..6b4dbce 100644 --- a/src/main/scala/scala/async/internal/AsyncId.scala +++ b/src/main/scala/scala/async/internal/AsyncId.scala @@ -7,7 +7,6 @@ package scala.async.internal import language.experimental.macros import scala.reflect.macros.Context import scala.reflect.api.Universe -import scala.reflect.internal.SymbolTable object AsyncId extends AsyncBase { lazy val futureSystem = IdentityFutureSystem @@ -52,12 +51,11 @@ object IdentityFutureSystem extends FutureSystem { type ExecContext = Unit type Tryy[A] = scala.util.Try[A] - def mkOps(c: SymbolTable): Ops {val universe: c.type} = new Ops { - val universe: c.type = c + def mkOps(c0: Context): Ops {val c: c0.type} = new Ops { + val c: c0.type = c0 + import c.universe._ - import universe._ - - def execContext: Expr[ExecContext] = Expr[Unit](Literal(Constant(()))) + def execContext: Expr[ExecContext] = c.Expr[Unit](Literal(Constant(()))) def promType[A: WeakTypeTag]: Type = weakTypeOf[Prom[A]] def tryType[A: WeakTypeTag]: Type = weakTypeOf[scala.util.Try[A]] @@ -76,12 +74,12 @@ object IdentityFutureSystem extends FutureSystem { def onComplete[A, U](future: Expr[Fut[A]], fun: Expr[Tryy[A] => U], execContext: Expr[ExecContext]): Expr[Unit] = reify { fun.splice.apply(util.Success(future.splice)) - Expr[Unit](Literal(Constant(()))).splice + c.Expr[Unit](Literal(Constant(()))).splice } def completeProm[A](prom: Expr[Prom[A]], value: Expr[Tryy[A]]): Expr[Unit] = reify { prom.splice.a = value.splice.get - Expr[Unit](Literal(Constant(()))).splice + c.Expr[Unit](Literal(Constant(()))).splice } def tryyIsFailure[A](tryy: Expr[Tryy[A]]): Expr[Boolean] = reify { diff --git a/src/main/scala/scala/async/internal/AsyncMacro.scala b/src/main/scala/scala/async/internal/AsyncMacro.scala index 78662fd..7215ce9 100644 --- a/src/main/scala/scala/async/internal/AsyncMacro.scala +++ b/src/main/scala/scala/async/internal/AsyncMacro.scala @@ -7,7 +7,7 @@ object AsyncMacro { def apply(c0: reflect.macros.Context, base: AsyncBase): AsyncMacro = { import language.reflectiveCalls val powerContext = c0.asInstanceOf[c0.type { val universe: Global; val callsiteTyper: universe.analyzer.Typer }] - new AsyncMacro { + new AsyncMacro { self => val c: scala.reflect.macros.Context { val universe: global.type } = c0.asInstanceOf[scala.reflect.macros.Context { val universe: global.type }] val global: powerContext.universe.type = powerContext.universe val callSiteTyper: global.analyzer.Typer = powerContext.callsiteTyper @@ -16,7 +16,7 @@ object AsyncMacro { val asyncBase: AsyncBase = base // These members are required by `ExprBuilder`: val futureSystem: FutureSystem = base.futureSystem - val futureSystemOps: futureSystem.Ops {val universe: global.type} = futureSystem.mkOps(global) + val futureSystemOps: futureSystem.Ops {val c: self.c.type} = futureSystem.mkOps(c) } } } diff --git a/src/main/scala/scala/async/internal/ExprBuilder.scala b/src/main/scala/scala/async/internal/ExprBuilder.scala index f314851..8fbb397 100644 --- a/src/main/scala/scala/async/internal/ExprBuilder.scala +++ b/src/main/scala/scala/async/internal/ExprBuilder.scala @@ -17,7 +17,7 @@ trait ExprBuilder { import defn._ val futureSystem: FutureSystem - val futureSystemOps: futureSystem.Ops { val universe: global.type } + val futureSystemOps: futureSystem.Ops { val c: builder.c.type } val stateAssigner = new StateAssigner val labelDefStates = collection.mutable.Map[Symbol, Int]() diff --git a/src/main/scala/scala/async/internal/FutureSystem.scala b/src/main/scala/scala/async/internal/FutureSystem.scala index 46c0bcf..1b1ffc3 100644 --- a/src/main/scala/scala/async/internal/FutureSystem.scala +++ b/src/main/scala/scala/async/internal/FutureSystem.scala @@ -4,7 +4,7 @@ package scala.async.internal import scala.language.higherKinds -import scala.reflect.internal.SymbolTable +import scala.reflect.macros.Context /** * An abstraction over a future system. @@ -27,10 +27,8 @@ trait FutureSystem { type Tryy[T] trait Ops { - val universe: reflect.internal.SymbolTable - - import universe._ - def Expr[T: WeakTypeTag](tree: Tree): Expr[T] = universe.Expr[T](rootMirror, universe.FixedMirrorTreeCreator(rootMirror, tree)) + val c: Context + import c.universe._ def promType[A: WeakTypeTag]: Type def tryType[A: WeakTypeTag]: Type @@ -53,7 +51,7 @@ trait FutureSystem { def completeProm[A](prom: Expr[Prom[A]], value: Expr[Tryy[A]]): Expr[Unit] def spawn(tree: Tree, execContext: Tree): Tree = - future(Expr[Unit](tree))(Expr[ExecContext](execContext)).tree + future(c.Expr[Unit](tree))(c.Expr[ExecContext](execContext)).tree def tryyIsFailure[A](tryy: Expr[Tryy[A]]): Expr[Boolean] @@ -65,7 +63,7 @@ trait FutureSystem { def postAnfTransform(tree: Block): Block = tree } - def mkOps(c: SymbolTable): Ops { val universe: c.type } + def mkOps(c0: Context): Ops { val c: c0.type } } object ScalaConcurrentFutureSystem extends FutureSystem { @@ -77,10 +75,9 @@ object ScalaConcurrentFutureSystem extends FutureSystem { type ExecContext = ExecutionContext type Tryy[A] = scala.util.Try[A] - def mkOps(c: SymbolTable): Ops {val universe: c.type} = new Ops { - val universe: c.type = c - - import universe._ + def mkOps(c0: Context): Ops {val c: c0.type} = new Ops { + val c: c0.type = c0 + import c.universe._ def promType[A: WeakTypeTag]: Type = weakTypeOf[Promise[A]] def tryType[A: WeakTypeTag]: Type = weakTypeOf[scala.util.Try[A]] @@ -105,7 +102,7 @@ object ScalaConcurrentFutureSystem extends FutureSystem { def completeProm[A](prom: Expr[Prom[A]], value: Expr[scala.util.Try[A]]): Expr[Unit] = reify { prom.splice.complete(value.splice) - Expr[Unit](Literal(Constant(()))).splice + c.Expr[Unit](Literal(Constant(()))).splice } def tryyIsFailure[A](tryy: Expr[scala.util.Try[A]]): Expr[Boolean] = reify { -- cgit v1.2.3