mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-06-22 11:11:54 +00:00
env module stub
This commit is contained in:
@ -4,7 +4,8 @@ use std::collections::hash_map::Entry;
|
||||
use parking_lot::RwLock;
|
||||
use elements::Module;
|
||||
use interpreter::Error;
|
||||
use interpreter::module::ModuleInstance;
|
||||
use interpreter::env::env_module;
|
||||
use interpreter::module::{ModuleInstance, ModuleInstanceInterface};
|
||||
|
||||
/// Program instance. Program is a set of instantiated modules.
|
||||
pub struct ProgramInstance {
|
||||
@ -15,15 +16,15 @@ pub struct ProgramInstance {
|
||||
/// Program instance essence.
|
||||
pub struct ProgramInstanceEssence {
|
||||
/// Loaded modules.
|
||||
modules: RwLock<HashMap<String, Arc<ModuleInstance>>>,
|
||||
modules: RwLock<HashMap<String, Arc<ModuleInstanceInterface>>>,
|
||||
}
|
||||
|
||||
impl ProgramInstance {
|
||||
/// Create new program instance.
|
||||
pub fn new() -> Self {
|
||||
ProgramInstance {
|
||||
essence: Arc::new(ProgramInstanceEssence::new()),
|
||||
}
|
||||
pub fn new() -> Result<Self, Error> {
|
||||
Ok(ProgramInstance {
|
||||
essence: Arc::new(ProgramInstanceEssence::new()?),
|
||||
})
|
||||
}
|
||||
|
||||
/// Instantiate module.
|
||||
@ -42,14 +43,17 @@ impl ProgramInstance {
|
||||
|
||||
impl ProgramInstanceEssence {
|
||||
/// Create new program essence.
|
||||
pub fn new() -> Self {
|
||||
ProgramInstanceEssence {
|
||||
modules: RwLock::new(HashMap::new()),
|
||||
}
|
||||
pub fn new() -> Result<Self, Error> {
|
||||
let mut modules = HashMap::new();
|
||||
let env_module: Arc<ModuleInstanceInterface> = Arc::new(env_module()?);
|
||||
modules.insert("env".into(), env_module);
|
||||
Ok(ProgramInstanceEssence {
|
||||
modules: RwLock::new(modules),
|
||||
})
|
||||
}
|
||||
|
||||
/// Get module reference.
|
||||
pub fn module(&self, name: &str) -> Option<Arc<ModuleInstance>> {
|
||||
pub fn module(&self, name: &str) -> Option<Arc<ModuleInstanceInterface>> {
|
||||
self.modules.read().get(name).cloned()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user