How to Write Your Own Compiler (2009)
staff.polito.it
staff.polito.it
I'm somewhat familiar witih SSA, but I don't know anything about polyhedral compilation. What does it buy you? Is there a concise intro you could point to?
(I thought I had heard someone say it makes your compiler slower for marginal benefit, but they/I could be wrong about that.)
FWIW I found this introduction to the new Go SSA back end pretty useful as an overview:
https://www.youtube.com/watch?v=uTMvKVma5ms
One thing that was interesting is that they seemed to have an LLVM TableGen-like "rules" DSL for both architecture-independent and -dependent optimizations / code gen.
I don't think polyhedral compilation was mentioned and I don't think they use it.
Yep, tableGen is nice but would be overkill for this tutorial project.
https://www.amazon.com/Brinch-Hansen-Pascal-Compilers/dp/013...
Uau! I should take care of my old books.
https://en.wikipedia.org/wiki/Compilers:_Principles,_Techniq...
In any case you're probably right, given that I like math and (so far) prefer algebra to analysis or applied mathematics.
I would primarily trust the dragon book for its theoretical content, although even that likely no longer represents the state of the art. I'm not all that knowledgeable about the state of the art in parsers, but I know that compiler optimisations have certainly moved beyond what is in the dragon book.
In short, while the dragon book still contains useful information, I don't think its notion of how a compiler is constructed is close to how compilers are actually constructed today.
https://compilers.iecc.com/crenshaw/
This page links to that and another, "A Nanopass Framework for Compiler Education" by Sarkar, Waddell, and Dybvig:
I've had a lot of fun hacking Forths, writing my own languages didn't really click until I finally had a serious look. Forth skips on most of the complexity of getting from bytes to semantics; even Lisp is complex in comparison; but is still powerful enough to do interesting things; and the best foundation for DSL's I've come across.
My latest rabbit hole is called Snabel: https://github.com/andreas-gone-wild/snackis/blob/master/sna...
Snabel looks like an interesting experiment in that regard..
I'm not very much into dogmatics and orthodoxy, Forth wasn't the final answer to anything. Nothing ever is. Implementing the same thing over and over again doesn't make sense to me; I have plenty of experience of my own that thinks differently, things I always wanted to work differently. So that's what I'm doing, my best to improve the status quo.
I'm not sure the ease of macro implementation is worth it. I'd love to see more efforts like Dylan. Or different kind of simplicity, like Smalltalk.
But the more code I write, the more I appreciate languages that stay out of my way until I ask for help; besides Lisp & Forth that basically means C/C++. Elaborate syntax, no matter how convenient; will always become an obstacle at some point. You might think it's funny to see C++ in that list, but these days its possible to use it as a static Common Lisp with crippled macros; Snabels implementation is a testament to that.
I was deeply in love with the idea of Smalltalk for a long time, but big pieces of code turn spongy on me as soon as I pass a certain level of complexity. I need more types than that, which is why Snabel had parameterized types from day one.
http://wiki.c2.com/?SweetExpressions
The wiki page makes a valid point; seemingly heavy lisp users will argue against non-s-expression syntax, but happily use prefix notation for quote, and infix for pairs...
Most languages look pretty much the same because we do have half a century of experience with what people get comfortable with. There's further centuries of experience with what people find readable in natural language. People seem to infer a lot more information from layout and structure than some seem to think.
But there is a split there between those who are fine with dense syntax and those who are not. Lisp, Forth, and many functional languages fall in a category that tend to be popular with people who also e.g. find mathematical notation straightforward and are happy to decipher symbol after symbol.
But for many of us, being able to instantly get an overview is a visual process that requires more distinct syntax. I can remember pages of code I saw 20-30 years ago by the overall shape of he code, and layout, and even the font, but if I'm asked to recall code by a sequence of tokens I had to read token by token, I'd draw a blank over code I saw days ago.
That's why you see languages like e.g. Ruby, that in themselves bring very little new on the semantics side, but that popularise ideas from other languages (e.g. Smalltalk, Self for Ruby, along with a lot of syntactical baggage from Perl).
In recent years a lot of ideas have been lifted from Lisp, but some of them are linked quite closely to Lisps syntax. We've started seeing languages tackle this, but it's still a tricky balance to get right.
But I think Forth lacks a language that can do this for it. Retaining the ideas of Forth while making it readable to a bigger audience seems like a hard problem, but it's been (reasonably well) tackled for Smalltalk and Lisp. That's what piqued my interested with your experiment.
I think it's more about familiarity rather than any inherent quality of the syntax itself.
> But for many of us, being able to instantly get an overview is a visual process that requires more distinct syntax.
I think colour and shape can go a long way here, too — and that applies to both Forth & Lisp.
An example is Snabels use of "|" for resetting the stack, "_" for dropping the top and "(..)" for grouping modifications; it smells a tiny bit like Perl in that it's not afraid of using what's available to get the wanted experience, but has a dramatic effect on code shape compared to regular mumble-Forth.
I've not done anything original in Forth, only hacking some existing code on FreeBSD, but I found Forth to be remarkable quiet to pick up once I took time to familiarise myself with it's syntax.
Unfortunately that was a while ago now with so little time spent in the language at the time and none spent in it since that I've now forgotten most of what I had learned.
Yes, that's something that every compiler (for languages with scopes that allow hiding) needs. Typically you also never compare variables by name but by pointer to a symbol structure or some numeric ID.
> Does anyone know of code that makes clear what is involved in def-use for a variable without saying "this is an exercise for the reader" ?
It's not code, but chapter 2 of Nielson/Nielson/Hankin's Principles of Program Analysis discusses how to do this. See accompanying slides on the book's website: http://www.imm.dtu.dk/~hrni/PPA/ppasup2004.html
In a sense, this must be an exercise for the reader, since if you are working on your own compiler, nobody's code will be compatible with yours.
A more convenient interface to go program analysis is https://godoc.org/golang.org/x/tools/go/loader. See https://blog.cloudflare.com/building-the-simplest-go-static-... for a basic tutorial on using the module.
> <html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns="http://www.w3.org/TR/REC-html40"><head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">