mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-06-18 01:11:49 +00:00
Pass state in ExecutionParams
This commit is contained in:
@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user