Thread overview | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
January 21, 2017 Compile to C? | ||||
---|---|---|---|---|
| ||||
Hi friends, Is there a way to "compile" d code to C, similar to what nim does? That would be cool for greater portability. |
January 21, 2017 Re: Compile to C? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nestor | On Saturday, 21 January 2017 at 18:38:22 UTC, Nestor wrote: > Hi friends, > > Is there a way to "compile" d code to C, similar to what nim does? > > That would be cool for greater portability. The wiki says there was a dmd fork that attempted this 5 years ago, don't know how far he got: https://wiki.dlang.org/Compilers https://github.com/yebblies/dmd/tree/microd |
January 21, 2017 Re: Compile to C? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nestor | On Saturday, 21 January 2017 at 18:38:22 UTC, Nestor wrote: > Hi friends, > > Is there a way to "compile" d code to C, similar to what nim does? > > That would be cool for greater portability. No, and this is actually a terrible idea. See https://forum.dlang.org/post/n1vbos$11ov$1@digitalmars.com |
January 21, 2017 Re: Compile to C? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nestor | On Saturday, 21 January 2017 at 18:38:22 UTC, Nestor wrote:
> That would be cool for greater portability.
The hard part in porting to a new platform is rarely the code generation - gdc and ldc have diverse backends already (indeed, they tend to work for D as well as C there). But you still have to port runtime library requirements where compiling to C wouldn't help at all.
|
January 23, 2017 Re: Compile to C? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Saturday, 21 January 2017 at 19:33:27 UTC, Adam D. Ruppe wrote:
> On Saturday, 21 January 2017 at 18:38:22 UTC, Nestor wrote:
>> That would be cool for greater portability.
>
> The hard part in porting to a new platform is rarely the code generation - gdc and ldc have diverse backends already (indeed, they tend to work for D as well as C there). But you still have to port runtime library requirements where compiling to C wouldn't help at all.
You mean phobos, or system libraries?
|
January 23, 2017 Re: Compile to C? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nestor | On Monday, 23 January 2017 at 01:12:21 UTC, Nestor wrote:
> You mean phobos, or system libraries?
Phobos but mostly the druntime that interfaces with the system.
|
January 23, 2017 Re: Compile to C? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Monday, 23 January 2017 at 01:17:20 UTC, Adam D. Ruppe wrote:
> On Monday, 23 January 2017 at 01:12:21 UTC, Nestor wrote:
>> You mean phobos, or system libraries?
>
> Phobos but mostly the druntime that interfaces with the system.
I see, I was mostly thinking in Android and/or other platforms, but it does seem like heavy work, though curiously this approach seems to be working for Nim (at least so far), is it that the language is better suited for that, or simply that more work has been put into it? (not bashing D, honest curiosity)
|
January 23, 2017 Re: Compile to C? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nestor | On 23/01/2017 3:20 PM, Nestor wrote:
> On Monday, 23 January 2017 at 01:17:20 UTC, Adam D. Ruppe wrote:
>> On Monday, 23 January 2017 at 01:12:21 UTC, Nestor wrote:
>>> You mean phobos, or system libraries?
>>
>> Phobos but mostly the druntime that interfaces with the system.
>
> I see, I was mostly thinking in Android and/or other platforms, but it
> does seem like heavy work, though curiously this approach seems to be
> working for Nim (at least so far), is it that the language is better
> suited for that, or simply that more work has been put into it? (not
> bashing D, honest curiosity)
Nim probably doesn't care too much about the platform its running on like C.
We support things like TLS and shared libraries with GC, that all requires druntime and having system support to some extent.
|
January 23, 2017 Re: Compile to C? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nestor | On Monday, 23 January 2017 at 02:20:02 UTC, Nestor wrote: > On Monday, 23 January 2017 at 01:17:20 UTC, Adam D. Ruppe wrote: >> On Monday, 23 January 2017 at 01:12:21 UTC, Nestor wrote: >>> You mean phobos, or system libraries? >> >> Phobos but mostly the druntime that interfaces with the system. > > I see, I was mostly thinking in Android and/or other platforms, but it does seem like heavy work, though curiously this approach seems to be working for Nim (at least so far), is it that the language is better suited for that, or simply that more work has been put into it? (not bashing D, honest curiosity) Btw, Ldc has good support for a lot of platforms already, including Android and iPhone: http://wiki.dlang.org/LDC Porting druntime to a new OS is not heavy work, mostly translating some C headers: https://github.com/dlang/druntime/pulls?utf8=✓&q=is%3Apr%20is%3Aopen%20netbsd |
January 23, 2017 Re: Compile to C? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jack Stouffer | On Saturday, 21 January 2017 at 19:30:31 UTC, Jack Stouffer wrote:
> On Saturday, 21 January 2017 at 18:38:22 UTC, Nestor wrote:
>> Hi friends,
>>
>> Is there a way to "compile" d code to C, similar to what nim does?
>>
>> That would be cool for greater portability.
>
> No, and this is actually a terrible idea. See https://forum.dlang.org/post/n1vbos$11ov$1@digitalmars.com
No valid arguments for it being a terrible idea in that thread.
Being able to translate code to other languages is a very useful feature and makes a language much more interesting in production.
|
Copyright © 1999-2021 by the D Language Foundation