[pypy-commit] pypy translation-cleanup: Don't wrap closure vars in Cell objects
rlamy
noreply at buildbot.pypy.org
Thu Oct 11 13:31:28 CEST 2012
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: translation-cleanup
Changeset: r58008:4ef541073dfa
Date: 2012-10-11 06:16 +0100
http://bitbucket.org/pypy/pypy/changeset/4ef541073dfa/
Log: Don't wrap closure vars in Cell objects
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
@@ -8,7 +8,6 @@
HAVE_ARGUMENT)
from pypy.interpreter.astcompiler.consts import (CO_GENERATOR, CO_NEWLOCALS,
CO_VARARGS, CO_VARKEYWORDS)
-from pypy.interpreter.nestedscope import Cell
from pypy.objspace.flow.model import Constant
class HostCode(object):
@@ -62,18 +61,6 @@
and **varkwarg, if they exist."""
return self.signature.scope_length()
- def make_cells(self, closure):
- """Convert a Python closure object into a list of Cells"""
- if closure is not None:
- closure = [Cell(Constant(c.cell_contents)) for c in closure]
- else:
- closure = []
- if len(closure) != len(self.co_freevars):
- raise ValueError("code object received a closure with "
- "an unexpected number of free variables")
- return closure
-
-
def read(self, pos):
"""
Decode the instruction starting at position ``next_instr``.
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
@@ -3,7 +3,6 @@
from pypy.tool.error import source_lines
from pypy.interpreter import pyframe
-from pypy.interpreter.nestedscope import Cell
from pypy.interpreter.argument import ArgumentsForTranslation
from pypy.interpreter.pyopcode import Return, BytecodeCorruption
from pypy.objspace.flow.model import (Constant, Variable, Block, Link,
@@ -229,7 +228,7 @@
self.w_globals = Constant(func.func_globals)
self.lastblock = None
- self.cells = code.make_cells(func.func_closure)
+ self.init_closure(func.func_closure)
self.f_lineno = code.co_firstlineno
self.last_instr = 0
@@ -238,6 +237,13 @@
self.joinpoints = {}
+ def init_closure(self, closure):
+ if closure is None:
+ self.closure = []
+ else:
+ self.closure = [self.space.wrap(c.cell_contents) for c in closure]
+ assert len(self.closure) == len(self.pycode.co_freevars)
+
def init_locals_stack(self, code):
"""
Initialize the locals and the stack.
@@ -676,6 +682,9 @@
self.pushvalue(w_value)
LOOKUP_METHOD = LOAD_ATTR
+ def LOAD_DEREF(self, varindex, next_instr):
+ self.pushvalue(self.closure[varindex])
+
def BUILD_LIST_FROM_ARG(self, _, next_instr):
# This opcode was added with pypy-1.8. Here is a simpler
# version, enough for annotation.
More information about the pypy-commit
mailing list