Compilers & interpreters
This course follows source code from text to execution. It explains what compilers and interpreters do, the spectrum between them, and the difference between AOT and JIT compilation. You build a small lexer and a recursive descent parser in Ruby, then inspect tokens, ASTs and YARV bytecode with Ripper, Prism and RubyVM tools. Later lessons cover stack-based virtual machines, the JVM, WebAssembly and ruby.wasm, bootsnap caching, and the JIT compilers in CRuby: MJIT, YJIT with basic block versioning, and the experimental ZJIT.
What you'll learn
- ✓The phases of a compilation pipeline, from lexing to code generation
- ✓How to write a simple lexer and a recursive descent parser in Ruby
- ✓How CRuby turns Ruby source into YARV bytecode and runs it
- ✓How to inspect tokens, ASTs and bytecode with Ripper, Prism and RubyVM
- ✓How stack-based virtual machines, the JVM and WebAssembly execute bytecode
- ✓How JIT compilation works in MJIT, YJIT and ZJIT
What is a compiler?
Computers only understand machine code: raw binary instructions specific to a CPU architecture (x86, ARM, etc.). But humans write code in high-level languages like Ruby, C, or Go. Something must bridge this gap.
Read the full lesson free →Curriculum
7 lessonsWhat is a compiler?
Covers what a compiler does, its phases, AOT versus JIT, and cross-compilation for native gems.
What is an interpreter?
Explains tree-walking interpreters, the compiler to interpreter spectrum, REPLs, Ruby's dynamic features and bootsnap caching.
Lexing and tokenization
Shows how a lexer groups characters into tokens, resolves ambiguity with lookahead, and how Ripper exposes it.
Parsing and the AST
Builds an AST with grammar rules and recursive descent, then inspects Ruby's AST with Ripper and Prism.
How Ruby runs: the CRuby pipeline
Traces the CRuby pipeline from source to tokens, AST, YARV bytecode and stack-based execution.
Bytecode and virtual machines
Compares bytecode with machine code and examines YARV, the JVM, WebAssembly and ruby.wasm in the browser.
JIT compilation and the future of Ruby
Explains JIT profiling and compilation, MJIT, YJIT with basic block versioning and deoptimization, and the experimental ZJIT.