Me and Cauterite were toying with the idea of AST macros but in a completely new form a while ago.

Below is the usage of it.

Something you'll notice about it is that it could turn the asm block into a library solution (which is clearly what we'd want anyway). Not to mention Linq style queries.

In theory it shouldn't be too complex to implement since you are only doing basic checks to determine if to parse the given statement / block to a rewriter function.

```D
void main() {
    // \/ parsed by iasm.c by matches {}'s and sending contents to it
    asm {
        ...
    }

    import linq;
    @Linq
    DataSource source = ...;
    Tree[] trees = source.trees.where(name = "abc").limit(20);

    import Assembly_x86;

    asm {
        ...
    }
}

struct Linq {
    string __ast(OnType, ExpectedType)(string statement) {
        assert(statement == "source.trees.where(name = "abc").limit(20);");
        static assert(OnType == DataSource);
        static assert(ExpectedType == Tree[]);
    }
}

// Assembly_x86.d

struct X86 {}
struct ASM {

    string __ast(OnType, ExpectedType)(string statement) {
        assert(statement == "asm {\n        ...\n    };");
        static assert(OnType == X86);
        static assert(ExpectedType == void);
    }
}

@ASM
X86 asm;
```

Reply via email to