wasm_interp: rename ValueStack::len -> depth

This commit is contained in:
Brian Carroll 2022-12-10 00:00:13 +00:00
parent 76341c7611
commit ed18bf7709
No known key found for this signature in database
GPG key ID: 5C7B2EC4101703C0
4 changed files with 11 additions and 11 deletions

View file

@ -62,7 +62,7 @@ impl<'a> CallStack<'a> {
self.set_local_help(i as u32, arg); self.set_local_help(i as u32, arg);
} }
self.value_stack_bases.push(value_stack.len() as u32); self.value_stack_bases.push(value_stack.depth() as u32);
// Parse local variable declarations in the function header. They're grouped by type. // Parse local variable declarations in the function header. They're grouped by type.
let local_group_count = u32::parse((), code_bytes, pc).unwrap(); let local_group_count = u32::parse((), code_bytes, pc).unwrap();
@ -209,7 +209,7 @@ impl<'a> CallStack<'a> {
let frame_value_count = { let frame_value_count = {
let value_stack_base = self.value_stack_bases[frame]; let value_stack_base = self.value_stack_bases[frame];
let next_value_stack_base = if frame == self.frame_offsets.len() - 1 { let next_value_stack_base = if frame == self.frame_offsets.len() - 1 {
value_stack.len() as u32 value_stack.depth() as u32
} else { } else {
self.value_stack_bases[frame + 1] self.value_stack_bases[frame + 1]
}; };

View file

@ -469,13 +469,13 @@ impl<'a, I: ImportDispatcher> Instance<'a, I> {
BLOCK => { BLOCK => {
self.fetch_immediate_u32(module); // blocktype (ignored) self.fetch_immediate_u32(module); // blocktype (ignored)
self.blocks.push(Block::Normal { self.blocks.push(Block::Normal {
vstack: self.value_stack.len(), vstack: self.value_stack.depth(),
}); });
} }
LOOP => { LOOP => {
self.fetch_immediate_u32(module); // blocktype (ignored) self.fetch_immediate_u32(module); // blocktype (ignored)
self.blocks.push(Block::Loop { self.blocks.push(Block::Loop {
vstack: self.value_stack.len(), vstack: self.value_stack.depth(),
start_addr: self.program_counter, start_addr: self.program_counter,
}); });
} }
@ -483,7 +483,7 @@ impl<'a, I: ImportDispatcher> Instance<'a, I> {
self.fetch_immediate_u32(module); // blocktype (ignored) self.fetch_immediate_u32(module); // blocktype (ignored)
let condition = self.value_stack.pop_i32()?; let condition = self.value_stack.pop_i32()?;
self.blocks.push(Block::Normal { self.blocks.push(Block::Normal {
vstack: self.value_stack.len(), vstack: self.value_stack.depth(),
}); });
if condition == 0 { if condition == 0 {
let mut depth = self.blocks.len(); let mut depth = self.blocks.len();

View file

@ -840,7 +840,7 @@ fn test_set_get_local() {
state.execute_next_instruction(&module).unwrap(); state.execute_next_instruction(&module).unwrap();
state.execute_next_instruction(&module).unwrap(); state.execute_next_instruction(&module).unwrap();
state.execute_next_instruction(&module).unwrap(); state.execute_next_instruction(&module).unwrap();
assert_eq!(state.value_stack.len(), 1); assert_eq!(state.value_stack.depth(), 1);
assert_eq!(state.value_stack.pop(), Value::I32(12345)); assert_eq!(state.value_stack.pop(), Value::I32(12345));
} }
@ -876,7 +876,7 @@ fn test_tee_get_local() {
state.execute_next_instruction(&module).unwrap(); state.execute_next_instruction(&module).unwrap();
state.execute_next_instruction(&module).unwrap(); state.execute_next_instruction(&module).unwrap();
state.execute_next_instruction(&module).unwrap(); state.execute_next_instruction(&module).unwrap();
assert_eq!(state.value_stack.len(), 2); assert_eq!(state.value_stack.depth(), 2);
assert_eq!(state.value_stack.pop(), Value::I32(12345)); assert_eq!(state.value_stack.pop(), Value::I32(12345));
assert_eq!(state.value_stack.pop(), Value::I32(12345)); assert_eq!(state.value_stack.pop(), Value::I32(12345));
} }
@ -903,7 +903,7 @@ fn test_global() {
state.execute_next_instruction(&module).unwrap(); state.execute_next_instruction(&module).unwrap();
state.execute_next_instruction(&module).unwrap(); state.execute_next_instruction(&module).unwrap();
state.execute_next_instruction(&module).unwrap(); state.execute_next_instruction(&module).unwrap();
assert_eq!(state.value_stack.len(), 2); assert_eq!(state.value_stack.depth(), 2);
assert_eq!(state.value_stack.pop(), Value::I32(555)); assert_eq!(state.value_stack.pop(), Value::I32(555));
assert_eq!(state.value_stack.pop(), Value::I32(222)); assert_eq!(state.value_stack.pop(), Value::I32(222));
} }

View file

@ -18,7 +18,7 @@ impl<'a> ValueStack<'a> {
} }
} }
pub(crate) fn len(&self) -> usize { pub(crate) fn depth(&self) -> usize {
self.values.len() self.values.len()
} }
@ -91,8 +91,8 @@ impl<'a> ValueStack<'a> {
self.values.iter() self.values.iter()
} }
pub(crate) fn truncate(&mut self, len: usize) { pub(crate) fn truncate(&mut self, depth: usize) {
self.values.truncate(len) self.values.truncate(depth)
} }
} }