diff --git a/src/interpreter/env.rs b/src/interpreter/emscripten.rs similarity index 97% rename from src/interpreter/env.rs rename to src/interpreter/emscripten.rs index fd0bba2..3d06963 100644 --- a/src/interpreter/env.rs +++ b/src/interpreter/emscripten.rs @@ -70,7 +70,7 @@ const INDEX_FUNC_MIN_NONUSED: u32 = 4; /// Max index of reserved function. const INDEX_FUNC_MAX: u32 = NATIVE_INDEX_FUNC_MIN - 1; -/// Environment parameters. +/// Emscripten environment parameters. pub struct EnvParams { /// Stack size in bytes. pub total_stack: u32, @@ -84,24 +84,24 @@ pub struct EnvParams { pub static_size: Option, } -pub struct EnvModuleInstance { +pub struct EmscriptenModuleInstance { _params: EnvParams, instance: ModuleInstance, } -impl EnvModuleInstance { +impl EmscriptenModuleInstance { pub fn new(params: EnvParams, module: Module) -> Result { let mut instance = ModuleInstance::new(Weak::default(), "env".into(), module)?; instance.instantiate(None)?; - Ok(EnvModuleInstance { + Ok(EmscriptenModuleInstance { _params: params, instance: instance, }) } } -impl ModuleInstanceInterface for EnvModuleInstance { +impl ModuleInstanceInterface for EmscriptenModuleInstance { fn execute_index(&self, index: u32, params: ExecutionParams) -> Result, Error> { self.instance.execute_index(index, params) } @@ -173,7 +173,7 @@ impl ModuleInstanceInterface for EnvModuleInstance { } } -pub fn env_module(params: EnvParams) -> Result { +pub fn env_module(params: EnvParams) -> Result { debug_assert!(params.total_stack < params.total_memory); debug_assert!((params.total_stack % LINEAR_MEMORY_PAGE_SIZE) == 0); debug_assert!((params.total_memory % LINEAR_MEMORY_PAGE_SIZE) == 0); @@ -241,7 +241,7 @@ pub fn env_module(params: EnvParams) -> Result { .build() .with_export(ExportEntry::new("getTotalMemory".into(), Internal::Function(INDEX_FUNC_GET_TOTAL_MEMORY))); - EnvModuleInstance::new(params, builder.build()) + EmscriptenModuleInstance::new(params, builder.build()) } impl Default for EnvParams { diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs index af9dccf..f0c056e 100644 --- a/src/interpreter/mod.rs +++ b/src/interpreter/mod.rs @@ -120,7 +120,7 @@ impl From for Error where U: UserError + Sized { } } -mod env; +mod emscripten; mod env_native; mod imports; mod memory; @@ -144,4 +144,4 @@ pub use self::program::ProgramInstance; pub use self::value::RuntimeValue; pub use self::variable::{VariableInstance, VariableType, ExternalVariableValue}; pub use self::env_native::{env_native_module, UserDefinedElements, UserFunctionExecutor, UserFunctionDescriptor}; -pub use self::env::EnvParams; +pub use self::emscripten::EnvParams; diff --git a/src/interpreter/program.rs b/src/interpreter/program.rs index 706f8dc..a56d99c 100644 --- a/src/interpreter/program.rs +++ b/src/interpreter/program.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use parking_lot::RwLock; use elements::Module; use interpreter::Error; -use interpreter::env::{self, env_module}; +use interpreter::emscripten::{self, env_module}; use interpreter::module::{ModuleInstance, ModuleInstanceInterface}; /// Program instance. Program is a set of instantiated modules. @@ -21,11 +21,11 @@ pub struct ProgramInstanceEssence { impl ProgramInstance { /// Create new program instance. pub fn new() -> Result { - ProgramInstance::with_env_params(env::EnvParams::default()) + ProgramInstance::with_env_params(emscripten::EnvParams::default()) } /// Create new program instance with custom env module params (mostly memory) - pub fn with_env_params(params: env::EnvParams) -> Result { + pub fn with_env_params(params: emscripten::EnvParams) -> Result { Ok(ProgramInstance { essence: Arc::new(ProgramInstanceEssence::with_env_params(params)?), }) @@ -65,10 +65,10 @@ impl ProgramInstance { impl ProgramInstanceEssence { /// Create new program essence. pub fn new() -> Result { - ProgramInstanceEssence::with_env_params(env::EnvParams::default()) + ProgramInstanceEssence::with_env_params(emscripten::EnvParams::default()) } - pub fn with_env_params(env_params: env::EnvParams) -> Result { + pub fn with_env_params(env_params: emscripten::EnvParams) -> Result { let env_mod = env_module(env_params)?; Ok(ProgramInstanceEssence::with_env_module(Arc::new(env_mod))) } @@ -81,7 +81,6 @@ impl ProgramInstanceEssence { } } - /// Get module reference. pub fn module(&self, name: &str) -> Option> { self.modules.read().get(name).cloned()