Skip to main content

Program

Struct Program 

Source
pub struct Program {
    pub chunks: Vec<Chunk>,
    pub main_index: usize,
    pub globals: Vec<String>,
    pub fn_names: Vec<String>,
    pub enum_variant_names: Vec<(String, String)>,
    pub structs: Vec<StructInfo>,
}
Expand description

a whole compiled program: one chunk per function, with the entry-point index and a globals table.

function indexes in CALL opcodes are indexes into Program::chunks; matching name lookups for the disassembler are in Program::fn_names. enum variant ids in MAKE_ENUM_VARIANT and MATCH_VARIANT are indexes into Program::enum_variant_names. struct ids in MAKE_STRUCT are indexes into Program::structs.

Fields§

§chunks: Vec<Chunk>

one chunk per function, indexed by function id (u16 in CALL operands).

§main_index: usize

the chunks index where execution starts. Phase 4 codegen sets this to the index of the main function.

§globals: Vec<String>

global names indexed by GET_GLOBAL / SET_GLOBAL u16 operands. v1 has no top-level let so this is empty in practice – kept for forward compatibility.

§fn_names: Vec<String>

function names parallel to chunks – the disassembler renders CALL #fn_id(name).

§enum_variant_names: Vec<(String, String)>

(enum_name, variant_name) pairs indexed by MAKE_ENUM_VARIANT / MATCH_VARIANT u16 operands. the disassembler renders #variant_id(Enum::Variant).

§structs: Vec<StructInfo>

one StructInfo per declared struct, indexed by MAKE_STRUCT u16 operands. records each struct’s name and field count so the VM can build a heap struct with the right type_name and pop the right number of fields. Program::default() gives an empty vec.

Implementations§

Source§

impl Program

Source

pub fn new() -> Self

construct an empty program. all vectors start empty; main_index defaults to 0.

Source

pub fn disassemble(&self) -> String

produce the human-readable listing for the whole program: one header line per chunk followed by the chunk’s body. byte- deterministic across runs by construction (iterates chunks in index order; no HashMap iteration). the format matches the locked playground bytecode-panel contract.

Source

pub fn optimize(&mut self)

run the peephole optimizer over every chunk in this program. invokes crate::optimizer::peephole. idempotent: a second call does no work, because the first pass already collapsed every matchable instruction window.

optimization is opt-in – the disassembler can show un-optimized bytecode by skipping this call, which supports the playground’s “show me what the compiler did” use case.

Trait Implementations§

Source§

impl Clone for Program

Source§

fn clone(&self) -> Program

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 Program

Source§

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

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

impl Default for Program

Source§

fn default() -> Program

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

Auto Trait Implementations§

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> 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
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> 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 = Infallible

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

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more