inkpad_executor/
derive.rs1pub use crate::{
3 func::HostFuncType,
4 value::{Type, Value},
5 Result,
6};
7use inkpad_std::Vec;
8
9pub type HostCall<M, F, T> = (M, F, HostFuncType<T>);
11
12pub type SealCall<T> = HostCall<&'static str, &'static str, T>;
14
15pub trait Memory: Sized + Clone {
17 fn new(initial: u32, maximum: Option<u32>) -> Result<Self>;
19
20 fn get(&self, ptr: u32, buf: &mut [u8]) -> Result<()>;
22
23 fn set(&self, ptr: u32, value: &[u8]) -> Result<()>;
25}
26
27pub trait Instance<T>: Sized {
29 type Builder: Builder<T>;
30
31 fn new(code: &[u8], builder: &Self::Builder, state: &mut T) -> Result<Self>;
33
34 fn invoke(&mut self, name: &str, args: &[Value], state: &mut T) -> Result<Value>;
36
37 fn get_global_val(&self, name: &str) -> Option<Value>;
39}
40
41pub trait Builder<T>: Sized {
43 type Memory: Memory;
44
45 fn new() -> Self;
47
48 fn add_host_func<M, F>(&mut self, module: M, field: F, f: HostFuncType<T>)
50 where
51 F: Into<Vec<u8>>,
52 M: Into<Vec<u8>>;
53
54 fn add_memory<M, F>(&mut self, module: M, field: F, mem: Self::Memory)
56 where
57 M: Into<Vec<u8>>,
58 F: Into<Vec<u8>>;
59}