merge 2 error enums

This commit is contained in:
Svyatoslav Nikolsky
2017-08-01 14:44:33 +03:00
parent a02fdf5836
commit 9437b7bdfc
20 changed files with 457 additions and 475 deletions

View File

@ -2,7 +2,7 @@ use std::sync::Arc;
use std::collections::HashMap;
use parking_lot::RwLock;
use elements::Module;
use interpreter::{Error, CustomUserError, InterpreterError};
use interpreter::{Error, CustomUserError};
use interpreter::env::{self, env_module};
use interpreter::module::{ModuleInstance, ModuleInstanceInterface};
@ -20,19 +20,19 @@ pub struct ProgramInstanceEssence<E: CustomUserError> {
impl<E> ProgramInstance<E> where E: CustomUserError {
/// Create new program instance.
pub fn new() -> Result<Self, Error> {
pub fn new() -> Result<Self, Error<E>> {
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> {
pub fn with_env_params(params: env::EnvParams) -> Result<Self, Error<E>> {
Ok(ProgramInstance {
essence: Arc::new(ProgramInstanceEssence::with_env_params(params)?),
})
}
/// Instantiate module with validation.
pub fn add_module<'a>(&self, name: &str, module: Module, externals: Option<&'a HashMap<String, Arc<ModuleInstanceInterface<E> + 'a>>>) -> Result<Arc<ModuleInstance<E>>, InterpreterError<E>> {
pub fn add_module<'a>(&self, name: &str, module: Module, externals: Option<&'a HashMap<String, Arc<ModuleInstanceInterface<E> + 'a>>>) -> Result<Arc<ModuleInstance<E>>, Error<E>> {
let mut module_instance = ModuleInstance::new(Arc::downgrade(&self.essence), name.into(), module)?;
module_instance.instantiate(externals)?;
@ -43,7 +43,7 @@ impl<E> ProgramInstance<E> where E: CustomUserError {
}
/// Insert instantiated module.
pub fn insert_loaded_module(&self, name: &str, module_instance: Arc<ModuleInstance<E>>) -> Result<Arc<ModuleInstance<E>>, Error> {
pub fn insert_loaded_module(&self, name: &str, module_instance: Arc<ModuleInstance<E>>) -> Result<Arc<ModuleInstance<E>>, Error<E>> {
// replace existing module with the same name with new one
self.essence.modules.write().insert(name.into(), module_instance.clone());
Ok(module_instance)
@ -57,11 +57,11 @@ impl<E> ProgramInstance<E> where E: CustomUserError {
impl<E> ProgramInstanceEssence<E> where E: CustomUserError {
/// Create new program essence.
pub fn new() -> Result<Self, Error> {
pub fn new() -> Result<Self, Error<E>> {
ProgramInstanceEssence::with_env_params(env::EnvParams::default())
}
pub fn with_env_params(env_params: env::EnvParams) -> Result<Self, Error> {
pub fn with_env_params(env_params: env::EnvParams) -> Result<Self, Error<E>> {
let mut modules = HashMap::new();
let env_module: Arc<ModuleInstanceInterface<E>> = Arc::new(env_module(env_params)?);
modules.insert("env".into(), env_module);