mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-05-24 13:11:34 +00:00
instantiate env module
This commit is contained in:
parent
a5da7d604b
commit
2f73f02831
@ -81,7 +81,8 @@ pub struct EnvModuleInstance {
|
|||||||
|
|
||||||
impl EnvModuleInstance {
|
impl EnvModuleInstance {
|
||||||
pub fn new(params: EnvParams, module: Module) -> Result<Self, Error> {
|
pub fn new(params: EnvParams, module: Module) -> Result<Self, Error> {
|
||||||
let instance = ModuleInstance::new(Weak::default(), "env".into(), module)?;
|
let mut instance = ModuleInstance::new(Weak::default(), "env".into(), module)?;
|
||||||
|
instance.instantiate(false, None)?;
|
||||||
|
|
||||||
Ok(EnvModuleInstance {
|
Ok(EnvModuleInstance {
|
||||||
_params: params,
|
_params: params,
|
||||||
|
@ -235,7 +235,6 @@ impl ModuleInstance {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// validate export section
|
// validate export section
|
||||||
if is_user_module { // TODO: env module exports STACKTOP global, which is mutable => check is failed
|
|
||||||
if let Some(export_section) = self.module.export_section() {
|
if let Some(export_section) = self.module.export_section() {
|
||||||
for export in export_section.entries() {
|
for export in export_section.entries() {
|
||||||
match export.internal() {
|
match export.internal() {
|
||||||
@ -245,7 +244,7 @@ impl ModuleInstance {
|
|||||||
},
|
},
|
||||||
&Internal::Global(global_index) => {
|
&Internal::Global(global_index) => {
|
||||||
self.global(ItemIndex::IndexSpace(global_index), None)
|
self.global(ItemIndex::IndexSpace(global_index), None)
|
||||||
.and_then(|g| if g.is_mutable() {
|
.and_then(|g| if g.is_mutable() && is_user_module {
|
||||||
Err(Error::Validation(format!("trying to export mutable global {}", export.field())))
|
Err(Error::Validation(format!("trying to export mutable global {}", export.field())))
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -263,7 +262,6 @@ impl ModuleInstance {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// validate import section
|
// validate import section
|
||||||
if let Some(import_section) = self.module.import_section() {
|
if let Some(import_section) = self.module.import_section() {
|
||||||
|
@ -211,38 +211,16 @@ fn single_program_different_modules() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn import_global() {
|
fn import_env_mutable_global() {
|
||||||
// create new program
|
|
||||||
let program = ProgramInstance::new().unwrap();
|
let program = ProgramInstance::new().unwrap();
|
||||||
// => env module is created
|
|
||||||
let env_instance = program.module("env").unwrap();
|
|
||||||
// => linear memory is created
|
|
||||||
let env_memory = env_instance.memory(ItemIndex::Internal(0)).unwrap();
|
|
||||||
|
|
||||||
// create native env module executor
|
|
||||||
let mut executor = FunctionExecutor {
|
|
||||||
memory: env_memory.clone(),
|
|
||||||
values: Vec::new(),
|
|
||||||
};
|
|
||||||
{
|
|
||||||
let functions: UserFunctions = UserFunctions {
|
|
||||||
executor: &mut executor,
|
|
||||||
functions: ::std::borrow::Cow::from(SIGNATURES),
|
|
||||||
};
|
|
||||||
let native_env_instance = Arc::new(env_native_module(env_instance, functions).unwrap());
|
|
||||||
let params = ExecutionParams::with_external("env".into(), native_env_instance);
|
|
||||||
|
|
||||||
let module = module()
|
let module = module()
|
||||||
.with_import(ImportEntry::new("env".into(), "STACKTOP".into(), External::Global(GlobalType::new(ValueType::I32, false))))
|
.with_import(ImportEntry::new("env".into(), "STACKTOP".into(), External::Global(GlobalType::new(ValueType::I32, false))))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// load module
|
program.add_module("main", module, None).unwrap();
|
||||||
program.add_module("main", module, Some(¶ms.externals)).unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn env_native_export_entry_type_check() {
|
fn env_native_export_entry_type_check() {
|
||||||
let program = ProgramInstance::new().unwrap();
|
let program = ProgramInstance::new().unwrap();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user