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.

Examples found in repository?
examples/throughput.rs (line 14)
11fn trivial_chunk() -> byteflow::Chunk {
12    let mut program = Program::new("throughput");
13    program.function("worker", 0, |f| {
14        let one = f.load_i32(1);
15        f.return_(one);
16    });
17    program.build()
18}
More examples
Hide additional examples
examples/jit_loop.rs (line 15)
11fn loop_chunk(iterations: i32) -> byteflow::Chunk {
12    let mut program = Program::new("jit-loop");
13    program.function("main", 0, |f| {
14        let limit = f.load_int(i64::from(iterations));
15        let counter = f.load_i32(0);
16        f.while_lt(counter, limit, |f| f.add_imm(counter, 1));
17        f.return_(counter);
18    });
19    program.build()
20}
Source

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

Load a constant-pool integer into a new local.

Examples found in repository?
examples/jit_loop.rs (line 14)
11fn loop_chunk(iterations: i32) -> byteflow::Chunk {
12    let mut program = Program::new("jit-loop");
13    program.function("main", 0, |f| {
14        let limit = f.load_int(i64::from(iterations));
15        let counter = f.load_i32(0);
16        f.while_lt(counter, limit, |f| f.add_imm(counter, 1));
17        f.return_(counter);
18    });
19    program.build()
20}
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.

Examples found in repository?
examples/jit_loop.rs (line 16)
11fn loop_chunk(iterations: i32) -> byteflow::Chunk {
12    let mut program = Program::new("jit-loop");
13    program.function("main", 0, |f| {
14        let limit = f.load_int(i64::from(iterations));
15        let counter = f.load_i32(0);
16        f.while_lt(counter, limit, |f| f.add_imm(counter, 1));
17        f.return_(counter);
18    });
19    program.build()
20}
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).

Examples found in repository?
examples/jit_loop.rs (line 16)
11fn loop_chunk(iterations: i32) -> byteflow::Chunk {
12    let mut program = Program::new("jit-loop");
13    program.function("main", 0, |f| {
14        let limit = f.load_int(i64::from(iterations));
15        let counter = f.load_i32(0);
16        f.while_lt(counter, limit, |f| f.add_imm(counter, 1));
17        f.return_(counter);
18    });
19    program.build()
20}
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)

Examples found in repository?
examples/throughput.rs (line 15)
11fn trivial_chunk() -> byteflow::Chunk {
12    let mut program = Program::new("throughput");
13    program.function("worker", 0, |f| {
14        let one = f.load_i32(1);
15        f.return_(one);
16    });
17    program.build()
18}
More examples
Hide additional examples
examples/jit_loop.rs (line 17)
11fn loop_chunk(iterations: i32) -> byteflow::Chunk {
12    let mut program = Program::new("jit-loop");
13    program.function("main", 0, |f| {
14        let limit = f.load_int(i64::from(iterations));
15        let counter = f.load_i32(0);
16        f.while_lt(counter, limit, |f| f.add_imm(counter, 1));
17        f.return_(counter);
18    });
19    program.build()
20}
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 (SEND / ASK target 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_at(&mut self, dst: Reg, function: FuncId, argc: u8)

Spawn into an explicit destination register (e.g. reg(255)).

Source

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

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 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: abnormal exit of either side kills the peer.

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 mints reply_cap on Self::send / Self::ask — 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, sender: Reg, request_id: Reg, tag: i32, payload: Reg, ) -> Reg

Build a Value::Message via make_msg at native_index.

Prefer Self::hop for outgoing messages. This low-level helper keeps the explicit sender slot for security regressions and legacy bytecode. Index 2 in crate::std_native_map. Args are packed into a contiguous four-register window; returns the message register.

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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, <T as TryFrom<U>>::Error>

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.