On Mon, Nov 12, 2012 at 1:51 PM, Jason House <span dir="ltr"><<a href="mailto:jason.james.house@gmail.com" target="_blank">jason.james.house@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Nov 11, 2012, at 8:38 PM, Walter Bright <<a href="mailto:walter@digitalmars.com">walter@digitalmars.com</a>> wrote:<br>
><br>
> Yes, adding const in would probably be an easy and effective change. Too bad C++ has no purity :-(<br>
<br>
<br>
</div>I've always thought an up and coming language should have a tool to automatically convert to C or C++ code. That allows support for all platforms supported by C/C++ and making a self-hosted compiler.<br>
<br>
How hard would a D to C++ converter be? I think ABI compatibility would be impossible, but might not be too big of a limitation. If such a thing existed, is it possible to incrementally convert pieces of the compiler to D?<br>
<div class="HOEnZb"><div class="h5"><br></div></div></blockquote><div><br></div><div>I have in the past explored two other options:</div><div><br></div><div>1 - Automatically convert the compiler to D. I had a go at this a while back with quite impressive results. dmd only uses a small, D-like subset of C++ which makes it possible. I managed to generate d code for the frontend with some minor tweaks, then got stuck on the backend's prolific use of #ifdefs halfway through expressions. This is not insurmountable, you just need to process the #ifdefs before trying to parse the code instead of trying to convert them to static if/version. At that point, I took a break to explore:</div>
<div><br></div><div>2 - Enhance D's ability to link with a subset of C++, then refactor the compiler until parts can be pulled out and ported to D. The ultimate goal would be to have the backend as a C++ static lib that is linked against a frontend written in D. I did a little bit of work on this at the beginning of the year but reached the limit of my backend knowledge, this needs debug info/mangling/codegen support.</div>
<div><br></div><div><span style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">On 11/11/2012 6:51 PM, Jason House wrote:</span><br style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<blockquote class="gmail_quote" style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255);margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
How hard would a D to C++ converter be? I think ABI compatibility would be impossible, but might not be too big of a limitation.</blockquote></div><div><span style="font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br>
</span></div><div><span style="background-color:rgb(255,255,255)"><font face="arial, sans-serif">My experience with the microd experiment shows that creating a D to C++ converter is not actually that difficult, so long as you're not trying to produce idiomatic (or even readable) C++. Most of D's features can be lowered to C++ features (because they are C++ features).</font></span></div>
<div><span style="background-color:rgb(255,255,255)"><font face="arial, sans-serif"><br></font></span></div><div><span style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">On Sunday, November 11, 2012 19:54:30 Walter Bright wrote:</span><br style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<span style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">> On 11/11/2012 6:51 PM, Jason House wrote:</span><br style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<span style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">> > If such a thing existed, is it possible to incrementally convert pieces of</span><br style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<span style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">> > the compiler to D?</span><br style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<span style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">></span><br style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<span style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">> That would leave the specter of having two headers for the data types, one</span><br style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<span style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">> in D and one in C++.</span></div><div><span style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br>
</span></div><div><span style="font-family:arial,sans-serif;background-color:rgb(255,255,255)">Header generation can be automated.</span></div></div>