DIP 50 - AST macros

Dmitry Olshansky dmitry.olsh at gmail.com
Mon Nov 11 03:34:58 PST 2013


11-Nov-2013 01:20, Jacob Carlborg пишет:
> I've been thinking quite long of how AST macros could look like in D.
> I've been posting my vision of AST macros here in the newsgroup a couple
> of times already. I've now been asked to create a DIP out of it, so here
> it is:
>
> http://wiki.dlang.org/DIP50
>

I have to say I like it.

I find it nice that it would allow one to finally ensure that inlining 
is always done by making critical primitives macros instead of 
functions. This is vastly superior compared to the _only_ current option 
of generating unrolled code with string mixins.

I'd call attribute macros - declaration macros in line with statement 
macros, then describe how they look - a lot like attributes.

Things to note though:
  - Can't implement scope(exit/success/failure) because that would need 
to capture the outer scope to pack it into try/catch/finally.
  - Can't implement foreach if only because of the syntax of the latter.
  - There is no definition of Ast!(T) construct - I take it's a struct 
or a class of sorts and the whole thing works with the CTFE engine. Then 
it also needs specification of Statements, Declarations.
  - It seems like I can use AST literal in R-T code as well? That would 
be useful but only if some library actually accepted these AST nodes.

-- 
Dmitry Olshansky


More information about the Digitalmars-d mailing list