Reimplement 'if' conditions.
This commit is contained in:
parent
a1adc55370
commit
586bc5d1da
2 changed files with 15 additions and 17 deletions
|
|
@ -162,8 +162,15 @@ impl<'a, 'tcx> Interpreter<'a, 'tcx> {
|
|||
use rustc::mir::repr::Terminator::*;
|
||||
match *block_data.terminator() {
|
||||
Return => break,
|
||||
|
||||
Goto { target } => block = target,
|
||||
|
||||
If { ref cond, targets: (then_target, else_target) } => {
|
||||
let cond_ptr = try!(self.operand_to_ptr(cond));
|
||||
let cond = try!(self.memory.read_bool(&cond_ptr));
|
||||
block = if cond { then_target } else { else_target }
|
||||
}
|
||||
|
||||
// Call { ref func, ref args, ref destination, .. } => {
|
||||
// let ptr = destination.as_ref().map(|&(ref lv, _)| self.lvalue_to_ptr(lv));
|
||||
// let func_val = self.operand_to_ptr(func);
|
||||
|
|
@ -192,15 +199,6 @@ impl<'a, 'tcx> Interpreter<'a, 'tcx> {
|
|||
// }
|
||||
// }
|
||||
|
||||
// If { ref cond, targets: (then_target, else_target) } => {
|
||||
// let cond_ptr = try!(self.operand_to_ptr(cond));
|
||||
// match self.operand_to_ptr(cond) {
|
||||
// Value::Bool(true) => block = then_target,
|
||||
// Value::Bool(false) => block = else_target,
|
||||
// cond_val => panic!("Non-boolean `if` condition value: {:?}", cond_val),
|
||||
// }
|
||||
// }
|
||||
|
||||
// SwitchInt { ref discr, ref values, ref targets, .. } => {
|
||||
// let discr_val = self.read_lvalue(discr);
|
||||
|
||||
|
|
|
|||
|
|
@ -51,15 +51,15 @@ fn boolean() -> bool {
|
|||
true
|
||||
}
|
||||
|
||||
// #[miri_run(expected = "Int(0)")]
|
||||
// fn if_false() -> i32 {
|
||||
// if false { 1 } else { 0 }
|
||||
// }
|
||||
#[miri_run]
|
||||
fn if_false() -> i32 {
|
||||
if false { 1 } else { 0 }
|
||||
}
|
||||
|
||||
// #[miri_run(expected = "Int(1)")]
|
||||
// fn if_true() -> i32 {
|
||||
// if true { 1 } else { 0 }
|
||||
// }
|
||||
#[miri_run]
|
||||
fn if_true() -> i32 {
|
||||
if true { 1 } else { 0 }
|
||||
}
|
||||
|
||||
// #[miri_run(expected = "Int(2)")]
|
||||
// fn call() -> i32 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue