4 Interpreter Fundamentals
This section covers how interpreters work, what choices designers make at each step, and how those choices affect multithreading. R’s design, and the help Rust’s type system gives, both make more sense after it.
The interpreter, the runtime around it, and the compiler are separate parts, and where one ends and the next begins shapes what is easy and what is hard. A tree-walking interpreter has different constraints than a bytecode virtual machine. A compiler solves different problems than either one.
The pages start with how text becomes code that executes, then go through the main interpretation strategies and their tradeoffs, with GNU R’s own parser, evaluator and byte-code engine as the running example.
After this section
- Define parser, AST, bytecode, tree-walking evaluation, and JIT compilation and explain what makes each distinct
- Identify which execution strategy a given interpreter uses and why
- Describe how an interpreter’s design shapes its constraints under parallelism
- Explain why R combines tree-walking with bytecode interpretation
- Read an interpreter’s core evaluation loop and understand its tradeoffs
The pages
Interpreter vs Runtime vs VM vs Compiler. Four distinct concepts that most writing conflates.
Source Text, Tokens, and Parsing. Lexing, grammar, precedence, parse errors, and how R’s parser produces executable R objects.
ASTs and Tree-Walking Evaluation. Recursive evaluation over syntax trees, environments for scope, and why tree-walking is the baseline cost.
Bytecode and Virtual Machines. Instructions, operand stacks, dispatch loops, and why flat sequences execute faster than pointer-chasing trees.
JIT Compilation and Deoptimization. Specializing code based on runtime data, guarding assumptions, and why dynamic languages resist compilation.
Before this section
Start with Orientation.
Where this leads
R has a tree-walking interpreter and a byte-code compiler, and in a default session most function bodies run as bytecode. How R Executes Code covers the full pipeline inside GNU R: parser, AST, evaluator, and the bytecode VM.
R Runtime Internals explains how the runtime around the interpreter works. Environments teach scopes and name bindings. Stack vs Heap covers call frames and stack allocation. Runtime value representation and how Rust encodes runtime values in enums both explain how interpreters store objects. Garbage Collection and Reference Counting vs Tracing Collection cover GC strategies and their tradeoffs.
Memory and CPU Performance explain the hardware-level costs that interpreter design must account for.