Skip to content

Commit f6a44fe

Browse files
committed
wip
1 parent ad80ab6 commit f6a44fe

File tree

4 files changed

+45
-7
lines changed

4 files changed

+45
-7
lines changed

compiler/src/dotty/tools/dotc/interpreter/Interpreter.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,25 @@ class Interpreter(implicit ctx: Context) {
5757
}
5858
}
5959

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+
6079
/** Returns the interpreted result of interpreting the code represented by the tree.
6180
* Returns the result of the interpreted tree.
6281
*

compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import typer.Implicits.SearchFailureType
2424
import scala.collection.mutable
2525
import dotty.tools.dotc.core.StdNames._
2626
import dotty.tools.dotc.core.quoted._
27+
import dotty.tools.dotc.interpreter.Interpreter
2728

2829

2930
/** Translates quoted terms and types to `unpickle` method calls.
@@ -515,13 +516,35 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
515516

516517
val tree1 =
517518
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)
518525
println("========================")
519526
println(tree.show)
520527
println()
521528
println(call.show)
522529
println(call)
523530
println()
531+
println(call.symbol)
532+
println(args)
524533
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))
525548
println()
526549
println()
527550
println()

compiler/src/dotty/tools/dotc/transform/Splicer.scala

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,7 @@ object Splicer {
2121
*/
2222
def splice(tree: Tree)(implicit ctx: Context): Tree = tree match {
2323
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)
3125
}
3226

3327
/** Splice the Tree for a Quoted expression which is constructed via a reflective call to the given method */

compiler/src/dotty/tools/dotc/typer/RefChecks.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,8 @@ class RefChecks extends MiniPhase { thisPhase =>
947947

948948
override def transformDefDef(tree: DefDef)(implicit ctx: Context) = {
949949
checkDeprecatedOvers(tree)
950+
if (tree.symbol.is(Macro))
951+
tree.symbol.resetFlag(Macro)
950952
tree
951953
}
952954

0 commit comments

Comments
 (0)