www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Does the D front-end write C code?

reply "Garett Bass" <garettbass studiotekne.com> writes:
Does the D front-end just write C code?  I'm curious because I'm currently 
writing an object-oriented C project for my languages class, and it seems 
possible that D is implemented similarly.

Thanks,
Garett 
Nov 29 2005
next sibling parent "Walter Bright" <newshound digitalmars.com> writes:
"Garett Bass" <garettbass studiotekne.com> wrote in message
news:dmjlkm$17c$1 digitaldaemon.com...
 Does the D front-end just write C code?
No. It's output is an intermediate form represented by a data structure.
Nov 30 2005
prev sibling parent reply Munchgreeble <"a" b.com \"munchgreeble xATx bigfoot xDOTx com\"> writes:
This would be an obvious way to us a "third" compiler. I'm definitely a 
fan of multiple compilers - I can't imagine persuading people to use a 
language for which GNU was the only implementation, even if we ended up 
using the GNU compiler on the project.

With D being similar to C, C may well make a good intermediate language. 
I'm pretty new here mind you so others may be able to point to reasons 
why C would not make a good intermediate language. Assuming it would 
however, we'd then be able to use our favourite C compiler. The Intel C 
compiler for example produces some very efficient object code on the x86 
platform, because it does some very x86 specific optimisations. It may 
just be that being able to bolt on those optimisations would give the 
fastest object code for at least some D programs.

Far more importantly, if you can compile down to ANSI C, then D becomes 
available on virtually any platform/OS you care to think of =)

I suspect this has been discussed before though?

Cheers

Munch

Garett Bass wrote:
 Does the D front-end just write C code?  I'm curious because I'm currently 
 writing an object-oriented C project for my languages class, and it seems 
 possible that D is implemented similarly.
 
 Thanks,
 Garett 
 
 
Nov 30 2005
parent reply JT <JT_member pathlink.com> writes:
In article <dmjpvu$4n5$1 digitaldaemon.com>, Munchgreeble says...
This would be an obvious way to us a "third" compiler. I'm definitely a 
fan of multiple compilers - I can't imagine persuading people to use a 
language for which GNU was the only implementation, even if we ended up 
using the GNU compiler on the project.

With D being similar to C, C may well make a good intermediate language. 
I'm pretty new here mind you so others may be able to point to reasons 
why C would not make a good intermediate language. Assuming it would 
however, we'd then be able to use our favourite C compiler. The Intel C 
compiler for example produces some very efficient object code on the x86 
platform, because it does some very x86 specific optimisations. It may 
just be that being able to bolt on those optimisations would give the 
fastest object code for at least some D programs.

Far more importantly, if you can compile down to ANSI C, then D becomes 
available on virtually any platform/OS you care to think of =)

I suspect this has been discussed before though?

Cheers

Munch

Garett Bass wrote:
 Does the D front-end just write C code?  I'm curious because I'm currently 
 writing an object-oriented C project for my languages class, and it seems 
 possible that D is implemented similarly.
 
 Thanks,
 Garett 
 
 
Ive got a D port of the DMD front end that currenty can reproduce D code from a compiled program - I really want to get it to output C or C++ but thats way down on my list. I think thats a very interesting solution for some cases. But it can be done relatively easy using the front end. In fact walter already has it generating a little bit of C code for symbols or someting Im not quite sure. http://trac.dsource.org/projects/dbug/browser/trunk/src/dparser fyi its got a few places I need to cleanup yet like complex numbers and a small bug in the second semantic pass where a variable isnt getting set, but I believe lexical analysis and semantic 1 should work.
Nov 30 2005
next sibling parent reply Chris <ctlajoie yahoo.com> writes:
On Wed, 30 Nov 2005 10:04:16 +0000 (UTC), JT <JT_member pathlink.com>
wrote:
Ive got a D port of the DMD front end that currenty can reproduce D code from a
compiled program - 
I read this as: "I made D decompiler" that can't be right... can it? I thought the front end is just a parser.
 I really want to get it to output C or C++ but thats way down
on my list. I think thats a very interesting solution for some cases. But it can
be done relatively easy using the front end. In fact walter already has it
generating a little bit of C code for symbols or someting Im not quite sure. 

http://trac.dsource.org/projects/dbug/browser/trunk/src/dparser

fyi its got a few places I need to cleanup yet like complex numbers and a small
bug in the second semantic pass where a variable isnt getting set, but I believe
lexical analysis and semantic 1 should work.
I've been following the progress on dbug for a while.. updating from the repository every few days. TBH I'm not sure exactly what you've been doing with the directory structure lately. But in any case, DBug is full of really neat code. I encourage everyone to check it out. btw, there's an unanswered post on the forums ;) Chris
Nov 30 2005
parent JT <JT_member pathlink.com> writes:
In article <e2kro15jefvv6tfc9em4knf0sph89e1oe1 4ax.com>, Chris says...
On Wed, 30 Nov 2005 10:04:16 +0000 (UTC), JT <JT_member pathlink.com>
wrote:
Ive got a D port of the DMD front end that currenty can reproduce D code from a
compiled program - 
I read this as: "I made D decompiler" that can't be right... can it? I thought the front end is just a parser.
 I really want to get it to output C or C++ but thats way down
