[pypy-svn] r35198 - in pypy/branch/jit-real-world/pypy: interpreter objspace/flow

arigo at codespeak.net arigo at codespeak.net
Fri Dec 1 13:22:41 CET 2006


Author: arigo
Date: Fri Dec  1 13:22:38 2006
New Revision: 35198

Modified:
   pypy/branch/jit-real-world/pypy/interpreter/pyopcode.py
   pypy/branch/jit-real-world/pypy/objspace/flow/framestate.py
Log:
Turn state_pack_variables() into a "constructor" static method,
instead of using instantiate() in the flow space.  This avoids
making multiple instances of SBreakLoop (needed for flowgraphing
the BREAK_LOOP function itself, which manipulates the singleton
directly).


Modified: pypy/branch/jit-real-world/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/branch/jit-real-world/pypy/interpreter/pyopcode.py	(original)
+++ pypy/branch/jit-real-world/pypy/interpreter/pyopcode.py	Fri Dec  1 13:22:38 2006
@@ -901,12 +901,10 @@
     """
     def nomoreblocks(self):
         raise BytecodeCorruption("misplaced bytecode - should not return")
-    # for the flow object space, a way to "pickle" and "unpickle" the
-    # ControlFlowException by enumerating the Variables it contains.
-    def state_unpack_variables(self, space):
-        return []     # by default, overridden below
-    def state_pack_variables(self, space, *values_w):
-        assert len(values_w) == 0
+
+    # NB. for the flow object space, the state_(un)pack_variables methods
+    # give a way to "pickle" and "unpickle" the SuspendedUnroller by
+    # enumerating the Variables it contains.
 
 class SReturnValue(SuspendedUnroller):
     """Signals a 'return' statement.
@@ -916,10 +914,12 @@
         self.w_returnvalue = w_returnvalue
     def nomoreblocks(self):
         return self.w_returnvalue
+
     def state_unpack_variables(self, space):
         return [self.w_returnvalue]
-    def state_pack_variables(self, space, w_returnvalue):
-        self.w_returnvalue = w_returnvalue
+    def state_pack_variables(space, w_returnvalue):
+        return SReturnValue(w_returnvalue)
+    state_pack_variables = staticmethod(state_pack_variables)
 
 class SApplicationException(SuspendedUnroller):
     """Signals an application-level exception
@@ -929,14 +929,23 @@
         self.operr = operr
     def nomoreblocks(self):
         raise self.operr
+
     def state_unpack_variables(self, space):
         return [self.operr.w_type, self.operr.w_value]
-    def state_pack_variables(self, space, w_type, w_value):
-        self.operr = OperationError(w_type, w_value)
+    def state_pack_variables(space, w_type, w_value):
+        return SApplicationException(OperationError(w_type, w_value))
+    state_pack_variables = staticmethod(state_pack_variables)
 
 class SBreakLoop(SuspendedUnroller):
     """Signals a 'break' statement."""
     kind = 0x04
+
+    def state_unpack_variables(self, space):
+        return []
+    def state_pack_variables(space):
+        return SBreakLoop.singleton
+    state_pack_variables = staticmethod(state_pack_variables)
+
 SBreakLoop.singleton = SBreakLoop()
 
 class SContinueLoop(SuspendedUnroller):
@@ -945,10 +954,12 @@
     kind = 0x08
     def __init__(self, jump_to):
         self.jump_to = jump_to
+
     def state_unpack_variables(self, space):
         return [space.wrap(self.jump_to)]
-    def state_pack_variables(self, space, w_jump_to):
-        self.jump_to = space.int_w(w_jump_to)
+    def state_pack_variables(space, w_jump_to):
+        return SContinueLoop(space.int_w(w_jump_to))
+    state_pack_variables = staticmethod(state_pack_variables)
 
 
 class FrameBlock:

Modified: pypy/branch/jit-real-world/pypy/objspace/flow/framestate.py
==============================================================================
--- pypy/branch/jit-real-world/pypy/objspace/flow/framestate.py	(original)
+++ pypy/branch/jit-real-world/pypy/objspace/flow/framestate.py	Fri Dec  1 13:22:38 2006
@@ -1,7 +1,6 @@
 from pypy.interpreter.pyframe import PyFrame
 from pypy.interpreter.pyopcode import SuspendedUnroller
 from pypy.interpreter.error import OperationError
-from pypy.rlib.objectmodel import instantiate
 from pypy.rlib.unroll import SpecTag
 from pypy.objspace.flow.model import *
 
@@ -175,6 +174,5 @@
             unrollerclass, argcount = UNPICKLE_TAGS[item]
             arguments = lst[i+1: i+1+argcount]
             del lst[i+1: i+1+argcount]
-            unroller = instantiate(unrollerclass)
-            unroller.state_pack_variables(space, *arguments)
+            unroller = unrollerclass.state_pack_variables(space, *arguments)
             lst[i] = space.wrap(unroller)



More information about the Pypy-commit mailing list