PeaBox Lab › PeaLang › Dev › Architecture
Runtime Architecture

How PeaLang executes your code

PeaLang has two execution engines over one front end, plus a portable artifact format. The split is deliberate: the interpreter is optimized for development feedback and debugging; the VM is optimized for predictable, resource-bounded production execution. A differential test harness keeps them behaviorally identical.

The front end

Lexer. Source text is tokenized into a flat token stream with positions attached — every diagnostic and stack trace maps back to file, line and column because of that threading. Keywords, identifiers, literals, operators and comments are recognized here.

Parser. A hand-written recursive-descent parser produces a syntax tree. Precedence is encoded structurally in the tree (not by re-associating later), which is why a + b * c parses into the shape it does. Error recovery is built in — the parser reports multiple errors per run instead of dying on the first one.

Semantic pass. Scope construction and the symbol table are built here, along with static checks: arity, undefined names, duplicate definitions, type-annotation consistency, and capability-use reporting for hosts that want to know what a script might touch before they run it.

Engine 1 — Tree-walking interpreter

The interpreter walks the syntax tree directly. Strengths: perfect step-level observability, trivial mapping between execution state and source, and forgiving resource instrumentation. Weaknesses: raw speed. It's the engine you debug with and the reference for VM conformance tests.

Engine 2 — Stack VM and PEAC bytecode

The compiler lowers the tree to stack bytecode: a constant pool, nested code objects and a compact instruction set (loads, stores, arithmetic, jumps, calls, module ops, exceptions). The PEAC format serializes a compiled module with a magic marker, version and content hashes — loadable and verifiable on any conforming host.

VM execution is governed by the same resource limits as the interpreter: instruction count, time, memory, recursion depth, stack depth, collection sizes, output volume, HTTP and file-read quotas. Limits are enforced, not advisory — exceeding one raises a structured error the host can map to a 429, 402 or 500.

Capabilities — security by construction

PeaLang has no ambient authority. Filesystem, network, logging, concurrency and every other sensitive operation exist only as host-granted capabilities, scoped by path, host or function. The safe default is deny; the recommended shape is a narrow wrapper function (e.g. get_policy_band(tier)) rather than a broad capability (e.g. "HTTP to anywhere"). Budgets sit on top of capabilities: even a granted operation can be boxed to N requests per run.

Embedding boundary

The portable value set crossing the host boundary is fixed: null, boolean, int, float, string, list and string-keyed map. Host objects convert at the edge. This is what makes the same module run under Python, a Java sidecar, a TypeScript/React service or in a browser sandbox without recompilation — and what makes validation in both directions tractable.

Where to read the code

← Back to Dev  ·  Build & test →