@@ -21,27 +21,22 @@ import dotty.tools.dotc.util.Positions.Position
2121import scala .reflect .ClassTag
2222
2323/** Utility class to splice quoted expressions */
24- class Splicer {
24+ object Splicer {
2525 import tpd ._
2626
27- private var classLoader : URLClassLoader = _
28-
2927 /** Splice the Tree for a Quoted expression. `~'(xyz)` becomes `xyz`
3028 * and for `~xyz` the tree of `xyz` is interpreted for which the
3129 * resulting expression is returned as a `Tree`
3230 *
3331 * See: `ReifyQuotes`
3432 */
35- def splice (tree : Tree , call : Tree , bindings : List [Tree ], pos : Position )(implicit ctx : Context ): Tree = tree match {
33+ def splice (tree : Tree , call : Tree , bindings : List [Tree ], pos : Position , classLoader : ClassLoader )(implicit ctx : Context ): Tree = tree match {
3634 case Quoted (quotedTree) => quotedTree
37- case _ => reflectiveSplice(tree, call, bindings, pos)
38- }
39-
40- private def reflectiveSplice (tree : Tree , call : Tree , bindings : List [Tree ], pos : Position )(implicit ctx : Context ): Tree = {
41- val liftedArgs = getLiftedArgs(call, bindings)
42- val interpreter = new Interpreter (pos)
43- val interpreted = interpreter.interpretCallToSymbol[Seq [Any ] => Object ](call.symbol)
44- interpreted.flatMap(lambda => evaluateLambda(lambda, liftedArgs, pos)).fold(tree)(PickledQuotes .quotedExprToTree)
35+ case _ =>
36+ val liftedArgs = getLiftedArgs(call, bindings)
37+ val interpreter = new Interpreter (pos, classLoader)
38+ val interpreted = interpreter.interpretCallToSymbol[Seq [Any ] => Object ](call.symbol)
39+ interpreted.flatMap(lambda => evaluateLambda(lambda, liftedArgs, pos)).fold(tree)(PickledQuotes .quotedExprToTree)
4540 }
4641
4742 /** Given the inline code and bindings, compute the lifted arguments that will be used to execute the macro
@@ -100,12 +95,7 @@ class Splicer {
10095 * The interpreter assumes that all calls in the trees are to code that was
10196 * previously compiled and is present in the classpath of the current context.
10297 */
103- private class Interpreter (pos : Position )(implicit ctx : Context ) {
104-
105- if (classLoader == null ) {
106- val urls = ctx.settings.classpath.value.split(':' ).map(cp => java.nio.file.Paths .get(cp).toUri.toURL)
107- classLoader = new URLClassLoader (urls, getClass.getClassLoader)
108- }
98+ private class Interpreter (pos : Position , classLoader : ClassLoader )(implicit ctx : Context ) {
10999
110100 /** Returns the interpreted result of interpreting the code a call to the symbol with default arguments.
111101 * Return Some of the result or None if some error happen during the interpretation.
0 commit comments