Skip to main content

Module bytecode

Module bytecode 

Source
Expand description

Instruction set, .bf (BFV0) wire format, assembler and verifier.

Pure data plane — no threads, no mailboxes. The scheduler and VM consume Chunk values produced here.

PiecePurpose
Opcode / InstructionISA (opcodes are append-only)
Value / MessageRuntime / constant-pool tags (ABI versioned)
Program / FnHost-side assembler with named registers
encode / decode.bf module bytes (MAGIC + ABI_VERSION)
verifyStructural checks before a crate::Runtime starts

Headers: ABI_VERSION (scalars, v5), ABI_VERSION_LISTS (v6), ABI_VERSION_MAPS (v7), and ABI_VERSION_RECORDS (v8). encode writes the oldest of these that can hold the constant pool. decode accepts all four.

Structs§

Cap
Authorization record stored in the runtime Cap table, never in bytecode.
CapId
Unpredictable capability token. Never a flow id.
CapRights
Fixed-width rights bitset. Keep this an explicit allow-list: every new bit here must be audited against the threat-model doc before production.
Chunk
A compiled unit of Byteflow bytecode: code, constants and the function table. One Chunk can back many concurrently-running flows — it is immutable after construction, so it is shared behind an Arc rather than copied per flow (see crate::Vm).
Fn
Emit instructions for one bytecode function.
FunctionDef
A callable entry point inside a Chunk: either bytecode-defined or a slot reserved for a native (Rust) function registered with the runtime via the FFI table.
Instruction
A single packed instruction word.
Label
An unresolved jump target, patched to a relative offset once its address is known (see ChunkBuilder::bind_label).
Message
Envelope carried in mailboxes and registers (Atomic Hop).
NativeMask
Bitset over NativeTable indices, sized once at boot to NativeTable::len(). Shared via Arc because attenuation clones the Cap far more often than it clones the mask.
Program
Assemble one bytecode module.
Reg
A virtual register in the current function.
RegWindow
Contiguous register window (e.g. four slots for make_msg natives).
RevocationCell
One revocation counter per capability issuer (a flow, the native table, the scheduler). Revoke is O(1); every derived Cap dies with it.
VerifyConfig
Knob for verify_with. Default trust is untrusted.

Enums§

AssembleError
Why a text listing could not become a verified Chunk.
CapIdError
Why CapId::random could not produce a token.
CapTarget
What a capability addresses. Bytecode never sees this enum — only the opaque CapId token.
ConstantKind
Constant-pool tags that untrusted modules must not embed.
FormatError
Why a .bf buffer failed to decode.
IntCmp
Integer comparison used by Opcode::ReceiveMatchCmp.
MapKey
Key of a Value::Map. Floats are not keys: equality would not be a useful match, and a NaN key could never be read back.
Opcode
A single Byteflow opcode.
RestartPolicy
Restart policy consulted when a supervised flow terminates.
TrustLevel
Whether the chunk may contain authority-bearing constants, and how aggressively the host should treat the module.
Value
A dynamically-tagged runtime value.
VerifyError
Why a Chunk failed verification.

Constants§

ABI_VERSION
Scalar module header (v5). A list, map, or record raises the header to ABI_VERSION_LISTS, ABI_VERSION_MAPS, or ABI_VERSION_RECORDS. Bump on any breaking change to instruction encoding, constant representation, or function-table layout.
ABI_VERSION_LISTS
ABI that introduces Value::List. encode emits this when the pool contains a list and no map or record. decode accepts v5 through v8. A v5 header rejects tag 9.
ABI_VERSION_MAPS
ABI that introduces Value::Map. Emitted when a constant contains a map and no record. A map nested in a record is written as ABI_VERSION_RECORDS. Decode accepts v5 through v8. A header below v7 rejects tag 10.
ABI_VERSION_RECORDS
ABI that introduces Value::Record. Emitted when a constant contains a record, including one nested in a list, map, or message. Decode accepts v5 through v8. A header below v8 rejects tag 11.
MAGIC
On-disk magic for the .bf module format (see design notes §32). Chosen so a corrupted/truncated file is rejected in the first 4 bytes rather than partway through decoding.
MAX_LIST_LEN
Most elements a Value::List may hold. Wider sequences are rejected by the decoder, ListPack, and Value::try_list.
MAX_MAP_LEN
Most pairs a Value::Map may hold. Keys are MapKey (Int or Str).
MAX_RECORD_LEN
Most fields a Value::Record may hold. Positional, not a map.
TAG_SYS_AWAIT
Reserved Atomic Hop tag for a host HostAwait completion. request_id is the ticket written into the await register.
TAG_SYS_DOWN
Reserved Atomic Hop tag for monitor DOWN events (not an application tag).
TAG_SYS_EXIT
Reserved Atomic Hop tag for linked-exit notices (Ask target death or trap_exit link signal).

Functions§

assemble
Parse a listing produced by super::disassemble and verify it.
decode
Decode a BFV0 module. Untrusted by default: Cap / Pid / Message constants are rejected (see decode_with).
decode_with
Decode with an explicit trust level. Trusted decode is for host-packed modules that may embed authority tags in the constant pool.
disassemble
Assemblable listing of a Chunk. super::assemble reads it back.
encode
Encode chunk as a BFV0 module (little-endian). Pure data — no I/O.
payload_matches
true when hop is a Value::Message with tag and a payload equal to expected.
verify
Verify structural invariants of chunk. See VerifyError for what is checked. This does not perform full dataflow/register-liveness verification (unlike, say, the JVM verifier) — v0 trades that off against implementation complexity.
verify_with
Like verify, with an explicit VerifyConfig.

Type Aliases§

FuncId
Function index returned by Program::function.
NativeIdx
Index into a crate::NativeTable.