Thread overview | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
October 20 Generating .di header files from ImportC files | ||||
---|---|---|---|---|
| ||||
Bruce and Adam and I met at a Red Robin in Seattle to chat about D, and they both made a case for the D compiler being able to translate C files into .di "header" files. The idea is to: 1. be able to work with D IDE programs that can only deal with D code 2. be able to handle the vast bulk of converting .h to D code, and then tweak by hand the bits that didn't translate well Anyhow, I pontificated that this couldn't be done, because some C code is not representable as D code. Silly me. But I got to thinking about it. It turns out that DMD can currently do this: dmd -c test.c -Hf=test.di and voila! It creates a .di file from the C file. Who knew? It could use some adjustment, but the bulk is there and it didn't crash or launch nuclear missiles. (Phew!) Just like I discovered that ImportC could successfully import and use D code (including templates!), this is another fine discovery that DMD can convert C code to D code! An unexpected feature that (nearly) comes for free! Wow! Anyhow, have fun experimenting with this! |
October 21 Re: Generating .di header files from ImportC files | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Saturday, 21 October 2023 at 02:13:24 UTC, Walter Bright wrote:
> Bruce and Adam and I met at a Red Robin in Seattle to chat about D, and they both made a case for the D compiler being able to translate C files into .di "header" files.
>
> [...]
Interesting indeed. Nice work.
Can you expand on how dmd can convert C to D? I didn't quite get that part.
|
October 21 Re: Generating .di header files from ImportC files | ||||
---|---|---|---|---|
| ||||
Posted in reply to Imperatorn | On 10/21/2023 1:12 AM, Imperatorn wrote:
> Can you expand on how dmd can convert C to D? I didn't quite get that part.
DMD already has the capability to read in a .d file, then from the AST generate a .di file. Since ImportC gets turned into an AST, too, it can turn that AST into a .di file, too.
|
October 21 Re: Generating .di header files from ImportC files | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Saturday, 21 October 2023 at 17:04:40 UTC, Walter Bright wrote:
> On 10/21/2023 1:12 AM, Imperatorn wrote:
>> Can you expand on how dmd can convert C to D? I didn't quite get that part.
>
> DMD already has the capability to read in a .d file, then from the AST generate a .di file. Since ImportC gets turned into an AST, too, it can turn that AST into a .di file, too.
I see, nice. I will experiment with that a bit.
|
October 21 Re: Generating .di header files from ImportC files | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Saturday, 21 October 2023 at 17:04:40 UTC, Walter Bright wrote:
> On 10/21/2023 1:12 AM, Imperatorn wrote:
>> Can you expand on how dmd can convert C to D? I didn't quite get that part.
>
> DMD already has the capability to read in a .d file, then from the AST generate a .di file. Since ImportC gets turned into an AST, too, it can turn that AST into a .di file, too.
Nice, I just tried it and as long as you have your path setup right, it works well :)
For others reading this, since I'm on Windows, I just opened the developer command prompt and just ran:
dmd -c hashmap.c -Hf="hashmap.di"
And it just worked. Pretty impressive.
|
October 21 Re: Generating .di header files from ImportC files | ||||
---|---|---|---|---|
| ||||
Posted in reply to Imperatorn | On 10/21/2023 11:33 AM, Imperatorn wrote:
> And it just worked. Pretty impressive.
Ain't it cool? I love it when things like this happen.
|
October 22 Re: Generating .di header files from ImportC files | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Saturday, 21 October 2023 at 02:13:24 UTC, Walter Bright wrote:
> Bruce and Adam and I met at a Red Robin in Seattle to chat about D, and they both made a case for the D compiler being able to translate C files into .di "header" files.
>
> The idea is to:
>
I could have sworn I told Bruce that he could do this two years ago shortly after importc came out!
|
October 22 Re: Generating .di header files from ImportC files | ||||
---|---|---|---|---|
| ||||
Posted in reply to Iain Buclaw | On Sunday, 22 October 2023 at 08:28:42 UTC, Iain Buclaw wrote:
> On Saturday, 21 October 2023 at 02:13:24 UTC, Walter Bright wrote:
>> Bruce and Adam and I met at a Red Robin in Seattle to chat about D, and they both made a case for the D compiler being able to translate C files into .di "header" files.
>>
>> The idea is to:
>>
>
> I could have sworn I told Bruce that he could do this two years ago shortly after importc came out!
You probably did! :-) I knew that others had it brewing for a bit but had not remembered it as being *that* old! Kudos.
Anyway, glad to see this is being explored/exposed. It's great to draft along behind the, well maintained, importC capability.
|
October 22 Re: Generating .di header files from ImportC files | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Saturday, 21 October 2023 at 02:13:24 UTC, Walter Bright wrote:
> Bruce and Adam and I met at a Red Robin in Seattle to chat about D, and they both made a case for the D compiler being able to translate C files into .di "header" files.
>
> [...]
Sorry but I don’t think I’ve ever used .di files. What is the significance of this?
|
October 22 Re: Generating .di header files from ImportC files | ||||
---|---|---|---|---|
| ||||
Posted in reply to jmh530 | On 10/22/2023 4:45 PM, jmh530 wrote:
> Sorry but I don’t think I’ve ever used .di files. What is the significance of this?
.di files serve the same purpose as .h files do in C.
|
Copyright © 1999-2021 by the D Language Foundation