<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 11 March 2013 16:01, Daniel Murphy <span dir="ltr"><<a href="mailto:yebblies@nospamgmail.com" target="_blank">yebblies@nospamgmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">"dennis luehring" <<a href="mailto:dl.soluz@gmx.net">dl.soluz@gmx.net</a>> wrote in message<br>

</div>news:khku3t$15ja$1@digitalmars.com...<br>
<div><div class="h5">> Am 11.03.2013 16:23, schrieb Daniel Murphy:<br>
>> "dennis luehring" <<a href="mailto:dl.soluz@gmx.net">dl.soluz@gmx.net</a>> wrote in message<br>
>> news:khkqug$v57$1@digitalmars.com...<br>
>>> Am 11.03.2013 15:20, schrieb Daniel Murphy:<br>
>>>> "Daniel Murphy" <<a href="mailto:yebblies@nospamgmail.com">yebblies@nospamgmail.com</a>> wrote in message<br>
>>>> news:khfoa6$fm7$1@digitalmars.com...<br>
>>>>> "Daniel Murphy" <<a href="mailto:yebblies@nospamgmail.com">yebblies@nospamgmail.com</a>> wrote in message<br>
>>>>> news:kgumek$2tp4$1@digitalmars.com...<br>
>>>>>> "Zach the Mystic" <reachBUTMINUSTHISzach@gOOGLYmail.com> wrote in<br>
>>>>>> message<br>
>>>>>> news:pabfuaorrjbljxzrglbv@forum.dlang.org...<br>
>>>>>>>><br>
>>>>>>>> Something like this <a href="https://github.com/yebblies/magicport2" target="_blank">https://github.com/yebblies/magicport2</a> ?<br>
>>>>>>><br>
>>>>>>> Yes! I need to look it over more thoroughly, but I couldn't ask for<br>
>>>>>>> a<br>
>>>>>>> better beginning. Can I trust that you'll be a willing part of<br>
>>>>>>> future<br>
>>>>>>> discussions on this matter, even if only to play Devil's Advocate?<br>
>>>>>><br>
>>>>>> More like a full-blown attempt than a beginning.  I started this a<br>
>>>>>> long<br>
>>>>>> time ago.<br>
>>>>>><br>
>>>>>> There are three parts to it:<br>
>>>>>> - c++ parser/d printer, with lots of cheating and special cases<br>
>>>>>> - patches to the c++ source<br>
>>>>>> - patched version of dmd to build the result (no error on variable<br>
>>>>>> shadowing etc)<br>
>>>>>><br>
>>>>>> It produces a 70000 line d file which appears to get through 3/7ths<br>
>>>>>> of<br>
>>>>>> semantic1.  Root needs to be ported, and a cleaner interface to the<br>
>>>>>> backend is needed to compile the glue layer.<br>
>>>>>><br>
>>>>><br>
>>>>> Update: With the bulk of root converting or ported, and the glue layer<br>
>>>>> stubbed out, I can build dmd from the converted source then lex and<br>
>>>>> parse<br>
>>>>> the source (+druntime headers) again.<br>
>>>>><br>
>>>>> The highlight was the dynamically resized struct in root/stringtable.<br>
>>>>> Something went horribly wrong there.<br>
>>>><br>
>>>> Update: I can now generate the source, then build a frontend from that,<br>
>>>> then<br>
>>>> process the frontend's source again with the built compiler.  It also<br>
>>>> works<br>
>>>> on the conversion tool, and pulls in a sizeable chunk of druntime and<br>
>>>> phobos.<br>
>>><br>
>>> do i get it right - you've converted the dmd C++ code with it?<br>
>>><br>
>><br>
>> Umm...<br>
>><br>
>> C++ compiler source -> my tool -> D source<br>
>> D source -> normal dmd -> self-host dmd<br>
>> D source -> self-host dmd -> no problems, but only the frontend so no<br>
>> code<br>
>> generation<br>
>> tool source -> self-host dmd -> same thing<br>
><br>
> but interesting enough to get its own root newsgroup post i think - or<br>
> it the "quality"(converted source etc. whatever) too bad<br>
><br>
><br>
<br>
</div></div>I'm planning to when it can do the entire test suite, and all of phobos and<br>
druntime.<br>
<br>
The code generated is very close to what you would get running it though a<br>
(bad) formatter, with comments removed.  I will eventually preserve the<br>
comments and improve the formatting.<br>
<br>
Performance wise the code is pretty nasty because I'm allocating all<br>
OutBuffers on the heap and inserting tracing code.  This will need to be<br>
fixed eventually but is fine for checking correctness.<br>
<br>
Here's an example conversion: (from PrettyFuncInitExp)<br>
<br>
Almost all of the differences are from the primitive pretty-printer.<br>
<br>
--------------------------------------------------------<br>
C++ version<br>
--------------------------------------------------------<br>
<br>
Expression *PrettyFuncInitExp::resolveLoc(Loc loc, Scope *sc)<br>
{<br>
    FuncDeclaration *fd;<br>
    if (sc->callsc && sc->callsc->func)<br>
        fd = sc->callsc->func;<br>
    else<br>
        fd = sc->func;<br>
<br>
    const char *s;<br>
    if (fd)<br>
    {<br>
        const char *funcStr = fd->Dsymbol::toPrettyChars();<br>
        HdrGenState hgs;<br>
        OutBuffer buf;<br>
        functionToCBuffer2((TypeFunction *)fd->type, &buf, &hgs, 0,<br>
funcStr);<br>
        buf.writebyte(0);<br>
        s = (const char *)buf.extractData();<br>
    }<br>
    else<br>
    {<br>
        s = "";<br>
    }<br>
<br>
    Expression *e = new StringExp(loc, (char *)s);<br>
    e = e->semantic(sc);<br>
    e = e->castTo(sc, type);<br>
    return e;<br>
}<br>
<br>
<br>
--------------------------------------------------------<br>
D version<br>
--------------------------------------------------------<br>
<br>
    Expression resolveLoc(Loc loc, Scope sc)<br>
    {<br>
    tracein("resolveLoc");<br>
    scope(success) traceout("resolveLoc");<br>
    scope(failure) traceerr("resolveLoc");<br>
    {<br>
        FuncDeclaration fd;<br>
        if ((sc.callsc && sc.callsc.func))<br>
        (fd = sc.callsc.func);<br>
         else (fd = sc.func);<br>
        const(char)* s;<br>
        if (fd)<br>
        {<br>
            const(char)* funcStr = fd.Dsymbol.toPrettyChars();<br>
            HdrGenState hgs;<br>
            OutBuffer buf = new OutBuffer();<br>
            functionToCBuffer2((cast(TypeFunction)fd.type), buf, (&hgs), 0,<br>
funcStr);<br>
            buf.writebyte(0);<br>
            (s = (cast(const(char)*)buf.extractData()));<br>
        }<br>
         else {<br>
            (s = "");<br>
        }<br>
        Expression e = (new StringExp(loc, (cast(char*)s)));<br>
        (e = e.semantic(sc));<br>
        (e = e.castTo(sc, type));<br>
        return e;<br>
    }<br>
    }<br>
<br>
<br>
</blockquote></div><br></div><div class="gmail_extra">(The D conversion seems to think it's lisp).<br clear="all"></div><div class="gmail_extra"><br>-- <br>Iain Buclaw<br><br>*(p < e ? p++ : p) = (c & 0x0f) + '0';
</div></div>