www.digitalmars.com         C & C++   DMDScript  

D.gnu - hello world compiled

reply "Ben Hinkle" <bhinkle4 juno.com> writes:
Since it's the new year and we all have a few days off I figure'd I'd try to
see just how bad it would be to modify the C++ front end to compile D.

After one day of search/replace cxx (and cp and tons of other stuff) with
dmd and one parser change to recognize "extern (C)" (in parse.y and the
wonderfully named file "spew.c") I got hello world to compile and run
(linked with libstc++):

extern (C) void printf(char*, ...);
extern (C) int main(int argc, char**argv)
{
    printf("hello world.\n");
    return 0;
}

[/home/bhinkle/d/gcc/build]845 %
../gcc-3.3.2/configure --enable-languages=c,dmd
[snip]
[/home/bhinkle/d/gcc/build]846 % make bootstrap
[snip]
[/home/bhinkle/d/gcc/build]847 % cd gcc
[/home/bhinkle/d/gcc/build/gcc]848 % gdmd
/home/bhinkle/hello.d -L. -L/home/bhinkle
[/home/bhinkle/d/gcc/build/gcc]849 % a.out
hello world.

Now my goal (something that would actually require work) is to get phobos
compiled. It doesn't look like there are any templates in there so templates
will wait. I figure I'll run into a brick wall at some point but what the
heck.

Anyway, I'm not sure how far I'll get but happy new year.

-Ben
Jan 02 2004
next sibling parent Ilya Minkov <minkov cs.tum.edu> writes:
Ben Hinkle wrote:
 Since it's the new year and we all have a few days off I figure'd I'd try to
 see just how bad it would be to modify the C++ front end to compile D.
 
 After one day of search/replace cxx (and cp and tons of other stuff) with
 dmd and one parser change to recognize "extern (C)" (in parse.y and the
 wonderfully named file "spew.c") I got hello world to compile and run
 (linked with libstc++):
Woohoo! So you're giving it a try another way around! You shall need a lot of good luck in rewriting the C++ front-end, if this really is what you intend to do... I was not going to dig within G++ until i understand and can dump DMD... But i had realized a while ago that i shall for a long while have time for neither. I'm sorry. Good luck and happy new year. -eye
Jan 02 2004
prev sibling next sibling parent reply Stephan Wienczny <wienczny web.de> writes:
Ben Hinkle wrote:
 Since it's the new year and we all have a few days off I figure'd I'd try to
 see just how bad it would be to modify the C++ front end to compile D.
 
 After one day of search/replace cxx (and cp and tons of other stuff) with
 dmd and one parser change to recognize "extern (C)" (in parse.y and the
 wonderfully named file "spew.c") I got hello world to compile and run
 (linked with libstc++):
 
 extern (C) void printf(char*, ...);
 extern (C) int main(int argc, char**argv)
 {
     printf("hello world.\n");
     return 0;
 }
 
 [/home/bhinkle/d/gcc/build]845 %
 ../gcc-3.3.2/configure --enable-languages=c,dmd
 [snip]
 [/home/bhinkle/d/gcc/build]846 % make bootstrap
 [snip]
 [/home/bhinkle/d/gcc/build]847 % cd gcc
 [/home/bhinkle/d/gcc/build/gcc]848 % gdmd
 /home/bhinkle/hello.d -L. -L/home/bhinkle
 [/home/bhinkle/d/gcc/build/gcc]849 % a.out
 hello world.
 
 Now my goal (something that would actually require work) is to get phobos
 compiled. It doesn't look like there are any templates in there so templates
 will wait. I figure I'll run into a brick wall at some point but what the
 heck.
 
 Anyway, I'm not sure how far I'll get but happy new year.
 
 -Ben
 
 
 
You did not use the 3.4 branch?!? Do you have a website? Sourceforge project etc? Stephan
Jan 03 2004
parent "Ben Hinkle" <bhinkle4 juno.com> writes:
 You did not use the 3.4 branch?!?
umm. whoops. I just got the latest release a few weeks ago or so. I'll check it out.
 Do you have a website?
 Sourceforge project etc?
if I actually get anywhere with it
 Stephan
Jan 03 2004
prev sibling parent reply "Walter" <walter digitalmars.com> writes:
"Ben Hinkle" <bhinkle4 juno.com> wrote in message
news:bt3thn$2i0a$1 digitaldaemon.com...
 Since it's the new year and we all have a few days off I figure'd I'd try
to
 see just how bad it would be to modify the C++ front end to compile D.
That is an interesting approach. It just might work!
 Now my goal (something that would actually require work) is to get phobos
 compiled. It doesn't look like there are any templates in there so
templates
 will wait. I figure I'll run into a brick wall at some point but what the
 heck.
D templates are easy - it's entirely handled within the front-end.
Jan 03 2004
parent reply "Ben Hinkle" <bhinkle4 juno.com> writes:
"Walter" <walter digitalmars.com> wrote in message
news:bt7qeh$294u$2 digitaldaemon.com...
 "Ben Hinkle" <bhinkle4 juno.com> wrote in message
 news:bt3thn$2i0a$1 digitaldaemon.com...
 Since it's the new year and we all have a few days off I figure'd I'd
try
 to
 see just how bad it would be to modify the C++ front end to compile D.
That is an interesting approach. It just might work!
I added alias and uchar, ushort and friends with no problem but my next goal was dynamic arrays and that has been harder. I haven't figured out enough about the G++ front end to make any real progress on that. It turns out the C notion of arrays is pretty hard-wired into gcc. Also I started ripping out the preprocessor but that caused havoc in the parse and lex code (and that lovely spew.c). Right now I'm looking at plugging in your lexer since it has the least dependencies on anything else and is *much* simpler than the G++ cpp-based lexer. I'm starting to think my approach will end up as a rather extensive transplant of certain G++ chunks with the DMD equivalents.
 Now my goal (something that would actually require work) is to get
phobos
 compiled. It doesn't look like there are any templates in there so
templates
 will wait. I figure I'll run into a brick wall at some point but what
the
 heck.
D templates are easy - it's entirely handled within the front-end.
easy, eh? Don't get my hopes up ;-)
Jan 03 2004
parent "Walter" <walter digitalmars.com> writes:
"Ben Hinkle" <bhinkle4 juno.com> wrote in message
news:bt84h2$2n84$1 digitaldaemon.com...
 Also I started ripping out
 the preprocessor but that caused havoc in the parse and lex code (and that
 lovely spew.c).
spew, gotta love it!
 Right now I'm looking at plugging in your lexer since it has
 the least dependencies on anything else and is *much* simpler than the G++
 cpp-based lexer.
I had the advantage here because whenever the D lexer started looking complicated, I simplified the language. Suggest simplifying the C++ language to make scanning easier, and one's compiler cajones get questioned <g>.
 D templates are easy - it's entirely handled within the front-end.
easy, eh? Don't get my hopes up ;-)
Once you get the rest of the DMD front end in, it should be easy!
Jan 03 2004