From 29c771cf708eb512ed4d3cbb5810997b950bb479 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Thu, 18 Apr 2019 19:35:41 +0300 Subject: [PATCH] show match --- .gitignore | 1 + src/prepare/compile.rs | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 6e67dd4..62707ec 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ **/*.rs.bk Cargo.lock spec/target +.idea diff --git a/src/prepare/compile.rs b/src/prepare/compile.rs index a79451e..9e33220 100644 --- a/src/prepare/compile.rs +++ b/src/prepare/compile.rs @@ -1012,14 +1012,23 @@ fn compute_drop_keep( start_value_stack_height, ))); } - if (actual_value_stack_height as u32 - start_value_stack_height as u32) < keep as u32 { - 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, - ))); + + match keep { + isa::Keep::Single => { + if actual_value_stack_height < start_value_stack_height + 1 { + 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 - start_value_stack_height - 1) as u32 + }, + isa::Keep::None => { + (actual_value_stack_height - start_value_stack_height) as u32 + } } - (actual_value_stack_height as u32 - start_value_stack_height as u32) - keep as u32 }; Ok(isa::DropKeep { drop, keep })