]> git.lizzy.rs Git - rust.git/commitdiff
simplify the stepper interface
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Fri, 10 Jun 2016 10:34:15 +0000 (12:34 +0200)
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Fri, 10 Jun 2016 10:34:15 +0000 (12:34 +0200)
src/interpreter/mod.rs
src/interpreter/stepper.rs

index a7a57a79601707928213c4e3fbb84b75cff90bd5..2673f5609032649d60df00ed49f4ca2e087d8e1c 100644 (file)
@@ -24,7 +24,7 @@
 
 mod stepper;
 
-struct GlobalEvalContext<'a, 'tcx: 'a> {
+pub struct GlobalEvalContext<'a, 'tcx: 'a> {
     /// The results of the type checker, from rustc.
     tcx: TyCtxt<'a, 'tcx, 'tcx>,
 
@@ -335,12 +335,6 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         err.emit();
     }
 
-    fn run(&mut self) -> EvalResult<()> {
-        let mut stepper = stepper::Stepper::new(self);
-        while stepper.step()? {}
-        Ok(())
-    }
-
     fn push_stack_frame(&mut self, def_id: DefId, span: codemap::Span, mir: CachedMir<'a, 'tcx>, substs: &'tcx Substs<'tcx>,
         return_ptr: Option<Pointer>)
     {
@@ -1414,14 +1408,22 @@ pub fn interpret_start_points<'a, 'tcx>(
 
                 gecx.push_stack_frame(tcx.map.local_def_id(id), mir.span, CachedMir::Ref(mir), substs, return_ptr);
 
-                match (gecx.run(), return_ptr) {
-                    (Ok(()), Some(ptr)) => if log_enabled!(::log::LogLevel::Debug) {
+                loop { match (stepper::step(&mut gecx), return_ptr) {
+                    (Ok(true), _) => {},
+                    (Ok(false), Some(ptr)) => if log_enabled!(::log::LogLevel::Debug) {
                         gecx.memory.dump(ptr.alloc_id);
+                        break;
+                    },
+                    (Ok(false), None) => {
+                        warn!("diverging function returned");
+                        break;
                     },
-                    (Ok(()), None) => warn!("diverging function returned"),
                     // FIXME: diverging functions can end up here in some future miri
-                    (Err(e), _) => gecx.report(e),
-                }
+                    (Err(e), _) => {
+                        gecx.report(e);
+                        break;
+                    },
+                } }
             }
         }
     }
index 47ee9874ad668ce2cf6204a13e0b0aad62696bb9..10145bdce2718d571bd7ba4bf22e3b36ae0544e8 100644 (file)
 use syntax::codemap::Span;
 use std::rc::Rc;
 
-pub struct Stepper<'fncx, 'a: 'fncx, 'tcx: 'a>{
+struct Stepper<'fncx, 'a: 'fncx, 'tcx: 'a>{
     gecx: &'fncx mut GlobalEvalContext<'a, 'tcx>,
 }
 
+pub fn step<'fncx, 'a: 'fncx, 'tcx: 'a>(gecx: &'fncx mut GlobalEvalContext<'a, 'tcx>) -> EvalResult<bool> {
+    Stepper::new(gecx).step()
+}
+
 impl<'fncx, 'a, 'tcx> Stepper<'fncx, 'a, 'tcx> {
-    pub(super) fn new(gecx: &'fncx mut GlobalEvalContext<'a, 'tcx>) -> Self {
+    fn new(gecx: &'fncx mut GlobalEvalContext<'a, 'tcx>) -> Self {
         Stepper {
             gecx: gecx,
         }
@@ -43,7 +47,7 @@ fn terminator(&mut self, terminator: &mir::Terminator<'tcx>) -> EvalResult<()> {
     }
 
     // returns true as long as there are more things to do
-    pub fn step(&mut self) -> EvalResult<bool> {
+    fn step(&mut self) -> EvalResult<bool> {
         if self.gecx.stack.is_empty() {
             return Ok(false);
         }