Re: Compile to C?

2017-01-23 Thread Ola Fosheim Grøstad via Digitalmars-d-learn

On Monday, 23 January 2017 at 15:24:09 UTC, aberba wrote:
Unless you will be limited by tge limitations of C. Vala 
programming language has that issue even though they utilize 
GObject


What limitations? C/C++ programs go around "limitations" by using 
compiler extensions and runtime libraries.


Vala is trying to keep code simple, like Go. Apples and oranges.



Re: Compile to C?

2017-01-23 Thread aberba via Digitalmars-d-learn
On Monday, 23 January 2017 at 14:40:18 UTC, Ola Fosheim Grøstad 
wrote:
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.


Unless you will be limited by tge limitations of C. Vala 
programming language has that issue even though they utilize 
GObject


Re: Compile to C?

2017-01-23 Thread Ola Fosheim Grøstad via Digitalmars-d-learn

On Monday, 23 January 2017 at 14:53:54 UTC, Bauss wrote:
I'd guess the code generation you'd get from doing so with D 
would be absolute horrific to read, because you'll get rid of 
CTFE, templates, proper class structure, globals properly 
stored, since everything in D is TLS and C doesn't then you'll 
see weird constructs everywhere.


TLS is a nonissue. You can wrap the TLS declarations in macros.


Re: Compile to C?

2017-01-23 Thread Bauss via Digitalmars-d-learn

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.


Nim is able to, because Nim doesn't really compile. The Nim 
compiler just translates Nim code to C code and then compiles the 
C code.


It's much harder to do properly in D, because D doesn't use C as 
a backend, but compiles directly to native.


I'd guess the code generation you'd get from doing so with D 
would be absolute horrific to read, because you'll get rid of 
CTFE, templates, proper class structure, globals properly stored, 
since everything in D is TLS and C doesn't then you'll see weird 
constructs everywhere.


If you ask me, it's probably not something you want to do and 
there really isn't a reason to do it with D either. D has an 
almost 100% compatibility with C already.


Re: Compile to C?

2017-01-23 Thread Ola Fosheim Grøstad via Digitalmars-d-learn

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.


Re: Compile to C?

2017-01-22 Thread Joakim via Digitalmars-d-learn

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


Re: Compile to C?

2017-01-22 Thread rikki cattermole via Digitalmars-d-learn

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.




Re: Compile to C?

2017-01-22 Thread Nestor via Digitalmars-d-learn

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)





Re: Compile to C?

2017-01-22 Thread Adam D. Ruppe via Digitalmars-d-learn

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.


Re: Compile to C?

2017-01-22 Thread Nestor via Digitalmars-d-learn

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?


Re: Compile to C?

2017-01-21 Thread Adam D. Ruppe via Digitalmars-d-learn

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.


Re: Compile to C?

2017-01-21 Thread Jack Stouffer via Digitalmars-d-learn

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


Re: Compile to C?

2017-01-21 Thread Joakim via Digitalmars-d-learn

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


Compile to C?

2017-01-21 Thread Nestor via Digitalmars-d-learn

Hi friends,

Is there a way to "compile" d code to C, similar to what nim does?

That would be cool for greater portability.


Re: Transform/Compile to C/CPP as a target

2016-07-28 Thread Seb via Digitalmars-d-learn

On Saturday, 23 July 2016 at 12:27:24 UTC, ParticlePeter wrote:
Is there any kind of project or workflow that converts D 
(subset) to C/CPP ?


Just FYI there is a project that does the reverse.

