use crate::error::Error;
use sp_wasm_interface::Value;
pub use sc_allocator::AllocationStats;
pub enum InvokeMethod<'a> {
Export(&'a str),
Table(u32),
TableWithWrapper {
dispatcher_ref: u32,
func: u32,
},
}
impl<'a> From<&'a str> for InvokeMethod<'a> {
fn from(val: &'a str) -> InvokeMethod<'a> {
InvokeMethod::Export(val)
}
}
pub trait WasmModule: Sync + Send {
fn new_instance(&self) -> Result<Box<dyn WasmInstance>, Error>;
}
pub trait WasmInstance: Send {
fn call(&mut self, method: InvokeMethod, data: &[u8]) -> Result<Vec<u8>, Error> {
self.call_with_allocation_stats(method, data).0
}
fn call_with_allocation_stats(
&mut self,
method: InvokeMethod,
data: &[u8],
) -> (Result<Vec<u8>, Error>, Option<AllocationStats>);
fn call_export(&mut self, method: &str, data: &[u8]) -> Result<Vec<u8>, Error> {
self.call(method.into(), data)
}
fn get_global_const(&mut self, name: &str) -> Result<Option<Value>, Error>;
fn linear_memory_base_ptr(&self) -> Option<*const u8> {
None
}
}
#[derive(Debug, Copy, Clone, PartialEq, Hash, Eq)]
pub enum HeapAllocStrategy {
Static {
extra_pages: u32,
},
Dynamic {
maximum_pages: Option<u32>,
},
}