Code Mixins for Compiler Bootstrapping
Russell Lewis
webmaster at villagersonline.com
Tue Feb 13 09:33:47 PST 2007
One of the original goals of D was to make it easy to write compilers
for it. I love the new features, but I am concerned that they are
making the language so feature-rich that it will be very difficult to
write a complete and correct compiler.
This new "code mixin" feature, though, opens up a set of interesting
possibilities: what if we developed a standard library, which would
parse "standard D" (whatever that standard becomes in the future) and
generates "simple D" (which is some simple version of D, which anybody
could trivial write a compiler for).
That is, you could create a complete standards-compliant D compiler
simply by writing a D compiler which implemented:
* Basic D structural features
* Code mixins
* The most basic of template handling (to parse the mixin)
We could, of course, make this easier to accomplish by implementing
various layers. Perhaps the outermost layer implements the more complex
template elements. The next layer of the compiler could then make use
of those elements to implement more compiler features. etc...
I'm not claiming that this would be fast, but it would allow for very
rapid implementation of new compilers, easy experimentation with new
language features, and the ability to drop new features (such as
alternative GCs) into existing compilers.
P.S. GCC does something alanogous to this. There is a version of gcc
which is very trivial and standards-compliant, which should build with
almost any C compiler. This produces a gcc compiler. Then, you use
this "bootstrap" compiler to compile the mainline gcc code, which is
more feature-rich and which doesn't necessarily work with all compilers.
More information about the Digitalmars-d
mailing list