diff --git a/src/execution/runtime.rs b/src/execution/runtime.rs index 1199491..d9aa725 100644 --- a/src/execution/runtime.rs +++ b/src/execution/runtime.rs @@ -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; }; @@ -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), @@ -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 @@ -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, @@ -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); @@ -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(); diff --git a/src/execution/store.rs b/src/execution/store.rs index 3f1f095..93f8c23 100644 --- a/src/execution/store.rs +++ b/src/execution/store.rs @@ -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) => { @@ -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; diff --git a/src/wasi/wasi_snapshot_preview1/preview1.rs b/src/wasi/wasi_snapshot_preview1/preview1.rs index 0c4a42f..ec4ed3e 100644 --- a/src/wasi/wasi_snapshot_preview1/preview1.rs +++ b/src/wasi/wasi_snapshot_preview1/preview1.rs @@ -53,7 +53,7 @@ impl WasiSnapshotPreview1 { fn proc_exit(&self, args: Vec) -> ! { let exit_code: i32 = args - .get(0) + .first() .expect("no any argument in proc_exit") .clone() .into(); @@ -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(); @@ -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(); @@ -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 @@ -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 @@ -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(); @@ -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(); @@ -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(); @@ -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