Hide MemoryType.
This commit is contained in:
parent
973d58a643
commit
e26ddb6d12
|
@ -1,12 +1,10 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use parity_wasm::elements::MemoryType;
|
|
||||||
use global::GlobalRef;
|
use global::GlobalRef;
|
||||||
use memory::MemoryRef;
|
use memory::MemoryRef;
|
||||||
use func::FuncRef;
|
use func::FuncRef;
|
||||||
use table::TableRef;
|
use table::TableRef;
|
||||||
use module::ModuleRef;
|
use module::ModuleRef;
|
||||||
use types::GlobalDescriptor;
|
use types::{GlobalDescriptor, TableDescriptor, MemoryDescriptor};
|
||||||
use types::TableDescriptor;
|
|
||||||
use {Error, Signature};
|
use {Error, Signature};
|
||||||
|
|
||||||
pub trait ImportResolver {
|
pub trait ImportResolver {
|
||||||
|
@ -28,7 +26,7 @@ pub trait ImportResolver {
|
||||||
&self,
|
&self,
|
||||||
module_name: &str,
|
module_name: &str,
|
||||||
field_name: &str,
|
field_name: &str,
|
||||||
memory_type: &MemoryType,
|
memory_type: &MemoryDescriptor,
|
||||||
) -> Result<MemoryRef, Error>;
|
) -> Result<MemoryRef, Error>;
|
||||||
|
|
||||||
fn resolve_table(
|
fn resolve_table(
|
||||||
|
@ -99,7 +97,7 @@ impl<'a> ImportResolver for ImportsBuilder<'a> {
|
||||||
&self,
|
&self,
|
||||||
module_name: &str,
|
module_name: &str,
|
||||||
field_name: &str,
|
field_name: &str,
|
||||||
memory_type: &MemoryType,
|
memory_type: &MemoryDescriptor,
|
||||||
) -> Result<MemoryRef, Error> {
|
) -> Result<MemoryRef, Error> {
|
||||||
self.resolver(module_name).ok_or_else(||
|
self.resolver(module_name).ok_or_else(||
|
||||||
Error::Instantiation(format!("Module {} not found", module_name))
|
Error::Instantiation(format!("Module {} not found", module_name))
|
||||||
|
@ -142,7 +140,7 @@ pub trait ModuleImportResolver {
|
||||||
fn resolve_memory(
|
fn resolve_memory(
|
||||||
&self,
|
&self,
|
||||||
field_name: &str,
|
field_name: &str,
|
||||||
_memory_type: &MemoryType,
|
_memory_type: &MemoryDescriptor,
|
||||||
) -> Result<MemoryRef, Error> {
|
) -> Result<MemoryRef, Error> {
|
||||||
Err(Error::Instantiation(
|
Err(Error::Instantiation(
|
||||||
format!("Export {} not found", field_name),
|
format!("Export {} not found", field_name),
|
||||||
|
@ -194,7 +192,7 @@ impl ModuleImportResolver for ModuleRef {
|
||||||
fn resolve_memory(
|
fn resolve_memory(
|
||||||
&self,
|
&self,
|
||||||
field_name: &str,
|
field_name: &str,
|
||||||
_memory_type: &MemoryType,
|
_memory_type: &MemoryDescriptor,
|
||||||
) -> Result<MemoryRef, Error> {
|
) -> Result<MemoryRef, Error> {
|
||||||
Ok(self.export_by_name(field_name)
|
Ok(self.export_by_name(field_name)
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
|
|
|
@ -135,7 +135,7 @@ pub use self::imports::{ModuleImportResolver, ImportResolver, ImportsBuilder};
|
||||||
pub use self::module::{ModuleInstance, ModuleRef, ExternVal, NotStartedModuleRef};
|
pub use self::module::{ModuleInstance, ModuleRef, ExternVal, NotStartedModuleRef};
|
||||||
pub use self::global::{GlobalInstance, GlobalRef};
|
pub use self::global::{GlobalInstance, GlobalRef};
|
||||||
pub use self::func::{FuncInstance, FuncRef};
|
pub use self::func::{FuncInstance, FuncRef};
|
||||||
pub use self::types::{Signature, ValueType, GlobalDescriptor, TableDescriptor};
|
pub use self::types::{Signature, ValueType, GlobalDescriptor, TableDescriptor, MemoryDescriptor};
|
||||||
|
|
||||||
pub struct LoadedModule {
|
pub struct LoadedModule {
|
||||||
labels: HashMap<usize, HashMap<usize, usize>>,
|
labels: HashMap<usize, HashMap<usize, usize>>,
|
||||||
|
|
|
@ -12,7 +12,7 @@ use table::TableRef;
|
||||||
use memory::MemoryRef;
|
use memory::MemoryRef;
|
||||||
use host::Externals;
|
use host::Externals;
|
||||||
use common::{DEFAULT_MEMORY_INDEX, DEFAULT_TABLE_INDEX};
|
use common::{DEFAULT_MEMORY_INDEX, DEFAULT_TABLE_INDEX};
|
||||||
use types::{GlobalDescriptor, TableDescriptor};
|
use types::{GlobalDescriptor, TableDescriptor, MemoryDescriptor};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct ModuleRef(Rc<ModuleInstance>);
|
pub struct ModuleRef(Rc<ModuleInstance>);
|
||||||
|
@ -396,7 +396,8 @@ impl ModuleInstance {
|
||||||
ExternVal::Table(table)
|
ExternVal::Table(table)
|
||||||
}
|
}
|
||||||
External::Memory(ref memory_type) => {
|
External::Memory(ref memory_type) => {
|
||||||
let memory = imports.resolve_memory(module_name, field_name, memory_type)?;
|
let memory_descriptor = MemoryDescriptor::from_elements(memory_type);
|
||||||
|
let memory = imports.resolve_memory(module_name, field_name, &memory_descriptor)?;
|
||||||
ExternVal::Memory(memory)
|
ExternVal::Memory(memory)
|
||||||
}
|
}
|
||||||
External::Global(ref global_type) => {
|
External::Global(ref global_type) => {
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
|
|
||||||
use parity_wasm::elements::MemoryType;
|
|
||||||
use {
|
use {
|
||||||
Error, Signature, Externals, FuncInstance, FuncRef, HostError, ImportsBuilder,
|
Error, Signature, Externals, FuncInstance, FuncRef, HostError, ImportsBuilder,
|
||||||
MemoryInstance, MemoryRef, TableInstance, TableRef, ModuleImportResolver, ModuleInstance, ModuleRef,
|
MemoryInstance, MemoryRef, TableInstance, TableRef, ModuleImportResolver, ModuleInstance, ModuleRef,
|
||||||
RuntimeValue, TryInto, LoadedModule, load_from_buffer, TableDescriptor,
|
RuntimeValue, TryInto, LoadedModule, load_from_buffer, TableDescriptor, MemoryDescriptor,
|
||||||
};
|
};
|
||||||
use types::ValueType;
|
use types::ValueType;
|
||||||
use wabt::wat2wasm;
|
use wabt::wat2wasm;
|
||||||
|
@ -195,7 +193,7 @@ impl ModuleImportResolver for TestHost {
|
||||||
fn resolve_memory(
|
fn resolve_memory(
|
||||||
&self,
|
&self,
|
||||||
field_name: &str,
|
field_name: &str,
|
||||||
_memory_type: &MemoryType,
|
_memory_type: &MemoryDescriptor,
|
||||||
) -> Result<MemoryRef, Error> {
|
) -> Result<MemoryRef, Error> {
|
||||||
Err(Error::Instantiation(
|
Err(Error::Instantiation(
|
||||||
format!("Export {} not found", field_name),
|
format!("Export {} not found", field_name),
|
||||||
|
@ -443,7 +441,7 @@ fn defer_providing_externals() {
|
||||||
fn resolve_memory(
|
fn resolve_memory(
|
||||||
&self,
|
&self,
|
||||||
field_name: &str,
|
field_name: &str,
|
||||||
_memory_type: &MemoryType,
|
_memory_type: &MemoryDescriptor,
|
||||||
) -> Result<MemoryRef, Error> {
|
) -> Result<MemoryRef, Error> {
|
||||||
if field_name == "mem" {
|
if field_name == "mem" {
|
||||||
Ok(self.mem.clone())
|
Ok(self.mem.clone())
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use parity_wasm::elements::MemoryType;
|
|
||||||
use {
|
use {
|
||||||
Error, Signature, FuncRef, GlobalInstance, GlobalRef, ImportsBuilder, MemoryInstance,
|
Error, Signature, FuncRef, GlobalInstance, GlobalRef, ImportsBuilder, MemoryInstance,
|
||||||
MemoryRef, ModuleImportResolver, ModuleInstance, NopExternals, RuntimeValue,
|
MemoryRef, ModuleImportResolver, ModuleInstance, NopExternals, RuntimeValue,
|
||||||
TableInstance, TableRef, LoadedModule, load_from_buffer, GlobalDescriptor, TableDescriptor,
|
TableInstance, TableRef, LoadedModule, load_from_buffer, GlobalDescriptor, TableDescriptor, MemoryDescriptor,
|
||||||
};
|
};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
|
||||||
|
@ -49,7 +48,7 @@ impl ModuleImportResolver for Env {
|
||||||
fn resolve_memory(
|
fn resolve_memory(
|
||||||
&self,
|
&self,
|
||||||
field_name: &str,
|
field_name: &str,
|
||||||
_memory_type: &MemoryType,
|
_memory_type: &MemoryDescriptor,
|
||||||
) -> Result<MemoryRef, Error> {
|
) -> Result<MemoryRef, Error> {
|
||||||
match field_name {
|
match field_name {
|
||||||
"memory" => Ok(self.memory.clone()),
|
"memory" => Ok(self.memory.clone()),
|
||||||
|
|
25
src/types.rs
25
src/types.rs
|
@ -1,4 +1,5 @@
|
||||||
use parity_wasm::elements::{FunctionType, ValueType as EValueType, GlobalType, TableType};
|
use parity_wasm::elements::{
|
||||||
|
FunctionType, ValueType as EValueType, GlobalType, TableType, MemoryType};
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub struct Signature {
|
pub struct Signature {
|
||||||
|
@ -101,3 +102,25 @@ impl TableDescriptor {
|
||||||
self.maximum
|
self.maximum
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct MemoryDescriptor {
|
||||||
|
initial: u32,
|
||||||
|
maximum: Option<u32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MemoryDescriptor {
|
||||||
|
pub(crate) fn from_elements(memory_type: &MemoryType) -> MemoryDescriptor {
|
||||||
|
MemoryDescriptor {
|
||||||
|
initial: memory_type.limits().initial(),
|
||||||
|
maximum: memory_type.limits().maximum(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn initial(&self) -> u32 {
|
||||||
|
self.initial
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn maximum(&self) -> Option<u32> {
|
||||||
|
self.maximum
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue