Skip to main content

Overview

Introducing edge python, a Rust compiler weighing less than 100 KB, based on adaptive bytecode interpretation to achieve speeds close to native Rust.

Terms

  • bytes: the compiler reads source as raw bytes, never copying into strings.
  • spans: instead of extracting substrings, the lexer marks where each token starts and ends in the original buffer.
  • tokens: the parser consumes positional markers, not text. Structure emerges from offsets alone.
  • bytecode: the parser emits opcodes directly as it reads tokens, collapsing parsing and code generation into a single pass.
  • quickening: the VM rewrites its own instructions as it runs. Once operand types are known, generic opcodes are replaced in-place with faster specialized ones. The bytecode never looks the same twice.
  • copy-and-patch: when quickening identifies a hotspot, the VM copies a precompiled native template into executable memory and patches the variable slots with real values. No code generation at runtime.

Basic Architecture

bytes -> spans -> tokens -> bytecode -> [inline caching + quickening] -> copy-and-patch -> native code
Γcompiler=CpatchVquickeningPparserLlexer\Gamma_{compiler} = \mathcal{C}_{patch} \circ \mathcal{V}_{quickening} \circ \mathcal{P}_{parser} \circ \mathcal{L}_{lexer}

References