Skip to content

Commit

Permalink
chore: fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
skanehira committed Apr 14, 2024
1 parent b13d4ce commit dc33c90
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
15 changes: 7 additions & 8 deletions src/execution/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,8 @@ impl Runtime {
trace!("call stack is empty, return");
break;
};
let insts = &frame.insts;
frame.pc += 1;
let Some(inst) = insts.get(frame.pc as usize) else {
let Some(inst) = frame.insts.get(frame.pc as usize) else {
trace!("reach the end of function");
break;
};
Expand Down Expand Up @@ -339,7 +338,7 @@ impl Runtime {
Instruction::Loop(block) => {
let arity = block.block_type.result_count();
let start_pc = frame.pc;
let pc = get_end_address(insts, frame.pc)?;
let pc = get_end_address(&frame.insts, frame.pc)?;

let label = Label {
start: Some(start_pc),
Expand All @@ -355,11 +354,11 @@ impl Runtime {
let cond: Value = stack.pop1()?;

// calc pc when the end of block
let next_pc = get_end_address(insts, frame.pc)?;
let next_pc = get_end_address(&frame.insts, frame.pc)?;

if !cond.is_true() {
// if the condition is false, skip the if block
frame.pc = get_else_or_end_address(insts, frame.pc)? as isize;
frame.pc = get_else_or_end_address(&frame.insts, frame.pc)? as isize;
}

// NOTE: if block has no any instruction, just continue
Expand Down Expand Up @@ -387,7 +386,7 @@ impl Runtime {
}
Instruction::Block(block) => {
let arity = block.block_type.result_count();
let pc = get_end_address(insts, frame.pc)?;
let pc = get_end_address(&frame.insts, frame.pc)?;

let label = Label {
start: None,
Expand Down Expand Up @@ -520,7 +519,7 @@ impl Runtime {
let store = self.store.borrow();
let memory = store
.memory
.get(0)
.first()
.with_context(|| Error::NotFoundMemory(dst))?;
let mut memory = memory.borrow_mut();
memory.data.copy_within(src..src + len, dst);
Expand All @@ -533,7 +532,7 @@ impl Runtime {
let store = self.store.borrow();
let memory = store
.memory
.get(0)
.first()
.with_context(|| Error::NotFoundMemory(dst))?;
let mut memory = memory.borrow_mut();

Expand Down
4 changes: 2 additions & 2 deletions src/execution/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl Store {
if importers.is_empty() {
bail!("not found import module: {}", module_name);
}
let importer = importers.get(0).unwrap();
let importer = importers.first().unwrap();

match import_info.kind {
crate::binary::types::ImportKind::Func(typeidx) => {
Expand Down Expand Up @@ -231,7 +231,7 @@ impl Store {
// table
if let Some(ref table_section) = module.table_section {
let table = table_section
.get(0) // NOTE: only support one table now
.first() // NOTE: only support one table now
.with_context(|| "cannot get table from table section")?; // NOTE: only support one table now
let min = table.limits.min as usize;

Expand Down
18 changes: 9 additions & 9 deletions src/wasi/wasi_snapshot_preview1/preview1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl WasiSnapshotPreview1 {

fn proc_exit(&self, args: Vec<Value>) -> ! {
let exit_code: i32 = args
.get(0)
.first()
.expect("no any argument in proc_exit")
.clone()
.into();
Expand All @@ -65,7 +65,7 @@ impl WasiSnapshotPreview1 {
let (mut offset, mut buf_offset) = (args[0] as usize, args[1] as usize);

let store = store.borrow();
let memory = store.memory.get(0).with_context(|| "not found memory")?;
let memory = store.memory.first().with_context(|| "not found memory")?;
let mut memory = memory.borrow_mut();

let env = std::env::vars();
Expand All @@ -89,7 +89,7 @@ impl WasiSnapshotPreview1 {
let (offset, buf_offset) = (args[0] as usize, args[1] as usize);

let store = store.borrow();
let memory = store.memory.get(0).with_context(|| "not found memory")?;
let memory = store.memory.first().with_context(|| "not found memory")?;
let mut memory = memory.borrow_mut();

let env = std::env::vars();
Expand Down Expand Up @@ -118,7 +118,7 @@ impl WasiSnapshotPreview1 {
);

let store = store.borrow();
let memory = store.memory.get(0).with_context(|| "not found memory")?;
let memory = store.memory.first().with_context(|| "not found memory")?;
let mut memory = memory.borrow_mut();

let file = self
Expand Down Expand Up @@ -159,7 +159,7 @@ impl WasiSnapshotPreview1 {
);

let store = store.borrow();
let memory = store.memory.get(0).with_context(|| "not found memory")?;
let memory = store.memory.first().with_context(|| "not found memory")?;
let mut memory = memory.borrow_mut();

let file = self
Expand Down Expand Up @@ -197,7 +197,7 @@ impl WasiSnapshotPreview1 {
let (mut offset, mut buf_offset) = (args[0] as usize, args[1] as usize);

let store = store.borrow();
let memory = store.memory.get(0).with_context(|| "not found memory")?;
let memory = store.memory.first().with_context(|| "not found memory")?;
let mut memory = memory.borrow_mut();

let args = std::env::args();
Expand All @@ -221,7 +221,7 @@ impl WasiSnapshotPreview1 {
let (offset, buf_offset) = (args[0] as usize, args[1] as usize);

let store = store.borrow();
let memory = store.memory.get(0).with_context(|| "not found memory")?;
let memory = store.memory.first().with_context(|| "not found memory")?;
let mut memory = memory.borrow_mut();

let args = std::env::args();
Expand All @@ -245,7 +245,7 @@ impl WasiSnapshotPreview1 {
let (mut offset, buf_len) = (args[0] as usize, args[1] as usize);

let store = store.borrow();
let memory = store.memory.get(0).with_context(|| "not found memory")?;
let memory = store.memory.first().with_context(|| "not found memory")?;
let mut memory = memory.borrow_mut();

let mut rng = thread_rng();
Expand All @@ -267,7 +267,7 @@ impl WasiSnapshotPreview1 {
let (fd, offset) = (args[0] as usize, args[1] as usize);

let store = store.borrow();
let memory = store.memory.get(0).with_context(|| "not found memory")?;
let memory = store.memory.first().with_context(|| "not found memory")?;
let mut memory = memory.borrow_mut();

let file = self
Expand Down

0 comments on commit dc33c90

Please sign in to comment.