Master the fundamental concepts of cpython internals through this focused micro-challenge.
The \`dis\` module prints the opcodes CPython will execute. Pairing \`dis\` output with \`Python/compile.c\` and \`ceval.c\` is how you learn what the compiler actually emitted.
Each line shows offset, opcode name, and argument:
For example, \`def add(a, b): return a + b\` disassembles to loads of \`a\` and \`b\`, \`BINARY_OP\` or \`BINARY_ADD\`, then \`RETURN_VALUE\`.
Match opcodes to compiler phases:
Specialized opcodes in CPython 3.11+ replace generic forms for common patterns. When dis output shows `CACHE` lines, you are looking at the adaptive specialization machinery, not user bytecode.
This exercise asks you to disassemble sample functions and map opcodes to CPython source concepts. You will document how \`dis\` reveals the stack operations behind familiar Python syntax.
You will use the same mental model here when reading production interpreter source later in the track. Sketch one concrete input on paper, predict the outcome, then confirm with code. That discipline catches logic errors early and makes debugging far faster when you extend the implementation in follow-on tasks.
Write a C program documenting Python bytecode.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github