From 694facf3958881e2845ac453f75c6fc387dad091 Mon Sep 17 00:00:00 2001 From: Scott Olson Date: Thu, 12 Nov 2015 17:44:29 -0600 Subject: [PATCH] Factor out constant evaluation. --- src/interpreter.rs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/interpreter.rs b/src/interpreter.rs index b42e4235cb8c..bf0fe3c17185 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -1,4 +1,4 @@ -use rustc::middle::ty; +use rustc::middle::{const_eval, ty}; use rustc_mir::mir_map::MirMap; use rustc_mir::repr::{self as mir, Mir}; use syntax::ast::Attribute; @@ -101,8 +101,7 @@ impl<'tcx> Interpreter<'tcx> { } } - fn eval_operand(&mut self, op: &mir::Operand) -> Value { - use rustc::middle::const_eval::ConstVal::*; + fn eval_operand(&self, op: &mir::Operand) -> Value { use rustc_mir::repr::Lvalue::*; use rustc_mir::repr::Operand::*; @@ -111,13 +110,29 @@ impl<'tcx> Interpreter<'tcx> { Consume(Temp(i)) => self.temp_vals[i as usize].clone(), Constant(ref constant) => { match constant.literal { - mir::Literal::Value { value: Int(n) } => Value::Int(n), - _ => unimplemented!(), + mir::Literal::Value { value: ref const_val } => self.eval_constant(const_val), + mir::Literal::Item { .. } => unimplemented!(), } } _ => unimplemented!(), } } + + fn eval_constant(&self, const_val: &const_eval::ConstVal) -> Value { + use rustc::middle::const_eval::ConstVal::*; + + match *const_val { + Float(_f) => unimplemented!(), + Int(i) => Value::Int(i), + Uint(_u) => unimplemented!(), + Str(ref _s) => unimplemented!(), + ByteStr(ref _bs) => unimplemented!(), + Bool(_b) => unimplemented!(), + Struct(_node_id) => unimplemented!(), + Tuple(_node_id) => unimplemented!(), + Function(_def_id) => unimplemented!(), + } + } } pub fn interpret_start_points<'tcx>(tcx: &ty::ctxt<'tcx>, mir_map: &MirMap<'tcx>) {