File tree Expand file tree Collapse file tree 4 files changed +45
-7
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 4 files changed +45
-7
lines changed Original file line number Diff line number Diff line change @@ -57,6 +57,25 @@ class Interpreter(implicit ctx: Context) {
57
57
}
58
58
}
59
59
60
+ def interpretCallToSymbol [T ](sym : Symbol )(implicit pos : Position ): T = {
61
+ val clazz = loadClass(sym.owner.companionModule.fullName)
62
+ val paramClasses = paramsSig(sym)
63
+ val interpretedArgs = paramClasses.map(_ => 1 .asInstanceOf [Object ])
64
+ println(" ----------------" )
65
+ println(clazz)
66
+ println(paramClasses)
67
+ println(interpretedArgs)
68
+ println()
69
+ println(sym.name)
70
+ println()
71
+ println()
72
+ println()
73
+
74
+ val method =
75
+ clazz.getMethod(sym.name.toString, paramClasses : _* )
76
+ stopIfRuntimeException(method.invoke(null , interpretedArgs : _* )).asInstanceOf [T ]
77
+ }
78
+
60
79
/** Returns the interpreted result of interpreting the code represented by the tree.
61
80
* Returns the result of the interpreted tree.
62
81
*
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ import typer.Implicits.SearchFailureType
24
24
import scala .collection .mutable
25
25
import dotty .tools .dotc .core .StdNames ._
26
26
import dotty .tools .dotc .core .quoted ._
27
+ import dotty .tools .dotc .interpreter .Interpreter
27
28
28
29
29
30
/** Translates quoted terms and types to `unpickle` method calls.
@@ -515,13 +516,35 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
515
516
516
517
val tree1 =
517
518
if (level == 0 ) {
519
+ def getArgs (tree : Tree , acc : List [Tree ]): List [Tree ] = tree match {
520
+ case Apply (fun, args) => getArgs(fun, args ::: acc)
521
+ case TypeApply (fun, args) => getArgs(fun, acc)
522
+ case _ => acc
523
+ }
524
+ val args = getArgs(call, Nil )
518
525
println(" ========================" )
519
526
println(tree.show)
520
527
println()
521
528
println(call.show)
522
529
println(call)
523
530
println()
531
+ println(call.symbol)
532
+ println(args)
524
533
println()
534
+ val lambda = (new Interpreter ).interpretCallToSymbol(call.symbol)(tree.pos).asInstanceOf [Seq [Any ] => Object ]
535
+ val args1 = args.map {
536
+ case Literal (Constant (v)) => v
537
+ case arg => new scala.quoted.Exprs .TreeExpr (tree)
538
+ }
539
+ println()
540
+ println(" ~~~~~~~~~~~~~~~~~~~" )
541
+ println(call.symbol.info)
542
+ println(call.symbol.info.show)
543
+ println()
544
+ println()
545
+ println(args1)
546
+ println()
547
+ println(lambda(args1))
525
548
println()
526
549
println()
527
550
println()
Original file line number Diff line number Diff line change @@ -21,13 +21,7 @@ object Splicer {
21
21
*/
22
22
def splice (tree : Tree )(implicit ctx : Context ): Tree = tree match {
23
23
case Quoted (quotedTree) => quotedTree
24
- case _ =>
25
- println()
26
- println(tree.show)
27
- println()
28
- println()
29
- println()
30
- reflectiveSplice(tree)
24
+ case _ => reflectiveSplice(tree)
31
25
}
32
26
33
27
/** Splice the Tree for a Quoted expression which is constructed via a reflective call to the given method */
Original file line number Diff line number Diff line change @@ -947,6 +947,8 @@ class RefChecks extends MiniPhase { thisPhase =>
947
947
948
948
override def transformDefDef (tree : DefDef )(implicit ctx : Context ) = {
949
949
checkDeprecatedOvers(tree)
950
+ if (tree.symbol.is(Macro ))
951
+ tree.symbol.resetFlag(Macro )
950
952
tree
951
953
}
952
954
You can’t perform that action at this time.
0 commit comments