@@ -21,27 +21,22 @@ import dotty.tools.dotc.util.Positions.Position
21
21
import scala .reflect .ClassTag
22
22
23
23
/** Utility class to splice quoted expressions */
24
- class Splicer {
24
+ object Splicer {
25
25
import tpd ._
26
26
27
- private var classLoader : URLClassLoader = _
28
-
29
27
/** Splice the Tree for a Quoted expression. `~'(xyz)` becomes `xyz`
30
28
* and for `~xyz` the tree of `xyz` is interpreted for which the
31
29
* resulting expression is returned as a `Tree`
32
30
*
33
31
* See: `ReifyQuotes`
34
32
*/
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 {
36
34
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)
45
40
}
46
41
47
42
/** Given the inline code and bindings, compute the lifted arguments that will be used to execute the macro
@@ -100,12 +95,7 @@ class Splicer {
100
95
* The interpreter assumes that all calls in the trees are to code that was
101
96
* previously compiled and is present in the classpath of the current context.
102
97
*/
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 ) {
109
99
110
100
/** Returns the interpreted result of interpreting the code a call to the symbol with default arguments.
111
101
* Return Some of the result or None if some error happen during the interpretation.
0 commit comments