pub struct Fn<'a> { /* private fields */ }Expand description
Emit instructions for one bytecode function.
Implementations§
Source§impl<'a> Fn<'a>
impl<'a> Fn<'a>
Sourcepub fn local(&mut self) -> Reg
pub fn local(&mut self) -> Reg
Allocate a fresh local register.
A frame is at most 255 slots (num_registers is a u8), so index
255 is not a real register. One more local emits Trap and returns
r0 instead of aliasing an existing slot.
Sourcepub fn reg(&mut self, index: u8) -> Reg
pub fn reg(&mut self, index: u8) -> Reg
Bind to an explicit register index without growing the declared frame.
Sourcepub fn window(&mut self, count: u8) -> RegWindow
pub fn window(&mut self, count: u8) -> RegWindow
Allocate count contiguous locals; useful before Self::native_n.
Sourcepub fn add_imm(&mut self, dst: Reg, imm: i32)
pub fn add_imm(&mut self, dst: Reg, imm: i32)
dst += imm in place. One Opcode::AddImm, no scratch register.
Sourcepub fn sub_imm(&mut self, dst: Reg, imm: i32)
pub fn sub_imm(&mut self, dst: Reg, imm: i32)
dst -= imm in place. One Opcode::SubImm.
Sourcepub fn lt_imm(&mut self, lhs: Reg, imm: i32) -> Reg
pub fn lt_imm(&mut self, lhs: Reg, imm: i32) -> Reg
lhs < imm as Bool, in a fresh local. One Opcode::LtImm.
Sourcepub fn mul_imm(&mut self, dst: Reg, imm: i32)
pub fn mul_imm(&mut self, dst: Reg, imm: i32)
dst *= imm in place. One Opcode::MulImm. Integer multiply wraps.
Sourcepub fn le_imm(&mut self, lhs: Reg, imm: i32) -> Reg
pub fn le_imm(&mut self, lhs: Reg, imm: i32) -> Reg
lhs <= imm as Bool, in a fresh local. One Opcode::LeImm.
Sourcepub fn bit_and(&mut self, lhs: Reg, rhs: Reg) -> Reg
pub fn bit_and(&mut self, lhs: Reg, rhs: Reg) -> Reg
lhs & rhs into a new local. Both operands must be Int at runtime.
Sourcepub fn shl(&mut self, lhs: Reg, rhs: Reg) -> Reg
pub fn shl(&mut self, lhs: Reg, rhs: Reg) -> Reg
lhs << rhs into a new local. The count keeps its low 6 bits.
Sourcepub fn shr(&mut self, lhs: Reg, rhs: Reg) -> Reg
pub fn shr(&mut self, lhs: Reg, rhs: Reg) -> Reg
Arithmetic lhs >> rhs into a new local. The count keeps its low 6 bits.
Sourcepub fn list_pack(&mut self, items: &[Reg]) -> Reg
pub fn list_pack(&mut self, items: &[Reg]) -> Reg
Pack items into a new list local. items must already be contiguous
registers (rN, rN+1, …) and at most 32 long.
pub fn list_get(&mut self, list: Reg, index: i32) -> Reg
pub fn list_len(&mut self, list: Reg) -> Reg
Sourcepub fn map_pack(&mut self, pairs: &[(Reg, Reg)]) -> Reg
pub fn map_pack(&mut self, pairs: &[(Reg, Reg)]) -> Reg
Pack pairs into a map. Each pair is (key, value) already in
registers. Keys are Int or Str. At most 32 pairs.
pub fn map_get(&mut self, map: Reg, key: Reg) -> Reg
pub fn map_len(&mut self, map: Reg) -> Reg
Sourcepub fn table_open(&mut self, name: Reg) -> Reg
pub fn table_open(&mut self, name: Reg) -> Reg
Open this flow’s table and return its Cap (SEND and RECV).
Sourcepub fn table_get(&mut self, table: Reg, key: Reg) -> Reg
pub fn table_get(&mut self, table: Reg, key: Reg) -> Reg
Read key from table. Missing key yields Unit.
pub fn sub(&mut self, lhs: Reg, rhs: Reg) -> Reg
pub fn mul(&mut self, lhs: Reg, rhs: Reg) -> Reg
pub fn div(&mut self, lhs: Reg, rhs: Reg) -> Reg
pub fn modulo(&mut self, lhs: Reg, rhs: Reg) -> Reg
pub fn neg(&mut self, src: Reg) -> Reg
pub fn eq(&mut self, lhs: Reg, rhs: Reg) -> Reg
Sourcepub fn eq_imm(&mut self, lhs: Reg, imm: i32) -> Reg
pub fn eq_imm(&mut self, lhs: Reg, imm: i32) -> Reg
lhs == imm as Bool, in a fresh local. One Opcode::EqImm.
The immediate is an Int. A float in lhs compares unequal.
pub fn lt(&mut self, lhs: Reg, rhs: Reg) -> Reg
pub fn le(&mut self, lhs: Reg, rhs: Reg) -> Reg
Sourcepub fn while_lt<F>(&mut self, counter: Reg, limit: Reg, body: F)
pub fn while_lt<F>(&mut self, counter: Reg, limit: Reg, body: F)
While counter < limit (interpreter Branch skips on falsy).
pub fn label(&mut self) -> Label
pub fn bind(&mut self, label: Label)
pub fn move_reg(&mut self, dst: Reg, src: Reg)
pub fn jump(&mut self, label: Label)
Sourcepub fn branch_if_falsy(&mut self, cond: Reg, target: Label)
pub fn branch_if_falsy(&mut self, cond: Reg, target: Label)
Branch when cond is falsy (0).
pub fn return_(&mut self, value: Reg)
Sourcepub fn call(&mut self, function: FuncId, args: &[Reg]) -> Reg
pub fn call(&mut self, function: FuncId, args: &[Reg]) -> Reg
Call function with args packed into a fresh Call window.
The ISA reads r[dst .. dst+argc] and writes the result to r[dst].
This copies args into that window so call(fn, &[a, b]) after
load_i32 actually passes those values — a bare argc does not.
pub fn halt(&mut self)
pub fn yield_(&mut self)
pub fn sleep(&mut self, millis: Reg)
pub fn exit(&mut self, reg: Reg)
Sourcepub fn self_cap(&mut self) -> Reg
pub fn self_cap(&mut self) -> Reg
Self Cap (CapRights::ADDRESSING:
SEND|ASK|LINK|MONITOR for this flow).
Despite the opcode name (SelfPid), the value is a crate::Value::Cap,
not a Pid. In BEAM terms this is closer to a reply address grant
than to self() — use Self::hop_sender on a delivered hop for
authenticated origin identity.
Sourcepub fn self_address(&mut self) -> Reg
pub fn self_address(&mut self) -> Reg
Alias for Self::self_cap — preferred name when coming from BEAM.
Sourcepub fn spawn(&mut self, function: FuncId, args: &[Reg]) -> Reg
pub fn spawn(&mut self, function: FuncId, args: &[Reg]) -> Reg
Spawn function with args packed into r[cap+1 .. cap+1+argc].
The ISA writes the child Cap into r[cap] and reads arguments from
the following slots — not from the registers you just load_*’d.
This allocates that window and copies args into it.
Sourcepub fn spawn_with_rights(
&mut self,
function: FuncId,
args: &[Reg],
rights: CapRights,
) -> Reg
pub fn spawn_with_rights( &mut self, function: FuncId, args: &[Reg], rights: CapRights, ) -> Reg
Spawn a child that receives only rights ⊆ parent authority.
Sourcepub fn spawn_confined(&mut self, function: FuncId, args: &[Reg]) -> Reg
pub fn spawn_confined(&mut self, function: FuncId, args: &[Reg]) -> Reg
Spawn with rights = NONE (confined by default).
Sourcepub fn spawn_at(&mut self, dst: Reg, function: FuncId, argc: u8)
pub fn spawn_at(&mut self, dst: Reg, function: FuncId, argc: u8)
Spawn into an explicit destination. Args must already sit in
r[dst+1 .. dst+1+argc] (see Self::window). Prefer Self::spawn.
Sourcepub fn spawn_at_with_rights(
&mut self,
dst: Reg,
function: FuncId,
argc: u8,
rights: CapRights,
)
pub fn spawn_at_with_rights( &mut self, dst: Reg, function: FuncId, argc: u8, rights: CapRights, )
Spawn into dst with an explicit rights mask. Same packing contract
as Self::spawn_at.
Sourcepub fn delegate(&mut self, src: Reg, rights: CapRights) -> Reg
pub fn delegate(&mut self, src: Reg, rights: CapRights) -> Reg
Attenuate src into a new Cap (rights mask is an immediate).
Native mask is unchanged (Delegate.c = 255).
Sourcepub fn delegate_with_native(
&mut self,
src: Reg,
rights: CapRights,
native_cap: Reg,
) -> Reg
pub fn delegate_with_native( &mut self, src: Reg, rights: CapRights, native_cap: Reg, ) -> Reg
Like Self::delegate, but AND the native mask from native_cap
(Delegate.c is that register, not 255). native_cap must carry
crate::CapRights::NATIVE.
pub fn send(&mut self, target_cap: Reg, msg: Reg)
Sourcepub fn cast(&mut self, target_cap: Reg, msg: Reg)
pub fn cast(&mut self, target_cap: Reg, msg: Reg)
Fire-and-forget hop (BEAM ! / gen_server:cast).
pub fn receive(&mut self) -> Reg
pub fn receive_timeout(&mut self, millis: Reg) -> Reg
pub fn receive_match(&mut self, tag: Reg) -> Reg
pub fn receive_match_imm(&mut self, tag: u16) -> Reg
Sourcepub fn receive_match_timeout(&mut self, tag: Reg, millis: Reg) -> Reg
pub fn receive_match_timeout(&mut self, tag: Reg, millis: Reg) -> Reg
Selective receive with BEAM after: Unit if millis elapses first.
Sourcepub fn receive_match_imm_timeout(&mut self, tag: u16, millis: Reg) -> Reg
pub fn receive_match_imm_timeout(&mut self, tag: u16, millis: Reg) -> Reg
Immediate-tag selective receive with BEAM after.
Sourcepub fn exit_signal(&mut self, cap: Reg, reason: Reg)
pub fn exit_signal(&mut self, cap: Reg, reason: Reg)
BEAM exit/2. reason is a crate::FlowExitReason as Int (0..=6).
Needs LINK on cap. Normal does nothing. Killed ignores trap_exit.
Sourcepub fn dict_put(&mut self, key: Reg, value: Reg) -> Reg
pub fn dict_put(&mut self, key: Reg, value: Reg) -> Reg
Process dictionary put/2. Returns the previous value or Unit.
The value is a scalar, Str, or Bytes. Heap values stay charged
after the source register is overwritten.
Sourcepub fn dict_erase(&mut self, key: Reg) -> Reg
pub fn dict_erase(&mut self, key: Reg) -> Reg
Process dictionary erase/1. Returns the removed value or Unit.
Sourcepub fn receive_match_cmp(&mut self, tag: Reg, bound: Reg, cmp: IntCmp) -> Reg
pub fn receive_match_cmp(&mut self, tag: Reg, bound: Reg, cmp: IntCmp) -> Reg
Selective receive: tag and an Int payload compared with bound.
Eq, Lt, and Le use signed integers. A hop whose payload is not
that Int, or that fails the comparison, stays in the mailbox.
Sourcepub fn receive_match_eq(&mut self, tag: Reg, payload: Reg) -> Reg
pub fn receive_match_eq(&mut self, tag: Reg, payload: Reg) -> Reg
Selective receive: application tag and Int payload equality.
Sourcepub fn receive_match_value(&mut self, tag: Reg, payload: Reg) -> Reg
pub fn receive_match_value(&mut self, tag: Reg, payload: Reg) -> Reg
Selective receive: tag and structural equality with payload.
payload may be any value (Str, Bytes, Bool, Float, nested
hop). Non-matching hops stay queued.
Sourcepub fn send_remote(&mut self, node: Reg, name: Reg, msg: Reg)
pub fn send_remote(&mut self, node: Reg, name: Reg, msg: Reg)
Deliver msg to name on node via crate::DistributionBridge.
Sourcepub fn start_supervisor(&mut self, strategy: RestartStrategy)
pub fn start_supervisor(&mut self, strategy: RestartStrategy)
Start a supervisor for this flow. Later Self::start_child attaches
to it. strategy is one-for-one, one-for-all, or rest-for-one.
Sourcepub fn start_child(&mut self, function: FuncId, policy: RestartPolicy) -> Reg
pub fn start_child(&mut self, function: FuncId, policy: RestartPolicy) -> Reg
OTP child of this flow’s supervisor. Caller must have been started
by crate::Supervisor. policy is Always / OnFailure / Never.
Sourcepub fn actor_loop(&mut self, tag: u16, body: impl FnMut(&mut Self, Reg))
pub fn actor_loop(&mut self, tag: u16, body: impl FnMut(&mut Self, Reg))
Server loop: receive_match_imm(tag) → body → jump back.
Sourcepub fn fresh_request_id(&mut self) -> Reg
pub fn fresh_request_id(&mut self) -> Reg
Next per-flow correlation id (Int, starts at 1).
Sourcepub fn receive_match_corr(&mut self, tag: Reg, request_id: Reg) -> Reg
pub fn receive_match_corr(&mut self, tag: Reg, request_id: Reg) -> Reg
Wait for tag == tag_reg and request_id == id_reg (FIFO skip).
Sourcepub fn receive_match_corr_imm(&mut self, tag: u16, request_id: Reg) -> Reg
pub fn receive_match_corr_imm(&mut self, tag: u16, request_id: Reg) -> Reg
Wait for immediate tag and request_id == id_reg (FIFO skip).
Sourcepub fn receive_match_kind(&mut self, kind: u8) -> Reg
pub fn receive_match_kind(&mut self, kind: u8) -> Reg
Wait for a hop whose payload.wire_tag() == kind (0..=10, FIFO skip).
Sourcepub fn hop_fresh(&mut self, tag: i32, payload: Reg) -> Reg
pub fn hop_fresh(&mut self, tag: i32, payload: Reg) -> Reg
Build a hop with a freshly minted request_id.
The id is written straight into the make_msg window, so the usual
copy from a temporary register is not emitted.
Sourcepub fn ask(&mut self, target_cap: Reg, msg: Reg) -> Reg
pub fn ask(&mut self, target_cap: Reg, msg: Reg) -> Reg
RPC hop: deliver msg to target_cap, wait for correlated reply.
If the target exits first, dest is a crate::TAG_SYS_EXIT hop
(not a hang).
Sourcepub fn ask_timeout(&mut self, target_cap: Reg, msg: Reg, millis: Reg) -> Reg
pub fn ask_timeout(&mut self, target_cap: Reg, msg: Reg, millis: Reg) -> Reg
Like Self::ask, but writes Unit into the dest if millis elapses.
Sourcepub fn monitor(&mut self, target_cap: Reg) -> Reg
pub fn monitor(&mut self, target_cap: Reg) -> Reg
One-way watch: when the flow addressed by target_cap exits, this
flow receives a crate::TAG_SYS_DOWN hop. Returns a monitor ref (Int).
pub fn demonitor(&mut self, monitor: Reg)
Sourcepub fn link(&mut self, target_cap: Reg) -> Reg
pub fn link(&mut self, target_cap: Reg) -> Reg
Bidirectional link: without trap_exit, abnormal exit of either side
kills the peer. With Self::set_trap_exit on a peer, that peer gets
crate::TAG_SYS_EXIT hops instead (including Normal).
pub fn unlink(&mut self, link: Reg)
Sourcepub fn set_trap_exit(&mut self, enabled: Reg)
pub fn set_trap_exit(&mut self, enabled: Reg)
BEAM process_flag(trap_exit, enabled). Truthy enabled converts
linked exits into crate::TAG_SYS_EXIT hops (including Normal)
instead of killing this flow / silently dropping the link.
Sourcepub fn set_restart_policy(&mut self, policy: RestartPolicy)
pub fn set_restart_policy(&mut self, policy: RestartPolicy)
Set this flow’s supervisor restart policy (bytecode slice of OTP
child_spec restart). Takes effect for the current incarnation;
the dying flow’s policy is what the supervisor consults on exit.
Sourcepub fn host_await(&mut self, op: u32, args: Reg) -> Reg
pub fn host_await(&mut self, op: u32, args: Reg) -> Reg
Register a host operation and return the register that holds its ticket (Int).
op is an opaque host discriminator (imm). args is a single
crate::Value handed to the bridge. The flow keeps running. The
host’s result arrives later as a crate::TAG_SYS_AWAIT hop
(request_id = ticket); read it with Self::receive.
Sourcepub fn load_bytes(&mut self, bytes: impl AsRef<[u8]>) -> Reg
pub fn load_bytes(&mut self, bytes: impl AsRef<[u8]>) -> Reg
Load a byte-buffer constant into a new local.
Sourcepub fn register_name(&mut self, name: Reg)
pub fn register_name(&mut self, name: Reg)
Publish name (Str) as this flow. Requires SEND on self-authority.
Sourcepub fn whereis(&mut self, name: Reg) -> Reg
pub fn whereis(&mut self, name: Reg) -> Reg
Look up name (Str): SEND Cap for the caller, or Unit.
pub fn trap(&mut self, code: i32)
Sourcepub fn native1_from(&mut self, src: Reg, native: u32) -> Reg
pub fn native1_from(&mut self, src: Reg, native: u32) -> Reg
Copy src, call a one-arg native, return the result in a new local.
The source register is preserved (CallNative clobbers its argument slot).
Sourcepub fn native1_on(&mut self, src: Reg, native: u32)
pub fn native1_on(&mut self, src: Reg, native: u32)
Side-effect native on a copy of src (e.g. print).
Sourcepub fn native_n(&mut self, base: Reg, native: u32, argc: u8)
pub fn native_n(&mut self, base: Reg, native: u32, argc: u8)
CallNative with argc args already at base..base+argc.
Sourcepub fn call_native(&mut self, base: Reg, native: u32, argc: u8)
pub fn call_native(&mut self, base: Reg, native: u32, argc: u8)
Call a native with argc args already in base..base+argc.
Sourcepub fn call_native0(&mut self, native: u32) -> Reg
pub fn call_native0(&mut self, native: u32) -> Reg
Call a zero-arg native; returns the result register.
Sourcepub fn hop(&mut self, request_id: Reg, tag: i32, payload: Reg) -> Reg
pub fn hop(&mut self, request_id: Reg, tag: i32, payload: Reg) -> Reg
Build an outgoing Atomic Hop (request_id, tag, payload).
The scheduler overwrites sender and attaches reply_cap on Self::send
/ Self::ask. Prefer Self::hop_fresh so request_id is unique.
Do not forge a sender (see crate::docs::security).
Sourcepub fn hop_sender(&mut self, msg: Reg) -> Reg
pub fn hop_sender(&mut self, msg: Reg) -> Reg
Extract authenticated origin from a delivered hop (Value::Pid).
pub fn hop_request_id(&mut self, msg: Reg) -> Reg
pub fn hop_tag(&mut self, msg: Reg) -> Reg
pub fn hop_payload(&mut self, msg: Reg) -> Reg
Sourcepub fn hop_reply_cap(&mut self, msg: Reg) -> Reg
pub fn hop_reply_cap(&mut self, msg: Reg) -> Reg
Reply address grant minted for the original sender (Value::Cap).
Sourcepub fn reply_to(&mut self, req: Reg, tag: i32, payload: Reg) -> Reg
pub fn reply_to(&mut self, req: Reg, tag: i32, payload: Reg) -> Reg
Build a reply hop echoing request_id from req.
Sourcepub fn send_reply(&mut self, req: Reg, tag: i32, payload: Reg)
pub fn send_reply(&mut self, req: Reg, tag: i32, payload: Reg)
Reply to req via its reply_cap (typical server pattern).
Sourcepub fn make_msg(
&mut self,
native_index: u32,
request_id: Reg,
tag: i32,
payload: Reg,
) -> Reg
pub fn make_msg( &mut self, native_index: u32, request_id: Reg, tag: i32, payload: Reg, ) -> Reg
Build a Value::Message via make_msg at native_index.
There is no sender operand — the scheduler stamps identity on Send.
A 4-arg legacy encoding is still accepted by the native (first arg
discarded) so forged-sender regressions keep compiling.