Keep::count
This commit is contained in:
parent
e8cc132972
commit
203d3d7151
10
src/isa.rs
10
src/isa.rs
|
@ -82,6 +82,16 @@ pub enum Keep {
|
||||||
Single,
|
Single,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Keep {
|
||||||
|
/// Reutrns a number of items that should be kept on the stack.
|
||||||
|
pub fn count(&self) -> u32 {
|
||||||
|
match *self {
|
||||||
|
Keep::None => 0,
|
||||||
|
Keep::Single => 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Specifies how many values we should keep and how many we should drop.
|
/// Specifies how many values we should keep and how many we should drop.
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct DropKeep {
|
pub struct DropKeep {
|
||||||
|
|
|
@ -1012,14 +1012,14 @@ fn compute_drop_keep(
|
||||||
start_value_stack_height,
|
start_value_stack_height,
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
if (actual_value_stack_height as u32 - start_value_stack_height as u32) < keep as u32 {
|
if (actual_value_stack_height as u32 - start_value_stack_height as u32) < keep.count() {
|
||||||
return Err(Error(format!(
|
return Err(Error(format!(
|
||||||
"Stack underflow detected: asked to keep {:?} values, but there are only {}",
|
"Stack underflow detected: asked to keep {:?} values, but there are only {}",
|
||||||
keep,
|
keep,
|
||||||
actual_value_stack_height as u32 - start_value_stack_height as u32,
|
actual_value_stack_height as u32 - start_value_stack_height as u32,
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
(actual_value_stack_height as u32 - start_value_stack_height as u32) - keep as u32
|
(actual_value_stack_height as u32 - start_value_stack_height as u32) - keep.count()
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(isa::DropKeep { drop, keep })
|
Ok(isa::DropKeep { drop, keep })
|
||||||
|
|
Loading…
Reference in New Issue