Keep::count

This commit is contained in:
Sergey Pepyakin 2019-04-18 18:48:47 +02:00
parent e8cc132972
commit 203d3d7151
2 changed files with 12 additions and 2 deletions

View File

@ -82,6 +82,16 @@ pub enum Keep {
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.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct DropKeep {

View File

@ -1012,14 +1012,14 @@ fn compute_drop_keep(
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!(
"Stack underflow detected: asked to keep {:?} values, but there are only {}",
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) - keep as u32
(actual_value_stack_height as u32 - start_value_stack_height as u32) - keep.count()
};
Ok(isa::DropKeep { drop, keep })