mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-06-21 18:51:52 +00:00
expose custom params for new program
This commit is contained in:
@ -3,7 +3,7 @@ use std::collections::HashMap;
|
||||
use parking_lot::RwLock;
|
||||
use elements::Module;
|
||||
use interpreter::Error;
|
||||
use interpreter::env::env_module;
|
||||
use interpreter::env::{self, env_module};
|
||||
use interpreter::module::{ModuleInstance, ModuleInstanceInterface};
|
||||
|
||||
/// Program instance. Program is a set of instantiated modules.
|
||||
@ -21,8 +21,13 @@ pub struct ProgramInstanceEssence {
|
||||
impl ProgramInstance {
|
||||
/// Create new program instance.
|
||||
pub fn new() -> Result<Self, Error> {
|
||||
ProgramInstance::with_env_params(env::EnvParams::default())
|
||||
}
|
||||
|
||||
/// Create new program instance with custom env module params (mostly memory)
|
||||
pub fn with_env_params(params: env::EnvParams) -> Result<Self, Error> {
|
||||
Ok(ProgramInstance {
|
||||
essence: Arc::new(ProgramInstanceEssence::new()?),
|
||||
essence: Arc::new(ProgramInstanceEssence::with_env_params(params)?),
|
||||
})
|
||||
}
|
||||
|
||||
@ -43,12 +48,16 @@ impl ProgramInstance {
|
||||
impl ProgramInstanceEssence {
|
||||
/// Create new program essence.
|
||||
pub fn new() -> Result<Self, Error> {
|
||||
ProgramInstanceEssence::with_env_params(env::EnvParams::default())
|
||||
}
|
||||
|
||||
pub fn with_env_params(env_params: env::EnvParams) -> Result<Self, Error> {
|
||||
let mut modules = HashMap::new();
|
||||
let env_module: Arc<ModuleInstanceInterface> = Arc::new(env_module()?);
|
||||
let env_module: Arc<ModuleInstanceInterface> = Arc::new(env_module(env_params)?);
|
||||
modules.insert("env".into(), env_module);
|
||||
Ok(ProgramInstanceEssence {
|
||||
modules: RwLock::new(modules),
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/// Get module reference.
|
||||
|
Reference in New Issue
Block a user