[pypy-commit] pypy translation-cleanup: Merge code into FlowExecutionContext.build_flow()

rlamy noreply at buildbot.pypy.org
Fri Aug 10 10:03:28 CEST 2012


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: translation-cleanup
Changeset: r56675:c92ffa1d817c
Date: 2012-08-08 15:13 +0100
http://bitbucket.org/pypy/pypy/changeset/c92ffa1d817c/

Log:	Merge code into FlowExecutionContext.build_flow()

	Inline .__init__(), .create_frame() and .produce_generator_mark()

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
@@ -187,32 +187,6 @@
 
 class FlowExecutionContext(ExecutionContext):
 
-    def __init__(self, space, func, constargs={}):
-        ExecutionContext.__init__(self, space)
-        code = PyCode._from_code(space, func.func_code)
-        self.is_generator = bool(code.co_flags & CO_GENERATOR)
-        self.code = code
-
-        self.w_globals = space.wrap(func.func_globals)
-
-        self.crnt_offset = -1
-        self.crnt_frame = None
-        if func.func_closure is not None:
-            cl = [c.cell_contents for c in func.func_closure]
-            self.closure = [nestedscope.Cell(Constant(value)) for value in cl]
-        else:
-            self.closure = None
-        frame = self.create_frame()
-        formalargcount = code.getformalargcount()
-        arg_list = [Variable() for i in range(formalargcount)]
-        for position, value in constargs.items():
-            arg_list[position] = Constant(value)
-        frame.setfastscope(arg_list)
-        self.joinpoints = {}
-        initialblock = SpamBlock(frame.getstate().copy())
-        self.pendingblocks = collections.deque([initialblock])
-        self._init_graph(func, initialblock)
-
     def _init_graph(self, func, initialblock):
         # CallableFactory.pycall may add class_ to functions that are methods
         name = func.func_name
@@ -231,15 +205,6 @@
 
     make_link = Link # overridable for transition tracking
 
-    def create_frame(self):
-        # create an empty frame suitable for the code object
-        # while ignoring any operation like the creation of the locals dict
-        self.recorder = []
-        frame = FlowSpaceFrame(self.space, self.code,
-                               self.w_globals, self)
-        frame.last_instr = 0
-        return frame
-
     def bytecode_trace(self, frame):
         self.recorder.bytecode_trace(self, frame)
 
@@ -266,12 +231,44 @@
                 w_exc_cls = egg.last_exception
         return outcome, w_exc_cls, w_exc_value
 
-    def build_flow(self):
+    def build_flow(self, func, constargs={}):
+        space = self.space
+        code = PyCode._from_code(space, func.func_code)
+        self.is_generator = bool(code.co_flags & CO_GENERATOR)
+        self.code = code
+
+        self.w_globals = space.wrap(func.func_globals)
+
+        self.crnt_offset = -1
+        self.crnt_frame = None
+        if func.func_closure is not None:
+            cl = [c.cell_contents for c in func.func_closure]
+            self.closure = [nestedscope.Cell(Constant(value)) for value in cl]
+        else:
+            self.closure = None
+        self.recorder = []
+        frame = FlowSpaceFrame(self.space, self.code,
+                               self.w_globals, self)
+        frame.last_instr = 0
+        formalargcount = code.getformalargcount()
+        arg_list = [Variable() for i in range(formalargcount)]
+        for position, value in constargs.items():
+            arg_list[position] = Constant(value)
+        frame.setfastscope(arg_list)
+        self.joinpoints = {}
+        initialblock = SpamBlock(frame.getstate().copy())
+        self.pendingblocks = collections.deque([initialblock])
+        self._init_graph(func, initialblock)
+
         if self.is_generator:
-            self.produce_generator_mark()
+            initialblock.operations.append(
+                SpaceOperation('generator_mark', [], Variable()))
+
         while self.pendingblocks:
             block = self.pendingblocks.popleft()
-            frame = self.create_frame()
+            frame = FlowSpaceFrame(self.space, self.code,
+                                self.w_globals, self)
+            frame.last_instr = 0
             try:
                 self.recorder = block.patchframe(frame)
             except StopFlowing:
@@ -335,11 +332,6 @@
             del self.recorder
         self.fixeggblocks()
 
-    def produce_generator_mark(self):
-        [initialblock] = self.pendingblocks
-        initialblock.operations.append(
-            SpaceOperation('generator_mark', [], Variable()))
-
     def generate_yield(self, frame, w_result):
         assert self.is_generator
         self.recorder.crnt_block.operations.append(
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
@@ -255,11 +255,11 @@
         """
         if func.func_doc and func.func_doc.lstrip().startswith('NOT_RPYTHON'):
             raise Exception, "%r is tagged as NOT_RPYTHON" % (func,)
-        ec = flowcontext.FlowExecutionContext(self, func, constargs)
+        ec = flowcontext.FlowExecutionContext(self)
         self.executioncontext = ec
 
         try:
-            ec.build_flow()
+            ec.build_flow(func, constargs)
         except error.FlowingError, a:
             # attach additional source info to AnnotatorError
             _, _, tb = sys.exc_info()


More information about the pypy-commit mailing list