Skip to content

Commit

Permalink
Fix build: Port scala#5797 to new syntax from scala#5458
Browse files Browse the repository at this point in the history
  • Loading branch information
Blaisorblade committed Jan 29, 2019
1 parent cfbdbd8 commit f079dd3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class TastyInterpreter extends TastyConsumer {
case DefDef("main", _, _, _, Some(rhs)) =>
val interpreter = new jvm.Interpreter(reflect)

interpreter.eval(rhs)(Map.empty)
interpreter.eval(rhs) with Map.empty
// TODO: recurse only for PackageDef, ClassDef
case tree =>
super.traverseTree(tree)
}
}
Traverser.traverseTree(root)(reflect.rootContext)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ abstract class TreeInterpreter[R <: Reflection & Singleton](val reflect: R) {
/** Representation of objects and values in the interpreter */
type AbstractAny

type Result = implicit Env => AbstractAny
type Result = Env |=> AbstractAny

def localValue(sym: Symbol)(implicit env: Env): LocalValue = env(sym)

def withLocalValue[T](sym: Symbol, value: LocalValue)(in: implicit Env => T)(implicit env: Env): T =
in(env.updated(sym, value))
def withLocalValue[T](sym: Symbol, value: LocalValue)(in: Env |=> T)(implicit env: Env): T =
in with env.updated(sym, value)

def withLocalValues[T](syms: List[Symbol], values: List[LocalValue])(in: implicit Env => T)(implicit env: Env): T =
in(env ++ syms.zip(values))
def withLocalValues[T](syms: List[Symbol], values: List[LocalValue])(in: Env |=> T)(implicit env: Env): T =
in with (env ++ syms.zip(values))

def interpretCall(instance: AbstractAny, sym: DefSymbol, args: List[AbstractAny]): Result = {
def interpretCall(inst: AbstractAny, sym: DefSymbol, args: List[AbstractAny]): Result = {
// TODO
// withLocalValue(`this`, instance) {
// withLocalValue(`this`, inst) {
val syms = sym.tree.paramss.headOption.getOrElse(Nil).map(_.symbol)
withLocalValues(syms, args.map(LocalValue.valFrom(_))) {
eval(sym.tree.rhs.get)
Expand Down Expand Up @@ -65,7 +65,7 @@ abstract class TreeInterpreter[R <: Reflection & Singleton](val reflect: R) {
def interpretBlock(stats: List[Statement], expr: Term): Result = {
val newEnv = stats.foldLeft(implicitly[Env])((accEnv, stat) => stat match {
case ValDef(name, tpt, Some(rhs)) =>
def evalRhs = eval(rhs)(accEnv)
def evalRhs = eval(rhs) with accEnv
val evalRef: LocalValue =
if (stat.symbol.flags.is(Flags.Lazy)) LocalValue.lazyValFrom(evalRhs)
else if (stat.symbol.flags.is(Flags.Mutable)) LocalValue.varFrom(evalRhs)
Expand All @@ -76,10 +76,10 @@ abstract class TreeInterpreter[R <: Reflection & Singleton](val reflect: R) {
// TODO: record the environment for closure purposes
accEnv
case stat =>
eval(stat)(accEnv)
eval(stat) with accEnv
accEnv
})
eval(expr)(newEnv)
eval(expr) with newEnv
}

def interpretUnit(): AbstractAny
Expand Down Expand Up @@ -213,4 +213,4 @@ abstract class TreeInterpreter[R <: Reflection & Singleton](val reflect: R) {
case _ => None
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,22 @@ class JVMReflection[R <: Reflection & Singleton](val reflect: R) {
}

def interpretStaticVal(moduleClass: Symbol, fn: Symbol): Object = {
val instance = loadModule(moduleClass)
val inst = loadModule(moduleClass)
val name = fn.name
val method = getMethod(instance.getClass, name, Nil)
method.invoke(instance)
val method = getMethod(inst.getClass, name, Nil)
method.invoke(inst)
}

def interpretStaticMethodCall(moduleClass: Symbol, fn: Symbol, args: List[Object]): Object = {
// TODO can we use interpretMethodCall instead?
val instance = loadModule(moduleClass)
val method = getMethod(instance.getClass, fn.name, paramsSig(fn))
method.invoke(instance, args: _*)
val inst = loadModule(moduleClass)
val method = getMethod(inst.getClass, fn.name, paramsSig(fn))
method.invoke(inst, args: _*)
}

def interpretMethodCall(instance: Object, fn: Symbol, args: List[Object]): Object = {
val method = getMethod(instance.getClass, fn.name, paramsSig(fn))
method.invoke(instance, args: _*)
def interpretMethodCall(inst: Object, fn: Symbol, args: List[Object]): Object = {
val method = getMethod(inst.getClass, fn.name, paramsSig(fn))
method.invoke(inst, args: _*)
}

def interpretNew(fn: Symbol, args: List[Object]): Object = {
Expand Down Expand Up @@ -113,4 +113,4 @@ class JVMReflection[R <: Reflection & Singleton](val reflect: R) {
}

private def extraMsg = ". The most common reason for that is that you apply macros in the compilation run that defines them"
}
}

0 comments on commit f079dd3

Please sign in to comment.