summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorHenry Gressmann <mail@henrygressmann.de>2025-05-06 21:36:25 +0200
committerHenry Gressmann <mail@henrygressmann.de>2025-05-06 21:36:25 +0200
commitf9f760f487cfb08aa7992439bf748f7dcd46466b (patch)
tree8d08b92b30eab6e4b107ecfc2fd65a1f3603f411 /crates
parent0f3581ef8fdb55ad21fdfd132eaefadaec242f85 (diff)
chore: cleanup
Signed-off-by: Henry Gressmann <mail@henrygressmann.de>
Diffstat (limited to 'crates')
-rw-r--r--crates/cli/Cargo.toml2
-rw-r--r--crates/parser/Cargo.toml2
-rw-r--r--crates/parser/src/module.rs2
-rw-r--r--crates/parser/src/visit.rs18
-rw-r--r--crates/tinywasm/Cargo.toml4
-rw-r--r--crates/tinywasm/src/error.rs2
-rw-r--r--crates/tinywasm/src/func.rs8
-rw-r--r--crates/tinywasm/src/imports.rs4
-rw-r--r--crates/tinywasm/src/instance.rs4
-rw-r--r--crates/tinywasm/src/interpreter/executor.rs132
-rw-r--r--crates/tinywasm/src/interpreter/values.rs33
-rw-r--r--crates/tinywasm/src/lib.rs2
-rw-r--r--crates/tinywasm/src/reference.rs9
-rw-r--r--crates/tinywasm/src/store/mod.rs8
-rw-r--r--crates/tinywasm/src/store/table.rs12
-rw-r--r--crates/tinywasm/tests/testsuite/mod.rs2
-rw-r--r--crates/tinywasm/tests/testsuite/util.rs6
-rw-r--r--crates/types/Cargo.toml2
-rw-r--r--crates/types/src/archive.rs10
-rw-r--r--crates/types/src/instructions.rs2
-rw-r--r--crates/types/src/lib.rs26
-rw-r--r--crates/types/src/value.rs28
22 files changed, 186 insertions, 132 deletions
diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml
index d5e64a8..097a7c4 100644
--- a/crates/cli/Cargo.toml
+++ b/crates/cli/Cargo.toml
@@ -7,6 +7,8 @@ license.workspace=true
authors.workspace=true
repository.workspace=true
rust-version.workspace=true
+keywords.workspace=true
+categories=["wasm"]
[[bin]]
name="tinywasm-cli"
diff --git a/crates/parser/Cargo.toml b/crates/parser/Cargo.toml
index 7bd9cad..3cbeee1 100644
--- a/crates/parser/Cargo.toml
+++ b/crates/parser/Cargo.toml
@@ -7,6 +7,8 @@ license.workspace=true
authors.workspace=true
repository.workspace=true
rust-version.workspace=true
+keywords.workspace=true
+categories.workspace=true
[dependencies]
wasmparser={workspace=true, features=["validate", "features", "simd"]}
diff --git a/crates/parser/src/module.rs b/crates/parser/src/module.rs
index 3a3becd..1651bf0 100644
--- a/crates/parser/src/module.rs
+++ b/crates/parser/src/module.rs
@@ -30,7 +30,7 @@ pub(crate) struct ModuleReader {
}
impl ModuleReader {
- pub(crate) fn new() -> ModuleReader {
+ pub(crate) fn new() -> Self {
Self::default()
}
diff --git a/crates/parser/src/visit.rs b/crates/parser/src/visit.rs
index 1635d2d..4ae2cc1 100644
--- a/crates/parser/src/visit.rs
+++ b/crates/parser/src/visit.rs
@@ -370,17 +370,13 @@ impl<'a, R: WasmModuleResources> wasmparser::VisitOperator<'a> for FunctionBuild
let if_instruction = &mut self.instructions[if_label_pointer];
- let (else_offset, end_offset) = match if_instruction {
- Instruction::If(else_offset, end_offset)
- | Instruction::IfWithFuncType(_, else_offset, end_offset)
- | Instruction::IfWithType(_, else_offset, end_offset) => (else_offset, end_offset),
- _ => {
- self.errors.push(crate::ParseError::UnsupportedOperator(
- "Expected to end an if block, but the last label was not an if".to_string(),
- ));
-
- return;
- }
+ let (Instruction::If(else_offset, end_offset)
+ | Instruction::IfWithFuncType(_, else_offset, end_offset)
+ | Instruction::IfWithType(_, else_offset, end_offset)) = if_instruction
+ else {
+ return self.errors.push(crate::ParseError::UnsupportedOperator(
+ "Expected to end an if block, but the last label was not an if".to_string(),
+ ));
};
*else_offset = (label_pointer - if_label_pointer)
diff --git a/crates/tinywasm/Cargo.toml b/crates/tinywasm/Cargo.toml
index 427b45e..19e75ff 100644
--- a/crates/tinywasm/Cargo.toml
+++ b/crates/tinywasm/Cargo.toml
@@ -7,6 +7,8 @@ license.workspace=true
authors.workspace=true
repository.workspace=true
rust-version.workspace=true
+keywords.workspace=true
+categories.workspace=true
readme="../../README.md"
[lib]
@@ -32,7 +34,7 @@ serde_json={version="1.0"}
serde={version="1.0", features=["derive"]}
[features]
-default=["std", "parser", "logging", "archive", "canonicalize_nans"]
+default=["std", "parser", "logging", "archive", "canonicalize_nans", "__simd"]
logging=["log", "tinywasm-parser?/logging", "tinywasm-types/logging"]
std=["tinywasm-parser?/std", "tinywasm-types/std"]
diff --git a/crates/tinywasm/src/error.rs b/crates/tinywasm/src/error.rs
index fcaac1a..4b3a969 100644
--- a/crates/tinywasm/src/error.rs
+++ b/crates/tinywasm/src/error.rs
@@ -51,6 +51,7 @@ pub enum Error {
#[derive(Debug)]
/// Errors that can occur when linking a WebAssembly module
+#[non_exhaustive]
pub enum LinkingError {
/// An unknown import was encountered
UnknownImport {
@@ -83,6 +84,7 @@ impl LinkingError {
/// A WebAssembly trap
///
/// See <https://webassembly.github.io/spec/core/intro/overview.html#trap>
+#[non_exhaustive]
pub enum Trap {
/// An unreachable instruction was executed
Unreachable,
diff --git a/crates/tinywasm/src/func.rs b/crates/tinywasm/src/func.rs
index 642377a..5e5eb25 100644
--- a/crates/tinywasm/src/func.rs
+++ b/crates/tinywasm/src/func.rs
@@ -1,6 +1,6 @@
use crate::interpreter::stack::{CallFrame, Stack};
+use crate::{log, unlikely, Function};
use crate::{Error, FuncContext, Result, Store};
-use crate::{Function, log, unlikely};
use alloc::{boxed::Box, format, string::String, string::ToString, vec, vec::Vec};
use tinywasm_types::{ExternRef, FuncRef, FuncType, ModuleInstanceAddr, ValType, WasmValue};
@@ -38,11 +38,11 @@ impl FuncHandle {
// 5. For each value type and the corresponding value, check if types match
if !(func_ty.params.iter().zip(params).enumerate().all(|(_i, (ty, param))| {
- if ty != &param.val_type() {
+ if ty == &param.val_type() {
+ true
+ } else {
log::error!("param type mismatch at index {_i}: expected {ty:?}, got {param:?}");
false
- } else {
- true
}
})) {
return Err(Error::Other("Type mismatch".into()));
diff --git a/crates/tinywasm/src/imports.rs b/crates/tinywasm/src/imports.rs
index 12876c8..90f4971 100644
--- a/crates/tinywasm/src/imports.rs
+++ b/crates/tinywasm/src/imports.rs
@@ -170,7 +170,7 @@ impl Extern {
let inner_func = move |ctx: FuncContext<'_>, args: &[WasmValue]| -> Result<Vec<WasmValue>> {
let args = P::from_wasm_value_tuple(args)?;
let result = func(ctx, args)?;
- Ok(result.into_wasm_value_tuple().to_vec())
+ Ok(result.into_wasm_value_tuple())
};
let ty = tinywasm_types::FuncType { params: P::val_types(), results: R::val_types() };
@@ -263,7 +263,7 @@ impl ResolvedImports {
impl Imports {
/// Create a new empty import set
pub fn new() -> Self {
- Imports { values: BTreeMap::new(), modules: BTreeMap::new() }
+ Self { values: BTreeMap::new(), modules: BTreeMap::new() }
}
/// Merge two import sets
diff --git a/crates/tinywasm/src/instance.rs b/crates/tinywasm/src/instance.rs
index 9a0d1e2..75c12d6 100644
--- a/crates/tinywasm/src/instance.rs
+++ b/crates/tinywasm/src/instance.rs
@@ -12,7 +12,7 @@ use crate::{Error, FuncHandle, FuncHandleTyped, Imports, MemoryRef, MemoryRefMut
#[derive(Debug, Clone)]
pub struct ModuleInstance(pub(crate) Rc<ModuleInstanceInner>);
-#[allow(dead_code)]
+#[expect(dead_code)]
#[derive(Debug)]
pub(crate) struct ModuleInstanceInner {
pub(crate) failed_to_instantiate: bool,
@@ -90,7 +90,7 @@ impl ModuleInstance {
exports: module.0.exports,
};
- let instance = ModuleInstance::new(instance);
+ let instance = Self::new(instance);
store.add_instance(instance.clone());
match (elem_trapped, data_trapped) {
diff --git a/crates/tinywasm/src/interpreter/executor.rs b/crates/tinywasm/src/interpreter/executor.rs
index 4bf4f5d..10e9ddd 100644
--- a/crates/tinywasm/src/interpreter/executor.rs
+++ b/crates/tinywasm/src/interpreter/executor.rs
@@ -142,16 +142,16 @@ impl<'store, 'stack> Executor<'store, 'stack> {
I64Load(m) => self.exec_mem_load::<i64, 8, _>(m.mem_addr(), m.offset(), |v| v)?,
F32Load(m) => self.exec_mem_load::<f32, 4, _>(m.mem_addr(), m.offset(), |v| v)?,
F64Load(m) => self.exec_mem_load::<f64, 8, _>(m.mem_addr(), m.offset(), |v| v)?,
- I32Load8S(m) => self.exec_mem_load::<i8, 1, _>(m.mem_addr(), m.offset(), |v| v as i32)?,
- I32Load8U(m) => self.exec_mem_load::<u8, 1, _>(m.mem_addr(), m.offset(), |v| v as i32)?,
- I32Load16S(m) => self.exec_mem_load::<i16, 2, _>(m.mem_addr(), m.offset(), |v| v as i32)?,
- I32Load16U(m) => self.exec_mem_load::<u16, 2, _>(m.mem_addr(), m.offset(), |v| v as i32)?,
- I64Load8S(m) => self.exec_mem_load::<i8, 1, _>(m.mem_addr(), m.offset(), |v| v as i64)?,
- I64Load8U(m) => self.exec_mem_load::<u8, 1, _>(m.mem_addr(), m.offset(), |v| v as i64)?,
- I64Load16S(m) => self.exec_mem_load::<i16, 2, _>(m.mem_addr(), m.offset(), |v| v as i64)?,
- I64Load16U(m) => self.exec_mem_load::<u16, 2, _>(m.mem_addr(), m.offset(), |v| v as i64)?,
- I64Load32S(m) => self.exec_mem_load::<i32, 4, _>(m.mem_addr(), m.offset(), |v| v as i64)?,
- I64Load32U(m) => self.exec_mem_load::<u32, 4, _>(m.mem_addr(), m.offset(), |v| v as i64)?,
+ I32Load8S(m) => self.exec_mem_load::<i8, 1, _>(m.mem_addr(), m.offset(), i32::from)?,
+ I32Load8U(m) => self.exec_mem_load::<u8, 1, _>(m.mem_addr(), m.offset(), i32::from)?,
+ I32Load16S(m) => self.exec_mem_load::<i16, 2, _>(m.mem_addr(), m.offset(), i32::from)?,
+ I32Load16U(m) => self.exec_mem_load::<u16, 2, _>(m.mem_addr(), m.offset(), i32::from)?,
+ I64Load8S(m) => self.exec_mem_load::<i8, 1, _>(m.mem_addr(), m.offset(), i64::from)?,
+ I64Load8U(m) => self.exec_mem_load::<u8, 1, _>(m.mem_addr(), m.offset(), i64::from)?,
+ I64Load16S(m) => self.exec_mem_load::<i16, 2, _>(m.mem_addr(), m.offset(), i64::from)?,
+ I64Load16U(m) => self.exec_mem_load::<u16, 2, _>(m.mem_addr(), m.offset(), i64::from)?,
+ I64Load32S(m) => self.exec_mem_load::<i32, 4, _>(m.mem_addr(), m.offset(), i64::from)?,
+ I64Load32U(m) => self.exec_mem_load::<u32, 4, _>(m.mem_addr(), m.offset(), i64::from)?,
I64Eqz => self.stack.values.replace_top::<i64, _>(|v| Ok(i32::from(v == 0))).to_cf()?,
I32Eqz => self.stack.values.replace_top_same::<i32>(|v| Ok(i32::from(v == 0))).to_cf()?,
@@ -238,32 +238,32 @@ impl<'store, 'stack> Executor<'store, 'stack> {
I64Rotr => self.stack.values.calculate_same::<i64>(|a, b| Ok(a.wasm_rotr(b))).to_cf()?,
I32Clz => self.stack.values.replace_top_same::<i32>(|v| Ok(v.leading_zeros() as i32)).to_cf()?,
- I64Clz => self.stack.values.replace_top_same::<i64>(|v| Ok(v.leading_zeros() as i64)).to_cf()?,
+ I64Clz => self.stack.values.replace_top_same::<i64>(|v| Ok(i64::from(v.leading_zeros()))).to_cf()?,
I32Ctz => self.stack.values.replace_top_same::<i32>(|v| Ok(v.trailing_zeros() as i32)).to_cf()?,
- I64Ctz => self.stack.values.replace_top_same::<i64>(|v| Ok(v.trailing_zeros() as i64)).to_cf()?,
+ I64Ctz => self.stack.values.replace_top_same::<i64>(|v| Ok(i64::from(v.trailing_zeros()))).to_cf()?,
I32Popcnt => self.stack.values.replace_top_same::<i32>(|v| Ok(v.count_ones() as i32)).to_cf()?,
- I64Popcnt => self.stack.values.replace_top_same::<i64>(|v| Ok(v.count_ones() as i64)).to_cf()?,
+ I64Popcnt => self.stack.values.replace_top_same::<i64>(|v| Ok(i64::from(v.count_ones()))).to_cf()?,
F32ConvertI32S => self.stack.values.replace_top::<i32, _>(|v| Ok(v as f32)).to_cf()?,
F32ConvertI64S => self.stack.values.replace_top::<i64, _>(|v| Ok(v as f32)).to_cf()?,
- F64ConvertI32S => self.stack.values.replace_top::<i32, _>(|v| Ok(v as f64)).to_cf()?,
+ F64ConvertI32S => self.stack.values.replace_top::<i32, _>(|v| Ok(f64::from(v))).to_cf()?,
F64ConvertI64S => self.stack.values.replace_top::<i64, _>(|v| Ok(v as f64)).to_cf()?,
F32ConvertI32U => self.stack.values.replace_top::<u32, _>(|v| Ok(v as f32)).to_cf()?,
F32ConvertI64U => self.stack.values.replace_top::<u64, _>(|v| Ok(v as f32)).to_cf()?,
- F64ConvertI32U => self.stack.values.replace_top::<u32, _>(|v| Ok(v as f64)).to_cf()?,
+ F64ConvertI32U => self.stack.values.replace_top::<u32, _>(|v| Ok(f64::from(v))).to_cf()?,
F64ConvertI64U => self.stack.values.replace_top::<u64, _>(|v| Ok(v as f64)).to_cf()?,
- I32Extend8S => self.stack.values.replace_top_same::<i32>(|v| Ok((v as i8) as i32)).to_cf()?,
- I32Extend16S => self.stack.values.replace_top_same::<i32>(|v| Ok((v as i16) as i32)).to_cf()?,
- I64Extend8S => self.stack.values.replace_top_same::<i64>(|v| Ok((v as i8) as i64)).to_cf()?,
- I64Extend16S => self.stack.values.replace_top_same::<i64>(|v| Ok((v as i16) as i64)).to_cf()?,
- I64Extend32S => self.stack.values.replace_top_same::<i64>(|v| Ok((v as i32) as i64)).to_cf()?,
- I64ExtendI32U => self.stack.values.replace_top::<u32, _>(|v| Ok(v as i64)).to_cf()?,
- I64ExtendI32S => self.stack.values.replace_top::<i32, _>(|v| Ok(v as i64)).to_cf()?,
+ I32Extend8S => self.stack.values.replace_top_same::<i32>(|v| Ok(i32::from(v as i8))).to_cf()?,
+ I32Extend16S => self.stack.values.replace_top_same::<i32>(|v| Ok(i32::from(v as i16))).to_cf()?,
+ I64Extend8S => self.stack.values.replace_top_same::<i64>(|v| Ok(i64::from(v as i8))).to_cf()?,
+ I64Extend16S => self.stack.values.replace_top_same::<i64>(|v| Ok(i64::from(v as i16))).to_cf()?,
+ I64Extend32S => self.stack.values.replace_top_same::<i64>(|v| Ok(i64::from(v as i32))).to_cf()?,
+ I64ExtendI32U => self.stack.values.replace_top::<u32, _>(|v| Ok(i64::from(v))).to_cf()?,
+ I64ExtendI32S => self.stack.values.replace_top::<i32, _>(|v| Ok(i64::from(v))).to_cf()?,
I32WrapI64 => self.stack.values.replace_top::<i64, _>(|v| Ok(v as i32)).to_cf()?,
F32DemoteF64 => self.stack.values.replace_top::<f64, _>(|v| Ok(v as f32)).to_cf()?,
- F64PromoteF32 => self.stack.values.replace_top::<f32, _>(|v| Ok(v as f64)).to_cf()?,
+ F64PromoteF32 => self.stack.values.replace_top::<f32, _>(|v| Ok(f64::from(v))).to_cf()?,
F32Abs => self.stack.values.replace_top_same::<f32>(|v| Ok(v.abs())).to_cf()?,
F64Abs => self.stack.values.replace_top_same::<f64>(|v| Ok(v.abs())).to_cf()?,
@@ -324,7 +324,19 @@ impl<'store, 'stack> Executor<'store, 'stack> {
#[cfg(feature = "__simd")] V128Bitselect => self.stack.values.calculate_same_3::<Value128>(|v1, v2, c| Ok((v1 & c) | (v2 & !c))).to_cf()?,
#[cfg(feature = "__simd")] V128AnyTrue => self.stack.values.replace_top::<Value128, i32>(|v| Ok((v.reduce_or() != 0) as i32)).to_cf()?,
#[cfg(feature = "__simd")] I8x16Swizzle => self.stack.values.calculate_same::<Value128>(|a, s| Ok(a.swizzle_dyn(s))).to_cf()?,
+
#[cfg(feature = "__simd")] V128Load(arg) => self.exec_mem_load::<Value128, 16, _>(arg.mem_addr(), arg.offset(), |v| v)?,
+ #[cfg(feature = "__simd")] V128Load8x8S(_arg) => unimplemented!(),
+ #[cfg(feature = "__simd")] V128Load8x8U(_arg) => unimplemented!(),
+ #[cfg(feature = "__simd")] V128Load16x4S(_arg) => unimplemented!(),
+ #[cfg(feature = "__simd")] V128Load16x4U(_arg) => unimplemented!(),
+ #[cfg(feature = "__simd")] V128Load32x2S(_arg) => unimplemented!(),
+ #[cfg(feature = "__simd")] V128Load32x2U(_arg) => unimplemented!(),
+ #[cfg(feature = "__simd")] V128Load8Splat(_arg) => unimplemented!(),
+ #[cfg(feature = "__simd")] V128Load16Splat(_arg) => unimplemented!(),
+ #[cfg(feature = "__simd")] V128Load32Splat(_arg) => unimplemented!(),
+ #[cfg(feature = "__simd")] V128Load64Splat(_arg) => unimplemented!(),
+
#[cfg(feature = "__simd")] V128Store(arg) => self.exec_mem_store::<Value128, Value128, 16>(arg.mem_addr(), arg.offset(), |v| v)?,
#[cfg(feature = "__simd")] V128Store8Lane(arg, lane) => self.exec_mem_store_lane::<i8x16, i8, 1>(arg.mem_addr(), arg.offset(), *lane)?,
@@ -358,6 +370,13 @@ impl<'store, 'stack> Executor<'store, 'stack> {
#[cfg(feature = "__simd")] V128Load32Lane(arg, lane) => self.exec_mem_load_lane::<i32, i32x4, 4>(arg.mem_addr(), arg.offset(), *lane)?,
#[cfg(feature = "__simd")] V128Load64Lane(arg, lane) => self.exec_mem_load_lane::<i64, i64x2, 8>(arg.mem_addr(), arg.offset(), *lane)?,
+ #[cfg(feature = "__simd")] I8x16ReplaceLane(_lane) => unimplemented!(),
+ #[cfg(feature = "__simd")] I16x8ReplaceLane(_lane) => unimplemented!(),
+ #[cfg(feature = "__simd")] I32x4ReplaceLane(_lane) => unimplemented!(),
+ #[cfg(feature = "__simd")] I64x2ReplaceLane(_lane) => unimplemented!(),
+ #[cfg(feature = "__simd")] F32x4ReplaceLane(_lane) => unimplemented!(),
+ #[cfg(feature = "__simd")] F64x2ReplaceLane(_lane) => unimplemented!(),
+
#[cfg(feature = "__simd")] I8x16Splat => self.stack.values.replace_top::<i32, i8x16>(|v| Ok(Simd::<i8, 16>::splat(v as i8))).to_cf()?,
#[cfg(feature = "__simd")] I16x8Splat => self.stack.values.replace_top::<i32, i16x8>(|v| Ok(Simd::<i16, 8>::splat(v as i16))).to_cf()?,
#[cfg(feature = "__simd")] I32x4Splat => self.stack.values.replace_top::<i32, i32x4>(|v| Ok(Simd::<i32, 4>::splat(v))).to_cf()?,
@@ -368,12 +387,14 @@ impl<'store, 'stack> Executor<'store, 'stack> {
#[cfg(feature = "__simd")] I8x16Eq => self.stack.values.calculate_same::<i8x16>(|a, b| Ok(a.simd_eq(b).to_int())).to_cf()?,
#[cfg(feature = "__simd")] I16x8Eq => self.stack.values.calculate_same::<i16x8>(|a, b| Ok(a.simd_eq(b).to_int())).to_cf()?,
#[cfg(feature = "__simd")] I32x4Eq => self.stack.values.calculate_same::<i32x4>(|a, b| Ok(a.simd_eq(b).to_int())).to_cf()?,
+ #[cfg(feature = "__simd")] I64x2Eq => self.stack.values.calculate_same::<i64x2>(|a, b| Ok(a.simd_eq(b).to_int())).to_cf()?,
#[cfg(feature = "__simd")] F32x4Eq => self.stack.values.calculate::<f32x4, _>(|a, b| Ok(a.simd_eq(b).to_int())).to_cf()?,
#[cfg(feature = "__simd")] F64x2Eq => self.stack.values.calculate::<f64x2, _>(|a, b| Ok(a.simd_eq(b).to_int())).to_cf()?,
#[cfg(feature = "__simd")] I8x16Ne => self.stack.values.calculate_same::<i8x16>(|a, b| Ok(a.simd_ne(b).to_int())).to_cf()?,
#[cfg(feature = "__simd")] I16x8Ne => self.stack.values.calculate_same::<i16x8>(|a, b| Ok(a.simd_ne(b).to_int())).to_cf()?,
#[cfg(feature = "__simd")] I32x4Ne => self.stack.values.calculate_same::<i32x4>(|a, b| Ok(a.simd_ne(b).to_int())).to_cf()?,
+ #[cfg(feature = "__simd")] I64x2Ne => self.stack.values.calculate_same::<i64x2>(|a, b| Ok(a.simd_ne(b).to_int())).to_cf()?,
#[cfg(feature = "__simd")] F32x4Ne => self.stack.values.calculate::<f32x4, _>(|a, b| Ok(a.simd_ne(b).to_int())).to_cf()?,
#[cfg(feature = "__simd")] F64x2Ne => self.stack.values.calculate::<f64x2, _>(|a, b| Ok(a.simd_ne(b).to_int())).to_cf()?,
@@ -500,6 +521,9 @@ impl<'store, 'stack> Executor<'store, 'stack> {
#[cfg(feature = "__simd")] I8x16SubSatU => self.stack.values.calculate_same::<u8x16>(|a, b| Ok(a.saturating_sub(b))).to_cf()?,
#[cfg(feature = "__simd")] I16x8SubSatU => self.stack.values.calculate_same::<u16x8>(|a, b| Ok(a.saturating_sub(b))).to_cf()?,
+ #[cfg(feature = "__simd")] I8x16AvgrU => unimplemented!(),
+ #[cfg(feature = "__simd")] I16x8AvgrU => unimplemented!(),
+
#[cfg(feature = "__simd")] I16x8ExtAddPairwiseI8x16S => unimplemented!(),
#[cfg(feature = "__simd")] I16x8ExtAddPairwiseI8x16U => unimplemented!(),
#[cfg(feature = "__simd")] I32x4ExtAddPairwiseI16x8S => unimplemented!(),
@@ -532,6 +556,7 @@ impl<'store, 'stack> Executor<'store, 'stack> {
#[cfg(feature = "__simd")] I64x2ExtendHighI32x4U => unimplemented!(),
#[cfg(feature = "__simd")] I8x16Popcnt => self.stack.values.replace_top::<i8x16, _>(|v| Ok(v.count_ones())).to_cf()?,
+ #[cfg(feature = "__simd")] I8x16Shuffle(_idx) => unimplemented!(),
#[cfg(feature = "__simd")]
I16x8Q15MulrSatS => self.stack.values.calculate_same::<i16x8>(|a, b| {
@@ -575,6 +600,8 @@ impl<'store, 'stack> Executor<'store, 'stack> {
#[cfg(feature = "__simd")] F64x2Floor => self.stack.values.replace_top_same::<f64x2>(|v| Ok(v.floor())).to_cf()?,
#[cfg(feature = "__simd")] F32x4Trunc => self.stack.values.replace_top_same::<f32x4>(|v| Ok(v.trunc())).to_cf()?,
#[cfg(feature = "__simd")] F64x2Trunc => self.stack.values.replace_top_same::<f64x2>(|v| Ok(v.trunc())).to_cf()?,
+ #[cfg(feature = "__simd")] F32x4Nearest => self.stack.values.replace_top_same::<f32x4>(|v| Ok(v.round())).to_cf()?,
+ #[cfg(feature = "__simd")] F64x2Nearest => self.stack.values.replace_top_same::<f64x2>(|v| Ok(v.round())).to_cf()?,
#[cfg(feature = "__simd")] F32x4Abs => self.stack.values.replace_top_same::<f32x4>(|v| Ok(v.abs())).to_cf()?,
#[cfg(feature = "__simd")] F64x2Abs => self.stack.values.replace_top_same::<f64x2>(|v| Ok(v.abs())).to_cf()?,
#[cfg(feature = "__simd")] F32x4Neg => self.stack.values.replace_top_same::<f32x4>(|v| Ok(-v)).to_cf()?,
@@ -664,15 +691,37 @@ impl<'store, 'stack> Executor<'store, 'stack> {
// not correct
#[cfg(feature = "__simd")] I32x4TruncSatF32x4S => self.stack.values.replace_top::<f32x4, f32x4>(|v| Ok(v.trunc())).to_cf()?,
#[cfg(feature = "__simd")] I32x4TruncSatF32x4U => self.stack.values.replace_top::<f32x4, f32x4>(|v| Ok(v.trunc())).to_cf()?,
- #[cfg(feature = "__simd")] F32x4ConvertI32x4S => {},
- #[cfg(feature = "__simd")] F32x4ConvertI32x4U => {},
- #[cfg(feature = "__simd")] F64x2ConvertLowI32x4S => {},
- #[cfg(feature = "__simd")] F64x2ConvertLowI32x4U => {},
- #[cfg(feature = "__simd")] F32x4DemoteF64x2Zero => {},
- #[cfg(feature = "__simd")] F64x2PromoteLowF32x4 => {},
+ #[cfg(feature = "__simd")] F32x4ConvertI32x4S => unimplemented!(),
+ #[cfg(feature = "__simd")] F32x4ConvertI32x4U => unimplemented!(),
+ #[cfg(feature = "__simd")] F64x2ConvertLowI32x4S => unimplemented!(),
+ #[cfg(feature = "__simd")] F64x2ConvertLowI32x4U => unimplemented!(),
+ #[cfg(feature = "__simd")] F32x4DemoteF64x2Zero => unimplemented!(),
+ #[cfg(feature = "__simd")] F64x2PromoteLowF32x4 => unimplemented!(),
#[cfg(feature = "__simd")] I32x4TruncSatF64x2SZero => unimplemented!(),
#[cfg(feature = "__simd")] I32x4TruncSatF64x2UZero => unimplemented!(),
+ #[cfg(feature = "__simd")] I8x16RelaxedSwizzle => unimplemented!(),
+ #[cfg(feature = "__simd")] I32x4RelaxedTruncF32x4S => unimplemented!(),
+ #[cfg(feature = "__simd")] I32x4RelaxedTruncF32x4U => unimplemented!(),
+ #[cfg(feature = "__simd")] I32x4RelaxedTruncF64x2SZero => unimplemented!(),
+ #[cfg(feature = "__simd")] I32x4RelaxedTruncF64x2UZero => unimplemented!(),
+ #[cfg(feature = "__simd")] F32x4RelaxedMadd => unimplemented!(),
+ #[cfg(feature = "__simd")] F32x4RelaxedNmadd => unimplemented!(),
+ #[cfg(feature = "__simd")] F64x2RelaxedMadd => unimplemented!(),
+ #[cfg(feature = "__simd")] F64x2RelaxedNmadd => unimplemented!(),
+ #[cfg(feature = "__simd")] I8x16RelaxedLaneselect => unimplemented!(),
+ #[cfg(feature = "__simd")] I16x8RelaxedLaneselect => unimplemented!(),
+ #[cfg(feature = "__simd")] I32x4RelaxedLaneselect => unimplemented!(),
+ #[cfg(feature = "__simd")] I64x2RelaxedLaneselect => unimplemented!(),
+ #[cfg(feature = "__simd")] F32x4RelaxedMin => unimplemented!(),
+ #[cfg(feature = "__simd")] F32x4RelaxedMax => unimplemented!(),
+ #[cfg(feature = "__simd")] F64x2RelaxedMin => unimplemented!(),
+ #[cfg(feature = "__simd")] F64x2RelaxedMax => unimplemented!(),
+ #[cfg(feature = "__simd")] I16x8RelaxedQ15mulrS => unimplemented!(),
+ #[cfg(feature = "__simd")] I16x8RelaxedDotI8x16I7x16S => unimplemented!(),
+ #[cfg(feature = "__simd")] I32x4RelaxedDotI8x16I7x16AddS => unimplemented!(),
+
+ #[allow(unreachable_patterns)]
i => return ControlFlow::Break(Some(Error::UnsupportedFeature(format!("unimplemented opcode: {i:?}")))),
};
@@ -690,18 +739,17 @@ impl<'store, 'stack> Executor<'store, 'stack> {
wasm_func: Rc<WasmFunction>,
owner: ModuleInstanceAddr,
) -> ControlFlow<Option<Error>> {
- if !IS_RETURN_CALL {
- let locals = self.stack.values.pop_locals(wasm_func.params, wasm_func.locals);
+ let locals = self.stack.values.pop_locals(wasm_func.params, wasm_func.locals);
+
+ if IS_RETURN_CALL {
+ self.cf.reuse_for(wasm_func, locals, self.stack.blocks.len() as u32, owner);
+ } else {
let new_call_frame = CallFrame::new_raw(wasm_func, owner, locals, self.stack.blocks.len() as u32);
self.cf.incr_instr_ptr(); // skip the call instruction
self.stack.call_stack.push(core::mem::replace(&mut self.cf, new_call_frame))?;
- self.module.swap_with(self.cf.module_addr(), self.store);
- } else {
- let locals = self.stack.values.pop_locals(wasm_func.params, wasm_func.locals);
- self.cf.reuse_for(wasm_func, locals, self.stack.blocks.len() as u32, owner);
- self.module.swap_with(self.cf.module_addr(), self.store);
}
+ self.module.swap_with(self.cf.module_addr(), self.store);
ControlFlow::Continue(())
}
fn exec_call_host(&mut self, host_func: Rc<imports::HostFunction>) -> ControlFlow<Option<Error>> {
@@ -880,7 +928,7 @@ impl<'store, 'stack> Executor<'store, 'stack> {
self.stack.values.push(val);
}
fn exec_ref_is_null(&mut self) {
- let is_null = self.stack.values.pop::<ValueRef>().is_none() as i32;
+ let is_null = i32::from(self.stack.values.pop::<ValueRef>().is_none());
self.stack.values.push::<i32>(is_null);
}
@@ -898,7 +946,7 @@ impl<'store, 'stack> Executor<'store, 'stack> {
let pages_delta = match mem.is_64bit() {
true => self.stack.values.pop::<i64>(),
- false => self.stack.values.pop::<i32>() as i64,
+ false => i64::from(self.stack.values.pop::<i32>()),
};
match (
@@ -1035,7 +1083,7 @@ impl<'store, 'stack> Executor<'store, 'stack> {
let addr = match mem.is_64bit() {
true => self.stack.values.pop::<i64>() as u64,
- false => self.stack.values.pop::<i32>() as u32 as u64,
+ false => u64::from(self.stack.values.pop::<i32>() as u32),
};
let Some(Ok(addr)) = offset.checked_add(addr).map(|a| a.try_into()) else {
@@ -1086,7 +1134,7 @@ impl<'store, 'stack> Executor<'store, 'stack> {
let addr = match mem.is_64bit() {
true => self.stack.values.pop::<i64>() as u64,
- false => self.stack.values.pop::<i32>() as u32 as u64,
+ false => u64::from(self.stack.values.pop::<i32>() as u32),
};
if let Err(e) = mem.store((offset + addr) as usize, val.len(), &val) {
@@ -1152,7 +1200,7 @@ impl<'store, 'stack> Executor<'store, 'stack> {
return Err(Trap::TableOutOfBounds { offset: 0, len: 0, max: 0 }.into());
};
- table.init(dst as i64, &items[offset as usize..(offset + size) as usize])
+ table.init(i64::from(dst), &items[offset as usize..(offset + size) as usize])
}
fn exec_table_grow(&mut self, table_index: u32) -> Result<()> {
let table = self.store.get_table_mut(self.module.resolve_table_addr(table_index));
@@ -1162,7 +1210,7 @@ impl<'store, 'stack> Executor<'store, 'stack> {
let val = self.stack.values.pop::<ValueRef>();
match table.grow(n, val.into()) {
- Ok(_) => self.stack.values.push(sz),
+ Ok(()) => self.stack.values.push(sz),
Err(_) => self.stack.values.push(-1_i32),
}
diff --git a/crates/tinywasm/src/interpreter/values.rs b/crates/tinywasm/src/interpreter/values.rs
index 779fc60..957b4bb 100644
--- a/crates/tinywasm/src/interpreter/values.rs
+++ b/crates/tinywasm/src/interpreter/values.rs
@@ -12,7 +12,7 @@ pub(crate) type Value128 = core::simd::u8x16;
#[cfg(not(feature = "__simd"))]
pub(crate) type Value128 = i128;
-#[derive(Debug, Clone, Copy, PartialEq)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
/// A untyped WebAssembly value
pub enum TinyWasmValue {
/// A 32-bit value
@@ -74,7 +74,7 @@ impl TinyWasmValue {
/// Asserts that the value is a 32-bit value and returns it (panics if the value is the wrong size)
pub fn unwrap_32(&self) -> Value32 {
match self {
- TinyWasmValue::Value32(v) => *v,
+ Self::Value32(v) => *v,
_ => unreachable!("Expected Value32"),
}
}
@@ -82,7 +82,7 @@ impl TinyWasmValue {
/// Asserts that the value is a 64-bit value and returns it (panics if the value is the wrong size)
pub fn unwrap_64(&self) -> Value64 {
match self {
- TinyWasmValue::Value64(v) => *v,
+ Self::Value64(v) => *v,
_ => unreachable!("Expected Value64"),
}
}
@@ -90,7 +90,7 @@ impl TinyWasmValue {
/// Asserts that the value is a 128-bit value and returns it (panics if the value is the wrong size)
pub fn unwrap_128(&self) -> Value128 {
match self {
- TinyWasmValue::Value128(v) => *v,
+ Self::Value128(v) => *v,
_ => unreachable!("Expected Value128"),
}
}
@@ -98,7 +98,7 @@ impl TinyWasmValue {
/// Asserts that the value is a reference value and returns it (panics if the value is the wrong size)
pub fn unwrap_ref(&self) -> ValueRef {
match self {
- TinyWasmValue::ValueRef(v) => *v,
+ Self::ValueRef(v) => *v,
_ => unreachable!("Expected ValueRef"),
}
}
@@ -125,15 +125,15 @@ impl TinyWasmValue {
impl From<&WasmValue> for TinyWasmValue {
fn from(value: &WasmValue) -> Self {
match value {
- WasmValue::I32(v) => TinyWasmValue::Value32(*v as u32),
- WasmValue::I64(v) => TinyWasmValue::Value64(*v as u64),
- WasmValue::F32(v) => TinyWasmValue::Value32(v.to_bits()),
- WasmValue::F64(v) => TinyWasmValue::Value64(v.to_bits()),
- WasmValue::RefExtern(v) => TinyWasmValue::ValueRef(v.addr()),
- WasmValue::RefFunc(v) => TinyWasmValue::ValueRef(v.addr()),
+ WasmValue::I32(v) => Self::Value32(*v as u32),
+ WasmValue::I64(v) => Self::Value64(*v as u64),
+ WasmValue::F32(v) => Self::Value32(v.to_bits()),
+ WasmValue::F64(v) => Self::Value64(v.to_bits()),
+ WasmValue::RefExtern(v) => Self::ValueRef(v.addr()),
+ WasmValue::RefFunc(v) => Self::ValueRef(v.addr()),
#[cfg(not(feature = "__simd"))]
- WasmValue::V128(v) => TinyWasmValue::Value128(*v),
+ WasmValue::V128(v) => Self::Value128(*v),
#[cfg(feature = "__simd")]
WasmValue::V128(v) => TinyWasmValue::Value128(v.to_le_bytes().into()),
@@ -143,12 +143,12 @@ impl From<&WasmValue> for TinyWasmValue {
impl From<WasmValue> for TinyWasmValue {
fn from(value: WasmValue) -> Self {
- TinyWasmValue::from(&value)
+ Self::from(&value)
}
}
mod sealed {
- #[allow(unreachable_pub)]
+ #[expect(unreachable_pub)]
pub trait Sealed {}
}
@@ -160,7 +160,6 @@ pub(crate) trait InternalValue: sealed::Sealed + Into<TinyWasmValue> {
fn stack_calculate(stack: &mut ValueStack, func: impl FnOnce(Self, Self) -> Result<Self>) -> Result<()>
where
Self: Sized;
- #[allow(dead_code)]
fn stack_calculate3(stack: &mut ValueStack, func: impl FnOnce(Self, Self, Self) -> Result<Self>) -> Result<()>
where
Self: Sized;
@@ -266,8 +265,8 @@ macro_rules! impl_internalvalue {
impl_internalvalue! {
Value32, stack_32, locals_32, u32, u32, |v| v, |v| v
Value64, stack_64, locals_64, u64, u64, |v| v, |v| v
- Value32, stack_32, locals_32, u32, i32, |v| v as u32, |v: u32| v as i32
- Value64, stack_64, locals_64, u64, i64, |v| v as u64, |v| v as i64
+ Value32, stack_32, locals_32, u32, i32, |v: i32| u32::from_ne_bytes(v.to_ne_bytes()), |v: u32| i32::from_ne_bytes(v.to_ne_bytes())
+ Value64, stack_64, locals_64, u64, i64, |v: i64| u64::from_ne_bytes(v.to_ne_bytes()), |v: u64| i64::from_ne_bytes(v.to_ne_bytes())
Value32, stack_32, locals_32, u32, f32, f32::to_bits, f32::from_bits
Value64, stack_64, locals_64, u64, f64, f64::to_bits, f64::from_bits
ValueRef, stack_ref, locals_ref, ValueRef, ValueRef, |v| v, |v| v
diff --git a/crates/tinywasm/src/lib.rs b/crates/tinywasm/src/lib.rs
index 9cb6c0a..b44a15e 100644
--- a/crates/tinywasm/src/lib.rs
+++ b/crates/tinywasm/src/lib.rs
@@ -75,7 +75,7 @@ extern crate alloc;
// log for logging (optional).
#[cfg(feature = "logging")]
-#[allow(clippy::single_component_path_imports)]
+#[expect(clippy::single_component_path_imports)]
use log;
// noop fallback if logging is disabled.
diff --git a/crates/tinywasm/src/reference.rs b/crates/tinywasm/src/reference.rs
index e32a2f3..790c313 100644
--- a/crates/tinywasm/src/reference.rs
+++ b/crates/tinywasm/src/reference.rs
@@ -1,8 +1,7 @@
use core::ffi::CStr;
-use alloc::ffi::CString;
use alloc::string::{String, ToString};
-use alloc::vec::Vec;
+use alloc::{ffi::CString, format, vec::Vec};
use crate::{MemoryInstance, Result};
@@ -92,19 +91,19 @@ pub trait MemoryStringExt: MemoryRefLoad {
/// Load a C-style string from memory
fn load_cstr(&self, offset: usize, len: usize) -> Result<&CStr> {
let bytes = self.load(offset, len)?;
- CStr::from_bytes_with_nul(bytes).map_err(|_| crate::Error::Other("Invalid C-style string".to_string()))
+ CStr::from_bytes_with_nul(bytes).map_err(|e| crate::Error::Other(format!("Invalid C-style string: {e}")))
}
/// Load a C-style string from memory, stopping at the first nul byte
fn load_cstr_until_nul(&self, offset: usize, max_len: usize) -> Result<&CStr> {
let bytes = self.load(offset, max_len)?;
- CStr::from_bytes_until_nul(bytes).map_err(|_| crate::Error::Other("Invalid C-style string".to_string()))
+ CStr::from_bytes_until_nul(bytes).map_err(|e| crate::Error::Other(format!("Invalid C-style string: {e}")))
}
/// Load a UTF-8 string from memory
fn load_string(&self, offset: usize, len: usize) -> Result<String> {
let bytes = self.load(offset, len)?;
- String::from_utf8(bytes.to_vec()).map_err(|_| crate::Error::Other("Invalid UTF-8 string".to_string()))
+ String::from_utf8(bytes.to_vec()).map_err(|e| crate::Error::Other(format!("Invalid UTF-8 string: {e}")))
}
/// Load a C-style string from memory
diff --git a/crates/tinywasm/src/store/mod.rs b/crates/tinywasm/src/store/mod.rs
index d53654e..634fdfe 100644
--- a/crates/tinywasm/src/store/mod.rs
+++ b/crates/tinywasm/src/store/mod.rs
@@ -288,7 +288,9 @@ impl Store {
})?;
self.data.globals[addr as usize].value.get().unwrap_ref()
}
- _ => return Err(Error::UnsupportedFeature(format!("const expression other than ref: {item:?}"))),
+ ElementItem::Expr(item) => {
+ return Err(Error::UnsupportedFeature(format!("const expression other than ref: {item:?}")));
+ }
};
Ok(res)
@@ -418,10 +420,10 @@ impl Store {
/// Evaluate a constant expression that's either a i32 or a i64 as a global or a const instruction
pub(crate) fn eval_size_const(&self, const_instr: tinywasm_types::ConstInstruction) -> Result<i64> {
Ok(match const_instr {
- ConstInstruction::I32Const(i) => i as i64,
+ ConstInstruction::I32Const(i) => i64::from(i),
ConstInstruction::I64Const(i) => i,
ConstInstruction::GlobalGet(addr) => match self.data.globals[addr as usize].value.get() {
- TinyWasmValue::Value32(i) => i as i64,
+ TinyWasmValue::Value32(i) => i64::from(i),
TinyWasmValue::Value64(i) => i as i64,
o => return Err(Error::Other(format!("expected i32 or i64, got {o:?}"))),
},
diff --git a/crates/tinywasm/src/store/table.rs b/crates/tinywasm/src/store/table.rs
index 6192119..bc4429d 100644
--- a/crates/tinywasm/src/store/table.rs
+++ b/crates/tinywasm/src/store/table.rs
@@ -159,8 +159,8 @@ pub(crate) enum TableElement {
impl From<Option<Addr>> for TableElement {
fn from(addr: Option<Addr>) -> Self {
match addr {
- None => TableElement::Uninitialized,
- Some(addr) => TableElement::Initialized(addr),
+ None => Self::Uninitialized,
+ Some(addr) => Self::Initialized(addr),
}
}
}
@@ -168,15 +168,15 @@ impl From<Option<Addr>> for TableElement {
impl TableElement {
pub(crate) fn addr(&self) -> Option<Addr> {
match self {
- TableElement::Uninitialized => None,
- TableElement::Initialized(addr) => Some(*addr),
+ Self::Uninitialized => None,
+ Self::Initialized(addr) => Some(*addr),
}
}
pub(crate) fn map(self, f: impl FnOnce(Addr) -> Addr) -> Self {
match self {
- TableElement::Uninitialized => TableElement::Uninitialized,
- TableElement::Initialized(addr) => TableElement::Initialized(f(addr)),
+ Self::Uninitialized => Self::Uninitialized,
+ Self::Initialized(addr) => Self::Initialized(f(addr)),
}
}
}
diff --git a/crates/tinywasm/tests/testsuite/mod.rs b/crates/tinywasm/tests/testsuite/mod.rs
index c1ba46e..140b063 100644
--- a/crates/tinywasm/tests/testsuite/mod.rs
+++ b/crates/tinywasm/tests/testsuite/mod.rs
@@ -41,7 +41,7 @@ impl TestSuite {
pub fn print_errors(&self) {
for (group_name, group) in &self.0 {
let tests = &group.tests;
- for (test_name, test) in tests.iter() {
+ for (test_name, test) in tests {
if let Err(e) = &test.result {
eprintln!(
"{} {} failed: {:?}",
diff --git a/crates/tinywasm/tests/testsuite/util.rs b/crates/tinywasm/tests/testsuite/util.rs
index 5e8558a..59013ad 100644
--- a/crates/tinywasm/tests/testsuite/util.rs
+++ b/crates/tinywasm/tests/testsuite/util.rs
@@ -74,7 +74,7 @@ pub fn encode_quote_wat(module: QuoteWat) -> (Option<String>, Vec<u8>) {
};
(module.id.map(|id| id.name().to_string()), wat.encode().expect("failed to encode module"))
}
- _ => unimplemented!("Not supported"),
+ QuoteWat::QuoteComponent(..) => unimplemented!("components are not supported"),
}
}
@@ -96,7 +96,7 @@ fn wastarg2tinywasmvalue(arg: wast::WastArg) -> Result<tinywasm_types::WasmValue
bail!("unsupported arg type: Component");
};
- use wast::core::WastArgCore::{F32, F64, I32, I64, RefExtern, RefNull, V128};
+ use wast::core::WastArgCore::*;
Ok(match arg {
F32(f) => WasmValue::F32(f32::from_bits(f.bits)),
F64(f) => WasmValue::F64(f64::from_bits(f.bits)),
@@ -113,7 +113,7 @@ fn wastarg2tinywasmvalue(arg: wast::WastArg) -> Result<tinywasm_types::WasmValue
}
_ => bail!("unsupported arg type: refnull: {:?}", t),
},
- v => bail!("unsupported arg type: {:?}", v),
+ RefHost(v) => bail!("unsupported arg type: RefHost"),
})
}
diff --git a/crates/types/Cargo.toml b/crates/types/Cargo.toml
index fda8a86..b986c2a 100644
--- a/crates/types/Cargo.toml
+++ b/crates/types/Cargo.toml
@@ -7,6 +7,8 @@ license.workspace=true
authors.workspace=true
repository.workspace=true
rust-version.workspace=true
+keywords.workspace=true
+categories.workspace=true
[dependencies]
log={workspace=true, optional=true}
diff --git a/crates/types/src/archive.rs b/crates/types/src/archive.rs
index b190d43..7d52049 100644
--- a/crates/types/src/archive.rs
+++ b/crates/types/src/archive.rs
@@ -34,10 +34,10 @@ pub enum TwasmError {
impl Display for TwasmError {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
match self {
- TwasmError::InvalidMagic => write!(f, "Invalid twasm: invalid magic number"),
- TwasmError::InvalidVersion => write!(f, "Invalid twasm: invalid version"),
- TwasmError::InvalidPadding => write!(f, "Invalid twasm: invalid padding"),
- TwasmError::InvalidArchive(e) => write!(f, "Invalid twasm: {e}"),
+ Self::InvalidMagic => write!(f, "Invalid twasm: invalid magic number"),
+ Self::InvalidVersion => write!(f, "Invalid twasm: invalid version"),
+ Self::InvalidPadding => write!(f, "Invalid twasm: invalid padding"),
+ Self::InvalidArchive(e) => write!(f, "Invalid twasm: {e}"),
}
}
}
@@ -49,7 +49,7 @@ impl core::error::Error for TwasmError {}
impl TinyWasmModule {
/// Creates a `TinyWasmModule` from a slice of bytes.
- pub fn from_twasm(wasm: &[u8]) -> Result<TinyWasmModule, TwasmError> {
+ pub fn from_twasm(wasm: &[u8]) -> Result<Self, TwasmError> {
let len = validate_magic(wasm)?;
postcard::from_bytes(&wasm[len..]).map_err(TwasmError::InvalidArchive)
diff --git a/crates/types/src/instructions.rs b/crates/types/src/instructions.rs
index 9db5ed5..aa57dfa 100644
--- a/crates/types/src/instructions.rs
+++ b/crates/types/src/instructions.rs
@@ -2,7 +2,7 @@ use super::{FuncAddr, GlobalAddr, LabelAddr, LocalAddr, TableAddr, TypeAddr, Val
use crate::{ConstIdx, DataAddr, ElemAddr, ExternAddr, MemAddr};
/// Represents a memory immediate in a WebAssembly memory instruction.
-#[derive(Debug, Copy, Clone, PartialEq)]
+#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))]
pub struct MemoryArg([u8; 12]);
diff --git a/crates/types/src/lib.rs b/crates/types/src/lib.rs
index 470c631..c34b705 100644
--- a/crates/types/src/lib.rs
+++ b/crates/types/src/lib.rs
@@ -119,7 +119,7 @@ pub struct TinyWasmModule {
/// A WebAssembly External Kind.
///
/// See <https://webassembly.github.io/spec/core/syntax/types.html#external-types>
-#[derive(Debug, Clone, Copy, PartialEq)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))]
pub enum ExternalKind {
/// A WebAssembly Function.
@@ -191,14 +191,14 @@ impl ExternVal {
/// The type of a WebAssembly Function.
///
/// See <https://webassembly.github.io/spec/core/syntax/types.html#function-types>
-#[derive(Debug, Clone, PartialEq, Default)]
+#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))]
pub struct FuncType {
pub params: Box<[ValType]>,
pub results: Box<[ValType]>,
}
-#[derive(Debug, Default, Clone, Copy, PartialEq)]
+#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))]
pub struct ValueCounts {
pub c32: u32,
@@ -207,7 +207,7 @@ pub struct ValueCounts {
pub cref: u32,
}
-#[derive(Debug, Default, Clone, Copy, PartialEq)]
+#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))]
pub struct ValueCountsSmall {
pub c32: u16,
@@ -218,7 +218,7 @@ pub struct ValueCountsSmall {
impl<'a, T: IntoIterator<Item = &'a ValType>> From<T> for ValueCounts {
fn from(types: T) -> Self {
- let mut counts = ValueCounts::default();
+ let mut counts = Self::default();
for ty in types {
match ty {
ValType::I32 | ValType::F32 => counts.c32 += 1,
@@ -233,7 +233,7 @@ impl<'a, T: IntoIterator<Item = &'a ValType>> From<T> for ValueCounts {
impl<'a, T: IntoIterator<Item = &'a ValType>> From<T> for ValueCountsSmall {
fn from(types: T) -> Self {
- let mut counts = ValueCountsSmall::default();
+ let mut counts = Self::default();
for ty in types {
match ty {
ValType::I32 | ValType::F32 => counts.c32 += 1,
@@ -256,14 +256,14 @@ pub struct WasmFunction {
pub ty: FuncType,
}
-#[derive(Debug, Clone, PartialEq, Default)]
+#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))]
pub struct WasmFunctionData {
pub v128_constants: Box<[i128]>,
}
/// A WebAssembly Module Export
-#[derive(Debug, Clone, PartialEq)]
+#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))]
pub struct Export {
/// The name of the export.
@@ -281,14 +281,14 @@ pub struct Global {
pub init: ConstInstruction,
}
-#[derive(Debug, Clone, Copy, PartialEq)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))]
pub struct GlobalType {
pub mutable: bool,
pub ty: ValType,
}
-#[derive(Debug, Clone, PartialEq)]
+#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))]
pub struct TableType {
pub element_type: ValType,
@@ -307,7 +307,7 @@ impl TableType {
}
/// Represents a memory's type.
-#[derive(Debug, Copy, Clone, PartialEq)]
+#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))]
pub struct MemoryType {
arch: MemoryArch,
@@ -353,7 +353,7 @@ pub enum MemoryArch {
I64,
}
-#[derive(Debug, Clone, PartialEq)]
+#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))]
pub struct Import {
pub module: Box<str>,
@@ -361,7 +361,7 @@ pub struct Import {
pub kind: ImportKind,
}
-#[derive(Debug, Clone, PartialEq)]
+#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))]
pub enum ImportKind {
Function(TypeAddr),
diff --git a/crates/types/src/value.rs b/crates/types/src/value.rs
index b68836b..22bb4eb 100644
--- a/crates/types/src/value.rs
+++ b/crates/types/src/value.rs
@@ -23,14 +23,14 @@ pub enum WasmValue {
RefFunc(FuncRef),
}
-#[derive(Clone, Copy, PartialEq)]
+#[derive(Clone, Copy, PartialEq, Eq)]
pub struct ExternRef(Option<ExternAddr>);
-#[derive(Clone, Copy, PartialEq)]
+#[derive(Clone, Copy, PartialEq, Eq)]
pub struct FuncRef(Option<FuncAddr>);
impl Debug for ExternRef {
- fn fmt(&self, f: &mut alloc::fmt::Formatter<'_>) -> alloc::fmt::Result {
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self.0 {
Some(addr) => write!(f, "extern({addr:?})"),
None => write!(f, "extern(null)"),
@@ -39,7 +39,7 @@ impl Debug for ExternRef {
}
impl Debug for FuncRef {
- fn fmt(&self, f: &mut alloc::fmt::Formatter<'_>) -> alloc::fmt::Result {
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self.0 {
Some(addr) => write!(f, "func({addr:?})"),
None => write!(f, "func(null)"),
@@ -114,7 +114,7 @@ impl WasmValue {
Self::F64(i) => ConstInstruction::F64Const(*i),
Self::V128(i) => ConstInstruction::V128Const(*i),
Self::RefFunc(i) => ConstInstruction::RefFunc(i.addr()),
- _ => unimplemented!("no const_instr for {:?}", self),
+ Self::RefExtern(_) => unimplemented!("no const_instr for RefExtern"),
}
}
@@ -220,15 +220,15 @@ impl WasmValue {
fn cold() {}
impl Debug for WasmValue {
- fn fmt(&self, f: &mut alloc::fmt::Formatter<'_>) -> alloc::fmt::Result {
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
- WasmValue::I32(i) => write!(f, "i32({i})"),
- WasmValue::I64(i) => write!(f, "i64({i})"),
- WasmValue::F32(i) => write!(f, "f32({i})"),
- WasmValue::F64(i) => write!(f, "f64({i})"),
- WasmValue::V128(i) => write!(f, "v128({i:?})"),
- WasmValue::RefExtern(i) => write!(f, "ref({i:?})"),
- WasmValue::RefFunc(i) => write!(f, "func({i:?})"),
+ Self::I32(i) => write!(f, "i32({i})"),
+ Self::I64(i) => write!(f, "i64({i})"),
+ Self::F32(i) => write!(f, "f32({i})"),
+ Self::F64(i) => write!(f, "f64({i})"),
+ Self::V128(i) => write!(f, "v128({i:?})"),
+ Self::RefExtern(i) => write!(f, "ref({i:?})"),
+ Self::RefFunc(i) => write!(f, "func({i:?})"),
}
}
}
@@ -278,7 +278,7 @@ impl ValType {
#[doc(hidden)]
#[inline]
pub fn is_simd(&self) -> bool {
- matches!(self, ValType::V128)
+ matches!(self, Self::V128)
}
}