Clean and detail End opcode.

This commit is contained in:
Sergey Pepyakin 2019-04-16 16:29:49 +02:00
parent 921dda469e
commit d5a383a442
1 changed files with 12 additions and 7 deletions

View File

@ -258,22 +258,27 @@ impl<'a> FunctionValidationContext<'a> {
}; };
if self.frame_stack.len() == 1 { if self.frame_stack.len() == 1 {
// We are about to close the last frame. Insert // We are about to close the last frame.
// an explicit return.
// Check the return type. // Check the return type.
if let BlockType::Value(value_type) = self.return_type { if let BlockType::Value(value_type) = self.return_type {
tee_value(&mut self.value_stack, &self.frame_stack, value_type.into())?; tee_value(&mut self.value_stack, &self.frame_stack, value_type.into())?;
} }
}
pop_label(&mut self.value_stack, &mut self.frame_stack)?; pop_label(&mut self.value_stack, &mut self.frame_stack)?;
// We just poped the last frame. To avoid some difficulties
// we prefer to keep this branch explicit and bail out here.
()
} else {
pop_label(&mut self.value_stack, &mut self.frame_stack)?;
// Push the result value. // Push the result value.
if let BlockType::Value(value_type) = block_type { if let BlockType::Value(value_type) = block_type {
push_value(&mut self.value_stack, value_type.into())?; push_value(&mut self.value_stack, value_type.into())?;
} }
} }
}
Br(depth) => { Br(depth) => {
self.validate_br(depth)?; self.validate_br(depth)?;
make_top_frame_polymorphic(&mut self.value_stack, &mut self.frame_stack); make_top_frame_polymorphic(&mut self.value_stack, &mut self.frame_stack);