From 346560b31809e2ca5459eb221f093fd0ab1abea1 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Fri, 3 Jun 2016 16:57:47 +0200 Subject: [PATCH] factor out the statement index into the stackframe --- src/interpreter/mod.rs | 4 ++++ src/interpreter/stepper.rs | 19 +++++++------------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs index f20a958cd0e7..079ed6cf59af 100644 --- a/src/interpreter/mod.rs +++ b/src/interpreter/mod.rs @@ -94,6 +94,9 @@ struct Frame<'a, 'tcx: 'a> { /// List of precomputed promoted constants promoted: HashMap, + + /// The index of the currently evaluated statment + stmt: usize, } #[derive(Copy, Clone, Debug, Eq, PartialEq)] @@ -246,6 +249,7 @@ impl<'a, 'b, 'mir, 'tcx> FnEvalContext<'a, 'b, 'mir, 'tcx> { span: span, def_id: def_id, substs: substs, + stmt: 0, }); let locals: Vec = arg_tys.chain(var_tys).chain(temp_tys).map(|ty| { diff --git a/src/interpreter/stepper.rs b/src/interpreter/stepper.rs index 4a0dedf8a0f9..448fa83fa676 100644 --- a/src/interpreter/stepper.rs +++ b/src/interpreter/stepper.rs @@ -22,8 +22,6 @@ pub enum Event { pub struct Stepper<'fncx, 'a: 'fncx, 'b: 'a + 'mir, 'mir: 'fncx, 'tcx: 'b>{ fncx: &'fncx mut FnEvalContext<'a, 'b, 'mir, 'tcx>, - // a stack of statement positions - stmt: Vec, mir: CachedMir<'mir, 'tcx>, process: fn (&mut Stepper<'fncx, 'a, 'b, 'mir, 'tcx>) -> EvalResult<()>, // a stack of constants @@ -35,7 +33,6 @@ impl<'fncx, 'a, 'b: 'a + 'mir, 'mir, 'tcx: 'b> Stepper<'fncx, 'a, 'b, 'mir, 'tcx Stepper { mir: fncx.mir(), fncx: fncx, - stmt: vec![0], process: Self::dummy, constants: vec![Vec::new()], } @@ -45,16 +42,17 @@ impl<'fncx, 'a, 'b: 'a + 'mir, 'mir, 'tcx: 'b> Stepper<'fncx, 'a, 'b, 'mir, 'tcx fn statement(&mut self) -> EvalResult<()> { let block_data = self.mir.basic_block_data(self.fncx.frame().next_block); - let stmt = &block_data.statements[*self.stmt.last().unwrap()]; + let stmt = &block_data.statements[self.fncx.frame().stmt]; let mir::StatementKind::Assign(ref lvalue, ref rvalue) = stmt.kind; let result = self.fncx.eval_assignment(lvalue, rvalue); self.fncx.maybe_report(stmt.span, result)?; - *self.stmt.last_mut().unwrap() += 1; + self.fncx.frame_mut().stmt += 1; Ok(()) } fn terminator(&mut self) -> EvalResult<()> { - *self.stmt.last_mut().unwrap() = 0; + // after a terminator we go to a new block + self.fncx.frame_mut().stmt = 0; let term = { let block_data = self.mir.basic_block_data(self.fncx.frame().next_block); let terminator = block_data.terminator(); @@ -65,7 +63,6 @@ impl<'fncx, 'a, 'b: 'a + 'mir, 'mir, 'tcx: 'b> Stepper<'fncx, 'a, 'b, 'mir, 'tcx TerminatorTarget::Block => {}, TerminatorTarget::Return => { self.fncx.pop_stack_frame(); - self.stmt.pop(); assert!(self.constants.last().unwrap().is_empty()); self.constants.pop(); if !self.fncx.stack.is_empty() { @@ -74,7 +71,6 @@ impl<'fncx, 'a, 'b: 'a + 'mir, 'mir, 'tcx: 'b> Stepper<'fncx, 'a, 'b, 'mir, 'tcx }, TerminatorTarget::Call => { self.mir = self.fncx.mir(); - self.stmt.push(0); self.constants.push(Vec::new()); }, } @@ -89,7 +85,6 @@ impl<'fncx, 'a, 'b: 'a + 'mir, 'mir, 'tcx: 'b> Stepper<'fncx, 'a, 'b, 'mir, 'tcx // FIXME: somehow encode that this is a promoted constant's frame let def_id = self.fncx.frame().def_id; self.fncx.push_stack_frame(def_id, span, mir, substs, Some(return_ptr)); - self.stmt.push(0); self.constants.push(Vec::new()); self.mir = self.fncx.mir(); }, @@ -97,7 +92,6 @@ impl<'fncx, 'a, 'b: 'a + 'mir, 'mir, 'tcx: 'b> Stepper<'fncx, 'a, 'b, 'mir, 'tcx trace!("adding static {:?}, {:?}", def_id, span); self.fncx.gecx.statics.insert(def_id, return_ptr); self.fncx.push_stack_frame(def_id, span, mir, substs, Some(return_ptr)); - self.stmt.push(0); self.constants.push(Vec::new()); self.mir = self.fncx.mir(); }, @@ -121,9 +115,10 @@ impl<'fncx, 'a, 'b: 'a + 'mir, 'mir, 'tcx: 'b> Stepper<'fncx, 'a, 'b, 'mir, 'tcx } let block = self.fncx.frame().next_block; + let stmt = self.fncx.frame().stmt; let basic_block = self.mir.basic_block_data(block); - if let Some(ref stmt) = basic_block.statements.get(*self.stmt.last().unwrap()) { + if let Some(ref stmt) = basic_block.statements.get(stmt) { assert!(self.constants.last().unwrap().is_empty()); ConstantExtractor { constants: &mut self.constants.last_mut().unwrap(), @@ -158,7 +153,7 @@ impl<'fncx, 'a, 'b: 'a + 'mir, 'mir, 'tcx: 'b> Stepper<'fncx, 'a, 'b, 'mir, 'tcx /// returns the statement that will be processed next pub fn stmt(&self) -> &mir::Statement { - &self.fncx.basic_block().statements[*self.stmt.last().unwrap()] + &self.fncx.basic_block().statements[self.fncx.frame().stmt] } /// returns the terminator of the current block