Reputation: 358
I always thought that macro declarations and implementation need to be defined as in the tutorials:
object Impl {
def m(c: Context)(body: c.Expr[Unit]): c.Expr[T] = ???
}
class Usage {
def m(body: Unit): T = macro Impl.m = ???
}
However now I came across:
class RecordMacros(val c: Context) {
import c.universe._
def apply_impl[Rep: c.WeakTypeTag](method: c.Expr[String])(v: c.Expr[(String, Any)]*): c.Expr[Any] = ???
}
source: https://github.com/TiarkRompf/virtualization-lms-core/blob/macro-trans/src/common/Records.scala
What is the difference, is it about refactoring the context out from each method? Also the class doesn't seem to be instantiated before the method is accessed. Thanks
Upvotes: 2
Views: 130
Reputation: 11270
They are called macro bundles available in 2.11 only and yes that's what they are for. http://docs.scala-lang.org/overviews/macros/bundles.html
Upvotes: 4