Ronan Lamy avatar Ronan Lamy committed 459fc98

Move code from FlowEC.build_flow() to FlowSpaceFrame.__init__()

Comments (0)

Files changed (2)

pypy/objspace/flow/flowcontext.py

         self.w_globals = space.wrap(func.func_globals)
 
         self.crnt_offset = -1
-        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.frame = 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.frame = frame = FlowSpaceFrame(self.space, code,
+                               self.w_globals, func, constargs)
         self.joinpoints = {}
         initialblock = SpamBlock(frame.getstate())
         self.pendingblocks = collections.deque([initialblock])
 
 class FlowSpaceFrame(pyframe.CPythonFrame):
 
+    def __init__(self, space, code, w_globals, func, constargs=None):
+        class outerfunc: pass # hack
+        if func.func_closure is not None:
+            cl = [c.cell_contents for c in func.func_closure]
+            outerfunc.closure = [nestedscope.Cell(Constant(value)) for value in cl]
+        else:
+            outerfunc.closure = None
+        super(FlowSpaceFrame, self).__init__(space, code, w_globals, outerfunc)
+        self.last_instr = 0
+
+        if constargs is None:
+            constargs = {}
+        formalargcount = code.getformalargcount()
+        arg_list = [Variable() for i in range(formalargcount)]
+        for position, value in constargs.items():
+            arg_list[position] = Constant(value)
+        self.setfastscope(arg_list)
+
     def getstate(self):
         # getfastscope() can return real None, for undefined locals
         data = self.save_locals_stack()

pypy/objspace/flow/test/test_framestate.py

 from pypy.interpreter.pycode import PyCode
 from pypy.rlib.unroll import SpecTag
 from pypy.objspace.flow.objspace import FlowObjSpace
+from pypy.objspace.flow.flowcontext import FlowSpaceFrame
 
 class TestFrameState:
     def setup_class(cls):
         code = func.func_code
         code = PyCode._from_code(self.space, code)
         w_globals = Constant({}) # space.newdict()
-        frame = self.space.createframe(code, w_globals)
-
-        formalargcount = code.getformalargcount()
-        dummy = Constant(None)
-        #dummy.dummy = True
-        arg_list = ([Variable() for i in range(formalargcount)] +
-                    [dummy] * (frame.pycode.co_nlocals - formalargcount))
-        frame.setfastscope(arg_list)
+        frame = FlowSpaceFrame(space, code, w_globals, func)
+        # hack the frame
+        frame.locals_stack_w[frame.pycode.co_nlocals-1] = Constant(None)
         return frame
 
     def func_simple(x):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.