Add ImportC compiler to dmd

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Mon May 10 11:38:50 UTC 2021


On Monday, 10 May 2021 at 11:03:43 UTC, Ola Fosheim Grøstad wrote:
> My point is that you don't need to translate headers if you 
> have an external tool that accept a set of header files and a 
> C-expression and provide a mechanism to do reflection on that 
> expression.

To elaborate on this assume you have something like this:

```d
#include "header1.h"
#include "header2.h"

DType1 x;
DType2 y;

int z = ©(FUNKYMACRO(1+*$x,*$y)

```

Where © says this is a C-expression and $ says it is a D 
identifier.

The the compiler would collect all #includes in the D-file and 
create a C-function with (cachable) source looking something like 
this:

```c
#include "header1.h"
#include "header2.h"

int __transpiled1234(__DType1_translated_to_C* __x, 
__DType2_translated_to_C* __y){
return FUNKYMACRO(1+*__x, *__y);
}

```

And generate the following D code:
```d
int z = __transpiled1234(&x, &y);

```


Something like that.



More information about the Digitalmars-d mailing list