mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-05-12 15:27:28 +00:00
Rename EnvParams → EmscriptenParams
This commit is contained in:
parent
2cb0781c41
commit
3160f61b64
@ -17,7 +17,7 @@ fn main() {
|
|||||||
// Intrepreter initialization.
|
// Intrepreter initialization.
|
||||||
// It also initializes a default "env" module.
|
// It also initializes a default "env" module.
|
||||||
let program = parity_wasm::ProgramInstance::with_emscripten_env(
|
let program = parity_wasm::ProgramInstance::with_emscripten_env(
|
||||||
interpreter::EnvParams {
|
interpreter::EmscriptenParams {
|
||||||
total_stack: 128*1024,
|
total_stack: 128*1024,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ fn main() {
|
|||||||
// Intrepreter initialization.
|
// Intrepreter initialization.
|
||||||
// It also initializes a default "env" module.
|
// It also initializes a default "env" module.
|
||||||
let program = parity_wasm::ProgramInstance::with_emscripten_env(
|
let program = parity_wasm::ProgramInstance::with_emscripten_env(
|
||||||
interpreter::EnvParams {
|
interpreter::EmscriptenParams {
|
||||||
total_stack: 128*1024,
|
total_stack: 128*1024,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ const INDEX_FUNC_MIN_NONUSED: u32 = 4;
|
|||||||
const INDEX_FUNC_MAX: u32 = NATIVE_INDEX_FUNC_MIN - 1;
|
const INDEX_FUNC_MAX: u32 = NATIVE_INDEX_FUNC_MIN - 1;
|
||||||
|
|
||||||
/// Emscripten environment parameters.
|
/// Emscripten environment parameters.
|
||||||
pub struct EnvParams {
|
pub struct EmscriptenParams {
|
||||||
/// Stack size in bytes.
|
/// Stack size in bytes.
|
||||||
pub total_stack: u32,
|
pub total_stack: u32,
|
||||||
/// Total memory size in bytes.
|
/// Total memory size in bytes.
|
||||||
@ -88,12 +88,12 @@ pub struct EnvParams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct EmscriptenModuleInstance {
|
pub struct EmscriptenModuleInstance {
|
||||||
_params: EnvParams,
|
_params: EmscriptenParams,
|
||||||
instance: ModuleInstance,
|
instance: ModuleInstance,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EmscriptenModuleInstance {
|
impl EmscriptenModuleInstance {
|
||||||
pub fn new(params: EnvParams, module: Module) -> Result<Self, Error> {
|
pub fn new(params: EmscriptenParams, 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)?;
|
||||||
|
|
||||||
@ -176,7 +176,7 @@ impl ModuleInstanceInterface for EmscriptenModuleInstance {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn env_module(params: EnvParams) -> Result<EmscriptenModuleInstance, Error> {
|
pub fn env_module(params: EmscriptenParams) -> 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);
|
||||||
@ -247,9 +247,9 @@ pub fn env_module(params: EnvParams) -> Result<EmscriptenModuleInstance, Error>
|
|||||||
EmscriptenModuleInstance::new(params, builder.build())
|
EmscriptenModuleInstance::new(params, builder.build())
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for EnvParams {
|
impl Default for EmscriptenParams {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
EnvParams {
|
EmscriptenParams {
|
||||||
total_stack: DEFAULT_TOTAL_STACK,
|
total_stack: DEFAULT_TOTAL_STACK,
|
||||||
total_memory: DEFAULT_TOTAL_MEMORY,
|
total_memory: DEFAULT_TOTAL_MEMORY,
|
||||||
allow_memory_growth: DEFAULT_ALLOW_MEMORY_GROWTH,
|
allow_memory_growth: DEFAULT_ALLOW_MEMORY_GROWTH,
|
||||||
@ -259,7 +259,7 @@ impl Default for EnvParams {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EnvParams {
|
impl EmscriptenParams {
|
||||||
fn max_memory(&self) -> Option<u32> {
|
fn max_memory(&self) -> Option<u32> {
|
||||||
if self.allow_memory_growth { None } else { Some(self.total_memory) }
|
if self.allow_memory_growth { None } else { Some(self.total_memory) }
|
||||||
}
|
}
|
||||||
|
@ -140,4 +140,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::native::{native_module, UserDefinedElements, UserFunctionExecutor, UserFunctionDescriptor};
|
pub use self::native::{native_module, UserDefinedElements, UserFunctionExecutor, UserFunctionDescriptor};
|
||||||
pub use self::emscripten::EnvParams;
|
pub use self::emscripten::EmscriptenParams;
|
||||||
|
@ -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::emscripten::{self, env_module};
|
use interpreter::emscripten::{EmscriptenParams, 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.
|
||||||
@ -29,7 +29,7 @@ impl ProgramInstance {
|
|||||||
/// Create new program instance with added Emscripten's `env` module.
|
/// Create new program instance with added Emscripten's `env` module.
|
||||||
///
|
///
|
||||||
/// You can specify desired environment params. Or you can just pass `Default::default()`.
|
/// You can specify desired environment params. Or you can just pass `Default::default()`.
|
||||||
pub fn with_emscripten_env(params: emscripten::EnvParams) -> Result<Self, Error> {
|
pub fn with_emscripten_env(params: EmscriptenParams) -> Result<Self, Error> {
|
||||||
Ok(ProgramInstance {
|
Ok(ProgramInstance {
|
||||||
essence: Arc::new(ProgramInstanceEssence::with_env_params(params)?),
|
essence: Arc::new(ProgramInstanceEssence::with_env_params(params)?),
|
||||||
})
|
})
|
||||||
@ -67,7 +67,7 @@ impl ProgramInstanceEssence {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_env_params(env_params: emscripten::EnvParams) -> Result<Self, Error> {
|
pub fn with_env_params(env_params: EmscriptenParams) -> 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)))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user