From f3d890a36d6299dbd70377ce57b0bd9d61de5c1b Mon Sep 17 00:00:00 2001 From: Henry Gressmann Date: Fri, 26 Jan 2024 12:03:59 +0100 Subject: docs: working selfhosted example Signed-off-by: Henry Gressmann --- crates/tinywasm/src/error.rs | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'crates') diff --git a/crates/tinywasm/src/error.rs b/crates/tinywasm/src/error.rs index 0344e82..4f68eaa 100644 --- a/crates/tinywasm/src/error.rs +++ b/crates/tinywasm/src/error.rs @@ -186,8 +186,8 @@ impl Display for Error { #[cfg(feature = "std")] Self::Io(err) => write!(f, "I/O error: {}", err), - Self::Trap(trap) => write!(f, "trap: {}", trap.message()), - Self::Linker(err) => write!(f, "linking error: {}", err.message()), + Self::Trap(trap) => write!(f, "trap: {}", trap), + Self::Linker(err) => write!(f, "linking error: {}", err), Self::CallStackEmpty => write!(f, "call stack empty"), Self::InvalidLabelType => write!(f, "invalid label type"), Self::Other(message) => write!(f, "unknown error: {}", message), @@ -200,6 +200,42 @@ impl Display for Error { } } +impl Display for LinkingError { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Self::UnknownImport { module, name } => write!(f, "unknown import: {}.{}", module, name), + Self::IncompatibleImportType { module, name } => { + write!(f, "incompatible import type: {}.{}", module, name) + } + } + } +} + +impl Display for Trap { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Self::Unreachable => write!(f, "unreachable"), + Self::MemoryOutOfBounds { offset, len, max } => { + write!(f, "out of bounds memory access: offset={}, len={}, max={}", offset, len, max) + } + Self::TableOutOfBounds { offset, len, max } => { + write!(f, "out of bounds table access: offset={}, len={}, max={}", offset, len, max) + } + Self::DivisionByZero => write!(f, "integer divide by zero"), + Self::InvalidConversionToInt => write!(f, "invalid conversion to integer"), + Self::IntegerOverflow => write!(f, "integer overflow"), + Self::CallStackOverflow => write!(f, "call stack exhausted"), + Self::UndefinedElement { index } => write!(f, "undefined element: index={}", index), + Self::UninitializedElement { index } => { + write!(f, "uninitialized element: index={}", index) + } + Self::IndirectCallTypeMismatch { expected, actual } => { + write!(f, "indirect call type mismatch: expected={:?}, actual={:?}", expected, actual) + } + } + } +} + #[cfg(any(feature = "std", all(not(feature = "std"), nightly)))] impl crate::std::error::Error for Error {} -- cgit v1.3.1