-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Typed Macros #135
Comments
One obvious optimization: On |
One area where this might cause bad problems with is in code such as the one you suggested to me with a problem: macro dependentMacro:
var myModule = FindMyModule(CompileUnit)
var checker = MacroSearcher()
myModule.Accept(checker)
return dependentMacro if checker.ContainsMacros
//perform your logic here
class MacroSearcher(DepthFirstVisitor):
property ContainsMacros as bool
override def OnMacroStatement(node as MacroStatement):
ContainsMacros = true Basically, the addition of typed macros could cause an infinite loop for macros that try to run in a certain order.. Maybe we should also come up with a better solution to somehow control the order of macro expansion. |
After thinking about it. I think perhaps that a better solution is to create some kind of "FutureTypeReference" in the cases where the type is inferred for type references. This would obviously change the structure a bit of the compiler, since any code with 'FutureTypeReference's would have to be error checked after type inference stage, but that would basically solve whatever a typed macro would solve without having to make a distinguishing of the macros. I also think it would be pretty easy to work with probably? |
A hypothetical |
True, you're right. I guess both would be good improvements! |
As powerful as Boo's macro system is, it has one very notable limitation: it runs before type binding takes place, which makes it extremely cumbersome to try to write macro code that needs to be aware of types for whatever reason.
It would be nice to add a mechanism for type-aware macros. This is simply a proposal at the moment, for discussion purposes, but here's an initial outline:
TypemacroMacro
which descends fromMacroMacro
and does exactly the same thing asMacroMacro
, except that the generated macro class is tagged with an attribute, virtual method, or other way of marking it as a typed macro.MacroExpander
encounters a macro, it first checks to see if it's a typed macro, and if so, it leaves it alone.MacroExpander
pass after type inference. This one unconditionally expands all macros, and runsCodeReifier
over the result. At this point, type information is available, which makes writing certain types of macros much, much easier.Implementing and testing this would be a non-trivial undertaking, so any thoughts on the subject would be welcomed.
The text was updated successfully, but these errors were encountered: