
Essentials of Low-level Interpretation
What you'll learn
- Virtual Machines implementations
- Stack-based vs. Register-based VMs
- Bytecode interpreter
- Compiler construction
- Call stack and Stack frames
- Low-level interpretation
- Object-oriented programming
- Functional programming
- Closures implementation
- Garbage Collection
- Mark-Sweep GC
- Understand how programming languages work under the hood
- Bytecode optimization
Requirements
- Basic C++
- Basic data structures (mapslistsstacktrees)
- "Building an Interpreter from scratch" class (if needed)
Description
Course overviewHow programming languages work under the hood? What’s the difference between compiler and interpreter? What is a virtual machineand JIT-compiler? And what about the difference between functional and imperative programming?
There are so many questions when it comes to implementing a programming language!
The problem with “compiler classes” in school is such classes are usually presented as some “hardcore rocket science” which is only for advanced engineers.
Moreoverclassic compiler books start from the least significant topicsuch as Lexical analysisgoing straight down to the theoretical aspects of formal grammars. And by the time of implementing the first Tokenizer modulestudents simply lose an interest to the topicnot having a chance to actually start implementing a programing language itself. And all this is spread to a whole semester of messing with tokenizers and BNF grammarswithout understanding an actual semantics of programming languages.
I believe we should be able to build and understand a full programming language semanticsend-to-endin 4-6 hours — with a content going straight to the pointshowed in live coding sessions as pair-programming and described in a comprehensible way.
In the Building a Virtual Machine class we focus specifically on runtime semanticsand build a stack-based VM for a programming language very similar to JavaScript or Python. Working closely with the bytecode level you will understand how lower-level interpretation works in production VMs today.
Implementing a programing language would also make your practical level in other programming languages more professional.
Prerequisites
There are two prerequisites for this class.
The Building a Virtual Machine course is a natural extension for the previous class — Building an Interpreter from scratch (aka Essentials of Interpretation)where we build also a full programming languagebut at a higherAST-level. Unless you already have understanding of how programming languages work at this leveli.e. what evala closurea scope chainenvironmentsand other constructs are — you have to take the interpreters class as a prerequisite.
Alsogoing to lower (bytecode) level where production VMs livewe need to have basic C++ experience. This class however is not about C++so we use just very basic (and transferrable) to other languages constructs.
Watch the introduction video for the details.
Who this class is for?
This class is for any curious engineerwho would like to gain skills of building complex systems (and building a programming language is an advanced engineering task!)and obtain a transferable knowledge for building such systems.
If you are interested specifically in compilersbytecode interpretersvirtual machinesand source code transformationthen this class is also for you.
What is used for implementation?
Since lower-level VMs are about performancethey are usually implemented in a low-level language such as C or C++. This is exactly what we use as wellhowever mainly basic features from C++not distracting to C++ specifics. The code should be easily convertible and portable to any other languagee.g. to Rust or even higher-level languages such as JavaScript — leveraging typed arrays to mimic memory concept. Using C++ also makes it easier implementing further JIT-compiler.
Note: we want our students to actually followunderstand and implement every detail of the VM themselvesinstead of just copy-pasting from final solution. Even though the full source code for the language is presented in the video lecturesthe code repository for the project contains /* Implement here */ assignmentswhich students have to solve.
What’s specific in this class?
The main features of these lectures are:
- Concise and straight to the point. Each lecture is self-sufficientconciseand describes information directly related to the topicnot distracting on unrelated materials or talks.
- Animated presentation combined with live-editing notes. This makes understanding of the topics easierand shows how the object structures are connected. Static slides simply don’t work for a complex content.
- Live coding session end-to-end with assignments. The full source codestarting from scratchand up to the very end is presented in the video lectures
What is in the course?
The course is divided into five partsin total of 29 lecturesand many sub-topics in each lecture. Below is the table of contents and curriculum.
PART 1: VM BASIC OPERATIONS
In this part we describe compilation and interpretation pipelinestarting building our language. Topics of Stack and Register VMsheap-allocated objects and compilation of the bytecode are discussed.
PART 2: CONTROL FLOW AND VARIABLES
In this part we implement control flow structures such as if expressions and while loopstalk about Global object and global variablesnested blocks and local variablesand also implement a disassembler.
PART 3.1: FUNCTIONS AND CALL STACK
In this part we start talking and implementing function abstraction and function calls. We describe concept of the Call stacknative and user-defined functionsand IILEs (Immediately-invoked lambda expressions).
PART 3.2: CLOSURES IMPLEMENTATION
In this part we focus on closures implementationtalking about scope and escape analysiscapturing free variablesand adding runtime support for closures.
PART 4: GARBAGE COLLECTION
This part is devoted to the automatic memory management known as Garbage collection. We discuss a tracing heap and implement Mark-Sweep garbage collector.
PART 5: OBJECT-ORIENTED PROGRAMMING
In the final part we add support for Object-oriented programmingimplementing classes and instances. In addition we build the final VM executable.
Who this course is for:
- Any curious engineer
- Programming language implementors

