mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
wasm_interp: dump a stack trace on error
This commit is contained in:
parent
5bdd1b5628
commit
6d43763ab7
4 changed files with 194 additions and 20 deletions
|
@ -199,6 +199,14 @@ impl<'a> ValueStack<'a> {
|
|||
pub(crate) fn get_slice<'b>(&'b self, index: usize) -> ValueStackSlice<'a, 'b> {
|
||||
ValueStackSlice { stack: self, index }
|
||||
}
|
||||
|
||||
pub(crate) fn iter<'b>(&'b self) -> ValueStackIter<'a, 'b> {
|
||||
ValueStackIter {
|
||||
stack: self,
|
||||
index: 0,
|
||||
bytes_index: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for ValueStack<'_> {
|
||||
|
@ -218,6 +226,29 @@ impl Debug for ValueStackSlice<'_, '_> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct ValueStackIter<'a, 'b> {
|
||||
stack: &'b ValueStack<'a>,
|
||||
index: usize,
|
||||
bytes_index: usize,
|
||||
}
|
||||
|
||||
impl Iterator for ValueStackIter<'_, '_> {
|
||||
type Item = Value;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.index >= self.stack.is_64.len() {
|
||||
None
|
||||
} else {
|
||||
let is_64 = self.stack.is_64[self.index];
|
||||
let is_float = self.stack.is_float[self.index];
|
||||
let value = self.stack.get(is_64, is_float, self.bytes_index);
|
||||
self.index += 1;
|
||||
self.bytes_index += if is_64 { 8 } else { 4 };
|
||||
Some(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue