Code generation
Turn Orbit into Kestrel assembly: parse into a tree, then walk the tree and emit an instruction for every node. Registers handed out by depth, a tree too deep for four of them, and characters on the terminal.
Open it in the simulatorWrite a compiler in Python on a Raspberry Pi that turns Orbit into machine code for the Kestrel: assembler, code generation, registers, jumps, a call stack and an optimizer, ending with your language running on the CPU you built from NAND gates.
0 of 7 done
7 lessons in 4 chapters, about 7 hours on a simulated Raspberry Pi 4 Model B. Free, in your browser, every step checked by the simulator.
Turn Orbit into Kestrel assembly: parse into a tree, then walk the tree and emit an instruction for every node. Registers handed out by depth, a tree too deep for four of them, and characters on the terminal.
Open it in the simulatorif and while compiled to labels and jumps, multiplication by a loop on a CPU with no multiply, not-equal as a subtraction, and a loop that never ends.
Open it in the simulatorMake the code smaller and faster without changing what it prints: constant folding in the parser, and a peephole pass that drops address loads and reloads the Kestrel does not need. Measured in words and cycles.
Open it in the simulatorEach lesson opens when the one before it is done, and each chapter ends in a project.
The Kestrel, its words, and a tree turned into instructions.
Meet the target: the Kestrel, the CPU built from NAND gates in From gates to a computer. Write an assembler in Python that turns its assembly into the 16-bit words its ROM holds, then an emulator that runs them.
0 of 5 steps
Turn Orbit into Kestrel assembly: parse into a tree, then walk the tree and emit an instruction for every node. Registers handed out by depth, a tree too deep for four of them, and characters on the terminal.
0 of 5 steps
Where each value lives, and if and while as jumps.
Variables in the Kestrel's 8 bytes of RAM, one register kept back for addresses, assignment, picking the cheaper instruction for a constant, and the ninth variable that lands on the first.
0 of 5 steps
if and while compiled to labels and jumps, multiplication by a loop on a CPU with no multiply, not-equal as a subtraction, and a loop that never ends.
0 of 5 steps
A call stack on a CPU with no call instruction, then fewer words and cycles.
Functions on a CPU with no call instruction: a return number and a jump table the compiler writes, a stack in RAM so calls can nest, recursion, and a stack overflow you can watch.
0 of 5 steps
Make the code smaller and faster without changing what it prints: constant folding in the parser, and a peephole pass that drops address loads and reloads the Kestrel does not need. Measured in words and cycles.
0 of 5 steps
Your language, compiled on the Pi, running on gates.
The Pi compiles an Orbit countdown with your compiler, and the words go into the program ROM of the computer you built from NAND gates. The Kestrel runs your language, and the terminal prints it.
0 of 4 steps
All 7 lessons, in order, each with what it covers. Any of them opens in the editor right away.
Every lesson runs in the simulator with nothing to buy. When you want the real thing, these kits have the parts.
Pick the starter kit you own and run every lesson in its manual with the same parts on the same pins.
See every kitYes. All 7 lessons of Compile a language to the Kestrel CPU are free and run in your browser, with nothing to install and no parts to buy before you start.
No. Every lesson runs on a simulated Raspberry Pi 4 Model B with its parts on the canvas, and the simulator checks each step as you go. When you want to build it for real, the same wiring and code work on a real board.
About 7 hours: 7 lessons in 4 chapters, each one a few short steps. Your progress is kept, so you can stop after any lesson and pick up where you left off.
Each chapter ends in a project that puts it together: Code generation, Control flow and Optimizing.
With "Targets and assembly", and each lesson builds on the one before it. New to circuits? Electronics basics is the course that starts from zero.