MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / drop_last

Method drop_last

winch/codegen/src/codegen/context.rs:631–649  ·  view source on GitHub ↗

Drops the last `n` elements of the stack, calling the provided function for each `n` stack value. The values are dropped in top-to-bottom order.

(&mut self, last: usize, mut f: F)

Source from the content-addressed store, hash-verified

629 /// function for each `n` stack value.
630 /// The values are dropped in top-to-bottom order.
631 pub fn drop_last<F>(&mut self, last: usize, mut f: F) -> Result<()>
632 where
633 F: FnMut(&mut RegAlloc, &Val) -> Result<()>,
634 {
635 if last > 0 {
636 let len = self.stack.len();
637 ensure!(last <= len, CodeGenError::unexpected_value_stack_index(),);
638 let truncate = self.stack.len() - last;
639 let stack_mut = self.stack.inner_mut();
640
641 // Invoke the callback in top-to-bottom order.
642 for v in stack_mut[truncate..].into_iter().rev() {
643 f(&mut self.regalloc, v)?
644 }
645 stack_mut.truncate(truncate);
646 }
647
648 Ok(())
649 }
650
651 /// Convenience wrapper around [`Self::spill_callback`].
652 ///

Callers 3

visit_dropMethod · 0.80
cleanupMethod · 0.80
truncate_stack_toMethod · 0.80

Calls 6

OkFunction · 0.85
inner_mutMethod · 0.80
fFunction · 0.50
lenMethod · 0.45
into_iterMethod · 0.45
truncateMethod · 0.45

Tested by

no test coverage detected