2018-01-05 17:52:29 +03:00
|
|
|
use elements::FunctionType;
|
|
|
|
use interpreter::value::RuntimeValue;
|
2017-12-11 16:28:05 +01:00
|
|
|
use interpreter::Error;
|
2017-12-11 19:22:45 +01:00
|
|
|
|
2018-01-05 17:52:29 +03:00
|
|
|
pub type HostFuncIndex = u32;
|
2017-12-15 18:23:54 +03:00
|
|
|
|
2018-01-05 17:52:29 +03:00
|
|
|
pub trait Externals {
|
|
|
|
fn invoke_index(
|
2017-12-18 16:37:48 +03:00
|
|
|
&mut self,
|
2018-01-05 17:52:29 +03:00
|
|
|
index: HostFuncIndex,
|
|
|
|
args: &[RuntimeValue],
|
|
|
|
) -> Result<Option<RuntimeValue>, Error>;
|
2017-12-12 15:18:35 +01:00
|
|
|
|
2018-01-05 17:52:29 +03:00
|
|
|
fn check_signature(&self, index: HostFuncIndex, signature: &FunctionType) -> bool;
|
2017-12-11 19:22:45 +01:00
|
|
|
}
|
|
|
|
|
2018-01-05 17:52:29 +03:00
|
|
|
pub struct EmptyExternals;
|
2017-12-14 15:33:40 +01:00
|
|
|
|
2018-01-05 17:52:29 +03:00
|
|
|
impl Externals for EmptyExternals {
|
|
|
|
fn invoke_index(
|
|
|
|
&mut self,
|
|
|
|
_index: HostFuncIndex,
|
|
|
|
_args: &[RuntimeValue],
|
|
|
|
) -> Result<Option<RuntimeValue>, Error> {
|
2018-01-08 19:07:23 +03:00
|
|
|
Err(Error::Trap("invoke index on empty externals".into()))
|
2017-12-14 15:33:40 +01:00
|
|
|
}
|
|
|
|
|
2018-01-05 17:52:29 +03:00
|
|
|
fn check_signature(&self, _index: HostFuncIndex, _signature: &FunctionType) -> bool {
|
2018-01-08 19:07:23 +03:00
|
|
|
false
|
2017-12-14 15:33:40 +01:00
|
|
|
}
|
2017-12-11 16:28:05 +01:00
|
|
|
}
|