Pass state in ExecutionParams

This commit is contained in:
Sergey Pepyakin
2017-12-11 16:38:52 +01:00
parent 5920cd93d5
commit 8588899f82
4 changed files with 29 additions and 19 deletions

View File

@ -20,9 +20,12 @@ const DEFAULT_FRAME_STACK_LIMIT: usize = 1024;
/// Execution context.
#[derive(Clone)]
pub struct ExecutionParams {
pub struct ExecutionParams<St: 'static> {
/// Arguments.
pub args: Vec<RuntimeValue>,
/// State that can be used by host functions,
pub state: St,
}
/// Export type.
@ -76,7 +79,7 @@ pub struct InternalFunction<'a> {
pub labels: &'a HashMap<usize, usize>,
}
impl ExecutionParams {
impl<St> ExecutionParams<St> {
/// Add argument.
pub fn add_argument(mut self, arg: RuntimeValue) -> Self {
self.args.push(arg);
@ -84,18 +87,20 @@ impl ExecutionParams {
}
}
impl Default for ExecutionParams {
impl<St: Default> Default for ExecutionParams<St> {
fn default() -> Self {
ExecutionParams {
args: Vec::default(),
state: St::default(),
}
}
}
impl<'a> From<Vec<RuntimeValue>> for ExecutionParams {
fn from(args: Vec<RuntimeValue>) -> ExecutionParams {
impl<'a, St: Default> From<Vec<RuntimeValue>> for ExecutionParams<St> {
fn from(args: Vec<RuntimeValue>) -> ExecutionParams<St> {
ExecutionParams {
args: args
args: args,
state: St::default(),
}
}
}