on my list. I think thats a very interesting solution for some cases. But it can
be done relatively easy using the front end. In fact walter already has it
generating a little bit of C code for symbols or someting Im not quite sure. 

http://trac.dsource.org/projects/dbug/browser/trunk/src/dparser

fyi its got a few places I need to cleanup yet like complex numbers and a small
bug in the second semantic pass where a variable isnt getting set, but I believe
lexical analysis and semantic 1 should work.
I've been following the progress on dbug for a while.. updating from the repository every few days. TBH I'm not sure exactly what you've been doing with the directory structure lately. But in any case, DBug is full of really neat code. I encourage everyone to check it out. btw, there's an unanswered post on the forums ;) Chris
no no, its not a decompiler. It takes a D program - parses it and produces a symbol tree - this is normally sent to the back end, and right now I have it simply reproducing itself back into D. Mostly for debugging - as what goes in should come back out. Yeah ive been re-organizeing the dir structure a little bit. The focus of the project has shifted a little bit as Im now making a D IDE called Cydonia. Im slowly moving the actual low level debugging library from "dmddebug" to "dbug" and DBug will become the debugging lib. And im moving some of the sub projects like the disassembler into the debugging library etc. Just trying to clean it up a little bit, as it was mostly a bunch of prototype stuff that im slowly trying to work into a release. I hope to have a version .001 or something very soon I just want to tie up a lot of loose ends first.
Nov 30 2005
prev sibling next sibling parent Munchgreeble <"a" b.com \"munchgreeble xATx bigfoot xDOTx com\"> writes:
Great! =)

 Ive got a D port of the DMD front end that currenty can reproduce D code from a
 compiled program - I really want to get it to output C or C++ but thats way
down
 on my list. I think thats a very interesting solution for some cases. But it
can
 be done relatively easy using the front end. In fact walter already has it
 generating a little bit of C code for symbols or someting Im not quite sure. 
 
 http://trac.dsource.org/projects/dbug/browser/trunk/src/dparser
 
 fyi its got a few places I need to cleanup yet like complex numbers and a small
 bug in the second semantic pass where a variable isnt getting set, but I
believe
 lexical analysis and semantic 1 should work.
 
 
 
Dec 01 2005
prev sibling parent reply Oskar Linde <oskar.lindeREM OVEgmail.com> writes:
In article <dmjtf0$9ev$1 digitaldaemon.com>, JT says...
Ive got a D port of the DMD front end that currenty can reproduce D code from a
compiled program - I really want to get it to output C or C++ but thats way down
on my list. I think thats a very interesting solution for some cases. But it can
be done relatively easy using the front end. In fact walter already has it
generating a little bit of C code for symbols or someting Im not quite sure. 

http://trac.dsource.org/projects/dbug/browser/trunk/src/dparser
Very nice! The dmd front end coding style maps very well onto D. I've actually been toying with converting the front end too, but since you have gotten much further, I've just scrapped my code. :)
fyi its got a few places I need to cleanup yet like complex numbers and a small
bug in the second semantic pass where a variable isnt getting set, but I believe
lexical analysis and semantic 1 should work.
Yes, seems to work fairly well. A bug I stumbled upon: aggregate.d:1045 if( (tc.sym.symtab !is null) || (tc.sym.scope is null) ) the conditions are inverted, should be: if( (tc.sym.symtab is null) || (tc.sym.scope !is null) ) Cheers, Oskar
Dec 02 2005
parent JT <JT_member pathlink.com> writes:
In article <dmpmui$1l6l$1 digitaldaemon.com>, Oskar Linde says...
In article <dmjtf0$9ev$1 digitaldaemon.com>, JT says...
Ive got a D port of the DMD front end that currenty can reproduce D code from a
compiled program - I really want to get it to output C or C++ but thats way down
on my list. I think thats a very interesting solution for some cases. But it can
be done relatively easy using the front end. In fact walter already has it
generating a little bit of C code for symbols or someting Im not quite sure. 

http://trac.dsource.org/projects/dbug/browser/trunk/src/dparser
Very nice! The dmd front end coding style maps very well onto D. I've actually been toying with converting the front end too, but since you have gotten much further, I've just scrapped my code. :)
fyi its got a few places I need to cleanup yet like complex numbers and a small
bug in the second semantic pass where a variable isnt getting set, but I believe
lexical analysis and semantic 1 should work.
Yes, seems to work fairly well. A bug I stumbled upon: aggregate.d:1045 if( (tc.sym.symtab !is null) || (tc.sym.scope is null) ) the conditions are inverted, should be: if( (tc.sym.symtab is null) || (tc.sym.scope !is null) ) Cheers, Oskar
THANK YOU! I think you just found one of the bugs Ive been putting off :D Yeah this is one of those late night "from struct ptr to class reference" bugs that crept in. Ive been planning on going over all these type expressions with a fine tooth comb and you just saved some time.
Dec 02 2005