Author: Ronan Lamy <ronan.l...@gmail.com>
Branch: less-stringly-ops
Changeset: r66237:019245b1068b
Date: 2013-04-30 15:32 +0100
http://bitbucket.org/pypy/pypy/changeset/019245b1068b/

Log:    Deal with FSFrame.last_instr a bit more explicitly

diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -410,7 +410,7 @@
         self.locals_stack_w[:len(items_w)] = items_w
         self.dropvaluesuntil(len(items_w))
 
-    def getstate(self):
+    def getstate(self, next_pos):
         # getfastscope() can return real None, for undefined locals
         data = self.save_locals_stack()
         if self.last_exception is None:
@@ -420,7 +420,7 @@
             data.append(self.last_exception.w_type)
             data.append(self.last_exception.w_value)
         recursively_flatten(data)
-        return FrameState(data, self.blockstack[:], self.last_instr)
+        return FrameState(data, self.blockstack[:], next_pos)
 
     def setstate(self, state):
         """ Reset the frame to the given state. """
@@ -432,7 +432,6 @@
             self.last_exception = None
         else:
             self.last_exception = FSException(data[-2], data[-1])
-        self.last_instr = state.next_instr
         self.blockstack = state.blocklist[:]
 
     def guessbool(self, w_condition, **kwds):
@@ -478,11 +477,12 @@
 
     def record_block(self, block):
         self.setstate(block.framestate)
+        next_pos = block.framestate.next_instr
         self.recorder = block.make_recorder()
         try:
             while True:
-                self.last_instr = self.handle_bytecode(self.last_instr)
-                self.recorder.final_state = self.getstate()
+                next_pos = self.handle_bytecode(next_pos)
+                self.recorder.final_state = self.getstate(next_pos)
 
         except ImplicitOperationError, e:
             if isinstance(e.w_type, Constant):
@@ -563,6 +563,7 @@
                     break
 
     def handle_bytecode(self, next_instr):
+        self.last_instr = next_instr
         next_instr, methodname, oparg = self.pycode.read(next_instr)
         try:
             res = getattr(self, methodname)(oparg)
diff --git a/rpython/flowspace/test/test_framestate.py 
b/rpython/flowspace/test/test_framestate.py
--- a/rpython/flowspace/test/test_framestate.py
+++ b/rpython/flowspace/test/test_framestate.py
@@ -25,55 +25,55 @@
 
     def test_eq_framestate(self):
         frame = self.getframe(self.func_simple)
-        fs1 = frame.getstate()
-        fs2 = frame.getstate()
+        fs1 = frame.getstate(0)
+        fs2 = frame.getstate(0)
         assert fs1 == fs2
 
     def test_neq_hacked_framestate(self):
         frame = self.getframe(self.func_simple)
-        fs1 = frame.getstate()
+        fs1 = frame.getstate(0)
         frame.locals_stack_w[frame.pycode.co_nlocals-1] = Variable()
-        fs2 = frame.getstate()
+        fs2 = frame.getstate(0)
         assert fs1 != fs2
 
     def test_union_on_equal_framestates(self):
         frame = self.getframe(self.func_simple)
-        fs1 = frame.getstate()
-        fs2 = frame.getstate()
+        fs1 = frame.getstate(0)
+        fs2 = frame.getstate(0)
         assert fs1.union(fs2) == fs1
 
     def test_union_on_hacked_framestates(self):
         frame = self.getframe(self.func_simple)
-        fs1 = frame.getstate()
+        fs1 = frame.getstate(0)
         frame.locals_stack_w[frame.pycode.co_nlocals-1] = Variable()
-        fs2 = frame.getstate()
+        fs2 = frame.getstate(0)
         assert fs1.union(fs2) == fs2  # fs2 is more general
         assert fs2.union(fs1) == fs2  # fs2 is more general
 
     def test_restore_frame(self):
         frame = self.getframe(self.func_simple)
-        fs1 = frame.getstate()
+        fs1 = frame.getstate(0)
         frame.locals_stack_w[frame.pycode.co_nlocals-1] = Variable()
         frame.setstate(fs1)
-        assert fs1 == frame.getstate()
+        assert fs1 == frame.getstate(0)
 
     def test_copy(self):
         frame = self.getframe(self.func_simple)
-        fs1 = frame.getstate()
+        fs1 = frame.getstate(0)
         fs2 = fs1.copy()
         assert fs1 == fs2
 
     def test_getvariables(self):
         frame = self.getframe(self.func_simple)
-        fs1 = frame.getstate()
+        fs1 = frame.getstate(0)
         vars = fs1.getvariables()
         assert len(vars) == 1
 
     def test_getoutputargs(self):
         frame = self.getframe(self.func_simple)
-        fs1 = frame.getstate()
+        fs1 = frame.getstate(0)
         frame.locals_stack_w[frame.pycode.co_nlocals-1] = Variable()
-        fs2 = frame.getstate()
+        fs2 = frame.getstate(0)
         outputargs = fs1.getoutputargs(fs2)
         # 'x' -> 'x' is a Variable
         # locals_w[n-1] -> locals_w[n-1] is Constant(None)
@@ -81,9 +81,9 @@
 
     def test_union_different_constants(self):
         frame = self.getframe(self.func_simple)
-        fs1 = frame.getstate()
+        fs1 = frame.getstate(0)
         frame.locals_stack_w[frame.pycode.co_nlocals-1] = Constant(42)
-        fs2 = frame.getstate()
+        fs2 = frame.getstate(0)
         fs3 = fs1.union(fs2)
         frame.setstate(fs3)
         assert isinstance(frame.locals_stack_w[frame.pycode.co_nlocals-1],
@@ -91,7 +91,7 @@
 
     def test_union_spectag(self):
         frame = self.getframe(self.func_simple)
-        fs1 = frame.getstate()
+        fs1 = frame.getstate(0)
         frame.locals_stack_w[frame.pycode.co_nlocals-1] = Constant(SpecTag())
-        fs2 = frame.getstate()
+        fs2 = frame.getstate(0)
         assert fs1.union(fs2) is None   # UnionError
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to