Slavik Shynkarenko

series2 notebooks · 15 plates · about 46 minutes of reading

How code becomes a program

I’m writing the compiler for Miri, my own programming language, so this is the corner of computing I spend my evenings in. These two notebooks are for anyone who has used a language for years and never looked inside one.

The first follows a program from source text to machine code. One stage per plate. The second asks what happens to all the memory that program allocates, and compares the very different answers languages have settled on.

start with № 05: The architecture of an ahead-of-time compiler →

Questions people ask

What does a compiler do?

It translates source code into machine code before the program runs: lexing, parsing, building an intermediate representation, optimising it, then generating instructions for the target processor. The compiler notebook runs each stage in the page, so you can watch one line of code change shape.

What is the difference between garbage collection and reference counting?

A tracing garbage collector periodically finds everything still reachable and frees the rest. Reference counting keeps a count on each object and frees it the moment the count reaches zero. Rust settles most of it at compile time, by checking who owns each value.

Is ahead-of-time compilation faster than an interpreter?

For most programs, yes, because the translation happens once, before the program starts. A just-in-time compiler closes much of the gap by compiling hot code while the program runs, and pays for it in start-up time and memory.