Skip to main content

Module binisa

Module binisa 

Source
Expand description

The binary Silicon ISA — the register bytecode as a stable, self-contained, chip-decodable byte stream. The text sibling is crate::vm::isa (emit_isa, the human-readable assembly listing); this is the machine form of the SAME opcode set.

Two roles, one artifact:

  1. Wire transport. encode_program / decode_program turn a whole CompiledProgram into a versioned, checksummed, SELF-CONTAINED frame. The frame carries its own symbol string-table, so a receiver with a fresh Interner re-interns and runs it byte-identically. This is what makes “send the language bytecode over the wire and execute it” real: the raw bytecode’s Symbols are interner-relative (see crate::vm::tier_cache) and thus NOT portable across machines; the frame lowers every symbol to a wire-local id into the string table and the decoder re-interns them on the far side.

  2. Chip ISA. opcode is the STABLE opcode number a hardware decoder shares. It is keyed on Op::name through an APPEND-ONLY table (ISA_OPCODES), so the number for a given op can never drift when the Op enum is reordered — the exact property a fabricated decoder needs (its wired constants outlive the source order). The reversible-core opcodes (RevAdd … RevSwap) sit at pinned low numbers so the adiabatic datapath’s control decode is fixed.

Constants§

ISA_MAGIC
The frame magic — LOGOS Bytecode, format 1. A receiver rejects any buffer that does not open with these four bytes (a foreign or truncated frame is not a program).
ISA_OPCODES
The APPEND-ONLY opcode table: opcode(op) == position of op.name() in this slice. Order IS the ABI — a new op appends at the end and keeps every prior number fixed; the totality lock (this module’s unit test opcode_map_is_total_over_the_isa) forces a newly-added Op to be registered here, and the append-only lock pins the reversible-core numbers so a chip decoder built against them can never silently mismatch. Never reorder or delete an entry.
ISA_VERSION
The wire-format version. Bumped when the frame layout changes incompatibly; a decoder rejects a version it does not understand rather than mis-parsing it.

Functions§

decode_program
Decode an ISA frame back into an executable CompiledProgram, re-interning its symbol table against interner (which may be BRAND NEW — the frame is self-contained). Returns None on any corruption: bad magic, wrong version, checksum mismatch, or malformed payload — a corrupt frame is not a program and is rejected, never half-executed.
encode_program
Serialize a whole compiled program into a self-contained, portable ISA frame: MAGIC ‖ version ‖ checksum ‖ bincode(WireProgram). The interner is the one the program was compiled against — every symbol string is captured from it so the frame stands alone.
opcode
The stable opcode number for an op — the value a hardware decoder keys on. Total over the ISA (a new op that forgets to register in ISA_OPCODES panics here, and the totality lock catches it in CI first).
opcode_of_name
The stable opcode number for an op name, or None if the name is not in the ISA table.