#[repr(u8)]pub enum Opcode {
Show 95 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,
MulImm = 122,
EqImm = 123,
LeImm = 124,
BitAnd = 125,
BitOr = 126,
BitXor = 127,
BitNot = 128,
Shl = 129,
Shr = 130,
ReceiveMatchCmp = 131,
MapPack = 132,
MapGet = 133,
MapLen = 134,
TableOpen = 135,
TableGet = 136,
TablePut = 137,
RecordPack = 138,
RecordGet = 139,
RecordLen = 140,
Ne = 141,
Gt = 142,
Ge = 143,
NeImm = 144,
GtImm = 145,
GeImm = 146,
Ushr = 147,
BranchTrue = 148,
StrLen = 149,
BytesLen = 150,
TailCall = 151,
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]. 0 means finalize already
consumed the row and propagated the exit; that value is not a link.
Unlink = 89
Unlink ra → drop the link in r[a] (Int id). 0 does nothing.
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..=10) 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 → register a host operation (op=imm, args=r[b])
and write its ticket id (Int) into r[a]. The flow keeps running.
The host completes with a crate::TAG_SYS_AWAIT hop (request_id
= ticket) that bytecode reads with 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 (b = restart policy 0..=2). Writes an addressing Cap into
r[a]. Attaches to the supervisor this flow started with
Self::StartSupervisor, otherwise to the host supervisor that
started this flow. With neither, the flow fails. 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..=256. 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).
MulImm = 122
MulImm ra, rb, imm → r[a] = r[b] * imm (imm sign-extended to
i64). Integer multiply wraps; a float in r[b] multiplies in
f64. Append-only (0x7A).
EqImm = 123
EqImm ra, rb, imm → r[a] = Bool(r[b] == Int(imm)).
The immediate is an integer. A float, bool, or string in r[b]
compares unequal, the same as Self::Eq against a LoadImm.
Append-only (0x7B).
LeImm = 124
LeImm ra, rb, imm → r[a] = r[b] <= imm as Bool. Integers
compare as signed i64. Floats compare as f64 (NaN is not less
or equal). Bool is not a number here. Append-only (0x7C).
BitAnd = 125
BitAnd ra, rb, rc → r[a] = r[b] & r[c]. Both operands must be
Int. Append-only (0x7D).
BitOr = 126
BitOr ra, rb, rc → r[a] = r[b] | r[c]. Both operands must be
Int. Append-only (0x7E).
BitXor = 127
BitXor ra, rb, rc → r[a] = r[b] ^ r[c]. Both operands must be
Int. Append-only (0x7F).
BitNot = 128
BitNot ra, rb → r[a] = !r[b]. r[b] must be Int.
Append-only (0x80).
Shl = 129
Shl ra, rb, rc → r[a] = r[b] << (r[c] & 63). Both operands must
be Int. The shift count keeps its low 6 bits, so a negative count
still names a shift in 0..64. Append-only (0x81).
Shr = 130
Shr ra, rb, rc → arithmetic r[a] = r[b] >> (r[c] & 63). Both
operands must be Int. The sign bit fills the vacated bits.
Append-only (0x82).
ReceiveMatchCmp = 131
ReceiveMatchCmp ra, rb, rc, imm → wait for tag r[b] and an Int
payload compared with r[c] by imm (0 eq, 1 lt, 2 le).
A hop that fails the comparison stays queued. Append-only (0x83).
MapPack = 132
MapPack ra, rb, imm → r[a] becomes a map of imm pairs starting
at r[b] (key, value, key, value, …). imm is 0..=256.
Keys are Int or Str. A duplicate key traps. Append-only (0x84).
MapGet = 133
MapGet ra, rb, rc → r[a] = r[b][r[c]]. Missing key writes Unit.
Append-only (0x85).
MapLen = 134
MapLen ra, rb → r[a] = len(r[b]) as Int. Append-only (0x86).
TableOpen = 135
TableOpen ra, rb → this flow’s table, named by the Str in r[b].
Writes a Cap (SEND|RECV, target = that table) into r[a].
A second open traps. Append-only (0x87).
TableGet = 136
TableGet ra, rb, rc → r[a] is the row of cap r[b] at key r[c].
Requires RECV. Missing key writes Unit. Append-only (0x88).
TablePut = 137
TablePut ra, rb, rc → store r[c] in cap r[a] at key r[b].
Requires SEND. Append-only (0x89).
RecordPack = 138
RecordPack ra, rb, imm → r[a] becomes a positional record of
imm fields starting at r[b]. imm is 0..=256. Append-only (0x8A).
RecordGet = 139
RecordGet ra, rb, imm → r[a] = r[b][imm]. r[b] must be a record.
Append-only (0x8B).
RecordLen = 140
RecordLen ra, rb → r[a] = len(r[b]) as Int. Append-only (0x8C).
Ne = 141
Ne ra, rb, rc → r[a] = Bool(r[b] != r[c]). Append-only (0x8D).
Gt = 142
Gt ra, rb, rc → r[a] = Bool(r[b] > r[c]). Append-only (0x8E).
Ge = 143
Ge ra, rb, rc → r[a] = Bool(r[b] >= r[c]). Append-only (0x8F).
NeImm = 144
NeImm ra, rb, imm → r[a] = Bool(r[b] != Int(imm)). Append-only (0x90).
GtImm = 145
GtImm ra, rb, imm → r[a] = Bool(r[b] > imm). Append-only (0x91).
GeImm = 146
GeImm ra, rb, imm → r[a] = Bool(r[b] >= imm). Append-only (0x92).
Ushr = 147
Ushr ra, rb, rc → logical r[a] = (r[b] as u64) >> (r[c] & 63). Both operands Int. Append-only (0x93).
BranchTrue = 148
BranchTrue ra, imm → jump by imm iff r[a] is truthy. Append-only (0x94).
StrLen = 149
StrLen ra, rb → r[a] = len(r[b]) as Int. Append-only (0x95).
BytesLen = 150
BytesLen ra, rb → r[a] = len(r[b]) as Int. Append-only (0x96).
TailCall = 151
TailCall ra, fb, nc → tail-recursive call replacing current frame. Append-only (0x97).
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 Forget for Opcode
impl Freeze for Opcode
impl Move 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.