| |
 | Posted by evilrat in reply to Andrey Zherikov | Permalink Reply |
|
evilrat 
Posted in reply to Andrey Zherikov
| On Wednesday, 18 June 2025 at 01:39:00 UTC, Andrey Zherikov wrote:
> On Monday, 16 June 2025 at 16:49:51 UTC, Dejan Lekic wrote:
> On Sunday, 15 June 2025 at 12:46:09 UTC, rempas wrote:
> That seems interesting! In general, it would be nice if we lived in a world where there would be a common IR and backend and languages would just target that, allowing you to use any symbol from any language.
In the case of C, C++ and D (and many others) that is exactly what is happening. They share the same backend.
I'm not an expert in compilers, but why can't languages be "married" on IR level? I mean compiler translates source code D and C++ to IR independently where these representations are "linked" together.
The problem is type-safety, iirc LLVM IR is just about type width, but then C++ and D also have structs, OOP, templates. But you are right, it can do this right now, LDC has options to output IR/bytecode.
However without this rich type information you MUST always write correct code because in that case compiler is unable to tell if you have a wrong types, and your program will end up malformed, doing nonsensical calculations on nonsensical inputs. Ok in reality you still need type information in form of manual declarations to please the type system.
btw check out my gentool, it partially translates C++ to D on AST level and nicely matches linker level interop feature of D, I built it originally to help with my gamedev needs, but since then there is not much interest even in D community so now it is basically in maintenance mode and I switched to godot.
|