mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-12 13:28:49 +00:00
Address most of the comments
This commit is contained in:
@@ -42,12 +42,6 @@ impl Default for Engine {
|
||||
}
|
||||
}
|
||||
|
||||
// impl Into<Engine> for engine_imp::Engine {
|
||||
// fn into(self) -> Engine {
|
||||
// Engine(self)
|
||||
// }
|
||||
// }
|
||||
|
||||
impl From<engine_imp::Engine> for Engine {
|
||||
fn from(inner: engine_imp::Engine) -> Self {
|
||||
Self(inner)
|
||||
|
||||
@@ -4,43 +4,6 @@ use thiserror::Error;
|
||||
#[cfg(feature = "sys")]
|
||||
pub use wasmer_compiler::{LinkError, RuntimeError};
|
||||
|
||||
// /// An error while instantiating a module.
|
||||
// ///
|
||||
// /// This is not a common WebAssembly error, however
|
||||
// /// we need to differentiate from a `LinkError` (an error
|
||||
// /// that happens while linking, on instantiation), a
|
||||
// /// Trap that occurs when calling the WebAssembly module
|
||||
// /// start function, and an error when initializing the user's
|
||||
// /// host environments.
|
||||
// #[derive(Debug)]
|
||||
// #[cfg_attr(feature = "std", derive(Error))]
|
||||
// pub enum InstantiationError {
|
||||
// /// A linking ocurred during instantiation.
|
||||
// #[cfg_attr(feature = "std", error(transparent))]
|
||||
// Link(LinkError),
|
||||
|
||||
// /// A runtime error occured while invoking the start function
|
||||
// #[cfg_attr(feature = "std", error(transparent))]
|
||||
// Start(RuntimeError),
|
||||
|
||||
// /// The module was compiled with a CPU feature that is not available on
|
||||
// /// the current host.
|
||||
// #[cfg_attr(feature = "std", error("missing required CPU features: {0:?}"))]
|
||||
// CpuFeature(String),
|
||||
|
||||
// /// Import from a different [`Store`].
|
||||
// /// This error occurs when an import from a different store is used.
|
||||
// #[cfg_attr(feature = "std", error("cannot mix imports from different stores"))]
|
||||
// DifferentStores,
|
||||
// }
|
||||
|
||||
// #[cfg(feature = "core")]
|
||||
// impl std::fmt::Display for InstantiationError {
|
||||
// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
// write!(f, "InstantiationError")
|
||||
// }
|
||||
// }
|
||||
|
||||
/// An error while instantiating a module.
|
||||
///
|
||||
/// This is not a common WebAssembly error, however
|
||||
@@ -49,28 +12,36 @@ pub use wasmer_compiler::{LinkError, RuntimeError};
|
||||
/// Trap that occurs when calling the WebAssembly module
|
||||
/// start function, and an error when initializing the user's
|
||||
/// host environments.
|
||||
#[derive(Error, Debug)]
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "std", derive(Error))]
|
||||
pub enum InstantiationError {
|
||||
/// A linking ocurred during instantiation.
|
||||
#[error(transparent)]
|
||||
#[cfg_attr(feature = "std", error(transparent))]
|
||||
Link(LinkError),
|
||||
|
||||
/// A runtime error occured while invoking the start function
|
||||
#[error(transparent)]
|
||||
#[cfg_attr(feature = "std", error(transparent))]
|
||||
Start(RuntimeError),
|
||||
|
||||
/// The module was compiled with a CPU feature that is not available on
|
||||
/// the current host.
|
||||
#[error("missing required CPU features: {0:?}")]
|
||||
#[cfg_attr(feature = "std", error("missing required CPU features: {0:?}"))]
|
||||
CpuFeature(String),
|
||||
|
||||
/// Import from a different Store.
|
||||
/// Import from a different [`Store`].
|
||||
/// This error occurs when an import from a different store is used.
|
||||
#[error("cannot mix imports from different stores")]
|
||||
#[cfg_attr(feature = "std", error("cannot mix imports from different stores"))]
|
||||
DifferentStores,
|
||||
|
||||
/// Import from a different Store.
|
||||
/// This error occurs when an import from a different store is used.
|
||||
#[error("incorrect OS or architecture")]
|
||||
#[cfg_attr(feature = "std", error("incorrect OS or architecture"))]
|
||||
DifferentArchOS,
|
||||
}
|
||||
|
||||
#[cfg(feature = "core")]
|
||||
impl std::fmt::Display for InstantiationError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "InstantiationError")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,25 +13,25 @@ impl ExternRef {
|
||||
where
|
||||
T: Any + Send + Sync + 'static + Sized,
|
||||
{
|
||||
unimplemented!();
|
||||
unimplemented!("ExternRef is not yet supported in Javascript");
|
||||
}
|
||||
|
||||
pub fn downcast<'a, T>(&self, store: &'a impl AsStoreRef) -> Option<&'a T>
|
||||
where
|
||||
T: Any + Send + Sync + 'static + Sized,
|
||||
{
|
||||
unimplemented!();
|
||||
unimplemented!("ExternRef is not yet supported in Javascript");
|
||||
}
|
||||
|
||||
pub(crate) fn vm_externref(&self) -> VMExternRef {
|
||||
unimplemented!();
|
||||
unimplemented!("ExternRef is not yet supported in Javascript");
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn from_vm_externref(
|
||||
store: &mut impl AsStoreMut,
|
||||
vm_externref: VMExternRef,
|
||||
) -> Self {
|
||||
unimplemented!();
|
||||
unimplemented!("ExternRef is not yet supported in Javascript");
|
||||
}
|
||||
|
||||
pub fn is_from_store(&self, store: &impl AsStoreRef) -> bool {
|
||||
|
||||
@@ -237,7 +237,8 @@ impl Module {
|
||||
bytes: impl IntoBytes,
|
||||
) -> Result<Self, DeserializeError> {
|
||||
#[cfg(feature = "js-serializable-module")]
|
||||
return Self::new(_engine, bytes.into_bytes()).map_err(|e| DeserializeError::Compiler(e));
|
||||
return Self::from_binary(_engine, &bytes.into_bytes())
|
||||
.map_err(|e| DeserializeError::Compiler(e));
|
||||
|
||||
#[cfg(not(feature = "js-serializable-module"))]
|
||||
return Err(DeserializeError::Generic("You need to enable the `js-serializable-module` feature flag to deserialize a `Module`".to_string()));
|
||||
|
||||
@@ -110,6 +110,7 @@ impl VMMemory {
|
||||
/// The shared memory is the same as the normal memory
|
||||
pub type VMSharedMemory = VMMemory;
|
||||
|
||||
/// The VM Global type
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct VMGlobal {
|
||||
pub(crate) global: JsGlobal,
|
||||
@@ -125,6 +126,7 @@ impl VMGlobal {
|
||||
unsafe impl Send for VMGlobal {}
|
||||
unsafe impl Sync for VMGlobal {}
|
||||
|
||||
/// The VM Table type
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct VMTable {
|
||||
pub(crate) table: JsTable,
|
||||
@@ -138,11 +140,14 @@ impl VMTable {
|
||||
pub(crate) fn new(table: JsTable, ty: TableType) -> Self {
|
||||
Self { table, ty }
|
||||
}
|
||||
|
||||
/// Get the table size at runtime
|
||||
pub fn get_runtime_size(&self) -> u32 {
|
||||
self.table.length()
|
||||
}
|
||||
}
|
||||
|
||||
/// The VM Function type
|
||||
#[derive(Clone)]
|
||||
pub struct VMFunction {
|
||||
pub(crate) function: JsFunction,
|
||||
|
||||
@@ -13,7 +13,7 @@ use wasmer_vm::init_traps;
|
||||
pub use wasmer_vm::TrapHandlerFn;
|
||||
|
||||
#[cfg(feature = "sys")]
|
||||
use crate::sys::WasmerCompilerEngine;
|
||||
use crate::sys::NativeEngineExt;
|
||||
#[cfg(feature = "sys")]
|
||||
pub use wasmer_vm::{StoreHandle, StoreObjects};
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ impl From<EngineBuilder> for crate::engine::Engine {
|
||||
|
||||
/// The custom trait to access to all the `sys` function in the common
|
||||
/// engine.
|
||||
pub trait WasmerCompilerEngine {
|
||||
pub trait NativeEngineExt {
|
||||
/// Create a new `Engine` with the given config
|
||||
#[cfg(feature = "compiler")]
|
||||
fn new(compiler_config: Box<dyn CompilerConfig>, target: Target, features: Features) -> Self;
|
||||
@@ -95,7 +95,7 @@ pub trait WasmerCompilerEngine {
|
||||
fn tunables(&self) -> &dyn Tunables;
|
||||
}
|
||||
|
||||
impl WasmerCompilerEngine for crate::engine::Engine {
|
||||
impl NativeEngineExt for crate::engine::Engine {
|
||||
fn new(compiler_config: Box<dyn CompilerConfig>, target: Target, features: Features) -> Self {
|
||||
crate::engine::Engine(Engine::new(compiler_config, target, features))
|
||||
}
|
||||
|
||||
2
lib/api/src/sys/externals/memory.rs
vendored
2
lib/api/src/sys/externals/memory.rs
vendored
@@ -1,6 +1,6 @@
|
||||
use super::memory_view::MemoryView;
|
||||
use crate::store::{AsStoreMut, AsStoreRef};
|
||||
use crate::sys::WasmerCompilerEngine;
|
||||
use crate::sys::NativeEngineExt;
|
||||
use crate::vm::VMExternMemory;
|
||||
use crate::MemoryAccessError;
|
||||
use crate::MemoryType;
|
||||
|
||||
2
lib/api/src/sys/externals/table.rs
vendored
2
lib/api/src/sys/externals/table.rs
vendored
@@ -1,5 +1,5 @@
|
||||
use crate::store::{AsStoreMut, AsStoreRef};
|
||||
use crate::sys::WasmerCompilerEngine;
|
||||
use crate::sys::NativeEngineExt;
|
||||
use crate::TableType;
|
||||
use crate::Value;
|
||||
use crate::{vm::VMExternTable, ExternRef, Function, RuntimeError};
|
||||
|
||||
@@ -6,7 +6,7 @@ pub(crate) mod module;
|
||||
mod tunables;
|
||||
pub(crate) mod typed_function;
|
||||
|
||||
pub use crate::sys::engine::WasmerCompilerEngine;
|
||||
pub use crate::sys::engine::NativeEngineExt;
|
||||
pub use crate::sys::tunables::BaseTunables;
|
||||
pub use target_lexicon::{Architecture, CallingConvention, OperatingSystem, Triple, HOST};
|
||||
#[cfg(feature = "compiler")]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::engine::AsEngineRef;
|
||||
use crate::sys::engine::WasmerCompilerEngine;
|
||||
use crate::sys::engine::NativeEngineExt;
|
||||
use bytes::Bytes;
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -6,7 +6,7 @@ pub use wasmer_compiler::BaseTunables;
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sys::WasmerCompilerEngine;
|
||||
use crate::sys::NativeEngineExt;
|
||||
use crate::TableType;
|
||||
use std::cell::UnsafeCell;
|
||||
use std::ptr::NonNull;
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
#[cfg(feature = "js")]
|
||||
pub(crate) use crate::js::vm::{
|
||||
VMExtern, VMExternFunction, VMExternGlobal, VMExternMemory, VMExternRef, VMExternTable,
|
||||
VMFuncRef, VMFunction, VMFunctionBody, VMFunctionEnvironment, VMGlobal, VMInstance, VMMemory,
|
||||
VMSharedMemory, VMTable, VMTrampoline,
|
||||
VMFuncRef, VMFunctionBody, VMFunctionEnvironment, VMInstance, VMTrampoline,
|
||||
};
|
||||
|
||||
#[cfg(feature = "sys")]
|
||||
@@ -13,17 +12,18 @@ pub(crate) use crate::sys::vm::{
|
||||
VMFuncRef, VMFunctionBody, VMFunctionEnvironment, VMInstance, VMTrampoline,
|
||||
};
|
||||
|
||||
#[cfg(feature = "js")]
|
||||
pub use crate::js::vm::{VMFunction, VMGlobal, VMMemory, VMSharedMemory, VMTable};
|
||||
|
||||
#[cfg(feature = "sys")]
|
||||
pub use wasmer_vm::{VMFunction, VMGlobal, VMMemory, VMSharedMemory, VMTable};
|
||||
|
||||
// Needed for tunables customization (those are public types now)
|
||||
#[cfg(feature = "sys")]
|
||||
pub use wasmer_vm::{
|
||||
// An extra one for VMMemory implementors
|
||||
LinearMemory,
|
||||
VMFunction,
|
||||
VMGlobal,
|
||||
VMMemory,
|
||||
VMMemoryDefinition,
|
||||
VMSharedMemory,
|
||||
VMTable,
|
||||
VMTableDefinition,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user