Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sile committed Jul 14, 2024
1 parent ef378fc commit 37765eb
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 61 deletions.
18 changes: 13 additions & 5 deletions src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ impl<V: VectorFactory> Name<V> {
pub fn len(&self) -> usize {
self.0.len()
}

pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
}

impl<V: VectorFactory> Decode<V> for Name<V> {
Expand Down Expand Up @@ -67,7 +71,7 @@ impl<V: VectorFactory> Clone for Import<V> {
Self {
module: self.module.clone(),
name: self.name.clone(),
desc: self.desc.clone(),
desc: self.desc,
}
}
}
Expand Down Expand Up @@ -118,7 +122,7 @@ impl<V: VectorFactory> Clone for Export<V> {
fn clone(&self) -> Self {
Self {
name: self.name.clone(),
desc: self.desc.clone(),
desc: self.desc,
}
}
}
Expand Down Expand Up @@ -464,7 +468,7 @@ impl<V: VectorFactory> Clone for Functype<V> {
fn clone(&self) -> Self {
Self {
params: V::clone_vector(&self.params),
result: self.result.clone(),
result: self.result,
}
}
}
Expand All @@ -477,6 +481,10 @@ impl Resulttype {
self.0.is_some() as usize
}

pub fn is_empty(self) -> bool {
self.0.is_none()
}

