Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Bytecode Instructions

This document defines the current VM instruction set in rust/vm/src/instr.rs.

Instruction Families

The VM groups instructions by execution concern.

FamilyInstructions
CommunicationSend, Receive, Offer, Choose
Session lifecycleOpen, Close
Effect and guardInvoke, Acquire, Release
SpeculationFork, Join, Abort
Ownership and knowledgeTransfer, Tag, Check
ControlSet, Move, Jump, Spawn, Yield, Halt

Instruction Reference

All register operands are bounds-checked at runtime. Out-of-range reads or writes fail with Fault::OutOfRegisters.

Communication

InstructionFieldsRuntime effect
Sendchan, valEmits a send on the endpoint in chan. Payload routing is decided through the effect handler path.
Receivechan, dstReads one message from the partner edge and writes the payload to dst.
Offerchan, labelPerforms internal choice and emits the selected label.
Choosechan, tableReads a label and branches by jump table entry.

Session lifecycle

InstructionFieldsRuntime effect
Openroles, local_types, handlers, dstsAllocates a new session, initializes local type state per role, binds edge handlers, and writes endpoint handles to destination registers.
ClosesessionCloses the referenced session and emits close and epoch events.

Effect and guard

InstructionFieldsRuntime effect
Invokeaction, dstExecutes an effect step through the bound handler for the session. dst is an optional compatibility field.
Acquirelayer, dstAttempts guard acquisition and writes evidence to dst when granted.
Releaselayer, evidenceReleases a guard layer using previously issued evidence.

Speculation

InstructionFieldsRuntime effect
ForkghostEnters speculation scope tied to a ghost session identifier.
JoinnoneCommits speculative state when reconciliation checks pass.
AbortnoneRestores scoped checkpoint state and exits speculation.

Ownership and knowledge

InstructionFieldsRuntime effect
Transferendpoint, target, bundleTransfers endpoint ownership and associated proof bundle to a target coroutine.
Tagfact, dstTags a local knowledge fact and returns the result in dst.
Checkknowledge, target, dstChecks a fact under the active flow policy and writes the check result to dst.

Control

InstructionFieldsRuntime effect
Setdst, valWrites an immediate value to a register.
Movedst, srcCopies a register value.
JumptargetPerforms an unconditional jump.
Spawntarget, argsSpawns a child coroutine with copied argument registers.
YieldnoneYields back to the scheduler.
HaltnoneTerminates coroutine execution.

Compilation From Local Types

rust/vm/src/compiler.rs exposes compile(local_type: &LocalTypeR) -> Vec<Instr>.

The compiler emits communication instructions, Invoke, and control-flow instructions. It does not emit guard, speculation, or ownership opcodes.

LocalTypeR nodeEmission pattern
single-branch SendSend then Invoke then continuation
multi-branch Senddeterministic Offer on first branch then continuation
single-branch RecvReceive then Invoke then continuation
multi-branch RecvChoose with patched jump table then branch blocks
Murecords loop target then compiles body
VarJump to loop target if bound, otherwise Halt
EndHalt

The compiler is intentionally simple. Full ISA coverage is provided by direct bytecode construction and runtime loaders.