Skip to content

4. The Interpreter

The evaluation loop, frames, stack-based execution, bytecode instructions, function and method calls, attribute lookup, exceptions, generators, coroutines, pattern matching, comprehensions, and closures.

ChapterTitle
27Evaluation Loop
28Frames
29Stack-Based Execution
30Bytecode Instructions
31Function Calls
32Method Calls
33Attribute Lookup
34Exception Handling
35Generators
36Coroutines and Async
37Pattern Matching
38Comprehensions
39Closures and Cells
27. Evaluation LoopThe main evaluation loop in Python/ceval.c, opcode dispatch via computed gotos, and the eval breaker mechanism.
24 min
28. FramesPyFrameObject and _PyInterpreterFrame layout, frame creation, the frame stack, and frame introspection.
18 min
29. Stack-Based ExecutionThe value stack, operand push/pop discipline, and how the interpreter maintains stack depth invariants.
20 min
30. Bytecode InstructionsCatalogue of CPython opcodes: LOAD/STORE variants, binary ops, comparison, jumps, and call instructions.
19 min
31. Function CallsCALL opcode mechanics, positional and keyword argument handling, *args/**kwargs unpacking, and call overhead.
17 min
32. Method CallsLOAD_METHOD and CALL_METHOD optimization, bound method objects, and the method cache.
17 min
33. Attribute LookupLOAD_ATTR bytecode, __getattribute__ dispatch, the descriptor protocol, and type version tag caching.
17 min
34. Exception HandlingException tables, the try/except/finally bytecode pattern, exception chaining, and the unwinding protocol.
16 min
35. GeneratorsGenerator object internals, YIELD_VALUE and RESUME opcodes, and frame suspension and resumption mechanics.
14 min
36. Coroutines and Asyncasync def, await, SEND opcode, coroutine wakeup, and how asyncio integrates with CPython's coroutine machinery.
14 min
37. Pattern Matchingmatch/case compilation to MATCH_* opcodes, pattern semantics, and guard evaluation in the interpreter.
16 min
38. ComprehensionsHow list/dict/set comprehensions and generator expressions compile to nested code objects with implicit iteration.
14 min
39. Closures and CellsMAKE_CELL, LOAD_DEREF, STORE_DEREF opcodes and the PyCellObject that captures variables in enclosing scopes.
14 min