Overloading relational operators separately; thoughts?

Jacob Carlborg via Digitalmars-d digitalmars-d at puremagic.com
Thu Sep 29 06:18:57 PDT 2016


On 2016-09-29 14:57, rikki cattermole wrote:
> 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;
> ```

Hmm, I find this to be somewhat difficult to follow. You get the AST as 
a string? Which means you need to implement a parser. How will the macro 
invocation be transformed? Return a string from the macro which will be 
reparsed by the compiler and inserted at the call site?

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list