www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Code Mixins for Compiler Bootstrapping

reply Russell Lewis <webmaster villagersonline.com> writes:
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.
Feb 13 2007
parent "Joel C. Salomon" <JoelCSalomon Gmail.com> writes:
Russell Lewis wrote:
 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)

I came aboard here because I’m taking a compiler theory class and had hopes of implementing D on a new platform (Plan 9; just incompatible enough with lunix to make porting GDC well-nigh impossible). I quickly learned that D as defined today is /not/ a “my first compiler” language — more so in that it’s still a moving target. Define this D-- and I’ll have a go at it. --Joel
Feb 14 2007