mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-04-25 07:12:15 +00:00
env → emscripten
This commit is contained in:
parent
a039fb5d08
commit
0482373afc
@ -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<u32>,
|
||||
}
|
||||
|
||||
pub struct EnvModuleInstance {
|
||||
pub struct EmscriptenModuleInstance {
|
||||
_params: EnvParams,
|
||||
instance: ModuleInstance,
|
||||
}
|
||||
|
||||
impl EnvModuleInstance {
|
||||
impl EmscriptenModuleInstance {
|
||||
pub fn new(params: EnvParams, module: Module) -> Result<Self, Error> {
|
||||
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<Option<RuntimeValue>, Error> {
|
||||
self.instance.execute_index(index, params)
|
||||
}
|
||||
@ -173,7 +173,7 @@ impl ModuleInstanceInterface for EnvModuleInstance {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn env_module(params: EnvParams) -> Result<EnvModuleInstance, Error> {
|
||||
pub fn env_module(params: EnvParams) -> Result<EmscriptenModuleInstance, Error> {
|
||||
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<EnvModuleInstance, Error> {
|
||||
.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 {
|
@ -120,7 +120,7 @@ impl<U> From<U> 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;
|
||||
|
@ -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<Self, Error> {
|
||||
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<Self, Error> {
|
||||
pub fn with_env_params(params: emscripten::EnvParams) -> Result<Self, Error> {
|
||||
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<Self, Error> {
|
||||
ProgramInstanceEssence::with_env_params(env::EnvParams::default())
|
||||
ProgramInstanceEssence::with_env_params(emscripten::EnvParams::default())
|
||||
}
|
||||
|
||||
pub fn with_env_params(env_params: env::EnvParams) -> Result<Self, Error> {
|
||||
pub fn with_env_params(env_params: emscripten::EnvParams) -> Result<Self, Error> {
|
||||
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<Arc<ModuleInstanceInterface>> {
|
||||
self.modules.read().get(name).cloned()
|
||||
|
Loading…
x
Reference in New Issue
Block a user