digitalmars.D.learn - Why can't we transpile C++ to D?
- Tejas (6/6) Jun 10 2021 Sorry, I'm rather ignorant when it comes to this, but why can't
- Imperatorn (2/9) Jun 10 2021 I'm guessing it's hard because of the grammar
- evilrat (28/38) Jun 10 2021 Well, still a grammar, though it was my little WTF moment.
- Dukc (4/11) Jun 10 2021 This is article is about transpiling old C++ to newer C++, but
- Tejas (2/14) Jun 10 2021 Damn that preprocessor! :@
- evilrat (3/10) Jun 10 2021 I leave this here, it does converts C++ to D to some extent
- Tejas (9/20) Jun 10 2021 Yes I saw the announcement earlier.
- evilrat (14/16) Jun 10 2021 It says bindings generator, but it has to convert the code
- sighoya (10/18) Jun 10 2021 See
Sorry, I'm rather ignorant when it comes to this, but why can't we use [pegged](https://github.com/PhilippeSigaud/Pegged) to transpile C++ code to D? Then we won't need a nogc compatible std library and so many other things could get easier, like getting legacy code to use Dlang. It might not be worth it for C+17 and beyond, but older codebases could benefit significantly, right?
Jun 10 2021
On Thursday, 10 June 2021 at 15:09:02 UTC, Tejas wrote:Sorry, I'm rather ignorant when it comes to this, but why can't we use [pegged](https://github.com/PhilippeSigaud/Pegged) to transpile C++ code to D? Then we won't need a nogc compatible std library and so many other things could get easier, like getting legacy code to use Dlang. It might not be worth it for C+17 and beyond, but older codebases could benefit significantly, right?I'm guessing it's hard because of the grammar
Jun 10 2021
On Thursday, 10 June 2021 at 15:57:44 UTC, Imperatorn wrote:On Thursday, 10 June 2021 at 15:09:02 UTC, Tejas wrote:Well, still a grammar, though it was my little WTF moment. for example this C++ grammar(often used in STL) where min is simple minimum function ```cpp float min(float l, float r) { return (l < r) ? l : r; } ``` ```cpp float foo(float a, float b) { return (min)(a,b); } ``` and this direct translation to D doesn't works ```d float foo(float a, float b) { return (min)(a,b); // Error: C style cast illegal, use `cast(min)(a , b)` } ``` but this does ```d float foo(float a, float b) { return (&min)(a,b); // ok } ```Sorry, I'm rather ignorant when it comes to this, but why can't we use [pegged](https://github.com/PhilippeSigaud/Pegged) to transpile C++ code to D? Then we won't need a nogc compatible std library and so many other things could get easier, like getting legacy code to use Dlang. It might not be worth it for C+17 and beyond, but older codebases could benefit significantly, right?I'm guessing it's hard because of the grammar
Jun 10 2021
On Thursday, 10 June 2021 at 15:09:02 UTC, Tejas wrote:Sorry, I'm rather ignorant when it comes to this, but why can't we use [pegged](https://github.com/PhilippeSigaud/Pegged) to transpile C++ code to D? Then we won't need a nogc compatible std library and so many other things could get easier, like getting legacy code to use Dlang. It might not be worth it for C+17 and beyond, but older codebases could benefit significantly, right?This is article is about transpiling old C++ to newer C++, but the same problem applies with translating C++ to D: https://scottmeyers.blogspot.com/2015/11/the-brick-wall-of-c-source-code.html
Jun 10 2021
On Thursday, 10 June 2021 at 16:49:59 UTC, Dukc wrote:On Thursday, 10 June 2021 at 15:09:02 UTC, Tejas wrote:Damn that preprocessor! :Sorry, I'm rather ignorant when it comes to this, but why can't we use [pegged](https://github.com/PhilippeSigaud/Pegged) to transpile C++ code to D? Then we won't need a nogc compatible std library and so many other things could get easier, like getting legacy code to use Dlang. It might not be worth it for C+17 and beyond, but older codebases could benefit significantly, right?This is article is about transpiling old C++ to newer C++, but the same problem applies with translating C++ to D: https://scottmeyers.blogspot.com/2015/11/the-brick-wall-of-c-source-code.html
Jun 10 2021
On Thursday, 10 June 2021 at 15:09:02 UTC, Tejas wrote:Sorry, I'm rather ignorant when it comes to this, but why can't we use [pegged](https://github.com/PhilippeSigaud/Pegged) to transpile C++ code to D? Then we won't need a nogc compatible std library and so many other things could get easier, like getting legacy code to use Dlang. It might not be worth it for C+17 and beyond, but older codebases could benefit significantly, right?I leave this here, it does converts C++ to D to some extent https://github.com/Superbelko/ohmygentool
Jun 10 2021
On Thursday, 10 June 2021 at 16:50:41 UTC, evilrat wrote:On Thursday, 10 June 2021 at 15:09:02 UTC, Tejas wrote:Yes I saw the announcement earlier. I was hoping for something native, rather than bindings. As you said youself, it's not exactly stable. Plus I don't want a hamster's death on my conscience. :( Please don't take this as me belittling your work, it is better than having nothing. But how scalable will this be? We have to get real D code to enrich our ambiguously-defined-small ecosystem.Sorry, I'm rather ignorant when it comes to this, but why can't we use [pegged](https://github.com/PhilippeSigaud/Pegged) to transpile C++ code to D? Then we won't need a nogc compatible std library and so many other things could get easier, like getting legacy code to use Dlang. It might not be worth it for C+17 and beyond, but older codebases could benefit significantly, right?I leave this here, it does converts C++ to D to some extent https://github.com/Superbelko/ohmygento
Jun 10 2021
On Thursday, 10 June 2021 at 19:06:42 UTC, Tejas wrote:But how scalable will this be? We have to get real D code to enrich our ambiguously-defined-small ecosystem.It says bindings generator, but it has to convert the code keeping the semantic as close as possible. It does direct translation on AST level (AST-to-source currently), there is quirks here and there, semantic discrepancies(for example sizeof/alignof differs in D vs C++), lack of struct inheritance and multiple inheritance, and other annoying stuff like implicit casts or implicit constructors, but overall this should work. Definitely better than doing it all by hand. I tried to run it on clang, phew, got 241k lines, and that's without .cpp files. Haven't even bothered with fixing it to compilable state (even then it will definitely have linking issues).
Jun 10 2021
On Thursday, 10 June 2021 at 15:09:02 UTC, Tejas wrote:Sorry, I'm rather ignorant when it comes to this, but why can't we use [pegged](https://github.com/PhilippeSigaud/Pegged) to transpile C++ code to D?See https://stackoverflow.com/questions/14589346/is-c-context-free-or-context-sensitive#answer-14589567 Mixing semantic with parsing isn't necessarily a good idea.Then we won't need a nogc compatible std library and so many other things could get easier, like getting legacy code to use Dlang.That doesn't solve the ABI compatibility to C++, only if source is available, but they may be compiled with compilers which can't build anymore with the current tool chain at least without to rebuild the tool chain.It might not be worth it for C+17 and beyond, but older codebases could benefit significantly, right?The problem is that old looking code doesn't become modern when it is transpired to D as the concepts to do things have changed.
Jun 10 2021