Comment by DaniFong
18 years ago
Alternatively, you can learn macros, as PG might suggest. Fundamentally, compilers just translate one string of symbols into another. The ones we're familiar with just translate a high level language into assembly. But there are others -- every object relational model system has a defacto compiler.
If you take a look at that nanopass paper, it's very much in the "just use macros" school of thought. It's even in Scheme.
For the tldr crowd, http://www.cs.indiana.edu/~dyb/pubs/nano-jfp.pdf.
That's an excellent paper, thank you.
One of the advantages of realizing that compilers are 'nothing special' is that you can start to use them all the time to simplify your work. It lets you think at a higher level.
This should be a little lesson on the dangers of skimming over dense prose, and the power of recommendations on YC. I completely skipped past the nanopass paper, even though it's an approach I condone, and skimming a behavior I frown upon.
Not a new idea-- Griswold wrote Snobol as a set of 360 macros.
In the world of programming languages, nothing's new; all of the good stuff was thought of by 1970. That's basically the extent of what I learned in college.
6 replies →
With that approach you won't be able to write a compiler for anything other than a (suboptimal) Lisp derivative, which itself is just a small part of computing world. Take a look at the GNU Compiler Collection and see how far it is to write a working optimizing compiler from the Lisp macro paradigm.
I don't claim that this is the only way to learn how to write compilers, it's just one surprisingly effective way.
And I actually think skill in generalised, simple, macro-type compilers is more useful, generally, than knowing the ins and outs of optimizing compilers, but that's just me.
For the sake of discussion, what are some of the important things for optimizing compilers that you can't do with this approach? I'm having trouble finding any -- both in a literal sense of possibility, and from a practical standpoint.
I may be underestimating macros but I can't imagine any optimization technique that can be done with them when generating low-level output, be it native or virtual machine code. Can you demonstrate (just theoretically, of course) copy propagation, removing loop invariants, automatic inlining of functions, to name a few?
7 replies →
And even if writing a more complete compiler wasn't difficult enough, there's more much to it. There are complex details like exception handling (stack unwinding, signals...), graphical debuggers, interface with GUI libraries, threads, etc.
The fact that only commercial (and expensive) Lisp implementations have all these features is a hint that they're not trivial.
I'm not sure that's true. Right now I am working on GNU CLISP with bindings to Oracle and a GUI (via Ltk). Sure it's not trivial, but it's not impossible either.
1 reply →
And in fact what we all need is a good, commercial grade open-source Lisp compiler + tools.
11 replies →