[pypy-commit] pypy translation-cleanup: Move code from FlowEC.build_flow() to FlowSpaceFrame.__init__()
rlamy
noreply at buildbot.pypy.org
Fri Aug 10 10:03:32 CEST 2012
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: translation-cleanup
Changeset: r56679:459fc98f6d75
Date: 2012-08-09 17:39 +0100
http://bitbucket.org/pypy/pypy/changeset/459fc98f6d75/
Log: Move code from FlowEC.build_flow() to FlowSpaceFrame.__init__()
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
@@ -216,19 +216,8 @@
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])
@@ -396,6 +385,24 @@
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()
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
@@ -3,6 +3,7 @@
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):
@@ -17,14 +18,9 @@
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):
More information about the pypy-commit
mailing list