[pypy-commit] pypy translation-cleanup: Copy PyCode._initialize() into HostCode, and simplify it.

rlamy noreply at buildbot.pypy.org
Sat Sep 29 01:09:33 CEST 2012


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: translation-cleanup
Changeset: r57640:370cabeb2e40
Date: 2012-09-28 05:05 +0100
http://bitbucket.org/pypy/pypy/changeset/370cabeb2e40/

Log:	Copy PyCode._initialize() into HostCode, and simplify it.

	Note that _init_flags() and _compute_flatcall() are useless for the
	flow space.

diff --git a/pypy/objspace/flow/bytecode.py b/pypy/objspace/flow/bytecode.py
--- a/pypy/objspace/flow/bytecode.py
+++ b/pypy/objspace/flow/bytecode.py
@@ -40,6 +40,30 @@
         self._signature = cpython_code_signature(self)
         self._initialize()
 
+    def _initialize(self):
+        # Precompute what arguments need to be copied into cellvars
+        self._args_as_cellvars = []
+
+        if self.co_cellvars:
+            argcount = self.co_argcount
+            assert argcount >= 0     # annotator hint
+            if self.co_flags & CO_VARARGS:
+                argcount += 1
+            if self.co_flags & CO_VARKEYWORDS:
+                argcount += 1
+            # Cell vars could shadow already-set arguments.
+            # See comment in PyCode._initialize()
+            argvars  = self.co_varnames
+            cellvars = self.co_cellvars
+            for i in range(len(cellvars)):
+                cellname = cellvars[i]
+                for j in range(argcount):
+                    if cellname == argvars[j]:
+                        # argument j has the same name as the cell var i
+                        while len(self._args_as_cellvars) <= i:
+                            self._args_as_cellvars.append(-1)   # pad
+                        self._args_as_cellvars[i] = j
+
     def read(self, pos):
         """
         Decode the instruction starting at position ``next_instr``.


More information about the pypy-commit mailing list