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)
| 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 | /// |