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.
|
/// Max index of reserved function.
|
||||||
const INDEX_FUNC_MAX: u32 = NATIVE_INDEX_FUNC_MIN - 1;
|
const INDEX_FUNC_MAX: u32 = NATIVE_INDEX_FUNC_MIN - 1;
|
||||||
|
|
||||||
/// Environment parameters.
|
/// Emscripten environment parameters.
|
||||||
pub struct EnvParams {
|
pub struct EnvParams {
|
||||||
/// Stack size in bytes.
|
/// Stack size in bytes.
|
||||||
pub total_stack: u32,
|
pub total_stack: u32,
|
||||||
@ -84,24 +84,24 @@ pub struct EnvParams {
|
|||||||
pub static_size: Option<u32>,
|
pub static_size: Option<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct EnvModuleInstance {
|
pub struct EmscriptenModuleInstance {
|
||||||
_params: EnvParams,
|
_params: EnvParams,
|
||||||
instance: ModuleInstance,
|
instance: ModuleInstance,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EnvModuleInstance {
|
impl EmscriptenModuleInstance {
|
||||||
pub fn new(params: EnvParams, module: Module) -> Result<Self, Error> {
|
pub fn new(params: EnvParams, module: Module) -> Result<Self, Error> {
|
||||||
let mut instance = ModuleInstance::new(Weak::default(), "env".into(), module)?;
|
let mut instance = ModuleInstance::new(Weak::default(), "env".into(), module)?;
|
||||||
instance.instantiate(None)?;
|
instance.instantiate(None)?;
|
||||||
|
|
||||||
Ok(EnvModuleInstance {
|
Ok(EmscriptenModuleInstance {
|
||||||
_params: params,
|
_params: params,
|
||||||
instance: instance,
|
instance: instance,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ModuleInstanceInterface for EnvModuleInstance {
|
impl ModuleInstanceInterface for EmscriptenModuleInstance {
|
||||||
fn execute_index(&self, index: u32, params: ExecutionParams) -> Result<Option<RuntimeValue>, Error> {
|
fn execute_index(&self, index: u32, params: ExecutionParams) -> Result<Option<RuntimeValue>, Error> {
|
||||||
self.instance.execute_index(index, params)
|
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 < params.total_memory);
|
||||||
debug_assert!((params.total_stack % LINEAR_MEMORY_PAGE_SIZE) == 0);
|
debug_assert!((params.total_stack % LINEAR_MEMORY_PAGE_SIZE) == 0);
|
||||||
debug_assert!((params.total_memory % 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()
|
.build()
|
||||||
.with_export(ExportEntry::new("getTotalMemory".into(), Internal::Function(INDEX_FUNC_GET_TOTAL_MEMORY)));
|
.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 {
|
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 env_native;
|
||||||
mod imports;
|
mod imports;
|
||||||
mod memory;
|
mod memory;
|
||||||
@ -144,4 +144,4 @@ pub use self::program::ProgramInstance;
|
|||||||
pub use self::value::RuntimeValue;
|
pub use self::value::RuntimeValue;
|
||||||
pub use self::variable::{VariableInstance, VariableType, ExternalVariableValue};
|
pub use self::variable::{VariableInstance, VariableType, ExternalVariableValue};
|
||||||
pub use self::env_native::{env_native_module, UserDefinedElements, UserFunctionExecutor, UserFunctionDescriptor};
|
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 parking_lot::RwLock;
|
||||||
use elements::Module;
|
use elements::Module;
|
||||||
use interpreter::Error;
|
use interpreter::Error;
|
||||||
use interpreter::env::{self, env_module};
|
use interpreter::emscripten::{self, env_module};
|
||||||
use interpreter::module::{ModuleInstance, ModuleInstanceInterface};
|
use interpreter::module::{ModuleInstance, ModuleInstanceInterface};
|
||||||
|
|
||||||
/// Program instance. Program is a set of instantiated modules.
|
/// Program instance. Program is a set of instantiated modules.
|
||||||
@ -21,11 +21,11 @@ pub struct ProgramInstanceEssence {
|
|||||||
impl ProgramInstance {
|
impl ProgramInstance {
|
||||||
/// Create new program instance.
|
/// Create new program instance.
|
||||||
pub fn new() -> Result<Self, Error> {
|
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)
|
/// 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 {
|
Ok(ProgramInstance {
|
||||||
essence: Arc::new(ProgramInstanceEssence::with_env_params(params)?),
|
essence: Arc::new(ProgramInstanceEssence::with_env_params(params)?),
|
||||||
})
|
})
|
||||||
@ -65,10 +65,10 @@ impl ProgramInstance {
|
|||||||
impl ProgramInstanceEssence {
|
impl ProgramInstanceEssence {
|
||||||
/// Create new program essence.
|
/// Create new program essence.
|
||||||
pub fn new() -> Result<Self, Error> {
|
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)?;
|
let env_mod = env_module(env_params)?;
|
||||||
Ok(ProgramInstanceEssence::with_env_module(Arc::new(env_mod)))
|
Ok(ProgramInstanceEssence::with_env_module(Arc::new(env_mod)))
|
||||||
}
|
}
|
||||||
@ -81,7 +81,6 @@ impl ProgramInstanceEssence {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Get module reference.
|
/// Get module reference.
|
||||||
pub fn module(&self, name: &str) -> Option<Arc<ModuleInstanceInterface>> {
|
pub fn module(&self, name: &str) -> Option<Arc<ModuleInstanceInterface>> {
|
||||||
self.modules.read().get(name).cloned()
|
self.modules.read().get(name).cloned()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user