Interpreter to compiler generator?

I'm curious. Has there been any research on techniques to generate a compiler based on an interpreter, or to generate both based on a specification of semantics? It strikes me as an overly ambitious approach that nonetheless seems very similar to a lot of what I've already seen in language design..

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

The third Futamura projection

In theory partial evaluation and the "third futamura projection" in particular can generate a compiler from an interpreter.

Static languages and metaprogramming

Wow. That really makes the idea crystal clear--it's all just partial evaluation in principle. It's a deep principle. Plus a good quote: "More generally, we can think of many, many code optimization problems as moving binding times around, where the same logic applies."

Too bad there's not good language support for this kind of thing in most languages. It's a shame too, since writing one yourself is tantamount to writing an interpreter for the language. That's a lot of duplicated effort.

It seems like so often the newer static languages get this close to letting you do some really neat metaprogramming. Like the language designers either just didn't see the potential, or consciously decided to seal off what would otherwise be a natural part of the language.

Shameless plug

It seems like so often the newer static languages get this close to letting you do some really neat metaprogramming.

You may then be interested in what I did with the Heron design. Heron is a simple object-oriented language, implemented using a two-phase interpreter. There is a meta-phase, where the AST is provided to an entry-point function called "Main" (think of it like a compile-time "Main()"). During this phase any part of the program can be executed, and any transformation can be performed on the AST.

When it comes time to execute "Main", the modified AST is executed.

So in theory compilation can be done by the interpreter from within any program by including a Heron library. (It's only theoretical, because I haven't completed the compiling library yet, I have done pretty printers and various AST manipulations).

Tagless Staged Interpreters

Tagless Staged Interpreters by some of our own LtUers is another good resource, for use in statically typed languages.

Finally tagless

Thanks for the reference. But the longer journal version is probably a better bet than the condensed APLAS version. And you'll probably want to look at the accompanying code to play around with the ideas.