diff --git a/lib/runtime-core/src/instance.rs b/lib/runtime-core/src/instance.rs index a7d47ae40..c708ef150 100644 --- a/lib/runtime-core/src/instance.rs +++ b/lib/runtime-core/src/instance.rs @@ -907,7 +907,8 @@ impl Exports { /// # use wasmer_runtime_core::{DynFunc, Func, Instance}; /// # use wasmer_runtime_core::global::Global; /// # use wasmer_runtime_core::types::Value; - /// # fn example_fn(instance: &Instance) -> Option<()> { + /// # use wasmer_runtime_core::error::ResolveResult; + /// # fn example_fn(instance: &Instance) -> ResolveResult<()> { /// // We can get a function as a static `Func` /// let func: Func = instance.exports.get("my_func")?; /// let _result = func.call(42); @@ -919,7 +920,7 @@ impl Exports { /// // We can also get other exports like `Global`s, `Memory`s, and `Table`s /// let _counter: Global = instance.exports.get("counter")?; /// - /// # Some(()) + /// # Ok(()) /// # } /// ``` pub fn get<'a, T: Exportable<'a>>(&'a self, name: &str) -> ResolveResult { diff --git a/lib/runtime-core/src/module.rs b/lib/runtime-core/src/module.rs index 1f99fa3c2..13fb64535 100644 --- a/lib/runtime-core/src/module.rs +++ b/lib/runtime-core/src/module.rs @@ -9,10 +9,10 @@ use crate::{ import::ImportObject, structures::{Map, TypedIndex}, types::{ - ElementType, FuncIndex, FuncSig, GlobalDescriptor, GlobalIndex, GlobalInit, - ImportedFuncIndex, ImportedGlobalIndex, ImportedMemoryIndex, ImportedTableIndex, - Initializer, LocalGlobalIndex, LocalMemoryIndex, LocalTableIndex, MemoryDescriptor, - MemoryIndex, SigIndex, TableDescriptor, TableIndex, Type, + FuncIndex, FuncSig, GlobalDescriptor, GlobalIndex, GlobalInit, ImportedFuncIndex, + ImportedGlobalIndex, ImportedMemoryIndex, ImportedTableIndex, Initializer, + LocalGlobalIndex, LocalMemoryIndex, LocalTableIndex, MemoryDescriptor, MemoryIndex, + SigIndex, TableDescriptor, TableIndex, }, Instance, }; @@ -181,7 +181,7 @@ impl Module { /// let function_names = /// module.exports() /// .filter(|ed| ed.kind == ExportKind::Function) - /// .map(|ed| ed.name) + /// .map(|ed| ed.name.to_string()) /// .collect::>(); /// /// // And here we count the number of global variables exported by this module. @@ -336,83 +336,42 @@ pub enum ImportType { // TODO: why does function have no data? Function, /// The import is a global variable. - Global { - /// Whether or not the variable can be mutated. - mutable: bool, - /// The Wasm type that the global variable holds. - // TODO: attempt to understand explanation about 128bit globals: - // https://github.com/WebAssembly/simd/blob/master/proposals/simd/SIMD.md#webassembly-module-instatiation - ty: Type, - }, + Global(GlobalDescriptor), /// A Wasm linear memory. - // TODO: discuss using `Pages` here vs u32 - Memory { - /// The minimum number of pages this memory must have. - minimum_pages: u32, - /// The maximum number of pages this memory can have. - maximum_pages: Option, - // TODO: missing fields, `shared`, `memory_type` - }, + Memory(MemoryDescriptor), /// A Wasm table. - Table { - /// The minimum number of elements this table must have. - minimum_elements: u32, - /// The maximum number of elements this table can have. - maximum_elements: Option, - /// The type that this table contains - element_type: ElementType, - }, + Table(TableDescriptor), } impl From for ImportType { fn from(other: MemoryDescriptor) -> Self { - ImportType::Memory { - minimum_pages: other.minimum.0, - maximum_pages: other.maximum.map(|inner| inner.0), - } + ImportType::Memory(other) } } impl From<&MemoryDescriptor> for ImportType { fn from(other: &MemoryDescriptor) -> Self { - ImportType::Memory { - minimum_pages: other.minimum.0, - maximum_pages: other.maximum.map(|inner| inner.0), - } + ImportType::Memory(*other) } } impl From for ImportType { fn from(other: TableDescriptor) -> Self { - ImportType::Table { - minimum_elements: other.minimum, - maximum_elements: other.maximum, - element_type: other.element, - } + ImportType::Table(other) } } impl From<&TableDescriptor> for ImportType { fn from(other: &TableDescriptor) -> Self { - ImportType::Table { - minimum_elements: other.minimum, - maximum_elements: other.maximum, - element_type: other.element, - } + ImportType::Table(*other) } } impl From for ImportType { fn from(other: GlobalDescriptor) -> Self { - ImportType::Global { - mutable: other.mutable, - ty: other.ty, - } + ImportType::Global(other) } } impl From<&GlobalDescriptor> for ImportType { fn from(other: &GlobalDescriptor) -> Self { - ImportType::Global { - mutable: other.mutable, - ty: other.ty, - } + ImportType::Global(*other) } } diff --git a/lib/runtime-core/src/types.rs b/lib/runtime-core/src/types.rs index 122aa544a..8a0a0d82f 100644 --- a/lib/runtime-core/src/types.rs +++ b/lib/runtime-core/src/types.rs @@ -254,7 +254,7 @@ pub enum ElementType { /// Describes the properties of a table including the element types, minimum and optional maximum, /// number of elements in the table. -#[derive(Serialize, Deserialize, Debug, Clone, Copy)] +#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)] pub struct TableDescriptor { /// Type of data stored in this table. pub element: ElementType,