diff --git a/lib/api/src/externals/function.rs b/lib/api/src/externals/function.rs new file mode 100644 index 000000000..05b873265 --- /dev/null +++ b/lib/api/src/externals/function.rs @@ -0,0 +1,8 @@ +#[cfg(feature = "js")] +pub use crate::js::externals::function::{ + FromToNativeWasmType, Function, HostFunction, WasmTypeList, +}; +#[cfg(feature = "sys")] +pub use crate::sys::externals::function::{ + FromToNativeWasmType, Function, HostFunction, WasmTypeList, +}; diff --git a/lib/api/src/externals/global.rs b/lib/api/src/externals/global.rs new file mode 100644 index 000000000..72fc12150 --- /dev/null +++ b/lib/api/src/externals/global.rs @@ -0,0 +1,4 @@ +#[cfg(feature = "js")] +pub use crate::js::externals::global::Global; +#[cfg(feature = "sys")] +pub use crate::sys::externals::global::Global; diff --git a/lib/api/src/externals/memory.rs b/lib/api/src/externals/memory.rs new file mode 100644 index 000000000..b8c9ee921 --- /dev/null +++ b/lib/api/src/externals/memory.rs @@ -0,0 +1,4 @@ +#[cfg(feature = "js")] +pub use crate::js::externals::memory::Memory; +#[cfg(feature = "sys")] +pub use crate::sys::externals::memory::Memory; diff --git a/lib/api/src/externals/memory_view.rs b/lib/api/src/externals/memory_view.rs new file mode 100644 index 000000000..200761583 --- /dev/null +++ b/lib/api/src/externals/memory_view.rs @@ -0,0 +1,4 @@ +#[cfg(feature = "js")] +pub use crate::js::externals::memory_view::MemoryView; +#[cfg(feature = "sys")] +pub use crate::sys::externals::memory_view::MemoryView; diff --git a/lib/api/src/externals/mod.rs b/lib/api/src/externals/mod.rs new file mode 100644 index 000000000..50d2b7c55 --- /dev/null +++ b/lib/api/src/externals/mod.rs @@ -0,0 +1,126 @@ +mod function; +mod global; +mod memory; +mod memory_view; +mod table; + +pub use self::function::{FromToNativeWasmType, Function, HostFunction, WasmTypeList}; +pub use self::global::Global; +pub use self::memory::Memory; +pub use self::memory_view::MemoryView; +pub use self::table::Table; + +use crate::exports::{ExportError, Exportable}; +use crate::ExternType; +use std::fmt; + +#[cfg(feature = "js")] +use crate::js::vm::VMExtern; +#[cfg(feature = "sys")] +use wasmer_vm::VMExtern; + +use crate::store::{AsStoreMut, AsStoreRef}; + +/// An `Extern` is the runtime representation of an entity that +/// can be imported or exported. +/// +/// Spec: +#[derive(Clone)] +pub enum Extern { + /// A external [`Function`]. + Function(Function), + /// A external [`Global`]. + Global(Global), + /// A external [`Table`]. + Table(Table), + /// A external [`Memory`]. + Memory(Memory), +} + +impl Extern { + /// Return the underlying type of the inner `Extern`. + pub fn ty(&self, store: &impl AsStoreRef) -> ExternType { + match self { + Self::Function(ft) => ExternType::Function(ft.ty(store)), + Self::Memory(ft) => ExternType::Memory(ft.ty(store)), + Self::Table(tt) => ExternType::Table(tt.ty(store)), + Self::Global(gt) => ExternType::Global(gt.ty(store)), + } + } + + /// Create an `Extern` from an `wasmer_engine::Export`. + pub fn from_vm_extern(store: &mut impl AsStoreMut, vm_extern: VMExtern) -> Self { + match vm_extern { + VMExtern::Function(f) => Self::Function(Function::from_vm_extern(store, f)), + VMExtern::Memory(m) => Self::Memory(Memory::from_vm_extern(store, m)), + VMExtern::Global(g) => Self::Global(Global::from_vm_extern(store, g)), + VMExtern::Table(t) => Self::Table(Table::from_vm_extern(store, t)), + } + } + + /// Checks whether this `Extern` can be used with the given context. + pub fn is_from_store(&self, store: &impl AsStoreRef) -> bool { + match self { + Self::Function(f) => f.is_from_store(store), + Self::Global(g) => g.is_from_store(store), + Self::Memory(m) => m.is_from_store(store), + Self::Table(t) => t.is_from_store(store), + } + } + + /// To `VMExtern`. + pub fn to_vm_extern(&self) -> VMExtern { + match self { + Self::Function(f) => f.to_vm_extern(), + Self::Global(g) => g.to_vm_extern(), + Self::Memory(m) => m.to_vm_extern(), + Self::Table(t) => t.to_vm_extern(), + } + } +} + +impl<'a> Exportable<'a> for Extern { + fn get_self_from_extern(_extern: &'a Self) -> Result<&'a Self, ExportError> { + // Since this is already an extern, we can just return it. + Ok(_extern) + } +} + +impl fmt::Debug for Extern { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!( + f, + "{}", + match self { + Self::Function(_) => "Function(...)", + Self::Global(_) => "Global(...)", + Self::Memory(_) => "Memory(...)", + Self::Table(_) => "Table(...)", + } + ) + } +} + +impl From for Extern { + fn from(r: Function) -> Self { + Self::Function(r) + } +} + +impl From for Extern { + fn from(r: Global) -> Self { + Self::Global(r) + } +} + +impl From for Extern { + fn from(r: Memory) -> Self { + Self::Memory(r) + } +} + +impl From for Extern { + fn from(r: Table) -> Self { + Self::Table(r) + } +} diff --git a/lib/api/src/externals/table.rs b/lib/api/src/externals/table.rs new file mode 100644 index 000000000..498eb6a1b --- /dev/null +++ b/lib/api/src/externals/table.rs @@ -0,0 +1,4 @@ +#[cfg(feature = "js")] +pub use crate::js::externals::table::Table; +#[cfg(feature = "sys")] +pub use crate::sys::externals::table::Table; diff --git a/lib/api/src/js/as_js.rs b/lib/api/src/js/as_js.rs index 974ae6812..15d417ea0 100644 --- a/lib/api/src/js/as_js.rs +++ b/lib/api/src/js/as_js.rs @@ -2,7 +2,6 @@ // use crate::store::{Store, StoreObject}; // use crate::js::RuntimeError; use crate::imports::Imports; -use crate::js::externals::{Extern, Function, Global, Memory, Table}; use crate::js::instance::Instance; use crate::js::vm::{VMExtern, VMFunction, VMGlobal, VMMemory, VMTable}; use crate::js::wasm_bindgen_polyfill::Global as JsGlobal; @@ -10,6 +9,7 @@ use crate::store::{AsStoreMut, AsStoreRef}; use crate::value::Value; use crate::Exports; use crate::Type; +use crate::{Extern, Function, Global, Memory, Table}; use js_sys::Function as JsFunction; use js_sys::WebAssembly::{Memory as JsMemory, Table as JsTable}; use std::collections::HashMap; diff --git a/lib/api/src/js/externals/function.rs b/lib/api/src/js/externals/function.rs index bfd527394..02ab10e78 100644 --- a/lib/api/src/js/externals/function.rs +++ b/lib/api/src/js/externals/function.rs @@ -2,11 +2,11 @@ pub use self::inner::{FromToNativeWasmType, HostFunction, WasmTypeList, WithEnv, use crate::exports::{ExportError, Exportable}; use crate::function_env::{FunctionEnv, FunctionEnvMut}; use crate::js::as_js::{param_from_js, AsJs}; /* ValFuncRef */ -use crate::js::externals::Extern; use crate::js::vm::VMExtern; use crate::js::RuntimeError; use crate::store::{AsStoreMut, AsStoreRef, StoreMut}; use crate::value::Value; +use crate::Extern; use crate::FunctionType; use crate::TypedFunction; use js_sys::{Array, Function as JSFunction}; diff --git a/lib/api/src/js/externals/global.rs b/lib/api/src/js/externals/global.rs index 410803f7d..e926447dd 100644 --- a/lib/api/src/js/externals/global.rs +++ b/lib/api/src/js/externals/global.rs @@ -1,10 +1,10 @@ use crate::exports::{ExportError, Exportable}; -use crate::js::externals::Extern; use crate::js::vm::{VMExtern, VMGlobal}; use crate::js::wasm_bindgen_polyfill::Global as JSGlobal; use crate::js::RuntimeError; use crate::store::{AsStoreMut, AsStoreRef}; use crate::value::Value; +use crate::Extern; use crate::GlobalType; use crate::Mutability; use wasm_bindgen::JsValue; diff --git a/lib/api/src/js/externals/memory.rs b/lib/api/src/js/externals/memory.rs index 4b45ba908..bed54b9a3 100644 --- a/lib/api/src/js/externals/memory.rs +++ b/lib/api/src/js/externals/memory.rs @@ -1,8 +1,8 @@ use crate::exports::{ExportError, Exportable}; -use crate::js::externals::Extern; use crate::js::vm::{VMExtern, VMMemory}; use crate::mem_access::MemoryAccessError; use crate::store::{AsStoreMut, AsStoreRef, StoreObjects}; +use crate::Extern; use crate::MemoryType; use std::marker::PhantomData; use std::mem::MaybeUninit; @@ -14,7 +14,7 @@ use wasm_bindgen::prelude::*; use wasm_bindgen::JsCast; use wasmer_types::{Pages, WASM_PAGE_SIZE}; -use super::MemoryView; +use super::memory_view::MemoryView; pub use wasmer_types::MemoryError; diff --git a/lib/api/src/js/externals/memory_view.rs b/lib/api/src/js/externals/memory_view.rs index 03619cda8..230d4aee7 100644 --- a/lib/api/src/js/externals/memory_view.rs +++ b/lib/api/src/js/externals/memory_view.rs @@ -9,8 +9,7 @@ use tracing::warn; use wasmer_types::{Bytes, Pages}; -use super::memory::MemoryBuffer; -use super::Memory; +use super::memory::{Memory, MemoryBuffer}; /// A WebAssembly `memory` view. /// diff --git a/lib/api/src/js/externals/mod.rs b/lib/api/src/js/externals/mod.rs index b58e17ae1..3575fe23b 100644 --- a/lib/api/src/js/externals/mod.rs +++ b/lib/api/src/js/externals/mod.rs @@ -3,119 +3,3 @@ pub(crate) mod global; pub(crate) mod memory; pub(crate) mod memory_view; pub(crate) mod table; - -pub use self::function::{FromToNativeWasmType, Function, HostFunction, WasmTypeList}; -pub use self::global::Global; -pub use self::memory::{Memory, MemoryError}; -pub use self::memory_view::MemoryView; -pub use self::table::Table; - -use crate::exports::{ExportError, Exportable}; -use crate::js::vm::VMExtern; -use crate::store::{AsStoreMut, AsStoreRef}; -use std::fmt; -use wasmer_types::ExternType; - -/// An `Extern` is the runtime representation of an entity that -/// can be imported or exported. -/// -/// Spec: -#[derive(Clone)] -pub enum Extern { - /// A external [`Function`]. - Function(Function), - /// A external [`Global`]. - Global(Global), - /// A external [`Table`]. - Table(Table), - /// A external [`Memory`]. - Memory(Memory), -} - -impl Extern { - /// Return the underlying type of the inner `Extern`. - pub fn ty(&self, store: &impl AsStoreRef) -> ExternType { - match self { - Self::Function(ft) => ExternType::Function(ft.ty(store)), - Self::Memory(ft) => ExternType::Memory(ft.ty(store)), - Self::Table(tt) => ExternType::Table(tt.ty(store)), - Self::Global(gt) => ExternType::Global(gt.ty(store)), - } - } - - /// Create an `Extern` from an `wasmer_engine::Export`. - pub fn from_vm_extern(store: &mut impl AsStoreMut, vm_extern: VMExtern) -> Self { - match vm_extern { - VMExtern::Function(f) => Self::Function(Function::from_vm_extern(store, f)), - VMExtern::Memory(m) => Self::Memory(Memory::from_vm_extern(store, m)), - VMExtern::Global(g) => Self::Global(Global::from_vm_extern(store, g)), - VMExtern::Table(t) => Self::Table(Table::from_vm_extern(store, t)), - } - } - - /// To `VMExtern`. - pub fn to_vm_extern(&self) -> VMExtern { - match self { - Self::Function(f) => f.to_vm_extern(), - Self::Global(g) => g.to_vm_extern(), - Self::Memory(m) => m.to_vm_extern(), - Self::Table(t) => t.to_vm_extern(), - } - } - - /// Checks whether this `Extern` can be used with the given context. - pub fn is_from_store(&self, store: &impl AsStoreRef) -> bool { - match self { - Self::Function(val) => val.is_from_store(store), - Self::Memory(val) => val.is_from_store(store), - Self::Global(val) => val.is_from_store(store), - Self::Table(val) => val.is_from_store(store), - } - } -} - -impl<'a> Exportable<'a> for Extern { - fn get_self_from_extern(_extern: &'a Self) -> Result<&'a Self, ExportError> { - // Since this is already an extern, we can just return it. - Ok(_extern) - } -} - -impl fmt::Debug for Extern { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!( - f, - "{}", - match self { - Self::Function(_) => "Function(...)", - Self::Global(_) => "Global(...)", - Self::Memory(_) => "Memory(...)", - Self::Table(_) => "Table(...)", - } - ) - } -} - -impl From for Extern { - fn from(r: Function) -> Self { - Self::Function(r) - } -} - -impl From for Extern { - fn from(r: Global) -> Self { - Self::Global(r) - } -} - -impl From for Extern { - fn from(r: Memory) -> Self { - Self::Memory(r) - } -} - -impl From
for Extern { - fn from(r: Table) -> Self { - Self::Table(r) - } -} diff --git a/lib/api/src/js/externals/table.rs b/lib/api/src/js/externals/table.rs index 631186602..ab3357ee9 100644 --- a/lib/api/src/js/externals/table.rs +++ b/lib/api/src/js/externals/table.rs @@ -1,9 +1,9 @@ use crate::exports::{ExportError, Exportable}; -use crate::js::externals::Extern; use crate::js::vm::{VMExtern, VMFunction, VMTable}; use crate::js::RuntimeError; use crate::store::{AsStoreMut, AsStoreRef}; use crate::value::Value; +use crate::Extern; use crate::{FunctionType, TableType}; use js_sys::Function; @@ -83,7 +83,7 @@ impl Table { if let Some(func) = self.handle.table.get(index).ok() { let ty = FunctionType::new(vec![], vec![]); let vm_function = VMFunction::new(func, ty); - let function = crate::js::externals::Function::from_vm_extern(store, vm_function); + let function = crate::Function::from_vm_extern(store, vm_function); Some(Value::FuncRef(Some(function))) } else { None diff --git a/lib/api/src/js/instance.rs b/lib/api/src/js/instance.rs index 2a54097ea..f392ea172 100644 --- a/lib/api/src/js/instance.rs +++ b/lib/api/src/js/instance.rs @@ -2,10 +2,10 @@ use crate::errors::InstantiationError; use crate::exports::Exports; use crate::imports::Imports; use crate::js::as_js::AsJs; -use crate::js::externals::Extern; use crate::js::vm::{VMExtern, VMInstance}; use crate::module::Module; use crate::store::{AsStoreMut, AsStoreRef}; +use crate::Extern; use crate::{LinkError, RuntimeError}; use js_sys::WebAssembly; diff --git a/lib/api/src/js/mod.rs b/lib/api/src/js/mod.rs index aab009b62..e7d136450 100644 --- a/lib/api/src/js/mod.rs +++ b/lib/api/src/js/mod.rs @@ -40,10 +40,6 @@ mod wasm_bindgen_polyfill; pub use crate::js::as_js::AsJs; pub use crate::js::error::{DeserializeError, LinkError, SerializeError}; -pub use crate::js::externals::{ - Extern, FromToNativeWasmType, Function, Global, HostFunction, Memory, MemoryError, MemoryView, - Table, WasmTypeList, -}; pub use crate::js::module::{Module, ModuleTypeHints}; pub use crate::js::store::StoreObjects; pub use crate::js::trap::RuntimeError; diff --git a/lib/api/src/js/module.rs b/lib/api/src/js/module.rs index fdf515275..85c6d2f3c 100644 --- a/lib/api/src/js/module.rs +++ b/lib/api/src/js/module.rs @@ -1,11 +1,11 @@ use crate::errors::InstantiationError; use crate::imports::Imports; -use crate::js::externals::Extern; use crate::js::vm::VMInstance; use crate::js::AsJs; use crate::js::RuntimeError; use crate::module::IoCompileError; use crate::store::AsStoreMut; +use crate::Extern; use crate::IntoBytes; use crate::{AsEngineRef, ExportType, ImportType}; use bytes::Bytes; diff --git a/lib/api/src/js/typed_function.rs b/lib/api/src/js/typed_function.rs index 075872f46..71faffa1c 100644 --- a/lib/api/src/js/typed_function.rs +++ b/lib/api/src/js/typed_function.rs @@ -9,10 +9,10 @@ //! ``` use std::marker::PhantomData; -use crate::js::externals::Function; -use crate::js::{FromToNativeWasmType, RuntimeError, WasmTypeList}; use crate::native_type::NativeWasmTypeInto; +use crate::Function; use crate::{AsStoreMut, AsStoreRef, TypedFunction}; +use crate::{FromToNativeWasmType, RuntimeError, WasmTypeList}; // use std::panic::{catch_unwind, AssertUnwindSafe}; use crate::js::as_js::{param_from_js, AsJs}; use js_sys::Array; diff --git a/lib/api/src/lib.rs b/lib/api/src/lib.rs index 907d1a9fa..d6f9c1520 100644 --- a/lib/api/src/lib.rs +++ b/lib/api/src/lib.rs @@ -433,6 +433,7 @@ mod engine; mod errors; mod exports; mod extern_ref; +mod externals; mod function_env; mod imports; mod instance; @@ -457,6 +458,10 @@ mod js; #[cfg(feature = "js")] pub use js::*; +pub use crate::externals::{ + Extern, FromToNativeWasmType, Function, Global, HostFunction, Memory, MemoryView, Table, + WasmTypeList, +}; pub use engine::{AsEngineRef, Engine}; pub use errors::InstantiationError; pub use exports::{ExportError, Exportable, Exports, ExportsIterator}; @@ -481,10 +486,10 @@ pub use wasmer_derive::ValueType; // TODO: OnCalledAction is needed for asyncify. It will be refactored with https://github.com/wasmerio/wasmer/issues/3451 pub use wasmer_types::{ is_wasm, Bytes, CompileError, CpuFeature, DeserializeError, ExportIndex, ExportType, - ExternType, FunctionType, GlobalInit, GlobalType, ImportType, LocalFunctionIndex, MemoryType, - MiddlewareError, Mutability, OnCalledAction, Pages, ParseCpuFeatureError, SerializeError, - TableType, Target, Type, ValueType, WasmError, WasmResult, WASM_MAX_PAGES, WASM_MIN_PAGES, - WASM_PAGE_SIZE, + ExternType, FunctionType, GlobalInit, GlobalType, ImportType, LocalFunctionIndex, MemoryError, + MemoryType, MiddlewareError, Mutability, OnCalledAction, Pages, ParseCpuFeatureError, + SerializeError, TableType, Target, Type, ValueType, WasmError, WasmResult, WASM_MAX_PAGES, + WASM_MIN_PAGES, WASM_PAGE_SIZE, }; #[cfg(feature = "wat")] pub use wat::parse_bytes as wat2wasm; diff --git a/lib/api/src/sys/externals/function.rs b/lib/api/src/sys/externals/function.rs index 13144c39c..a5d1ea1c4 100644 --- a/lib/api/src/sys/externals/function.rs +++ b/lib/api/src/sys/externals/function.rs @@ -7,7 +7,7 @@ use wasmer_vm::{ use crate::exports::{ExportError, Exportable}; use crate::store::{AsStoreMut, AsStoreRef}; -use crate::sys::externals::Extern; +use crate::Extern; use crate::FunctionEnv; use crate::{FunctionType, RuntimeError, TypedFunction}; diff --git a/lib/api/src/sys/externals/global.rs b/lib/api/src/sys/externals/global.rs index 58394d330..c16c7b212 100644 --- a/lib/api/src/sys/externals/global.rs +++ b/lib/api/src/sys/externals/global.rs @@ -1,8 +1,8 @@ use crate::exports::{ExportError, Exportable}; use crate::store::{AsStoreMut, AsStoreRef}; -use crate::sys::externals::Extern; use crate::sys::RuntimeError; use crate::value::Value; +use crate::Extern; use crate::GlobalType; use crate::Mutability; use wasmer_vm::{InternalStoreHandle, StoreHandle, VMExtern, VMGlobal}; diff --git a/lib/api/src/sys/externals/memory.rs b/lib/api/src/sys/externals/memory.rs index 364f6fac5..c4619df42 100644 --- a/lib/api/src/sys/externals/memory.rs +++ b/lib/api/src/sys/externals/memory.rs @@ -1,6 +1,6 @@ use crate::exports::{ExportError, Exportable}; use crate::store::{AsStoreMut, AsStoreRef}; -use crate::sys::externals::Extern; +use crate::Extern; use crate::MemoryAccessError; use crate::MemoryType; use std::convert::TryInto; @@ -13,7 +13,7 @@ use tracing::warn; use wasmer_types::Pages; use wasmer_vm::{InternalStoreHandle, LinearMemory, MemoryError, StoreHandle, VMExtern, VMMemory}; -use super::MemoryView; +use super::memory_view::MemoryView; /// A WebAssembly `memory` instance. /// diff --git a/lib/api/src/sys/externals/memory_view.rs b/lib/api/src/sys/externals/memory_view.rs index 94044f877..8adc29d91 100644 --- a/lib/api/src/sys/externals/memory_view.rs +++ b/lib/api/src/sys/externals/memory_view.rs @@ -7,8 +7,7 @@ use std::slice; use wasmer_types::Pages; use wasmer_vm::LinearMemory; -use super::memory::MemoryBuffer; -use super::Memory; +use super::memory::{Memory, MemoryBuffer}; /// A WebAssembly `memory` view. /// diff --git a/lib/api/src/sys/externals/mod.rs b/lib/api/src/sys/externals/mod.rs index f2d63fe8b..3575fe23b 100644 --- a/lib/api/src/sys/externals/mod.rs +++ b/lib/api/src/sys/externals/mod.rs @@ -3,121 +3,3 @@ pub(crate) mod global; pub(crate) mod memory; pub(crate) mod memory_view; pub(crate) mod table; - -pub use self::function::{FromToNativeWasmType, Function, HostFunction, WasmTypeList}; - -pub use self::global::Global; -pub use self::memory::Memory; -pub use self::memory_view::MemoryView; -pub use self::table::Table; - -use crate::exports::{ExportError, Exportable}; -use crate::ExternType; -use std::fmt; -use wasmer_vm::VMExtern; - -use crate::store::{AsStoreMut, AsStoreRef}; - -/// An `Extern` is the runtime representation of an entity that -/// can be imported or exported. -/// -/// Spec: -#[derive(Clone)] -pub enum Extern { - /// A external [`Function`]. - Function(Function), - /// A external [`Global`]. - Global(Global), - /// A external [`Table`]. - Table(Table), - /// A external [`Memory`]. - Memory(Memory), -} - -impl Extern { - /// Return the underlying type of the inner `Extern`. - pub fn ty(&self, store: &impl AsStoreRef) -> ExternType { - match self { - Self::Function(ft) => ExternType::Function(ft.ty(store)), - Self::Memory(ft) => ExternType::Memory(ft.ty(store)), - Self::Table(tt) => ExternType::Table(tt.ty(store)), - Self::Global(gt) => ExternType::Global(gt.ty(store)), - } - } - - /// Create an `Extern` from an `wasmer_engine::Export`. - pub fn from_vm_extern(store: &mut impl AsStoreMut, vm_extern: VMExtern) -> Self { - match vm_extern { - VMExtern::Function(f) => Self::Function(Function::from_vm_extern(store, f)), - VMExtern::Memory(m) => Self::Memory(Memory::from_vm_extern(store, m)), - VMExtern::Global(g) => Self::Global(Global::from_vm_extern(store, g)), - VMExtern::Table(t) => Self::Table(Table::from_vm_extern(store, t)), - } - } - - /// Checks whether this `Extern` can be used with the given context. - pub fn is_from_store(&self, store: &impl AsStoreRef) -> bool { - match self { - Self::Function(f) => f.is_from_store(store), - Self::Global(g) => g.is_from_store(store), - Self::Memory(m) => m.is_from_store(store), - Self::Table(t) => t.is_from_store(store), - } - } - - /// To `VMExtern`. - pub fn to_vm_extern(&self) -> VMExtern { - match self { - Self::Function(f) => f.to_vm_extern(), - Self::Global(g) => g.to_vm_extern(), - Self::Memory(m) => m.to_vm_extern(), - Self::Table(t) => t.to_vm_extern(), - } - } -} - -impl<'a> Exportable<'a> for Extern { - fn get_self_from_extern(_extern: &'a Self) -> Result<&'a Self, ExportError> { - // Since this is already an extern, we can just return it. - Ok(_extern) - } -} - -impl fmt::Debug for Extern { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!( - f, - "{}", - match self { - Self::Function(_) => "Function(...)", - Self::Global(_) => "Global(...)", - Self::Memory(_) => "Memory(...)", - Self::Table(_) => "Table(...)", - } - ) - } -} - -impl From for Extern { - fn from(r: Function) -> Self { - Self::Function(r) - } -} - -impl From for Extern { - fn from(r: Global) -> Self { - Self::Global(r) - } -} - -impl From for Extern { - fn from(r: Memory) -> Self { - Self::Memory(r) - } -} - -impl From
for Extern { - fn from(r: Table) -> Self { - Self::Table(r) - } -} diff --git a/lib/api/src/sys/externals/table.rs b/lib/api/src/sys/externals/table.rs index 66942d470..b64e955b0 100644 --- a/lib/api/src/sys/externals/table.rs +++ b/lib/api/src/sys/externals/table.rs @@ -1,6 +1,6 @@ use crate::exports::{ExportError, Exportable}; use crate::store::{AsStoreMut, AsStoreRef}; -use crate::sys::externals::Extern; +use crate::Extern; use crate::TableType; use crate::Value; use crate::{sys::RuntimeError, ExternRef, Function}; diff --git a/lib/api/src/sys/instance.rs b/lib/api/src/sys/instance.rs index 88a6dee38..a2ef1cbc3 100644 --- a/lib/api/src/sys/instance.rs +++ b/lib/api/src/sys/instance.rs @@ -5,7 +5,7 @@ use wasmer_vm::{StoreHandle, VMInstance}; use crate::imports::Imports; use crate::store::AsStoreMut; -use crate::sys::externals::Extern; +use crate::Extern; #[derive(Clone)] pub struct Instance { diff --git a/lib/api/src/sys/mod.rs b/lib/api/src/sys/mod.rs index 312effcfd..dc6bf5cdd 100644 --- a/lib/api/src/sys/mod.rs +++ b/lib/api/src/sys/mod.rs @@ -6,11 +6,6 @@ pub(crate) mod module; mod tunables; pub(crate) mod typed_function; -pub use crate::sys::externals::{ - Extern, FromToNativeWasmType, Function, Global, HostFunction, Memory, MemoryView, Table, - WasmTypeList, -}; - pub use crate::sys::tunables::BaseTunables; pub use target_lexicon::{Architecture, CallingConvention, OperatingSystem, Triple, HOST}; #[cfg(feature = "compiler")] diff --git a/lib/api/src/sys/tunables.rs b/lib/api/src/sys/tunables.rs index 51d2f9ffd..0e7946b82 100644 --- a/lib/api/src/sys/tunables.rs +++ b/lib/api/src/sys/tunables.rs @@ -6,7 +6,7 @@ pub use wasmer_compiler::BaseTunables; #[cfg(test)] mod tests { use super::*; - use crate::sys::TableType; + use crate::TableType; use std::cell::UnsafeCell; use std::ptr::NonNull; use wasmer_compiler::Tunables;