Calypso creates a bridge between DMD/LDC and Clang, both at the 
AST level (DMD <=> Clang's AST, Sema, ...) and at the code 
generation level (LDC <=> Clang's Codegen) to make D interface 
directly with the almost full set of C++ features, and no 
binding is needed.


https://github.com/Syniurge/Calypso


Re: Transform/Compile to C/CPP as a target

2016-07-28 Thread Sebastien Alaiwan via Digitalmars-d-learn

On Monday, 25 July 2016 at 07:53:17 UTC, Stefan Koch wrote:

On Saturday, 23 July 2016 at 12:27:24 UTC, ParticlePeter wrote:
Is there any kind of project or workflow that converts D 
(subset) to C/CPP ?


The short answer is no, not for any recent version of D.


The long answer is it's kind of possible, but the resulting C 
code is not human-readable.
I just managed today to achieve some transformation to C with the 
below script:


# compile the D modules to llvm bitcode
$ ldc2 hello.d -c -output-ll -ofhello.ll
$ ldc2 lib.d -c -output-ll -oflib.ll

# merge them into one LLVM bitcode module
$ llvm-link-3.8 hello.ll lib.ll -o full.bc
$ llvm-dis-3.8 full.bc -o=full.ll

# convert bitcode to C
$ llvm-cbe full.ll

# patch the generated C, so it's compilable
$ sed -i "s/.*APInt.*//" full.cbe.c
$ sed -i "s/^uint32_t main(uint32_t llvm_cbe_argc_arg, 
uint8_t\*\* llvm_cbe_argv_arg)/int main(int llvm_cbe_argc_arg, 
char** llvm_cbe_argv_arg)/" full.cbe.c
$ sed -i "s/^uint32_t main(uint32_t, uint8_t\*\*)/int main(int, 
char**)/" full.cbe.c


# compile the C program and run it.
$ gcc -w full.cbe.c -o full.exe -lphobos2
$ ./full.exe
Hello, world: 46

I only tried this with a very minimalistic subset of D at the 
moment.
Most of the magic occurs in the "llvm-cbe" program, which is a 
"resurrected LLVM C backend" ( 
https://github.com/JuliaComputing/llvm-cbe ).







Re: Transform/Compile to C/CPP as a target

2016-07-25 Thread Stefan Koch via Digitalmars-d-learn

On Saturday, 23 July 2016 at 12:27:24 UTC, ParticlePeter wrote:
Is there any kind of project or workflow that converts D 
(subset) to C/CPP ?


The short answer is no, not for any recent version of D.



Re: Transform/Compile to C/CPP as a target

2016-07-24 Thread ParticlePeter via Digitalmars-d-learn

On Saturday, 23 July 2016 at 19:20:10 UTC, Jacob Carlborg wrote:

On 2016-07-23 14:27, ParticlePeter wrote:
Is there any kind of project or workflow that converts D 
(subset) to

C/CPP ?


No idea about the status but: 
https://github.com/adamdruppe/tools/blob/dtoh/dtoh.d


Thanks, I am looking into this, but I think its still not that 
what I am searching, it seems to create only C/CPP headers for D 
libs. I would like to have the whole source code transformed.


Re: Transform/Compile to C/CPP as a target

2016-07-23 Thread Jacob Carlborg via Digitalmars-d-learn

On 2016-07-23 14:27, ParticlePeter wrote:

Is there any kind of project or workflow that converts D (subset) to
C/CPP ?


No idea about the status but: 
https://github.com/adamdruppe/tools/blob/dtoh/dtoh.d


--
/Jacob Carlborg


Re: Transform/Compile to C/CPP as a target

2016-07-23 Thread ParticlePeter via Digitalmars-d-learn

On Saturday, 23 July 2016 at 12:29:45 UTC, rikki cattermole wrote:

On 24/07/2016 12:27 AM, ParticlePeter wrote:
Is there any kind of project or workflow that converts D 
(subset) to

C/CPP ?


This probably will interest you for ldc: 
http://stackoverflow.com/questions/5180914/llvm-ir-back-to-human-readable-source-language


Cool, I didn't know that one but I also didn't invest time in 
LLVM till now.
However, this converts bitcode to C/CPP, my guess would be that 
the job can be done much better if the original D source would be 
used in tandem.


Re: Transform/Compile to C/CPP as a target

2016-07-23 Thread rikki cattermole via Digitalmars-d-learn

On 24/07/2016 12:27 AM, ParticlePeter wrote:

Is there any kind of project or workflow that converts D (subset) to
C/CPP ?


This probably will interest you for ldc: 
http://stackoverflow.com/questions/5180914/llvm-ir-back-to-human-readable-source-language


Transform/Compile to C/CPP as a target

2016-07-23 Thread ParticlePeter via Digitalmars-d-learn
Is there any kind of project or workflow that converts D (subset) 
to C/CPP ?