pub fn get(self) -> Option<Valtype> {
self.0
}
Expand Down Expand Up @@ -686,7 +694,7 @@ impl<V: VectorFactory> Clone for Elem<V> {
fn clone(&self) -> Self {
Self {
table: self.table,
offset: self.offset.clone(),
offset: self.offset,
init: V::clone_vector(&self.init),
}
}
Expand Down Expand Up @@ -771,7 +779,7 @@ impl<V: VectorFactory> Clone for Data<V> {
fn clone(&self) -> Self {
Self {
data: self.data,
offset: self.offset.clone(),
offset: self.offset,
init: V::clone_vector(&self.init),
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ impl<V: VectorFactory> Executor<V> {
}

pub fn set_local(&mut self, i: Localidx, v: Val) {
let i = self.current_frame.locals_start + i.get() as usize;
let i = self.current_frame.locals_start + i.get();
self.locals[i] = v;
}

pub fn get_local(&self, i: Localidx) -> Val {
let i = self.current_frame.locals_start + i.get() as usize;
let i = self.current_frame.locals_start + i.get();
self.locals[i]
}

Expand Down Expand Up @@ -572,7 +572,7 @@ impl<V: VectorFactory> Executor<V> {
}

let v = v.as_i32().ok_or(ExecuteError::Trapped)? as i16; // TODO:
(&mut self.mem[start..end]).copy_from_slice(&v.to_le_bytes());
self.mem[start..end].copy_from_slice(&v.to_le_bytes());
}
Instr::I64Store8(arg) => {
// TODO: handle alignment
Expand All @@ -596,7 +596,7 @@ impl<V: VectorFactory> Executor<V> {
}

let v = v.as_i64().ok_or(ExecuteError::Trapped)? as i16; // TODO:
(&mut self.mem[start..end]).copy_from_slice(&v.to_le_bytes());
self.mem[start..end].copy_from_slice(&v.to_le_bytes());
}
Instr::I64Store32(arg) => {
// TODO: handle alignment
Expand All @@ -609,7 +609,7 @@ impl<V: VectorFactory> Executor<V> {
}

let v = v.as_i64().ok_or(ExecuteError::Trapped)? as i32; // TODO:
(&mut self.mem[start..end]).copy_from_slice(&v.to_le_bytes());
self.mem[start..end].copy_from_slice(&v.to_le_bytes());
}
Instr::MemorySize => {
let size = self.mem.len() / PAGE_SIZE;
Expand Down Expand Up @@ -685,7 +685,7 @@ impl<V: VectorFactory> Executor<V> {
Instr::I32Xor => self.apply_binop_i32(|v0, v1| v0 ^ v1),
Instr::I32Shl => self.apply_binop_i32(|v0, v1| v0.wrapping_shl(v1 as u32)), // TODO: wrapping?
Instr::I32ShrS => self.apply_binop_i32(|v0, v1| v0.wrapping_shr(v1 as u32)), // TODO: wrapping?
Instr::I32ShrU => self.apply_binop_u32(|v0, v1| v0.wrapping_shr(v1 as u32)), // TODO: wrapping?
Instr::I32ShrU => self.apply_binop_u32(|v0, v1| v0.wrapping_shr(v1)), // TODO: wrapping?
Instr::I32Rotl => self.apply_binop_i32(|v0, v1| v0.rotate_left(v1 as u32)),
Instr::I32Rotr => self.apply_binop_i32(|v0, v1| v0.rotate_right(v1 as u32)),
Instr::I64Clz => self.apply_unop_i64(|v| v.leading_zeros() as i64),
Expand Down
14 changes: 7 additions & 7 deletions src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ impl<V: VectorFactory, H: HostFunc> ModuleInstance<V, H> {
let ty = module
.types()
.get(typeidx.get())
.ok_or_else(|| ExecuteError::UnresolvedImport { index })?;
.ok_or(ExecuteError::UnresolvedImport { index })?;
let host_func = resolver
.resolve_func(
import.module.as_str(),
import.name.as_str(),
&ty.params,
ty.result,
)
.ok_or_else(|| ExecuteError::UnresolvedImport { index })?;
.ok_or(ExecuteError::UnresolvedImport { index })?;
imported_funcs.push(FuncInst::Imported {
imports_index: index,
host_func,
Expand All @@ -128,21 +128,21 @@ impl<V: VectorFactory, H: HostFunc> ModuleInstance<V, H> {
Importdesc::Table(ty) => {
let resolved = resolver
.resolve_table(import.module.as_str(), import.name.as_str(), ty.limits)
.ok_or_else(|| ExecuteError::UnresolvedImport { index })?;
.ok_or(ExecuteError::UnresolvedImport { index })?;
let resolved = V::clone_vector(resolved);
imported_table = Some(resolved);
}
Importdesc::Mem(ty) => {
let resolved = resolver
.resolve_mem(import.module.as_str(), import.name.as_str(), *ty)
.ok_or_else(|| ExecuteError::UnresolvedImport { index })?;
.ok_or(ExecuteError::UnresolvedImport { index })?;
let resolved = V::clone_vector(resolved);
imported_mem = Some(resolved);
}
Importdesc::Global(ty) => {
let resolved = resolver
.resolve_global(import.module.as_str(), import.name.as_str(), ty.valtype())
.ok_or_else(|| ExecuteError::UnresolvedImport { index })?;
.ok_or(ExecuteError::UnresolvedImport { index })?;
imported_globals.push(GlobalVal::new(ty.is_const(), resolved));
}
}
Expand Down Expand Up @@ -187,7 +187,7 @@ impl<V: VectorFactory, H: HostFunc> ModuleInstance<V, H> {
for (index, global) in module.globals().iter().enumerate() {
let v = global
.init(imported_globals)
.ok_or_else(|| ExecuteError::InvalidGlobal { index })?;
.ok_or(ExecuteError::InvalidGlobal { index })?;
globals.push(v);
}
Ok(globals)
Expand Down Expand Up @@ -231,7 +231,7 @@ impl<V: VectorFactory, H: HostFunc> ModuleInstance<V, H> {
if mem.len() < end {
return Err(ExecuteError::InvalidData { index });
}
(&mut mem[start..end]).copy_from_slice(&data.init);
mem[start..end].copy_from_slice(&data.init);
}

Ok(mem)
Expand Down
80 changes: 40 additions & 40 deletions src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,48 +600,48 @@ impl<V: VectorFactory> Clone for Instr<V> {
Self::Block(v) => Self::Block(v.clone()),
Self::Loop(v) => Self::Loop(v.clone()),
Self::If(v) => Self::If(v.clone()),
Self::Br(v) => Self::Br(v.clone()),
Self::BrIf(v) => Self::BrIf(v.clone()),
Self::Br(v) => Self::Br(*v),
Self::BrIf(v) => Self::BrIf(*v),
Self::BrTable(v) => Self::BrTable(v.clone()),
Self::Return => Self::Return,
Self::Call(v) => Self::Call(v.clone()),
Self::CallIndirect(v) => Self::CallIndirect(v.clone()),
Self::Call(v) => Self::Call(*v),
Self::CallIndirect(v) => Self::CallIndirect(*v),
Self::Drop => Self::Drop,
Self::Select => Self::Select,
Self::LocalGet(v) => Self::LocalGet(v.clone()),
Self::LocalSet(v) => Self::LocalSet(v.clone()),
Self::LocalTee(v) => Self::LocalTee(v.clone()),
Self::GlobalGet(v) => Self::GlobalGet(v.clone()),
Self::GlobalSet(v) => Self::GlobalSet(v.clone()),
Self::I32Load(v) => Self::I32Load(v.clone()),
Self::I64Load(v) => Self::I64Load(v.clone()),
Self::F32Load(v) => Self::F32Load(v.clone()),
Self::F64Load(v) => Self::F64Load(v.clone()),
Self::I32Load8S(v) => Self::I32Load8S(v.clone()),
Self::I32Load8U(v) => Self::I32Load8U(v.clone()),
Self::I32Load16S(v) => Self::I32Load16S(v.clone()),
Self::I32Load16U(v) => Self::I32Load16U(v.clone()),
Self::I64Load8S(v) => Self::I64Load8S(v.clone()),
Self::I64Load8U(v) => Self::I64Load8U(v.clone()),
Self::I64Load16S(v) => Self::I64Load16S(v.clone()),
Self::I64Load16U(v) => Self::I64Load16U(v.clone()),
Self::I64Load32S(v) => Self::I64Load32S(v.clone()),
Self::I64Load32U(v) => Self::I64Load32U(v.clone()),
Self::I32Store(v) => Self::I32Store(v.clone()),
Self::I64Store(v) => Self::I64Store(v.clone()),
Self::F32Store(v) => Self::F32Store(v.clone()),
Self::F64Store(v) => Self::F64Store(v.clone()),
Self::I32Store8(v) => Self::I32Store8(v.clone()),
Self::I32Store16(v) => Self::I32Store16(v.clone()),
Self::I64Store8(v) => Self::I64Store8(v.clone()),
Self::I64Store16(v) => Self::I64Store16(v.clone()),
Self::I64Store32(v) => Self::I64Store32(v.clone()),
Self::LocalGet(v) => Self::LocalGet(*v),
Self::LocalSet(v) => Self::LocalSet(*v),
Self::LocalTee(v) => Self::LocalTee(*v),
Self::GlobalGet(v) => Self::GlobalGet(*v),
Self::GlobalSet(v) => Self::GlobalSet(*v),
Self::I32Load(v) => Self::I32Load(*v),
Self::I64Load(v) => Self::I64Load(*v),
Self::F32Load(v) => Self::F32Load(*v),
Self::F64Load(v) => Self::F64Load(*v),
Self::I32Load8S(v) => Self::I32Load8S(*v),
Self::I32Load8U(v) => Self::I32Load8U(*v),
Self::I32Load16S(v) => Self::I32Load16S(*v),
Self::I32Load16U(v) => Self::I32Load16U(*v),
Self::I64Load8S(v) => Self::I64Load8S(*v),
Self::I64Load8U(v) => Self::I64Load8U(*v),
Self::I64Load16S(v) => Self::I64Load16S(*v),
Self::I64Load16U(v) => Self::I64Load16U(*v),
Self::I64Load32S(v) => Self::I64Load32S(*v),
Self::I64Load32U(v) => Self::I64Load32U(*v),
Self::I32Store(v) => Self::I32Store(*v),
Self::I64Store(v) => Self::I64Store(*v),
Self::F32Store(v) => Self::F32Store(*v),
Self::F64Store(v) => Self::F64Store(*v),
Self::I32Store8(v) => Self::I32Store8(*v),
Self::I32Store16(v) => Self::I32Store16(*v),
Self::I64Store8(v) => Self::I64Store8(*v),
Self::I64Store16(v) => Self::I64Store16(*v),
Self::I64Store32(v) => Self::I64Store32(*v),
Self::MemorySize => Self::MemorySize,
Self::MemoryGrow => Self::MemoryGrow,
Self::I32Const(v) => Self::I32Const(v.clone()),
Self::I64Const(v) => Self::I64Const(v.clone()),
Self::F32Const(v) => Self::F32Const(v.clone()),
Self::F64Const(v) => Self::F64Const(v.clone()),
Self::I32Const(v) => Self::I32Const(*v),
Self::I64Const(v) => Self::I64Const(*v),
Self::F32Const(v) => Self::F32Const(*v),
Self::F64Const(v) => Self::F64Const(*v),
Self::I32Eqz => Self::I32Eqz,
Self::I32Eq => Self::I32Eq,
Self::I32Ne => Self::I32Ne,
Expand Down Expand Up @@ -766,7 +766,7 @@ impl<V: VectorFactory> Clone for Instr<V> {
Self::F32ReinterpretI32 => Self::F32ReinterpretI32,
Self::F64ReinterpretI64 => Self::F64ReinterpretI64,
#[cfg(feature = "sign_extension")]
Self::SignExtension(v) => Self::SignExtension(v.clone()),
Self::SignExtension(v) => Self::SignExtension(*v),
}
}
}
Expand Down Expand Up @@ -803,7 +803,7 @@ impl<V: VectorFactory> Debug for BlockInstr<V> {
impl<V: VectorFactory> Clone for BlockInstr<V> {
fn clone(&self) -> Self {
Self {
blocktype: self.blocktype.clone(),
blocktype: self.blocktype,
instrs: V::clone_vector(&self.instrs),
}
}
Expand Down Expand Up @@ -841,7 +841,7 @@ impl<V: VectorFactory> Debug for LoopInstr<V> {
impl<V: VectorFactory> Clone for LoopInstr<V> {
fn clone(&self) -> Self {
Self {
blocktype: self.blocktype.clone(),
blocktype: self.blocktype,
instrs: V::clone_vector(&self.instrs),
}
}
Expand Down Expand Up @@ -902,7 +902,7 @@ impl<V: VectorFactory> Debug for IfInstr<V> {
impl<V: VectorFactory> Clone for IfInstr<V> {
fn clone(&self) -> Self {
Self {
blocktype: self.blocktype.clone(),
blocktype: self.blocktype,
then_instrs: V::clone_vector(&self.then_instrs),
else_instrs: V::clone_vector(&self.else_instrs),
}
Expand Down
6 changes: 3 additions & 3 deletions src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ impl<V: VectorFactory> Module<V> {

if section_id < last_section_id {
return Err(DecodeError::InvalidSectionOrder {
current_section_id: section_id as u8,
last_section_id: last_section_id as u8,
current_section_id: section_id,
last_section_id,
});
}

Expand Down Expand Up @@ -153,7 +153,7 @@ impl<V: VectorFactory> Module<V> {

if !section_reader.is_empty() {
return Err(DecodeError::InvalidSectionByteSize {
section_id: section_id as u8,
section_id,
expected_byte_size: section_size,
actual_byte_size: section_reader.position(),
});
Expand Down

0 comments on commit 37765eb

Please sign in to comment.