The library

How a program runs

Follow your source code through every stage to the instructions that run, well enough to read a compiler error as a stage report, to explain an optimisation that changed your program's behaviour, and to know what the compiler is and is not allowed to do

Turning Text Into Instructions

A compiler is not a black box, it is six stages with a clear job each. This course builds the path from text to instructions: parsing, meaning, the intermediate form, the optimisations, and what the hardware does afterwards anyway.

8 lessons, written and corrected before you arrived. Reading them here needs no account. The first reads the whole way through; the others open and then stop, because a page nobody owns cannot tell who is reading it. Starting the course gives you your own copy, where every idea has problems standing under it and you can ask about any sentence.

Start reading

  1. 01Before It Can Read Your Program It Has to Decide Where the Words EndSource code is one long run of characters. Something has to cut it into pieces, and the cutting rules decide what your program means before anything has parsed it.
  2. 02Precedence Is Not a Table You Memorise, It Is the Shape of the Rulesopening onlyA parser turns a flat list into a tree. The order of operations you learned as a table is actually a consequence of how the grammar was layered, and nothing else.
  3. 03The Stage That Finds Out Whether Your Names Refer to Anythingopening onlyA correct shape is not a correct program. This stage works out what every name refers to and what type every node has, and it is the last one that can refuse.
  4. 04One Neutral Form in the Middle Turns a Multiplication Into an Additionopening onlyThe tree gets flattened into a plain list of tiny operations. That form is deliberately neutral, and the reason is an arithmetic argument about how much work a compiler family costs.
  5. 05Every Transformation Obeys One Rule, and the Rule Is Narrower Than You Thinkopening onlyThe standard optimisations are each simple enough to do by hand. What matters is the single property all of them preserve, and how little that property actually promises.
  6. 06The Compiler Deleted Your Safety Check Because You Had Already Broken the Ruleopening onlyA language rule you did not know you made is a fact the optimiser is entitled to assume. Here is one real case followed from the source to the surprising output.
  7. 07Thousands of Values and Sixteen Places to Keep Themopening onlyThe middle form invented names without limit. The machine has a few dozen fast slots. Deciding which values get one, and which get pushed to memory, decides the speed of the output.
  8. 08Your Instructions Arrive in Order and Are Executed in Whatever Order Suitsopening onlyThe compiler rearranged your program and then handed it to a processor that rearranges it again at run time. The second reordering is invisible until a second thread is watching.