What type functions mean on a language level

Max Haughton maxhaton at gmail.com
Sat Jan 2 19:04:15 UTC 2021


On Saturday, 2 January 2021 at 08:47:07 UTC, Jacob Carlborg wrote:
> On 2021-01-02 01:05, Stefan Koch wrote:
>
>> [...]
>
> I'm not sure if it needs to have an API. Just look at how Zig 
> does it.
>
> __type__ LinkedList(__type__ ElementType)
> {
>     return struct {
>         static struct Node
>         {
>             ElementType element;
>             Node* next;
>             Node* prev;
>         }
>
>         Node* first;
>         Node* last;
>     }
> }
>
> LinkedList(int) list;
>
> If you want to pass in the field names, I guess you'll have to 
> resort to string mixins. Sure, there could be better 
> alternatives than string mixins, but I think that's a separate 
> issue.
>
>> [...]
>
> Here I've experimented in exposing the compiler AST [1].
>
> [1] 
> https://github.com/jacob-carlborg/druntime/blob/517dafcf54ad73049fb35d1ed5fa2ad6619b9ac4/src/core/ast/expression.d

Did you get as far as actually emitting it to be used during 
compilation? I'm not about the best way of actually using the AST 
structure inside the compiler


More information about the Digitalmars-d mailing list