mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-06-21 18:51:52 +00:00
user-functions initial
This commit is contained in:
@ -4,7 +4,7 @@ use std::collections::hash_map::Entry;
|
||||
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.
|
||||
@ -27,6 +27,12 @@ impl ProgramInstance {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn with_functions(funcs: env::UserFunctions) -> Result<Self, Error> {
|
||||
Ok(ProgramInstance {
|
||||
essence: Arc::new(ProgramInstanceEssence::with_functions(funcs)?),
|
||||
})
|
||||
}
|
||||
|
||||
/// Instantiate module.
|
||||
pub fn add_module(&self, name: &str, module: Module) -> Result<Arc<ModuleInstance>, Error> {
|
||||
let module_instance = Arc::new(ModuleInstance::new(Arc::downgrade(&self.essence), module)?);
|
||||
@ -49,8 +55,12 @@ impl ProgramInstance {
|
||||
impl ProgramInstanceEssence {
|
||||
/// Create new program essence.
|
||||
pub fn new() -> Result<Self, Error> {
|
||||
ProgramInstanceEssence::with_functions(HashMap::with_capacity(0))
|
||||
}
|
||||
|
||||
pub fn with_functions(funcs: env::UserFunctions) -> 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(funcs)?);
|
||||
modules.insert("env".into(), env_module);
|
||||
Ok(ProgramInstanceEssence {
|
||||
modules: RwLock::new(modules),
|
||||
|
Reference in New Issue
Block a user