Skip to main content

Chunk

Struct Chunk 

Source
pub struct Chunk {
    pub constants: Vec<Const>,
    pub code: Vec<u8>,
    pub functions: Vec<FuncMeta>,
    pub top_locals: u16,
}
Expand description

A compiled bytecode chunk — the unit of compilation and execution.

Fields§

§constants: Vec<Const>

Constant pool (strings, IRIs).

§code: Vec<u8>

Bytecode instructions.

§functions: Vec<FuncMeta>

User-defined function metadata.

§top_locals: u16

Module-level local count (for top-level execution).

Implementations§

Source§

impl Chunk

Source

pub fn new() -> Self

Create an empty chunk.

Source

pub fn add_string(&mut self, s: &str) -> u16

Add a string constant and return its index.

Source

pub fn add_iri(&mut self, s: &str) -> u16

Add an IRI constant and return its index.

Source

pub fn find_function(&self, name: &str) -> Option<u16>

Find a function by name. Returns its index in functions.

Source

pub fn current_offset(&self) -> u16

Current code offset (where the next instruction will be emitted).

Source

pub fn emit(&mut self, b: u8)

Emit a raw byte.

Source

pub fn emit_op(&mut self, op: Op)

Emit an opcode.

Source

pub fn emit_u16(&mut self, v: u16)

Emit a u16 operand (little-endian).

Source

pub fn emit_u8(&mut self, v: u8)

Emit a u8 operand.

Source

pub fn emit_i64(&mut self, v: i64)

Emit an i64 operand (little-endian).

Source

pub fn emit_u64(&mut self, v: u64)

Emit a u64 operand (little-endian).

Source

pub fn emit_f64(&mut self, v: f64)

Emit an f64 operand (little-endian bits).

Source

pub fn patch_u16(&mut self, offset: usize, value: u16)

Patch a u16 operand at the given code offset.

Trait Implementations§

Source§

impl Clone for Chunk

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Chunk

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Chunk

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Chunk

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Chunk

Auto Trait Implementations§

§

impl Freeze for Chunk

§

impl RefUnwindSafe for Chunk

§

impl Send for Chunk

§

impl Sync for Chunk

§

impl Unpin for Chunk

§

impl UnsafeUnpin for Chunk

§

impl UnwindSafe for Chunk

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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, !>

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

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,