Bytecode Created 2026-10-14 Updated 2026-10-31
An encoded instruction representation for a software execution mechanism. Compilation can produce bytecode that an interpreter executes.
Code object 2026-11-05
In CPython, a code object represents compiled executable Python code. It stores bytecode and metadata such as constants, referenced names and source positions. A function object additionally supplies the global namespace, default argument values and, when needed, a closure connecting free variables to captured values. A code object by itself does not contain that execution context.[ref]
For example, calling a function factory twice can create two functions with the same code object but different captured values. Their behavior differs because their closures differ, even though their instructions are shared. Inspecting
f.__code__ therefore describes executable structure rather than a complete snapshot of f's environment. Python documents code objects as immutable; version-specific bytecode details should not be treated as a permanent cross-version file format. Compilation arithmetic example Created 2026-10-14 Updated 2026-11-05
Consider the program expression
x*(2+3)-4 in a deliberately small programming language. Its only program identifier is x, supplied as an integer input. Its literal values are nonnegative decimal numerals, interpreted as integers. Whitespace is ignored between lexical tokens. Its context-free grammar is:expression ::= term (("+" | "-") term)*
term ::= factor ("*" factor)*
factor ::= numeral | "x" | "(" expression ")"
numeral ::= digit digit*
digit ::= "0" | "1" | "2" | "3" | "4"
| "5" | "6" | "7" | "8" | "9"Here
* outside quotation marks means zero or more repetitions. Repeated operators are grouped to the left, specifying operator associativity; term gives multiplication higher operator precedence than addition and subtraction. Parentheses override that grouping. There is no unary minus, variable assignment, function call, or side effect in this language. Evaluation obtains each left operand before its right operand and uses exact integer arithmetic, with no fixed-width overflow.Lexical analysis recognizes
x, *, (, 2, +, 3, ), -, 4. Parsing constructs the concrete abstract syntax tree Sub(Mul(Name(x), Add(Int(2), Int(3))), Int(4)). Parentheses have done their work by making Add a child of Mul; they need not survive as nodes. Constant folding changes this to Sub(Mul(Name(x), Int(5)), Int(4)). It cannot replace Name(x) by a literal value because the input is supplied at execution. The resulting function of the input is .A compiler for our stack machine emits
LOAD x; PUSH 5; MUL; PUSH 4; SUB. LOAD x pushes the current input; PUSH n pushes the integer literal value n. Each binary instruction removes the top item as its right operand, then the next item as its left operand, and pushes the result. The instruction sequence is an intermediate representation that an interpreter can execute; no machine code has been emitted. A compact binary encoding could make it bytecode, but these printed instruction names are only a readable notation.Why does this compilation preserve the result? A structural induction supplies a short proof outline. Translating a literal value or
x appends its value to any initial stack. For a binary abstract syntax tree node, first translating the left child and then the right child appends the two operand values; the matching instruction replaces them by exactly the original operation's result. Previously present stack items remain intact. Constant folding also preserves the result because in the specified integer arithmetic. Together these facts explain agreement for every integer input, rather than merely agreement for one trial. Compiler Created 2026-10-13 Updated 2026-10-14
A compiler translates a program from one representation to another while aiming to preserve its programming language semantics. Its input might be source code or an intermediate representation; its output might be another programming language, bytecode, an intermediate representation, or machine code. Producing machine code is therefore one possible destination, rather than the definition of compilation. For example, the LLVM 20.1.0 tutorial translates an abstract syntax tree into an intermediate representation before introducing execution.[ref]
Compilation can use an abstract syntax tree for checking and transformations such as constant folding before producing machine code. These are useful possibilities, not a compulsory sequence of separate stages for every compiler. The central distinction is between translating a program and executing its operations: a compiler can translate
x*(2+3)-4 without knowing the input value of x, whereas an interpreter needs that value to produce this program expression's result.Different representations expose different questions. Source code preserves what a programmer wrote; an abstract syntax tree exposes grouping; a type system checks permitted combinations; a stack machine makes operand movement explicit. Retaining abstract syntax tree source locations across compilation helps an error message identify the original construct even after constant folding has changed its shape. A malformed
x*(2+)-4 is a programming language syntax error; an unavailable x in the valid example is instead a missing input. Locating the failing rule is more helpful than treating both as an unexplained execution failure. Computer program 2026-11-05
A computer program specifies operations or constraints that an implementation can execute or interpret. Its representation can be source code, bytecode or machine code; the same intended computation can have several computer program representations. Its behavior depends on the language semantics, input and execution environment.
For example, a source expression adding two variables is not yet one fixed result. A compiler can translate it into lower-level operations, while an interpreter or CPU performs those operations for particular values. Calling a library or reading a file makes additional parts of the environment relevant. A computer program is consequently distinct from its one observed execution trace and from the abstract algorithm it implements: two programs can implement the same algorithm with different representations, error behavior or resource costs.
CPython Created 2026-10-14 Updated 2026-11-05
CPython is the principal implementation of Python, developed in the Python project's source repository and distributed through python.org. It parses source code and compiles it into code objects containing bytecode, which its execution machinery evaluates. The
dis module makes the bytecode instructions visible, connecting source-level functions with their compiled representation.[ref]For example, a function that returns
len(items) needs to obtain the callable and argument, perform the call and return its result. A bytecode listing reveals those operations, together with version-specific supporting instructions. CPython can specialize instructions as a program runs. Exact instruction names and layouts are implementation details that can change between releases; the meaning of the Python source expression is specified at the language level. Ignition (JavaScript interpreter) 2026-11-05
Ignition is the register-based interpreter used within V8. It executes an internal representation of JavaScript computations rather than being a separate programming language with different source-level results.[ref]
Ignition in the V8 documentation. Opening description, low-level register-based interpreter
A small abstract bytecode example explains the role of such a representation. To compute a function returning
x + 2, imagine instructions load_arg r0; const r1, 2; add r2, r0, r1; return r2. For argument 5, the represented values are r0 = 5, r1 = 2 and r2 = 7, so the result is 7. An interpreter selects and performs the operation named by each instruction.This instruction spelling is invented for explanation; it is not an Ignition disassembly or a promise about a particular V8 release. The example separates source syntax, an intermediate instruction representation and execution. A register machine supplies a related abstract way to reason about stored intermediate values and operations, without identifying its formal instruction set with a production engine's bytecode.
Actual JavaScript operations require more than an arithmetic mnemonic. The expression
x + 2 can produce numerical addition or string concatenation depending on the value of x. Supplying "5" yields "52" rather than 7. Whatever internal instructions implement it must preserve the applicable ECMAScript behavior.[ref]ECMAScript Language Specification by Ecma International. Addition Operator, string concatenation and numeric addition
Understanding Ignition is therefore useful for studying execution and implementation costs, while the language specification remains the reference for observable program meaning.
Intermediate representation 2026-10-14
A program representation used between input and final output, convenient for analysis, transformation or execution. An abstract syntax tree and bytecode can each serve this role.
Interpreter (computing) Created 2026-10-13 Updated 2026-10-14
An interpreter executes a program's operations according to its programming language semantics. It can recursively evaluate an abstract syntax tree, or follow an instruction sequence using an execution state such as a stack and an instruction pointer. It need not repeatedly read source code characters, and it need not use an abstract syntax tree at all.
Compilation and interpretation can coexist. In CPython, Python source code is compiled into bytecode for execution by an interpreter; its bytecode is not promised to remain stable between releases.[ref]
Glossary, Python 3.14 documentation. Python 3.14 documentation; Python 3.14 glossary: bytecode and virtual machine entries; compilation, execution and release-specific bytecodes
The Python 3.14 compile function accepts text or an abstract syntax tree and can produce a code object, which eval or exec can execute.[ref]Built-in Functions, Python 3.14 documentation. Python 3.14 documentation; Python 3.14 Built-in Functions: compile, accepted source forms, code objects and execution by eval or exec
These operations make translation and execution separately accessible without requiring them to live in different applications.Just-in-time compilation gives another combination: an interactive implementation can translate a submitted program expression into machine code and then execute it immediately. The LLVM 20.1.0 tutorial demonstrates this by adding an intermediate representation module to its just-in-time compilation facility, looking up the generated function, and calling it.[ref]
4. Kaleidoscope: Adding JIT and Optimizer Support. LLVM 20.1.0 documentation; Implementing a language with LLVM, chapter 4, section 4.4: HandleTopLevelExpression, addModule, lookup and calling the generated native function
Thus calling a programming language permanently "compiled" or "interpreted" hides an implementation choice: ask which representation is translated, which is executed, and when. JavaScript engine 2026-11-05
A JavaScript engine implements the execution of JavaScript programs according to the applicable ECMAScript language rules. It reads program structure and performs the operations that produce values, state changes and errors. The engine is one component of an environment; a web browser additionally supplies document, networking and interaction facilities.[ref]
ECMAScript Language Specification by Ecma International. §§1–2, Scope and Conformance; §4.2, Hosts and Implementations
For example,
function square(n) { return n * n; } square(7); evaluates to 49. An interpreter can execute a representation of these operations, while compilation can translate operations into another executable form. Just-in-time compilation performs compilation during execution rather than requiring a wholly separate advance compilation step. These implementation choices do not change the multiplication result required by the language.A concrete implementation is V8, whose Ignition is documented as a register-based interpreter. Such an implementation can use intermediate bytecode rather than repeatedly treating source text as its direct execution format. This example describes one engine architecture, not a requirement that every JavaScript engine use the same machinery.[ref]
Ignition in the V8 documentation. Opening description and linked interpreter overview
Host facilities must be distinguished from language execution. Evaluating a call involving
document requires the environment to supply that object; implementing ECMAScript alone does not promise the Document Object Model. Conversely, numerical computations need not create any document nodes.Performance comparisons require a specified workload. Parsing, first execution, repeated execution and calls into host facilities can have different costs. Timing only a tiny warmed-up function therefore does not measure every aspect of loading or running an application, even when the returned values are identical.
Java virtual machine 2026-11-05
The Java virtual machine is the abstract execution machine specified for Java class files and bytecode. It defines runtime data areas, stack frames, operand stacks, local variables and instruction behavior, while leaving implementation choices such as interpretation and just-in-time compilation open.[ref]
For example, two integer loads followed by an integer-add instruction obtain operands from a stack frame and leave their sum on its operand stack. A method call establishes a new stack frame and later returns a result to its caller. These specified effects remain the contract even if a compiler keeps the values in native registers and emits one machine instruction. The virtual-machine interface therefore supports portable compiled code without requiring every implementation to execute bytecode one instruction at a time.
Operand stack 2026-11-05
An operand stack holds intermediate values used by bytecode operations in a Java virtual machine method invocation. Each stack frame has its own last-in-first-out operand stack, initially empty; its maximum depth is recorded in the class file. Values can be loaded from local variables, consumed by operations and replaced by results.[ref]
Starting from an empty operand stack,
iconst_2; iconst_3; iadd produces the successive contents 2, 2,3 and 5, with the top shown at the right. The addition consumes both operands. This abstract execution rule does not require a physical memory push for each operation: just-in-time compilation may retain values in processor registers while preserving the specified behavior. V8 2026-11-05
V8 is an open-source engine implementing JavaScript through ECMAScript and also executing WebAssembly. It can be embedded in applications, so the engine and the application supplying its environment are distinct components.[ref]
For a simple language-level example,
[1, 2, 3].map(x => x * x) evaluates to an array containing 1, 4, 9. The specified array and multiplication behavior belongs to ECMAScript; V8 supplies an implementation of that behavior. The same expression does not require a document or a web browser.The project's d8 developer shell supplies a small environment for running programs. A file containing
console.log(6 * 7); prints 42 when run in that shell. The multiplication is language behavior, whereas the output facility is supplied by the environment.[ref]Using d8 in the V8 documentation. Print to the command line, JavaScript files and console.log
V8 includes Ignition, a register-based interpreter. Interpreter machinery, bytecode and compilation strategies concern how an engine executes a program, rather than changing the program's specified mathematical result.[ref]
Ignition in the V8 documentation. Opening description, register-based interpreter
An embedding application can supply additional objects and functions. A Document Object Model operation therefore depends on a suitable host, not merely on the presence of V8. Likewise, a performance comparison must name the engine version, workload and measurement conditions rather than treating one fast numerical expression as a measurement of an entire application.
Virtual machine 2026-11-05
A virtual machine presents a specified machine interface implemented using another system. A system virtual machine supplies virtual processors, memory and devices to a guest operating system. A hypervisor mediates access to the underlying resources; execution can combine hardware assistance and software emulation.[ref]
Introduction to System Emulation in the QEMU documentation. system emulation and virtualisation accelerators
For example, a guest can maintain its own kernel and filesystem view while a host schedules several guests on one physical machine. A Java virtual machine instead exposes a bytecode execution model to programs, illustrating a different level of abstraction. A container usually shares the host kernel rather than supplying a separate full guest kernel. The interface being virtualized determines which compatibility and isolation properties a particular virtual machine provides.