From e9b972586013fb563cf4d4bcbf40a6ab46eadfdd Mon Sep 17 00:00:00 2001 From: Adam Kelly Date: Fri, 24 Aug 2018 17:39:33 +0100 Subject: [PATCH] JumpIf - evaluate truthyness of argument. --- vm/src/vm.rs | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/vm/src/vm.rs b/vm/src/vm.rs index c15643289..564c7d8db 100644 --- a/vm/src/vm.rs +++ b/vm/src/vm.rs @@ -12,6 +12,7 @@ use super::builtins; use super::bytecode; use super::frame::{copy_code, Block, Frame}; use super::import::import; +use super::objbool; use super::objlist; use super::objobject; use super::objstr; @@ -746,21 +747,15 @@ impl VirtualMachine { } bytecode::Instruction::JumpIf { target } => { let obj = self.pop_value(); - // TODO: determine if this value is True-ish: - //if *v == NativeType::Boolean(true) { - // curr_frame.lasti = curr_frame.labels.get(target).unwrap().clone(); - //} - let x = obj.borrow(); - let result: bool = match x.kind { - PyObjectKind::Boolean { ref value } => *value, - _ => { - panic!("Not impl {:?}", x); + match objbool::boolval(self, obj) { + Ok(value) => { + if value { + self.jump(target); + } + None } - }; - if result { - self.jump(target); + Err(value) => Some(Err(value)), } - None } bytecode::Instruction::Raise { argc } => {