Skip to main content

Fn

Struct Fn 

Source
pub struct Fn<'a> { /* private fields */ }
Expand description

Emit instructions for one bytecode function.

Implementations§

Source§

impl<'a> Fn<'a>

Source

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.

Source

pub fn reg(&mut self, index: u8) -> Reg

Bind to an explicit register index without growing the declared frame.

Source

pub fn reserve(&mut self, count: u8)

Ensure the register file is at least count slots wide.

Source

pub fn window(&mut self, count: u8) -> RegWindow

Allocate count contiguous locals; useful before Self::native_n.

Source

pub fn load_i32(&mut self, n: i32) -> Reg

Load a small immediate into a new local.

Source

pub fn load_int(&mut self, n: i64) -> Reg

Load a constant-pool integer into a new local.

Source

pub fn set(&mut self, reg: Reg, imm: i32)

Store an immediate into an existing register.

Source

pub fn mov(&mut self, dst: Reg, src: Reg)

dst = src

Source

pub fn add(&mut self, lhs: Reg, rhs: Reg) -> Reg

dst = lhs + rhs into a new local.

Source

pub fn add_imm(&mut self, dst: Reg, imm: i32)

dst += imm in place. One Opcode::AddImm, no scratch register.

Source

pub fn sub_imm(&mut self, dst: Reg, imm: i32)

dst -= imm in place. One Opcode::SubImm.

Source

pub fn lt_imm(&mut self, lhs: Reg, imm: i32) -> Reg

lhs < imm as Bool, in a fresh local. One Opcode::LtImm.

Source

pub fn mul_imm(&mut self, dst: Reg, imm: i32)

dst *= imm in place. One Opcode::MulImm. Integer multiply wraps.

Source

pub fn le_imm(&mut self, lhs: Reg, imm: i32) -> Reg

lhs <= imm as Bool, in a fresh local. One Opcode::LeImm.

Source

pub fn bit_and(&mut self, lhs: Reg, rhs: Reg) -> Reg

lhs & rhs into a new local. Both operands must be Int at runtime.

Source

pub fn bit_or(&mut self, lhs: Reg, rhs: Reg) -> Reg

lhs | rhs into a new local.

Source

pub fn bit_xor(&mut self, lhs: Reg, rhs: Reg) -> Reg

lhs ^ rhs into a new local.

Source

pub fn bit_not(&mut self, src: Reg) -> Reg

!src into a new local.

Source

pub fn shl(&mut self, lhs: Reg, rhs: Reg) -> Reg

lhs << rhs into a new local. The count keeps its low 6 bits.

Source

pub fn shr(&mut self, lhs: Reg, rhs: Reg) -> Reg

Arithmetic lhs >> rhs into a new local. The count keeps its low 6 bits.

Source

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.

Source

pub fn list_get(&mut self, list: Reg, index: i32) -> Reg

Source

pub fn list_len(&mut self, list: Reg) -> Reg

Source

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.

Source

pub fn map_get(&mut self, map: Reg, key: Reg) -> Reg

Source

pub fn map_len(&mut self, map: Reg) -> Reg

Source

pub fn table_open(&mut self, name: Reg) -> Reg

Open this flow’s table and return its Cap (SEND and RECV).

Source

pub fn table_get(&mut self, table: Reg, key: Reg) -> Reg

Read key from table. Missing key yields Unit.

Source

pub fn table_put(&mut self, table: Reg, key: Reg, value: Reg)

Store value at key in table.

Source

pub fn sub(&mut self, lhs: Reg, rhs: Reg) -> Reg

Source

pub fn mul(&mut self, lhs: Reg, rhs: Reg) -> Reg

Source

pub fn div(&mut self, lhs: Reg, rhs: Reg) -> Reg

Source

pub fn modulo(&mut self, lhs: Reg, rhs: Reg) -> Reg

Source

pub fn neg(&mut self, src: Reg) -> Reg

Source

pub fn eq(&mut self, lhs: Reg, rhs: Reg) -> Reg

Source

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.

Source

pub fn lt(&mut self, lhs: Reg, rhs: Reg) -> Reg

Source

pub fn le(&mut self, lhs: Reg, rhs: Reg) -> Reg

Source

pub fn while_lt<F>(&mut self, counter: Reg, limit: Reg, body: F)
where F: FnOnce(&mut Fn<'_>),

While counter < limit (interpreter Branch skips on falsy).

Source

pub fn label(&mut self) -> Label

Source

pub fn bind(&mut self, label: Label)

Source

pub fn move_reg(&mut self, dst: Reg, src: Reg)

Source

pub fn jump(&mut self, label: Label)

Source

pub fn branch_if_falsy(&mut self, cond: Reg, target: Label)

Branch when cond is falsy (0).

Source

pub fn return_(&mut self, value: Reg)

Source

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.

Source

pub fn halt(&mut self)

Source

pub fn yield_(&mut self)

Source

pub fn sleep(&mut self, millis: Reg)

Source

pub fn exit(&mut self, reg: Reg)

Source

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.

Source

pub fn self_address(&mut self) -> Reg

Alias for Self::self_cap — preferred name when coming from BEAM.

Source

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.

Source

pub fn spawn_with_rights( &mut self, function: FuncId, args: &[Reg], rights: CapRights, ) -> Reg

Spawn a child that receives only rights ⊆ parent authority.

Source

pub fn spawn_confined(&mut self, function: FuncId, args: &[Reg]) -> Reg

Spawn with rights = NONE (confined by default).

Source

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.

Source

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.

Source

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).

