Hide TableType.
This commit is contained in:
parent
b323d004fe
commit
973d58a643
|
@ -1,11 +1,12 @@
|
|||
use std::collections::HashMap;
|
||||
use parity_wasm::elements::{MemoryType, TableType};
|
||||
use parity_wasm::elements::MemoryType;
|
||||
use global::GlobalRef;
|
||||
use memory::MemoryRef;
|
||||
use func::FuncRef;
|
||||
use table::TableRef;
|
||||
use module::ModuleRef;
|
||||
use types::GlobalDescriptor;
|
||||
use types::TableDescriptor;
|
||||
use {Error, Signature};
|
||||
|
||||
pub trait ImportResolver {
|
||||
|
@ -34,7 +35,7 @@ pub trait ImportResolver {
|
|||
&self,
|
||||
module_name: &str,
|
||||
field_name: &str,
|
||||
table_type: &TableType,
|
||||
table_type: &TableDescriptor,
|
||||
) -> Result<TableRef, Error>;
|
||||
}
|
||||
|
||||
|
@ -109,7 +110,7 @@ impl<'a> ImportResolver for ImportsBuilder<'a> {
|
|||
&self,
|
||||
module_name: &str,
|
||||
field_name: &str,
|
||||
table_type: &TableType,
|
||||
table_type: &TableDescriptor,
|
||||
) -> Result<TableRef, Error> {
|
||||
self.resolver(module_name).ok_or_else(||
|
||||
Error::Instantiation(format!("Module {} not found", module_name))
|
||||
|
@ -151,7 +152,7 @@ pub trait ModuleImportResolver {
|
|||
fn resolve_table(
|
||||
&self,
|
||||
field_name: &str,
|
||||
_table_type: &TableType,
|
||||
_table_type: &TableDescriptor,
|
||||
) -> Result<TableRef, Error> {
|
||||
Err(Error::Instantiation(
|
||||
format!("Export {} not found", field_name),
|
||||
|
@ -208,7 +209,7 @@ impl ModuleImportResolver for ModuleRef {
|
|||
fn resolve_table(
|
||||
&self,
|
||||
field_name: &str,
|
||||
_table_type: &TableType,
|
||||
_table_type: &TableDescriptor,
|
||||
) -> Result<TableRef, Error> {
|
||||
Ok(self.export_by_name(field_name)
|
||||
.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::global::{GlobalInstance, GlobalRef};
|
||||
pub use self::func::{FuncInstance, FuncRef};
|
||||
pub use self::types::{Signature, ValueType, GlobalDescriptor};
|
||||
pub use self::types::{Signature, ValueType, GlobalDescriptor, TableDescriptor};
|
||||
|
||||
pub struct LoadedModule {
|
||||
labels: HashMap<usize, HashMap<usize, usize>>,
|
||||
|
|
|
@ -12,7 +12,7 @@ use table::TableRef;
|
|||
use memory::MemoryRef;
|
||||
use host::Externals;
|
||||
use common::{DEFAULT_MEMORY_INDEX, DEFAULT_TABLE_INDEX};
|
||||
use types::GlobalDescriptor;
|
||||
use types::{GlobalDescriptor, TableDescriptor};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ModuleRef(Rc<ModuleInstance>);
|
||||
|
@ -391,7 +391,8 @@ impl ModuleInstance {
|
|||
ExternVal::Func(func)
|
||||
}
|
||||
External::Table(ref table_type) => {
|
||||
let table = imports.resolve_table(module_name, field_name, table_type)?;
|
||||
let table_descriptor = TableDescriptor::from_elements(table_type);
|
||||
let table = imports.resolve_table(module_name, field_name, &table_descriptor)?;
|
||||
ExternVal::Table(table)
|
||||
}
|
||||
External::Memory(ref memory_type) => {
|
||||
|
@ -399,7 +400,7 @@ impl ModuleInstance {
|
|||
ExternVal::Memory(memory)
|
||||
}
|
||||
External::Global(ref global_type) => {
|
||||
let global_descriptor = GlobalDescriptor::from_global_type(global_type);
|
||||
let global_descriptor = GlobalDescriptor::from_elements(global_type);
|
||||
let global = imports.resolve_global(module_name, field_name, &global_descriptor)?;
|
||||
ExternVal::Global(global)
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
|
||||
use parity_wasm::elements::{MemoryType, TableType};
|
||||
use parity_wasm::elements::MemoryType;
|
||||
use {
|
||||
Error, Signature, Externals, FuncInstance, FuncRef, HostError, ImportsBuilder,
|
||||
MemoryInstance, MemoryRef, TableInstance, TableRef, ModuleImportResolver, ModuleInstance, ModuleRef,
|
||||
RuntimeValue, TryInto, LoadedModule, load_from_buffer,
|
||||
RuntimeValue, TryInto, LoadedModule, load_from_buffer, TableDescriptor,
|
||||
};
|
||||
use types::ValueType;
|
||||
use wabt::wat2wasm;
|
||||
|
@ -696,7 +696,7 @@ fn dynamically_add_host_func() {
|
|||
fn resolve_table(
|
||||
&self,
|
||||
field_name: &str,
|
||||
_table_type: &TableType,
|
||||
_table_type: &TableDescriptor,
|
||||
) -> Result<TableRef, Error> {
|
||||
if field_name == "table" {
|
||||
Ok(self.table.clone())
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use parity_wasm::elements::{MemoryType, TableType};
|
||||
use parity_wasm::elements::MemoryType;
|
||||
use {
|
||||
Error, Signature, FuncRef, GlobalInstance, GlobalRef, ImportsBuilder, MemoryInstance,
|
||||
MemoryRef, ModuleImportResolver, ModuleInstance, NopExternals, RuntimeValue,
|
||||
TableInstance, TableRef, LoadedModule, load_from_buffer, GlobalDescriptor,
|
||||
TableInstance, TableRef, LoadedModule, load_from_buffer, GlobalDescriptor, TableDescriptor,
|
||||
};
|
||||
use std::fs::File;
|
||||
|
||||
|
@ -60,7 +60,7 @@ impl ModuleImportResolver for Env {
|
|||
}
|
||||
}
|
||||
|
||||
fn resolve_table(&self, field_name: &str, _table_type: &TableType) -> Result<TableRef, Error> {
|
||||
fn resolve_table(&self, field_name: &str, _table_type: &TableDescriptor) -> Result<TableRef, Error> {
|
||||
match field_name {
|
||||
"table" => Ok(self.table.clone()),
|
||||
_ => Err(Error::Instantiation(
|
||||
|
|
28
src/types.rs
28
src/types.rs
|
@ -1,4 +1,4 @@
|
|||
use parity_wasm::elements::{FunctionType, ValueType as EValueType, GlobalType};
|
||||
use parity_wasm::elements::{FunctionType, ValueType as EValueType, GlobalType, TableType};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Signature {
|
||||
|
@ -64,7 +64,7 @@ pub struct GlobalDescriptor {
|
|||
}
|
||||
|
||||
impl GlobalDescriptor {
|
||||
pub(crate) fn from_global_type(global_type: &GlobalType) -> GlobalDescriptor {
|
||||
pub(crate) fn from_elements(global_type: &GlobalType) -> GlobalDescriptor {
|
||||
GlobalDescriptor {
|
||||
value_type: ValueType::from_elements(global_type.content_type()),
|
||||
mutable: global_type.is_mutable(),
|
||||
|
@ -78,4 +78,26 @@ impl GlobalDescriptor {
|
|||
pub fn is_mutable(&self) -> bool {
|
||||
self.mutable
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TableDescriptor {
|
||||
initial: u32,
|
||||
maximum: Option<u32>,
|
||||
}
|
||||
|
||||
impl TableDescriptor {
|
||||
pub(crate) fn from_elements(table_type: &TableType) -> TableDescriptor {
|
||||
TableDescriptor {
|
||||
initial: table_type.limits().initial(),
|
||||
maximum: table_type.limits().maximum(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn initial(&self) -> u32 {
|
||||
self.initial
|
||||
}
|
||||
|
||||
pub fn maximum(&self) -> Option<u32> {
|
||||
self.maximum
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue