◄ WORLD V · SONNY 5DART 264 · a helldive at the net

THE BYTECODE compile once to a compact instruction set, interpret anywhere

Bytecode is a compact, machine-independent instruction set for a virtual machine: the compiler lowers source to a byte-per-opcode stream, and a small interpreter executes it. It is the middle path between a slow tree-walker and a fragile native compiler — portable (compile once, run anywhere), dense, and easy to verify. BCPL's O-code and Pascal's p-code pioneered it; Smalltalk-80 and the JVM made it the default shape of a language runtime. Almost every dynamic language you use — Python, Ruby, Lua, the JVM, the CLR — runs bytecode on a VM.

THE TECHNIQUE lower to opcodes; a tiny interpreter dispatches them

A five-opcode bytecode program for (5 - 3) * 2. The demo dispatches each opcode on the VM's stack: live demo


HISTORY & CREDIT O-code 1969 · p-code 1975

“Interpreted means re-parsing the source each time.” — bytecode is parsed once into opcodes; after that the loop just dispatches numbers. Portability and speed come from compiling to a virtual instruction set instead of a real one. cited

1969 · Martin Richards — BCPL's O-code, an early portable intermediate code.
1975 · Nori, Ammann, Jensen, Nageli & Jacobi — Pascal p-code, which made Pascal portable everywhere.
1980 · Smalltalk-80; then the JVM (1995) — bytecode as the default runtime shape.

Compile to a virtual instruction set and the interpreter is small, the programs are portable, and the bytecode is easy to check before it runs. Distance from the metal, bought back as portability. O-code / p-code

RECOMMEND FOR I-13 bytecode interpreted, computed

On the canonical compiler, the 5-opcode program for (5 - 3) * 2 interprets to 4:

$ i13 run m_bytecode.i13 # dispatch [5,3,SUB,2,MUL] RUN OK . 259 step(s) . peak stack 10 . call depth 6 ops = 5 result = 4
Recommend: i13 already is a bytecode VM — it compiles source to its IVM opcode stream and interprets it (its check reports the op count; the wasm build ships the same interpreter self-contained). The demo hand-rolls a little bytecode loop on top of i13, but i13's real answer is one level down: it lowers to a bounded opcode set (~19 ops) and single-pass-validates that stream before running it. Bytecode is not a recommend for i13; it is i13's implementation strategy — the reason a whole language fits in an 8.5 KB WASM VM.