expose custom params for new program

This commit is contained in:
NikVolf
2017-05-30 17:15:36 +03:00
parent c3821d5833
commit d981bf4803
2 changed files with 24 additions and 16 deletions

View File

@ -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.