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.

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.

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

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 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, argc: u8) -> Reg

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, argc: u8) -> Reg

Source

pub fn spawn_with_rights( &mut self, function: FuncId, argc: u8, rights: CapRights, ) -> Reg

Spawn a child that receives only rights ⊆ parent authority.

Source

pub fn spawn_confined(&mut self, function: FuncId, argc: u8) -> 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 register (e.g. reg(255)).

Source

pub fn delegate(&mut self, src: Reg, rights: CapRights) -> Reg

Attenuate src into a new Cap (rights mask is an immediate).

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. Value must be a scalar (Unit, Bool, Int, Float).

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_eq(&mut self, tag: Reg, payload: Reg) -> Reg

Selective receive: application tag and Int payload equality.

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..=8, FIFO skip).

Source

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

Build a hop with a freshly minted request_id.

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

Park until the host crate::HostAwaitBridge completes.

op is an opaque host discriminator (imm). args is a single crate::Value handed to the bridge. On success the result is written into the returned register (Receive-style writeback).

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.