Bytecode Instructions
5 OpcodesCPython instruction pointer stream evaluated by _PyEval_EvalFrameDefault:
RESUME and unified BINARY_OP format.
Analyze how Python evaluates expressions such as 2 + 2 versus "2" + "2": from lexing & Abstract Syntax Tree nodes to compiler stack bytecode and C-level type dispatch (long_add vs unicode_concat).
CPython instruction pointer stream evaluated by _PyEval_EvalFrameDefault:
RESUME and unified BINARY_OP format.
Python does not perform implicit type coercion during binary operations. In CPython, every object possesses an ob_type pointer. When executing the BINARY_OP (+) opcode, the virtual machine extracts the operands and checks their type slots: for strings, it calls PyUnicode_Concat() which allocates a new unicode buffer combining '2' and '2' into '22'. For integers, it invokes long_add() which extracts C digit arrays to calculate 2 + 2 = 4. If you mix "2" + 2, neither type provides a compatible conversion slot, raising an immediate TypeError.