On 2013-11-11 12:34, Dmitry Olshansky wrote:

I have to say I like it.

Cool :)

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.

Ok, I can change that.

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.

Right. scope(exit) could perhaps be implement with a custom struct and calling a block in the destructor.

  - Can't implement foreach if only because of the syntax of the latter.

I would think something like this:

macro foreach (T) (Context context, Ast!(Symbol) var, Ast!(T) collection, Statement block)
{
    if (isRange(collection))
    {
        return <[
            for (auto __r = $collection; !__r.empty; __r.popFront())
            {
                auto $var = __r.front;
                block;
            }
        ]>;
    }

    else if (hasOpApply(collection))
    {
        ...
    }

    else ...
}

Perhaps not all of the existing syntax can fit in a macro.

  - 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.

Yes, something like that. I don't know exactly how the Ast type need to look like. See one of my replies to bearophile:

http://forum.dlang.org/thread/[email protected]

  - 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.

Actually, I haven't thought about this. I think my original idea was that <[ ]> should only work inside macros. But that it would be possible to pass Ast nodes to other functions.

--
/Jacob Carlborg

Reply via email to