Source

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.

Source

pub fn send(&mut self, target_cap: Reg, msg: Reg)

Source

pub fn cast(&mut self, target_cap: Reg, msg: Reg)

Fire-and-forget hop (BEAM ! / gen_server:cast).

Source

pub fn receive(&mut self) -> Reg

Source

pub fn receive_timeout(&mut self, millis: Reg) -> Reg

Source

pub fn receive_match(&mut self, tag: Reg) -> Reg

Source

pub fn receive_match_imm(&mut self, tag: u16) -> Reg

Source

pub fn receive_match_timeout(&mut self, tag: Reg, millis: Reg) -> Reg

Selective receive with BEAM after: Unit if millis elapses first.

Source

pub fn receive_match_imm_timeout(&mut self, tag: u16, millis: Reg) -> Reg

Immediate-tag selective receive with BEAM after.

Source

pub fn is_alive(&mut self, cap: Reg) -> Reg

BEAM is_process_alive/1 for a Cap this flow holds.

Source

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.

Source

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.

Source

pub fn dict_get(&mut self, key: Reg) -> Reg

Process dictionary get/1. Missing key → Unit.

Source

pub fn dict_erase(&mut self, key: Reg) -> Reg

Process dictionary erase/1. Returns the removed value or Unit.

Source

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.

Source

pub fn receive_match_eq(&mut self, tag: Reg, payload: Reg) -> Reg

Selective receive: application tag and Int payload equality.

Source

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.

Source

pub fn send_remote(&mut self, node: Reg, name: Reg, msg: Reg)

Deliver msg to name on node via crate::DistributionBridge.

Source

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.

Source

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.

Source

pub fn actor_loop(&mut self, tag: u16, body: impl FnMut(&mut Self, Reg))

Server loop: receive_match_imm(tag) → body → jump back.

Source

pub fn fresh_request_id(&mut self) -> Reg

Next per-flow correlation id (Int, starts at 1).

Source

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).

Source

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).

Source

pub fn receive_match_kind(&mut self, kind: u8) -> Reg

Wait for a hop whose payload.wire_tag() == kind (0..=10, FIFO skip).

Source

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.

Source

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).

Source

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.

Source

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).

Source

pub fn demonitor(&mut self, monitor: 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).

Source

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.

Source

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.

Source

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.

Source

pub fn load_str(&mut self, s: impl AsRef<str>) -> Reg

Load a UTF-8 constant into a new local.

Source

pub fn load_bytes(&mut self, bytes: impl AsRef<[u8]>) -> Reg

Load a byte-buffer constant into a new local.

Source

pub fn register_name(&mut self, name: Reg)

Publish name (Str) as this flow. Requires SEND on self-authority.

Source

pub fn whereis(&mut self, name: Reg) -> Reg

Look up name (Str): SEND Cap for the caller, or Unit.

Source

pub fn trap(&mut self, code: i32)

Source

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).

Source

pub fn native1_on(&mut self, src: Reg, native: u32)

Side-effect native on a copy of src (e.g. print).

Source

pub fn native_n(&mut self, base: Reg, native: u32, argc: u8)

CallNative with argc args already at base..base+argc.

Source

pub fn call_native(&mut self, base: Reg, native: u32, argc: u8)

Call a native with argc args already in base..base+argc.

Source

pub fn call_native0(&mut self, native: u32) -> Reg

Call a zero-arg native; returns the result register.

Source

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).

Source

pub fn hop_sender(&mut self, msg: Reg) -> Reg

Extract authenticated origin from a delivered hop (Value::Pid).

Source

pub fn hop_request_id(&mut self, msg: Reg) -> Reg

Source

pub fn hop_tag(&mut self, msg: Reg) -> Reg

Source

pub fn hop_payload(&mut self, msg: Reg) -> Reg

Source

pub fn hop_reply_cap(&mut self, msg: Reg) -> Reg

Reply address grant minted for the original sender (Value::Cap).

Source

pub fn reply_to(&mut self, req: Reg, tag: i32, payload: Reg) -> Reg

Build a reply hop echoing request_id from req.

Source

pub fn send_reply(&mut self, req: Reg, tag: i32, payload: Reg)

Reply to req via its reply_cap (typical server pattern).

Source

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.

Source

pub fn make_msg_legacy_sender( &mut self, native_index: u32, sender: Reg, request_id: Reg, tag: i32, payload: Reg, ) -> Reg

Legacy 4-arg make_msg (sender slot is ignored by the native).

Auto Trait Implementations§

§

impl<'a> !UnwindSafe for Fn<'a>

§

impl<'a> Freeze for Fn<'a>

§

impl<'a> RefUnwindSafe for Fn<'a>

§

impl<'a> Send for Fn<'a>

§

impl<'a> Sync for Fn<'a>

§

impl<'a> Unpin for Fn<'a>

§

impl<'a> UnsafeUnpin for Fn<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.