mirror of
https://github.com/fluencelabs/wasmer
synced 2025-04-17 06:32:14 +00:00
Simplify ImportType
This commit is contained in:
parent
a0dca15fbc
commit
7cd9e82015
@ -907,7 +907,8 @@ impl Exports {
|
|||||||
/// # use wasmer_runtime_core::{DynFunc, Func, Instance};
|
/// # use wasmer_runtime_core::{DynFunc, Func, Instance};
|
||||||
/// # use wasmer_runtime_core::global::Global;
|
/// # use wasmer_runtime_core::global::Global;
|
||||||
/// # use wasmer_runtime_core::types::Value;
|
/// # 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`
|
/// // We can get a function as a static `Func`
|
||||||
/// let func: Func<i32, i32> = instance.exports.get("my_func")?;
|
/// let func: Func<i32, i32> = instance.exports.get("my_func")?;
|
||||||
/// let _result = func.call(42);
|
/// 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
|
/// // We can also get other exports like `Global`s, `Memory`s, and `Table`s
|
||||||
/// let _counter: Global = instance.exports.get("counter")?;
|
/// let _counter: Global = instance.exports.get("counter")?;
|
||||||
///
|
///
|
||||||
/// # Some(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn get<'a, T: Exportable<'a>>(&'a self, name: &str) -> ResolveResult<T> {
|
pub fn get<'a, T: Exportable<'a>>(&'a self, name: &str) -> ResolveResult<T> {
|
||||||
|
@ -9,10 +9,10 @@ use crate::{
|
|||||||
import::ImportObject,
|
import::ImportObject,
|
||||||
structures::{Map, TypedIndex},
|
structures::{Map, TypedIndex},
|
||||||
types::{
|
types::{
|
||||||
ElementType, FuncIndex, FuncSig, GlobalDescriptor, GlobalIndex, GlobalInit,
|
FuncIndex, FuncSig, GlobalDescriptor, GlobalIndex, GlobalInit, ImportedFuncIndex,
|
||||||
ImportedFuncIndex, ImportedGlobalIndex, ImportedMemoryIndex, ImportedTableIndex,
|
ImportedGlobalIndex, ImportedMemoryIndex, ImportedTableIndex, Initializer,
|
||||||
Initializer, LocalGlobalIndex, LocalMemoryIndex, LocalTableIndex, MemoryDescriptor,
|
LocalGlobalIndex, LocalMemoryIndex, LocalTableIndex, MemoryDescriptor, MemoryIndex,
|
||||||
MemoryIndex, SigIndex, TableDescriptor, TableIndex, Type,
|
SigIndex, TableDescriptor, TableIndex,
|
||||||
},
|
},
|
||||||
Instance,
|
Instance,
|
||||||
};
|
};
|
||||||
@ -181,7 +181,7 @@ impl Module {
|
|||||||
/// let function_names =
|
/// let function_names =
|
||||||
/// module.exports()
|
/// module.exports()
|
||||||
/// .filter(|ed| ed.kind == ExportKind::Function)
|
/// .filter(|ed| ed.kind == ExportKind::Function)
|
||||||
/// .map(|ed| ed.name)
|
/// .map(|ed| ed.name.to_string())
|
||||||
/// .collect::<Vec<String>>();
|
/// .collect::<Vec<String>>();
|
||||||
///
|
///
|
||||||
/// // And here we count the number of global variables exported by this module.
|
/// // 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?
|
// TODO: why does function have no data?
|
||||||
Function,
|
Function,
|
||||||
/// The import is a global variable.
|
/// The import is a global variable.
|
||||||
Global {
|
Global(GlobalDescriptor),
|
||||||
/// 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,
|
|
||||||
},
|
|
||||||
/// A Wasm linear memory.
|
/// A Wasm linear memory.
|
||||||
// TODO: discuss using `Pages` here vs u32
|
Memory(MemoryDescriptor),
|
||||||
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<u32>,
|
|
||||||
// TODO: missing fields, `shared`, `memory_type`
|
|
||||||
},
|
|
||||||
/// A Wasm table.
|
/// A Wasm table.
|
||||||
Table {
|
Table(TableDescriptor),
|
||||||
/// The minimum number of elements this table must have.
|
|
||||||
minimum_elements: u32,
|
|
||||||
/// The maximum number of elements this table can have.
|
|
||||||
maximum_elements: Option<u32>,
|
|
||||||
/// The type that this table contains
|
|
||||||
element_type: ElementType,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<MemoryDescriptor> for ImportType {
|
impl From<MemoryDescriptor> for ImportType {
|
||||||
fn from(other: MemoryDescriptor) -> Self {
|
fn from(other: MemoryDescriptor) -> Self {
|
||||||
ImportType::Memory {
|
ImportType::Memory(other)
|
||||||
minimum_pages: other.minimum.0,
|
|
||||||
maximum_pages: other.maximum.map(|inner| inner.0),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl From<&MemoryDescriptor> for ImportType {
|
impl From<&MemoryDescriptor> for ImportType {
|
||||||
fn from(other: &MemoryDescriptor) -> Self {
|
fn from(other: &MemoryDescriptor) -> Self {
|
||||||
ImportType::Memory {
|
ImportType::Memory(*other)
|
||||||
minimum_pages: other.minimum.0,
|
|
||||||
maximum_pages: other.maximum.map(|inner| inner.0),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<TableDescriptor> for ImportType {
|
impl From<TableDescriptor> for ImportType {
|
||||||
fn from(other: TableDescriptor) -> Self {
|
fn from(other: TableDescriptor) -> Self {
|
||||||
ImportType::Table {
|
ImportType::Table(other)
|
||||||
minimum_elements: other.minimum,
|
|
||||||
maximum_elements: other.maximum,
|
|
||||||
element_type: other.element,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl From<&TableDescriptor> for ImportType {
|
impl From<&TableDescriptor> for ImportType {
|
||||||
fn from(other: &TableDescriptor) -> Self {
|
fn from(other: &TableDescriptor) -> Self {
|
||||||
ImportType::Table {
|
ImportType::Table(*other)
|
||||||
minimum_elements: other.minimum,
|
|
||||||
maximum_elements: other.maximum,
|
|
||||||
element_type: other.element,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl From<GlobalDescriptor> for ImportType {
|
impl From<GlobalDescriptor> for ImportType {
|
||||||
fn from(other: GlobalDescriptor) -> Self {
|
fn from(other: GlobalDescriptor) -> Self {
|
||||||
ImportType::Global {
|
ImportType::Global(other)
|
||||||
mutable: other.mutable,
|
|
||||||
ty: other.ty,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl From<&GlobalDescriptor> for ImportType {
|
impl From<&GlobalDescriptor> for ImportType {
|
||||||
fn from(other: &GlobalDescriptor) -> Self {
|
fn from(other: &GlobalDescriptor) -> Self {
|
||||||
ImportType::Global {
|
ImportType::Global(*other)
|
||||||
mutable: other.mutable,
|
|
||||||
ty: other.ty,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,7 +254,7 @@ pub enum ElementType {
|
|||||||
|
|
||||||
/// Describes the properties of a table including the element types, minimum and optional maximum,
|
/// Describes the properties of a table including the element types, minimum and optional maximum,
|
||||||
/// number of elements in the table.
|
/// number of elements in the table.
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
|
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub struct TableDescriptor {
|
pub struct TableDescriptor {
|
||||||
/// Type of data stored in this table.
|
/// Type of data stored in this table.
|
||||||
pub element: ElementType,
|
pub element: ElementType,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user