Skip to content

masak/compiler-book

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 

Repository files navigation

So, I'm writing a compiler book. Inspiration comes from this HN comment. Kudos also to Matthew Walton for thinking it'd be a good idea. ☺

These plans will most likely converge with bootstrapping 007 Alma, and successively building out the language and the compiler can be interwoven with explaining and building optimizations. The different compiler steps can even be used as realistic benchmarking targets.

The plan that falls out of that idea is something like this:

  • Variables and assignments
    • Constant folding
    • Constant propagation
    • Common subexpression elimination
    • Dead code elimination
  • Integers and strings
  • Control flow: if, while, and for
    • Basic blocks
    • SSA
    • Live variables analysis
    • Define-use chain analysis
    • Strength reduction
  • Subroutines
    • Inlining
    • Closures
    • Escape analysis
    • Lowering to local variables
    • Built-in functions
  • Register allocation
    • A naive allocator
    • Graph coloring
    • A linear allocator
  • Modules
  • Operators
    • Precedence and associativity
    • Built-in operators
    • Parsing user-defined operators
  • Classes and objects
    • Dynamic dispatch
    • Lowering to primitives
    • Scalar replacement
    • First-class subroutines
    • Garbage collection
    • Built-in classes
  • Meta-object protocol
    • Object and Type
    • Bootstrapping everything
  • Type declarations
    • Typed variables and parameters
    • Type inference
    • Interfaces
    • Generic types
  • Macros
  • JIT
  • ...
  • IDE errors and warnings (using the IntelliJ stack)

Material

I expect to delve deeply into the Dragon book, SICP, and Modern Compiler Design in order to learn more of the theory and practice of writing compilers. It'll be both a learning experience and a teaching experience. ☺

vendethiel suggested I have a look at this set of AST-based compiler optimizations. Looks very cool. Apparently there's a tool to see exactly what an optimization did.

This post about compiling a small example language to C is just incredibly clear and inspiring.

Here's a nice collection of links.

I found T3X, a nice small self-hosting language/compiler.

This book looks worth pursuing. So does this one.

About

A book about writing compilers. In very early stages of writing.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published