[pypy-commit] pypy translation-cleanup: Instantiate HostCode and PyGraph outside FSFrame

rlamy noreply at buildbot.pypy.org
Mon Oct 1 17:28:13 CEST 2012


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: translation-cleanup
Changeset: r57704:7b4ca127653c
Date: 2012-10-01 16:20 +0100
http://bitbucket.org/pypy/pypy/changeset/7b4ca127653c/

Log:	Instantiate HostCode and PyGraph outside FSFrame

diff --git a/pypy/objspace/flow/flowcontext.py b/pypy/objspace/flow/flowcontext.py
--- a/pypy/objspace/flow/flowcontext.py
+++ b/pypy/objspace/flow/flowcontext.py
@@ -219,8 +219,9 @@
 
 class FlowSpaceFrame(pyframe.CPythonFrame):
 
-    def __init__(self, space, func):
-        code = HostCode._from_code(space, func.func_code)
+    def __init__(self, space, graph, code):
+        self.graph = graph
+        func = graph.func
         self.pycode = code
         self.space = space
         self.w_globals = Constant(func.func_globals)
@@ -234,9 +235,6 @@
         self.w_locals = None # XXX: only for compatibility with PyFrame
 
         self.joinpoints = {}
-        self.graph = PyGraph(func, code)
-        self.pendingblocks = collections.deque([self.graph.startblock])
-        self.setstate(self.graph.startblock.framestate) # for testing
 
     def init_locals_stack(self, code):
         """
@@ -315,6 +313,8 @@
         return self.recorder.guessexception(self, *exceptions)
 
     def build_flow(self):
+        graph = self.graph
+        self.pendingblocks = collections.deque([graph.startblock])
         while self.pendingblocks:
             block = self.pendingblocks.popleft()
             try:
@@ -332,14 +332,14 @@
                 msg = "implicit %s shouldn't occur" % exc_cls.__name__
                 w_type = Constant(AssertionError)
                 w_value = Constant(AssertionError(msg))
-                link = Link([w_type, w_value], self.graph.exceptblock)
+                link = Link([w_type, w_value], graph.exceptblock)
                 self.recorder.crnt_block.closeblock(link)
 
             except FSException, e:
                 if e.w_type is self.space.w_ImportError:
                     msg = 'import statement always raises %s' % e
                     raise ImportError(msg)
-                link = Link([e.w_type, e.w_value], self.graph.exceptblock)
+                link = Link([e.w_type, e.w_value], graph.exceptblock)
                 self.recorder.crnt_block.closeblock(link)
 
             except StopFlowing:
@@ -348,7 +348,7 @@
             except Return:
                 w_result = self.popvalue()
                 assert w_result is not None
-                link = Link([w_result], self.graph.returnblock)
+                link = Link([w_result], graph.returnblock)
                 self.recorder.crnt_block.closeblock(link)
 
         del self.recorder
diff --git a/pypy/objspace/flow/objspace.py b/pypy/objspace/flow/objspace.py
--- a/pypy/objspace/flow/objspace.py
+++ b/pypy/objspace/flow/objspace.py
@@ -6,9 +6,11 @@
 from pypy.interpreter.argument import ArgumentsForTranslation
 from pypy.objspace.flow.model import (Constant, Variable, WrapException,
     UnwrapException, checkgraph, SpaceOperation)
+from pypy.objspace.flow.bytecode import HostCode
 from pypy.objspace.flow import operation
 from pypy.objspace.flow.flowcontext import (FlowSpaceFrame, fixeggblocks,
     FSException, FlowingError)
+from pypy.objspace.flow.pygraph import PyGraph
 from pypy.objspace.flow.specialcase import SPECIAL_CASES
 from pypy.rlib.unroll import unrolling_iterable, _unroller
 from pypy.rlib import rstackovf, rarithmetic
@@ -235,9 +237,10 @@
         """
         if func.func_doc and func.func_doc.lstrip().startswith('NOT_RPYTHON'):
             raise Exception, "%r is tagged as NOT_RPYTHON" % (func,)
-        frame = self.frame = FlowSpaceFrame(self, func)
+        code = HostCode._from_code(self, func.func_code)
+        graph = PyGraph(func, code)
+        frame = self.frame = FlowSpaceFrame(self, graph, code)
         frame.build_flow()
-        graph = frame.graph
         fixeggblocks(graph)
         checkgraph(graph)
         if graph.is_generator and tweak_for_generator:
diff --git a/pypy/objspace/flow/test/test_framestate.py b/pypy/objspace/flow/test/test_framestate.py
--- a/pypy/objspace/flow/test/test_framestate.py
+++ b/pypy/objspace/flow/test/test_framestate.py
@@ -2,6 +2,8 @@
 from pypy.rlib.unroll import SpecTag
 from pypy.objspace.flow.objspace import FlowObjSpace
 from pypy.objspace.flow.flowcontext import FlowSpaceFrame
+from pypy.objspace.flow.bytecode import HostCode
+from pypy.objspace.flow.pygraph import PyGraph
 
 class TestFrameState:
     def setup_class(cls):
@@ -12,8 +14,11 @@
             func = func.im_func
         except AttributeError:
             pass
-        frame = FlowSpaceFrame(self.space, func)
+        code = HostCode._from_code(self.space, func.func_code)
+        graph = PyGraph(func, code)
+        frame = FlowSpaceFrame(self.space, graph, code)
         # hack the frame
+        frame.setstate(graph.startblock.framestate)
         frame.locals_stack_w[frame.pycode.co_nlocals-1] = Constant(None)
         return frame
 


More information about the pypy-commit mailing list