Skip to content

Commit

Permalink
Fix new tests after merge
Browse files Browse the repository at this point in the history
# Conflicts:
#	tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/TastyInterpreter.scala
#	tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/TreeInterpreter.scala
  • Loading branch information
odersky committed Jan 30, 2019
1 parent 8d64f2d commit da3fe87
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 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) given 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 = given 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: given Env => T)(implicit env: Env): T =
in given 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: given Env => T)(implicit env: Env): T =
in given (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) given 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) given accEnv
accEnv
})
eval(expr)(newEnv)
eval(expr) given newEnv
}

def interpretUnit(): AbstractAny
Expand Down

0 comments on commit da3fe87

Please sign in to comment.