pub use crate::{
func::HostFuncType,
value::{Type, Value},
Result,
};
use ceres_std::Vec;
pub type HostCall<M, F, T> = (M, F, HostFuncType<T>);
pub type SealCall<T> = HostCall<&'static str, &'static str, T>;
pub trait Memory: Sized + Clone {
fn new(initial: u32, maximum: Option<u32>) -> Result<Self>;
fn get(&self, ptr: u32, buf: &mut [u8]) -> Result<()>;
fn set(&self, ptr: u32, value: &[u8]) -> Result<()>;
}
pub trait Instance<T>: Sized {
type Builder: Builder<T>;
fn new(code: &[u8], builder: &Self::Builder, state: &mut T) -> Result<Self>;
fn invoke(&mut self, name: &str, args: &[Value], state: &mut T) -> Result<Value>;
fn get_global_val(&self, name: &str) -> Option<Value>;
}
pub trait Builder<T>: Sized {
type Memory: Memory;
fn new() -> Self;
fn add_host_func<M, F>(&mut self, module: M, field: F, f: HostFuncType<T>)
where
F: Into<Vec<u8>>,
M: Into<Vec<u8>>;
fn add_memory<M, F>(&mut self, module: M, field: F, mem: Self::Memory)
where
M: Into<Vec<u8>>,
F: Into<Vec<u8>>;
}