- About Scala
- In the Enterprise
- Scala Community
- Language Research
- In the Press
- The Scala Team
- Scala's Prehistory
- Contact Us
- Learning Scala
- Tour of Scala
- Scala API
- Setup & Getting Started
- Programming Guides
- Other Guides
- Code Examples
- Scala Developers
Classloader for macros
A few days ago we've got the first end-to-end prototype of macros
(if you wish to take a look, go to sandbox in the root of the clone
and run the test script), and this brought an important question.
Here's a simplified version of the test script mentioned above:
> scalac -Xexperimental Printf.scala -d ./macros
> scalac -toolcp ./macros:$toolcp -Xexperimental Test.scala
> scala Test
Our implementation of macros involves two-step compilation scheme.
During the first step, you compile macros themselves (i.e. macros get
transformed from macro defs into tree transformers and then get
compiled into bytecodes). During the second step, you compile your
application as usual. Then you run the application in a normal fashion
(which is expected, since macros only affect compilation).
To glue the first and the second compilation runs, we need to somehow
tell the compiler where to look for the bytecodes of macro bodies.
This raises the question: how do we do that?
Basically, there are three alternatives:
1) Use normal classpath: scalac -cp ...
2) Use tool classpath: scalac -toolcp ...
3) Use separate classpath: scalac -macrocp ...
Today we've discussed this point with Martin and came to the following
The first option seems to be the most natural. If we want macros to
feel totally like regular methods (and we do our best to achieve
that), then it's the obvious choice.
The second option seems dangerous. Why would we allow anyone to mess
with compiler's internal classpath? Our current implementation does
exactly that just because it's simple to implement, but this will be
changed once the decision is finalized.
The third option seems awkward. Despite of, say, Nemerle going this
route, we wouldn't like the users jump through hoops to use macros.
That would negate our efforts towards seamless integration of macros
into the language.
However, classpath matters have proven to be very subtle, so I'd like
to ask for your feedback. Do you also prefer option #1? What would you
like to add to the discussion?