1
Fork 0

Allow switching on non-integer types.

This commit is contained in:
Scott Olson 2016-03-13 04:50:16 -06:00
parent 96c51dc8ed
commit cc8b8efd33
3 changed files with 13 additions and 14 deletions

View file

@ -158,16 +158,15 @@ impl<'a, 'tcx: 'a> Interpreter<'a, 'tcx> {
} }
SwitchInt { ref discr, ref values, ref targets, .. } => { SwitchInt { ref discr, ref values, ref targets, .. } => {
// FIXME(tsion): Handle non-integer switch types.
let (discr_ptr, discr_repr) = try!(self.eval_lvalue(discr)); let (discr_ptr, discr_repr) = try!(self.eval_lvalue(discr));
let discr_val = try!(self.memory.read_i64(discr_ptr)); let discr_val = try!(self.memory.read_primval(discr_ptr, &discr_repr));
// Branch to the `otherwise` case by default, if no match is found. // Branch to the `otherwise` case by default, if no match is found.
current_block = targets[targets.len() - 1]; current_block = targets[targets.len() - 1];
for (index, val_const) in values.iter().enumerate() { for (index, val_const) in values.iter().enumerate() {
let ptr = try!(self.const_to_ptr(val_const)); let ptr = try!(self.const_to_ptr(val_const));
let val = try!(self.memory.read_i64(ptr)); let val = try!(self.memory.read_primval(ptr, &discr_repr));
if discr_val == val { if discr_val == val {
current_block = targets[index]; current_block = targets[index];
break; break;

View file

@ -16,11 +16,11 @@ fn if_true() -> i64 {
if true { 1 } else { 0 } if true { 1 } else { 0 }
} }
// #[miri_run] #[miri_run]
// fn match_bool() -> i64 { fn match_bool() -> i16 {
// let b = true; let b = true;
// match b { match b {
// true => 1, true => 1,
// false => 0, _ => 0,
// } }
// } }

View file

@ -24,13 +24,13 @@ fn indirect_add() -> i64 {
} }
#[miri_run] #[miri_run]
fn arith() -> i64 { fn arith() -> i32 {
3*3 + 4*4 3*3 + 4*4
} }
#[miri_run] #[miri_run]
fn match_int() -> i64 { fn match_int() -> i16 {
let n = 2i64; let n = 2;
match n { match n {
0 => 0, 0 => 0,
1 => 10, 1 => 10,