summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/tinywasm/src/error.rs17
-rw-r--r--crates/tinywasm/src/interpreter/no_std_floats.rs9
-rw-r--r--crates/types/src/lib.rs12
3 files changed, 26 insertions, 12 deletions
diff --git a/crates/tinywasm/src/error.rs b/crates/tinywasm/src/error.rs
index e0510b2..1d488d8 100644
--- a/crates/tinywasm/src/error.rs
+++ b/crates/tinywasm/src/error.rs
@@ -1,6 +1,7 @@
use alloc::string::{String, ToString};
use alloc::vec::Vec;
use core::{fmt::Display, ops::ControlFlow};
+use tinywasm_types::archive::TwasmError;
use tinywasm_types::FuncType;
#[cfg(feature = "parser")]
@@ -8,6 +9,7 @@ pub use tinywasm_parser::ParseError;
/// Errors that can occur for `TinyWasm` operations
#[derive(Debug)]
+#[non_exhaustive]
pub enum Error {
/// A WebAssembly trap occurred
Trap(Trap),
@@ -41,7 +43,10 @@ pub enum Error {
#[cfg(feature = "parser")]
/// A parsing error occurred
- ParseError(ParseError),
+ Parser(ParseError),
+
+ /// A serialization error occurred
+ Twasm(TwasmError),
}
#[derive(Debug)]
@@ -169,6 +174,11 @@ impl From<LinkingError> for Error {
}
}
+impl From<TwasmError> for Error {
+ fn from(value: TwasmError) -> Self {
+ Self::Twasm(value)
+ }
+}
impl From<Trap> for Error {
fn from(value: Trap) -> Self {
Self::Trap(value)
@@ -179,11 +189,12 @@ impl Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
#[cfg(feature = "parser")]
- Self::ParseError(err) => write!(f, "error parsing module: {err:?}"),
+ Self::Parser(err) => write!(f, "error parsing module: {err:?}"),
#[cfg(feature = "std")]
Self::Io(err) => write!(f, "I/O error: {err}"),
+ Self::Twasm(err) => write!(f, "serialization error: {err}"),
Self::Trap(trap) => write!(f, "trap: {trap}"),
Self::Linker(err) => write!(f, "linking error: {err}"),
Self::InvalidLabelType => write!(f, "invalid label type"),
@@ -238,7 +249,7 @@ impl core::error::Error for Error {}
#[cfg(feature = "parser")]
impl From<tinywasm_parser::ParseError> for Error {
fn from(value: tinywasm_parser::ParseError) -> Self {
- Self::ParseError(value)
+ Self::Parser(value)
}
}
diff --git a/crates/tinywasm/src/interpreter/no_std_floats.rs b/crates/tinywasm/src/interpreter/no_std_floats.rs
index 5b9471e..e273184 100644
--- a/crates/tinywasm/src/interpreter/no_std_floats.rs
+++ b/crates/tinywasm/src/interpreter/no_std_floats.rs
@@ -1,34 +1,25 @@
pub(super) trait NoStdFloatExt {
fn round(self) -> Self;
- fn abs(self) -> Self;
- fn signum(self) -> Self;
fn ceil(self) -> Self;
fn floor(self) -> Self;
fn trunc(self) -> Self;
fn sqrt(self) -> Self;
- fn copysign(self, other: Self) -> Self;
}
#[rustfmt::skip]
impl NoStdFloatExt for f64 {
#[inline] fn round(self) -> Self { libm::round(self) }
- #[inline] fn abs(self) -> Self { libm::fabs(self) }
- #[inline] fn signum(self) -> Self { libm::copysign(1.0, self) }
#[inline] fn ceil(self) -> Self { libm::ceil(self) }
#[inline] fn floor(self) -> Self { libm::floor(self) }
#[inline] fn trunc(self) -> Self { libm::trunc(self) }
#[inline] fn sqrt(self) -> Self { libm::sqrt(self) }
- #[inline] fn copysign(self, other: Self) -> Self { libm::copysign(self, other) }
}
#[rustfmt::skip]
impl NoStdFloatExt for f32 {
#[inline] fn round(self) -> Self { libm::roundf(self) }
- #[inline] fn abs(self) -> Self { libm::fabsf(self) }
- #[inline] fn signum(self) -> Self { libm::copysignf(1.0, self) }
#[inline] fn ceil(self) -> Self { libm::ceilf(self) }
#[inline] fn floor(self) -> Self { libm::floorf(self) }
#[inline] fn trunc(self) -> Self { libm::truncf(self) }
#[inline] fn sqrt(self) -> Self { libm::sqrtf(self) }
- #[inline] fn copysign(self, other: Self) -> Self { libm::copysignf(self, other) }
}
diff --git a/crates/types/src/lib.rs b/crates/types/src/lib.rs
index 81eec13..d9f2234 100644
--- a/crates/types/src/lib.rs
+++ b/crates/types/src/lib.rs
@@ -45,6 +45,18 @@ pub use value::*;
#[cfg(feature = "archive")]
pub mod archive;
+#[cfg(not(feature = "archive"))]
+pub mod archive {
+ #[derive(Debug)]
+ pub enum TwasmError {}
+ impl core::fmt::Display for TwasmError {
+ fn fmt(&self, _: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+ Err(core::fmt::Error)
+ }
+ }
+ impl core::error::Error for TwasmError {}
+}
+
/// A `TinyWasm` WebAssembly Module
///
/// This is the internal representation of a WebAssembly module in `TinyWasm`.