select: int condition on stack top

This commit is contained in:
Sergey Pepyakin 2018-01-29 18:01:50 +03:00
parent ee7ef764de
commit 508c918522
1 changed files with 4 additions and 5 deletions

View File

@ -470,11 +470,10 @@ impl<'a, E: Externals> Interpreter<'a, E> {
.value_stack_mut()
.pop_triple()
.and_then(|(left, mid, right)| {
let right: Result<_, Error> = right.try_into();
match (left, mid, right) {
(left, mid, Ok(condition)) => Ok((left, mid, condition)),
_ => Err(Error::Stack("expected to get int value from stack".into()))
}
let condition = right
.try_into()
.expect("Due to validation stack top should be int");
Ok((left, mid, condition))
})
.map(|(left, mid, condition)| if condition { left } else { mid })
.map(|val| context.value_stack_mut().push(val))