Related articles |
---|
How far will C/C++ get me as an intermediate form for my language? tony@my.net (Tony) (2008-10-31) |
Re: How far will C/C++ get me as an intermediate form for my language? tuxisthebirdforme@gmail.com (tuxisthebirdforme@gmail.com) (2008-11-15) |
From: | "Tony" <tony@my.net> |
Newsgroups: | comp.compilers |
Date: | Fri, 31 Oct 2008 21:27:11 -0500 |
Organization: | at&t http://my.att.net/ |
Keywords: | C++ |
Posted-Date: | 01 Nov 2008 08:28:11 EDT |
I'll give you a little bit of background first... I have used C++
extensively and used C before that, and other languages mildly (Pascal
in college, FORTRAN in engineering). While I think C++ is great for
the crowd of programmers that like all the bells and whistles, I could
do with a much more stripped down language. I am mildly pursuing
development of a language that would, for one goal but not necessarily
the main goal, make compilers a commodity (read: an easy to implement
language, but still a powerful language). As it happens though, I
don't have a background in compiler development or assembly (and
everytime I look at that stuff, I can just tell that I'm better suited
doing other types of design and development).
That said, (i.e., that I feel a little "handicapped" as of yet about
_implementing_ my language concepts), I thought I'd ask some questions
in this group. I guess I should ask first how yaz all feel about
someone actually designing a language that could "make compilers,
compiler technology commodities"?
But that's not the question I was thinking of when I opened the "new
post" window. The above is just a teeny bit of background so you know
a teeny bit of where I am coming from and going with this part-time
fixation. Apparently one company has been able to implement the whole
C++ standard by outputting C code to feed into platform compilers to
produce the final program. This is good news to my ears. But I am
perplexed about how that is possible (surely because of my lack of in
depth knowledge of what hidden code gets generated by compilers from
the code a programmer writes). So, finally, my first question:
How is it possible to generate C code that would implement a class
object on the stack, calling its constructor when entering the scope
and calling it's destructor when leaving the scope?
I think the first thing I want to "play around with" in my new
language is classes and objects and object models, (somewhat different
than C++ of course or else I wouldn't be pursuing this), hence the
above question. Again, I don't know how to go about implementing
this. How I imagine it works is something like:
When I code up:
void some_func()
{
MyClass X();
}
The compiler actually spits out:
void some_func()
{
// compiler puts X in a table or list or something
MyClass X(); // ok, this is the easy part cuz the parens look like a
direct constructor call
} // somewhere before the scope exit X's destructor is called buy how? was
it put into a list previously?
Anyway, you can tell I know little about what goes on behind the
scenes but that I am infinitely curious. I'm currently reading "Inside
the C++ Object Model", but just started that. I want to experiment
with language features but I prefer not to become a compiler expert to
do so! For some reason, I think I'd rather preprocess my language code
and generate C or C++ rather than specifying a grammar with lex or
yacc or something like that (?). Is that really where I should be
headed with this though (lex/yacc type stuff?)? It seems to me that
some kind of "language designer's toolkit" is sorely lacking?
I hope I haven't bored y'all.
Tony
[Translating C++ into C isn't much different from going all the way to
assembler or machine language. You have to figure out everything that's
going on in the C++ code, and generate all of the dispatch tables, implicit
constructor and destructor calls and all the other glop that C++ requires.
The resulting C doesn't look much like the original C++. The compiler you're
thinking of that generates C is probably Comeau's, which is a pretty good
deal at only $50. -John]
Return to the
comp.compilers page.
Search the
comp.compilers archives again.