3 ms·
Tiny does not mean "simple", and this is very true in compilers. There are ways of making a compiler trivial and extremely comprehensible, but it involves some
by sklogic 11y ago
Tiny does not mean "simple", and this is very true in compilers. There are ways of making a compiler trivial and extremely comprehensible, but it involves somewhat lengthy code. A tiny compiler which fuses multiple transforms into one may be much harder to comprehend than a larger compiler made of a long sequence of much simpler passes.
So your suggestion may be quite intimidating to the beginners. I'd rather recommend to start with the Racket-style language extensions and DSLs first.
- nils-m-holm 11y agohttp://t3x.org/subc/ http://t3x.org/subc/ is tiny and simple. But I'm supposed to say that!
- sitkack 11y agoIf you ported one of your excellent compiler books to Rust, I would buy it again, twice. Nils Holm, master compiler educator http://www.lulu.com/shop/search.ep?contributorId=740596 http://www.lulu.com/shop/search.ep?contributorId=740596
- sklogic 11y agoIt is nice and simple indeed but does not really show anything instructive in terms of backend, which is the focus of this thread. And once you go into SSA and proper isel, there is no way to do it both easily and compactly at the same time, passes must be split for simplicity or fused into a mess for a compactness. Of course, I am only talking about a number of lines of code, besides this you can keep your compiler totally trivial for any degree of optimisations complexity.
- nils-m-holm 11y agoIt does show you how to approach building a back-end in the first place, which I would consider to be quite instructive for someone who has never done it before. And it does separate the phases and still remains compact. Of course, once you have progressed to things like SSA, you might want to study something more complex. BTW, the current version of SubC has a much more interesting back-end and even uses AST-level optimization.