Commits

Ronan Lamy committed f1d90d0

Do not wrap unrollers.

Since they aren't Python objects, it doesn't make much sense to wrap them
inside Constant(). Not doing it simplifies the code a bit.

+ Remove costly isinstance() check.

  • Participants
  • Parent commits 93f4450
  • Branches translation-cleanup

Comments (0)

Files changed (2)

File pypy/objspace/flow/flowcontext.py

         if w_top == self.space.w_None:
             # finally: block with no unroller active
             return
-        try:
-            unroller = self.space.unwrap(w_top)
-        except UnwrapException:
-            pass
+        elif isinstance(w_top, SuspendedUnroller):
+            # case of a finally: block
+            return self.unroll_finally(w_top)
         else:
-            if isinstance(unroller, SuspendedUnroller):
-                # case of a finally: block
-                return self.unroll_finally(unroller)
-        # case of an except: block.  We popped the exception type
-        self.popvalue()        #     Now we pop the exception value
-        unroller = self.space.unwrap(self.popvalue())
-        return self.unroll_finally(unroller)
+            # case of an except: block.  We popped the exception type
+            self.popvalue()        #     Now we pop the exception value
+            unroller = self.popvalue()
+            return self.unroll_finally(unroller)
 
     def unroll_finally(self, unroller):
         # go on unrolling the stack
         # and cannot suppress the exception.
         # This opcode changed a lot between CPython versions
         if sys.version_info >= (2, 6):
-            w_unroller = self.popvalue()
+            unroller = self.popvalue()
             w_exitfunc = self.popvalue()
-            self.pushvalue(w_unroller)
+            self.pushvalue(unroller)
         else:
             w_exitfunc = self.popvalue()
-            w_unroller = self.peekvalue(0)
+            unroller = self.peekvalue(0)
 
-        unroller = self.space.unwrap(w_unroller)
         w_None = self.space.w_None
         if isinstance(unroller, SApplicationException):
             operr = unroller.operr
         # the stack setup is slightly different than in CPython:
         # instead of the traceback, we store the unroller object,
         # wrapped.
-        frame.pushvalue(frame.space.wrap(unroller))
+        frame.pushvalue(unroller)
         frame.pushvalue(operationerr.get_w_value(frame.space))
         frame.pushvalue(operationerr.w_type)
         frame.last_exception = operationerr
         # any abnormal reason for unrolling a finally: triggers the end of
         # the block unrolling and the entering the finally: handler.
         self.cleanupstack(frame)
-        frame.pushvalue(frame.space.wrap(unroller))
+        frame.pushvalue(unroller)
         return self.handlerposition   # jump to the handler
 
 

File pypy/objspace/flow/framestate.py

         self.mergeable = mergeable
         self.blocklist = blocklist
         self.next_instr = next_instr
-        for w1 in self.mergeable:
-            assert isinstance(w1, (Variable, Constant)) or w1 is None, (
-                '%r found in frame state' % w1)
 
     def copy(self):
         "Make a copy of this state in which all Variables are fresh."
     from pypy.objspace.flow.flowcontext import SuspendedUnroller
     i = 0
     while i < len(lst):
-        item = lst[i]
-        if not (isinstance(item, Constant) and
-                isinstance(item.value, SuspendedUnroller)):
+        unroller = lst[i]
+        if not isinstance(unroller, SuspendedUnroller):
             i += 1
         else:
-            unroller = item.value
             vars = unroller.state_unpack_variables(space)
             key = unroller.__class__, len(vars)
             try:
             arguments = lst[i+1: i+1+argcount]
             del lst[i+1: i+1+argcount]
             unroller = unrollerclass.state_pack_variables(space, *arguments)
-            lst[i] = space.wrap(unroller)
+            lst[i] = unroller