2 ms·
> [A tree interpreter] is really only used for extremely simple languages and small DSLs. I don't agree; maintaining a tree interpreter for the entire language
by kazinator 3y ago
> [A tree interpreter] is really only used for extremely simple languages and small DSLs.
I don't agree; maintaining a tree interpreter for the entire language, in parallel with a compiler, allows you to write the compiler and library in that same language, without having a bootstrapping problem (needing an existing installation of the language to rebuild the language). You can bootstrap from some popular language that is readily available everywhere, like C.
You also have the language features specified in three ways: documentation, compiled semantics, interpreted semantics. If two out of three agree, the third is probably wrong.
I find it a great boon in the TXR project that if I'm chasing some problem where something in the library is miscompiled, all I have to do is delete that module's compiled file to have that module be tree-interpreted.
There is also this trick. If in a file that is being compiled we suspect that we have some top-level (expr ...) that is being mishandled by the compiler, we can change it like this:
(eval '(expr ..))
Now when the compiler sees this, it will compile it to a single function call to eval, which passes the literal code to it. When the compiled file is loaded, then (expr ...) is tree-interpreted, while everything else is compiled.
The tree interpreter can be your boostrapper and life jacket; don't throw it away too casually.
- PartiallyTyped 3y agoI agree with this, plus doing property based testing where parity between interp and compiler is checked with arbitrarily complex trees seems like a great idea to be honest.