Skip to main content

Module bytecode

Module bytecode 

Source
Expand description

The bytecode an EEL2 program compiles to, and its text encoding.

The seam between the two halves of Plan 0100. milkconv compiles .milk text into an EelProgram; core executes one. Nothing here parses EEL2 — the parser is in the converter and never ships (ADR-0113).

§Why the encoding is text

A bundle carries a program as assembly text, not as packed bytes, and it is a deliberate trade of a few kilobytes for four properties:

  • No serialization dependency. serde would have to describe an enum with thirty-odd variants into a format toml can carry; hand-written Display + FromStr over one op per line costs nothing and adds no crate (lightweight is a feature).
  • A bundle is diffable. A converted preset’s program shows up in review as lines, so a converter change that perturbs codegen is visible rather than a changed blob.
  • Round-tripping is a property, not a hope. EelProgram::to_assembly and EelProgram::from_assembly are inverses, which is assertable and asserted.
  • A malformed program is a surfaced load error, like every other preset boundary (ADR-0002 / NFR §10) — the decoder validates jump targets and register indices once, here, so the VM can trust them.

§What the VM may assume after decoding

EelProgram::from_assembly rejects a program whose jump target is out of range or whose register index is at or past n_regs. Everything downstream — vm::run — indexes on that guarantee, which is what lets the interpreter loop stay free of bounds checks it would otherwise pay per op per vertex. Nothing constructs an EelProgram except this decoder and the converter’s codegen, and the codegen runs its own output through EelProgram::validate before writing it.

Structs§

EelProgram
One compiled EEL2 program: flat bytecode over a fixed register file.

Enums§

Binary
A two-argument builtin.
Mem
Which scratch arena a memory op addresses.
Op
One bytecode instruction.
ProgramError
What is wrong with a program, as a surfaced load error.
Unary
A one-argument builtin.

Constants§

COMPARE_EPSILON
EEL2’s comparison epsilon: == is true within this, and != outside it.