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
impl Interpreter
Sourcepub fn mem_set_i32(
&mut self,
id: MemoryId,
address: u64,
value: i32,
) -> Result<()>
pub fn mem_set_i32( &mut self, id: MemoryId, address: u64, value: i32, ) -> Result<()>
Set the value
Sourcepub fn add_function(
&mut self,
name: impl AsRef<str>,
func: impl FnMut(&mut Interpreter, &[Value]) -> Result<Vec<Value>> + 'static,
)
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.
Sourcepub fn set_interrupt_handler(
&mut self,
handler: impl FnMut(&mut Interpreter, &Instr, (FunctionId, InstrSeqId, usize)) -> Result<()> + 'static,
)
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
Sourcepub fn set_interrupt_handler_mem(
&mut self,
handler: impl FnMut(&mut Interpreter, &Instr, (FunctionId, InstrSeqId, usize), (MemoryId, u64, Value, MemoryAccessType)) -> Result<()> + 'static,
)
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.
Sourcepub fn call_interrupt_handler(
&mut self,
instr: &Instr,
id: (FunctionId, InstrSeqId, usize),
) -> Result<()>
pub fn call_interrupt_handler( &mut self, instr: &Instr, id: (FunctionId, InstrSeqId, usize), ) -> Result<()>
Call the interrupt handler. This will call the interrupt handler
Sourcepub fn call_interrupt_handler_mem(
&mut self,
instr: &Instr,
id: (FunctionId, InstrSeqId, usize),
mem: (MemoryId, u64, Value, MemoryAccessType),
) -> Result<()>
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