On Five compilation models for C++
Jeff Messner sent me a link to a paper titled Five compilation models for C++. It describes transforming C++ into an intermediate dynamically-typed language (types are checked at run-time), then possibly using a “partial evaluator” to finish the transformation to a statically-checked language. This C++ compiler is called Lunar.
A few interesting points in “the quest for Meta”:
Type-Passing Style
The intermediate code Lunar generates is in type-passing style; new parameters are introduced to functions to carry types. Assertions are performed on types in non-template code, and other type computations are emitted for template code. The partial evaluator “evaluates away” the type parameters, then should be able to remove them from the final code since they are no longer used.
It’s interesting that the term “type-passing style” has already been coined. One aspect of the unification of generic programming (which takes types as parameters and returns a function or type) and functional programming (which takes values as parameters and returns a value) which I’ve been thinking about is unifying the calling syntax. This would mean that some function could take both value and type arguments, as well as the function could be specialized on the type of value parameters.
It seems, though, that the authors haven’t hit the “grand unified theory” that I’m trying for, as evidenced by the fact they have chosen to omit the features which are hard. Take parameter overloading as an example: if types are passed as parameters, then two functions statically dispatched on type have the same ’signature’. In C++, you could implement these in different compilation modules, but you can’t do this in an intermediate language because the compiler would need to implement a centralized dispatch on type with knowledge of all the different implementations – even if this is later resolved at compile time.
I’m also thinking about saying, “Screw it, let’s throw out the ’sacred cow’ of being able to compile separate ‘compilation units’ individually. Computers have gotten fast, memory is cheap, we can make a compiler which reads all the source, thinks for a while, then spits out the answer.”
Quadruple Form
I’m always curious about new forms for intermediate languages. This is an area that I haven’t decided on for Meta just yet, since I need to get a better idea of how the type system will work. In any case, the intermediate language has a general form called “quadruple form”, which is a form where, as the article states:
In quadruple form, most instructions are of the form: r <- x1 * x2, where r is a name for the result, x1 and x2 are names or literals, and * is an operator.
Interesting, but it doesn’t appear as powerful as lambda calculus and seems geared for imperative languages.
