#[repr(u8)]pub enum Opcode {
Show 55 variants
Halt = 0,
LoadConst = 1,
Move = 2,
LoadImm = 3,
Add = 16,
Sub = 17,
Mul = 18,
Div = 19,
Mod = 20,
Neg = 21,
Eq = 24,
Lt = 25,
Le = 26,
Jump = 32,
Branch = 33,
Call = 48,
Return = 49,
CallNative = 50,
Spawn = 64,
Yield = 65,
Sleep = 66,
Exit = 67,
SelfPid = 68,
Send = 80,
Receive = 81,
ReceiveTimeout = 82,
ReceiveMatch = 83,
ReceiveMatchImm = 84,
Ask = 85,
Monitor = 86,
Demonitor = 87,
Link = 88,
Unlink = 89,
AskTimeout = 90,
Delegate = 91,
FreshRequestId = 92,
ReceiveMatchCorr = 93,
ReceiveMatchCorrImm = 94,
SetTrapExit = 95,
RegisterName = 98,
Whereis = 99,
ReceiveMatchKind = 100,
SetRestartPolicy = 101,
HostAwait = 102,
ReceiveMatchTimeout = 103,
ReceiveMatchImmTimeout = 104,
IsAlive = 105,
ExitSignal = 106,
DictPut = 107,
DictGet = 108,
DictErase = 109,
ReceiveMatchEq = 110,
StartChild = 111,
Trap = 96,
Nop = 97,
}Expand description
A single Byteflow opcode.
Numeric values are part of the stable on-disk ABI (byteflow-bytecode
module format, see super::chunk::MAGIC) — never renumber an existing
variant, only append.
Variants§
Halt = 0
Stop the current Flow’s VM loop. Terminal state.
LoadConst = 1
LoadConst ra, kb → r[a] = constants[b]
Move = 2
Move ra, rb → r[a] = r[b]
LoadImm = 3
LoadImm ra, imm → r[a] = imm as i64 (fast path, skips const pool)
Add = 16
Sub = 17
Mul = 18
Div = 19
Mod = 20
Neg = 21
Eq = 24
Lt = 25
Le = 26
Jump = 32
Jump imm → unconditional relative jump (imm = signed offset in
instructions from the next pc).
Branch = 33
Branch ra, imm → jump by imm iff r[a] is falsy (Bool(false),
Unit, or Int(0)). This is the only conditional branch; if/else and
loops both lower to Branch + Jump, keeping the interpreter’s branch
predictor state small.
Call = 48
Call ra, fb, nc → call function fb with nc arguments taken from
r[a..a+nc], result written back into r[a].
Return = 49
Return ra → return r[a] to the caller frame (or complete the
Flow if this is the outermost frame).
CallNative = 50
CallNative ra, fb, nc → like Call but fb indexes the native
function table instead of the bytecode function table.
Spawn = 64
Spawn ra, fb, nc → create a new virtual Flow starting at
function fb, passing nc arguments taken from r[a+1..a+1+nc]
(deliberately not overlapping r[a] itself, which is where the
scheduler writes a Cap to the child once created — FlowCap;
see crate::VmResult::Spawn).
Yield = 65
Yield → cooperative yield. Control returns to the scheduler, the
Flow is re-enqueued as Ready and may resume on any worker.
Sleep = 66
Sleep ra → suspend until r[a] (interpreted as milliseconds,
Value::Int) has elapsed. Registered on the timer wheel.
Exit = 67
Exit ra → terminate the Flow, r[a] is delivered to .join().
SelfPid = 68
SelfPid ra → r[a] = a self Cap
(CapRights::ADDRESSING =
SEND|ASK|LINK|MONITOR) for this flow.
(Opcode name kept for ABI; the value is Value::Cap, not Pid.)
The VM does not store its own id (it has no scheduler state); this
is a scheduler effect, same class as Spawn/Receive.
Send = 80
Send ra, rb → Atomic Hop: deliver r[b] (Message) to the Cap in
r[a]. With a full Reject inbox the sender parks (WAITING_SEND);
otherwise the hop is queued / handed off without blocking the worker
(see crate::docs::mailbox).
VM requires Cap + Message; worker resolves Cap (SEND), stamps sender
reply_cap, then pushes to the resolved mailbox.
Receive = 81
Receive ra → pop the next message into r[a]; if the mailbox is
empty, suspends the Flow in Waiting state until a message
arrives.
ReceiveTimeout = 82
ReceiveTimeout ra, rb → like Receive but gives up after r[b]
milliseconds, writing Value::Unit into r[a] on timeout.
ReceiveMatch = 83
ReceiveMatch ra, rb → Atomic Hop selective receive: block until
a crate::Value::Message with tag == r[b] (as u16) is available.
Non-matching hops stay in the mailbox in FIFO order (skip, don’t drop).
ReceiveMatchImm = 84
ReceiveMatchImm ra, imm → like ReceiveMatch with an immediate tag
(imm must fit in u16).
Ask = 85
Ask ra, rb, rc → atomic request/reply hop.
- Validate
r[b]as Cap andr[c]as Message (VM). - Scheduler resolves Cap (ASK), stamps
sender+ mintsreply_cap. - Deliver the request to the resolved FlowId (like
Send). - Suspend until a reply hop matches
request_id == request.request_id && sender == resolved_FlowId. - Write the reply
Messageintor[a].
Append-only ABI slot (0x55).
Monitor = 86
Monitor ra, rb → install a one-way watch on Cap r[b]; write
crate::MonitorRef as Int into r[a].
Demonitor = 87
Demonitor ra → drop the monitor in r[a] (Int ref).
Link = 88
Link ra, rb → bidirectional link with Cap r[b]; write
crate::LinkId as Int into r[a].
Unlink = 89
Unlink ra → drop the link in r[a] (Int id).
AskTimeout = 90
AskTimeout ra, rb, rc, rd → like Ask, but give up after
r[imm] milliseconds and write Value::Unit into ra.
Encoding: a=dest, b=cap, c=msg, imm=millis_reg.
Append-only ABI slot (0x5A); Trap stays 0x60.
Delegate = 91
Delegate ra, rb, rights, rc? → write an attenuated Cap into r[a].
r[b] is the source Cap; imm is the requested rights mask;
c = 255 means no extra native-mask narrowing. The scheduler
calls Cap::attenuate — the only derivation path.
Append-only ABI slot (0x5B); Trap stays 0x60.
FreshRequestId = 92
FreshRequestId ra → r[a] = next per-flow correlation id (Int).
Starts at 1; 0 is reserved as “unset” so Send / Ask can mint.
Not a capability — uniqueness, not unpredictability.
Append-only ABI slot (0x5C); Trap stays 0x60.
ReceiveMatchCorr = 93
ReceiveMatchCorr ra, rb, rc → wait for a hop with
tag == r[b] and request_id == r[c]. Non-matching hops stay queued.
Append-only ABI slot (0x5D); Trap stays 0x60.
ReceiveMatchCorrImm = 94
ReceiveMatchCorrImm ra, rb, imm → like Self::ReceiveMatchCorr
with immediate tag (imm as u16) and request_id from r[b].
Append-only ABI slot (0x5E); Trap stays 0x60.
SetTrapExit = 95
SetTrapExit ra → BEAM process_flag(trap_exit, r[a]).
Truthy r[a] (same rules as Opcode::Branch) enables trapping:
this flow receives crate::TAG_SYS_EXIT when a linked peer exits
(including Normal), instead of being killed / silently dropping the
link.
Append-only ABI slot (0x5F); Trap stays 0x60.
RegisterName = 98
RegisterName ra → publish r[a] (Str) as this flow’s name.
Only the calling flow is registered. Requires SEND on self-authority
(confined spawn cannot squat names). Append-only (0x62).
Whereis = 99
Whereis ra, rb → look up r[b] (Str); write a SEND Cap for
the caller, or Unit if missing. Never a raw FlowId. (0x63)
ReceiveMatchKind = 100
ReceiveMatchKind ra, imm → block until a crate::Value::Message
whose payload.wire_tag() == imm (BFV0 tag 0..=8) is available.
Non-matching hops stay queued (FIFO skip). Append-only (0x64);
Trap stays 0x60.
SetRestartPolicy = 101
SetRestartPolicy imm → set this flow’s supervisor restart policy:
0 = Always, 1 = OnFailure, 2 = Never. Invalid imm → Trap.
Append-only (0x65); Trap stays 0x60.
HostAwait = 102
HostAwait ra, rb, imm → park this flow and hand (op=imm, args=r[b])
to the host crate::HostAwaitBridge. On completion the host writes
a crate::Value into r[a] (register writeback, like Receive).
Requires a bridge on crate::RuntimeConfig; otherwise the flow fails.
Append-only (0x66); not a CallNative / std-native slot.
ReceiveMatchTimeout = 103
ReceiveMatchTimeout ra, rb, rc → like Self::ReceiveMatch but
give up after r[c] milliseconds and write Value::Unit (BEAM
receive … after). Non-matching hops stay queued. Append-only (0x67).
ReceiveMatchImmTimeout = 104
ReceiveMatchImmTimeout ra, rb, imm → like Self::ReceiveMatchImm
with timeout register r[b] (imm = tag). Writes Unit on expiry.
Append-only (0x68).
IsAlive = 105
IsAlive ra, rb → r[a] = Bool: the Cap in r[b] is held by this
flow and still names a live flow (BEAM is_process_alive/1).
Unknown / not-held / revoked / non-flow target → false (no trap).
Append-only (0x69).
ExitSignal = 106
ExitSignal ra, rb → BEAM exit/2: signal the flow addressed by
Cap r[a] (needs LINK) with reason r[b] (FlowExitReason as Int).
Normal is ignored. Killed cannot be trapped. Other reasons become
a crate::TAG_SYS_EXIT hop when the target has trap_exit.
Append-only (0x6A).
DictPut = 107
DictPut ra, rb, rc → process dictionary: r[a] = old, key r[b]
(Int), value r[c] (scalar: Unit/Bool/Int/Float). Missing old → Unit.
Append-only (0x6B).
DictGet = 108
DictGet ra, rb → r[a] = dict[r[b]] or Unit. Append-only (0x6C).
DictErase = 109
DictErase ra, rb → remove key r[b], write the old value or Unit
into r[a]. Append-only (0x6D).
ReceiveMatchEq = 110
ReceiveMatchEq ra, rb, rc → selective receive: tag == r[b] and
payload Int == r[c]. Non-matching hops stay queued. Append-only (0x6E).
StartChild = 111
StartChild ra, policy, fn → spawn function imm as a supervised
child of this flow’s supervisor (b = restart policy 0..=2).
Writes an addressing Cap into r[a]. The caller must itself have
been started by a host crate::Supervisor. Append-only (0x6F).
Trap = 96
Trap imm → deliberate fault (assertion failure, div-by-zero, bad
opcode encountered by a corrupt/foreign module, capability
violation). Propagates to the Flow supervisor as crate::FlowOutcome::Failed.
Nop = 97
Nop → no-op, used by the assembler to pad jump targets.
Implementations§
Source§impl Opcode
impl Opcode
Sourcepub fn from_u8(byte: u8) -> Option<Opcode>
pub fn from_u8(byte: u8) -> Option<Opcode>
Decode a raw byte into an Opcode, used when loading foreign/untrusted
modules. Rejects anything outside the currently defined ISA rather
than transmuting garbage into a jump-table index (which is exactly
the class of bug that turns a VM into a code-execution primitive).
pub fn as_u8(self) -> u8
Trait Implementations§
impl Copy for Opcode
impl Eq for Opcode
impl StructuralPartialEq for Opcode
Auto Trait Implementations§
impl Freeze for Opcode
impl RefUnwindSafe for Opcode
impl Send for Opcode
impl Sync for Opcode
impl Unpin for Opcode
impl UnsafeUnpin for Opcode
impl UnwindSafe for Opcode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.