[pypy-commit] pypy translation-cleanup: FSFrame: consolidate locals_stack_w init into .init_locals_stack()

rlamy noreply at buildbot.pypy.org
Sun Sep 30 01:20:31 CEST 2012


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: translation-cleanup
Changeset: r57685:3f3e76986566
Date: 2012-09-30 00:18 +0100
http://bitbucket.org/pypy/pypy/changeset/3f3e76986566/

Log:	FSFrame: consolidate locals_stack_w init into .init_locals_stack()

	FSFrame doesn't use PyFrame.setfastscope() any more.

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
@@ -239,24 +239,35 @@
         self.pycode = code
         self.space = space
         self.w_globals = Constant(func.func_globals)
-        self.locals_stack_w = [None] * (code.co_nlocals + code.co_stacksize)
-        self.valuestackdepth = code.co_nlocals
         self.lastblock = None
 
         self.cells = code.make_cells(func.func_closure)
         self.f_lineno = code.co_firstlineno
         self.last_instr = 0
 
-        formalargcount = code.getformalargcount()
-        arg_list = [Variable() for i in range(formalargcount)]
-        self.setfastscope(arg_list)
-
+        self.init_locals_stack(code)
         self.w_locals = None # XXX: only for compatibility with PyFrame
 
         self.joinpoints = {}
         self._init_graph(func)
         self.pendingblocks = collections.deque([self.graph.startblock])
 
+    def init_locals_stack(self, code):
+        """
+        Initialize the locals and the stack.
+
+        The locals are ordered according to self.pycode.signature().
+        """
+        self.valuestackdepth = code.co_nlocals
+        formalargcount = code.getformalargcount()
+        n_uninitialised_locals = code.co_nlocals - formalargcount
+        if n_uninitialised_locals < 0:
+            raise ValueError, "new fastscope is longer than the allocated area"
+        arg_list = [Variable() for i in range(formalargcount)]
+        self.locals_stack_w = (arg_list +
+                [None] * (code.co_stacksize + n_uninitialised_locals))
+        self.init_cells()
+
     def _init_graph(self, func):
         # CallableFactory.pycall may add class_ to functions that are methods
         name = func.func_name


More information about the pypy-commit mailing list