pub struct Interpreter { /* private fields */ }
Expand description

A ready-to-go interpreter of a wasm module.

An interpreter currently represents effectively cached state. It is reused between calls to interpret and is precomputed from a Module. It houses state like the wasm stack, wasm memory, etc.

Implementations§

source§

impl Interpreter

source

pub fn new(module: &Module) -> Result<Interpreter, Error>

Creates a new interpreter from a provided Module, precomputing all information necessary to interpret further.

Note that the module passed in to this function must be the same as the module passed to interpret below.

source

pub fn interpret_descriptor( &mut self, id: FunctionId, module: &Module ) -> Option<&[u32]>

Interprets the execution of the descriptor function func.

This function will execute func in the module provided. Note that the module provided here must be the same as the one passed to new when this Interpreter was constructed.

The func must be a wasm-bindgen descriptor function meaning that it doesn’t do anything like use floats or i64. Instead all it should do is call other functions, sometimes some stack pointer manipulation, and then call the one imported __wbindgen_describe function. Anything else will cause this interpreter to panic.

When the descriptor has finished running the assembled descriptor list is returned. The descriptor returned can then be re-parsed into an actual Descriptor in the cli-support crate.

§Return value

Returns Some if func was found in the module and None if it was not found in the module.

source

pub fn interpret_closure_descriptor( &mut self, id: FunctionId, module: &Module, entry_removal_list: &mut HashSet<(ElementId, usize)> ) -> Option<&[u32]>

Interprets a “closure descriptor”, figuring out the signature of the closure that was intended.

This function will take an id which is known to internally execute __wbindgen_describe_closure and interpret it. The wasm-bindgen crate controls all callers of this internal import. It will then take the index passed to __wbindgen_describe_closure and interpret it as a function pointer. This means it’ll look up within the element section (function table) which index it points to. Upon finding the relevant entry it’ll assume that function is a descriptor function, and then it will execute the descriptor function.

The returned value is the return value of the descriptor function found. The entry_removal_list list is also then populated with an index of the entry in the elements section (and then the index within that section) of the function that needs to be snip’d out.

source

pub fn describe_closure_id(&self) -> Option<FunctionId>

Returns the function id of the __wbindgen_describe_closure imported function.

source

pub fn function_table_id(&self) -> Option<TableId>

Returns the detected id of the function table.

Trait Implementations§

source§

impl Default for Interpreter

source§

fn default() -> Interpreter

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> 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>,

§

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>,

§

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.