Skip to main content

Interpreter

Struct Interpreter 

Source
pub struct Interpreter {
    pub globals: BTreeMap<GlobalId, Value>,
    pub mem: BTreeMap<MemoryId, BTreeMap<usize, [u8; 4]>>,
    pub stack: Vec<Value>,
    pub tables: BTreeMap<TableId, Vec<FunctionId>>,
    pub memory_size: BTreeMap<MemoryId, usize>,
    /* 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.

Fields§

§globals: BTreeMap<GlobalId, Value>

The globals of the module. These are set up at the start of the module and are used to store the state of the module.

§mem: BTreeMap<MemoryId, BTreeMap<usize, [u8; 4]>>

The memory of the module. This is set up at the start of the module and is used to store the state of the module.

§stack: Vec<Value>

The stack of the module. This is set up at the start of the module and is used to store the state of the module.

§tables: BTreeMap<TableId, Vec<FunctionId>>

The tables of the module. These are set up at the start of the module and are used to store the state of the module.

§memory_size: BTreeMap<MemoryId, usize>

The size of the memory of the module. This is set up at the start of the module and is used to store the state of the module. pages per 64kiB

Implementations§

Source§

impl Interpreter

Source

pub fn new(module: &Module) -> Result<Self>

Create a new interpreter for a given module.

Source

pub fn mem_set_i32( &mut self, id: MemoryId, address: u64, value: i32, ) -> Result<()>

Set the value

Source

pub fn add_function( &mut self, name: impl AsRef<str>, func: impl FnMut(&mut Interpreter, &[Value]) -> Result<Vec<Value>> + 'static, )

Add a function to the interpreter. This function will be called whenever the interpreter encounters a call to it.

Source

pub fn set_interrupt_handler( &mut self, handler: impl FnMut(&mut Interpreter, &Instr, (FunctionId, InstrSeqId, usize)) -> Result<()> + 'static, )

Add a function to the interpreter. This function will be called

Source

pub fn set_interrupt_handler_mem( &mut self, handler: impl FnMut(&mut Interpreter, &Instr, (FunctionId, InstrSeqId, usize), (MemoryId, u64, Value, MemoryAccessType)) -> Result<()> + 'static, )

Add a function to the interpreter. This function will be called whenever the interpreter encounters a call to it.

Source

pub fn call_interrupt_handler( &mut self, instr: &Instr, id: (FunctionId, InstrSeqId, usize), ) -> Result<()>

Call the interrupt handler. This will call the interrupt handler

Source

pub fn call_interrupt_handler_mem( &mut self, instr: &Instr, id: (FunctionId, InstrSeqId, usize), mem: (MemoryId, u64, Value, MemoryAccessType), ) -> Result<()>

Call the interrupt handler. This will call the interrupt handler

Source

pub fn call( &mut self, id: FunctionId, module: &Module, args: &[Value], ) -> Result<Vec<Value>>

Call a function in the module with the given arguments.

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

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.