#[repr(u8)]pub enum Opcode {
Show 65 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,
ReceiveMatchValue = 112,
SendRemote = 113,
StartSupervisor = 114,
AddImm = 115,
CallNativeFrom = 116,
SubImm = 117,
LtImm = 118,
ListPack = 119,
ListGet = 120,
ListLen = 121,
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, imm → r[a] = constants[imm]
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, imm → 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..=9) 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, Str, or Bytes). Str / Bytes
are charged on the flow quota for as long as the dictionary holds
them. 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).
ReceiveMatchValue = 112
ReceiveMatchValue ra, rb, rc → selective receive: tag == r[b] and
payload structurally equal to r[c] (any crate::Value, not only
Int). Non-matching hops stay queued. Append-only (0x70).
SendRemote = 113
SendRemote ra, rb, rc → deliver hop r[c] to node r[a] (Int)
service r[b] (Str). The host drains crate::DistributionBridge.
Byteflow does not open a socket. Append-only (0x71).
StartSupervisor = 114
StartSupervisor imm → start a supervisor owned by this flow.
imm: 0 one-for-one, 1 one-for-all, 2 rest-for-one.
Later StartChild attaches to it. Append-only (0x72).
AddImm = 115
AddImm ra, rb, imm → r[a] = r[b] + imm (imm sign-extended to
i64). Integer add wraps; a float in r[b] adds in f64. One
instruction instead of LoadImm plus Add, and no scratch register.
Append-only (0x73).
CallNativeFrom = 116
CallNativeFrom ra, rb, native → r[a] = native_1(r[b]).
Same FFI slot as Self::CallNative (imm is the native index) but
the argument is r[b] and the result lands in r[a]. r[b] survives
when a != b, so unpacking a Message does not need a preceding
Move. Append-only (0x74).
SubImm = 117
SubImm ra, rb, imm → r[a] = r[b] - imm (imm sign-extended to
i64). Integer subtraction wraps; a float in r[b] subtracts in
f64. Append-only (0x75).
LtImm = 118
LtImm ra, rb, imm → r[a] = r[b] < imm as Bool. Integers compare
as signed i64. Floats compare as f64 (NaN is not less). Bool
is not a number here. Append-only (0x76).
ListPack = 119
ListPack ra, rb, imm → r[a] becomes a list of imm values
starting at r[b]. imm is 0..=32. Append-only (0x77).
ListGet = 120
ListGet ra, rb, imm → r[a] = r[b][imm]. r[b] must be a list
and imm a valid index. Append-only (0x78).
ListLen = 121
ListLen ra, rb → r[a] = len(r[b]) as Int. Append-only (0x79).
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.