Add ImportC compiler to dmd

Max Haughton maxhaton at gmail.com
Sat May 15 16:09:19 UTC 2021


On Saturday, 15 May 2021 at 16:03:01 UTC, Andrei Alexandrescu 
wrote:
> On 5/15/21 4:34 AM, Markk wrote:
>> On Monday, 10 May 2021 at 09:27:35 UTC, Walter Bright wrote:
>> 
>>> Since this is all front end work, and it translates the C 
>>> code into D AST nodes, it should "just work".
>> 
>> With that crucial information added it suddenly made perfect 
>> sense to me.
>> 
>> Brilliant!
>
> ImportC is one of the coolest hacks I've seen in many years.
>
> To think it took only 4 KLOC. I can't find my behind with a map 
> in 4 KLOC.

wrt to it being 4KLOC, I'm reserving judgement until it can 
compile something useful. The dmd AST is already a bit of a mess, 
making it compile two languages (i.e. more bitflags everywhere!) 
could make 4KLOC in the parser trickle down elsewhere all over 
the place (e.g. Struct forward decls, initializer lists etc. all 
have to find a home somewhere in the AST).

One thing of note here is that if it can compile a given C file, 
the compiler doesn't do a terrible job of representing it's AST 
as a string so this could also be utilized as a C to D converter.


More information about the Digitalmars-d mailing list