[pypy-commit] pypy translation-cleanup: Don't wrap objects inside HostCode

rlamy noreply at buildbot.pypy.org
Thu Oct 4 20:10:59 CEST 2012


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: translation-cleanup
Changeset: r57782:1e60a9eae76b
Date: 2012-10-04 19:10 +0100
http://bitbucket.org/pypy/pypy/changeset/1e60a9eae76b/

Log:	Don't wrap objects inside HostCode

	HostCode attributes could only contain Constants, not Variables, so
	that wrapping and unwrapping was always trivial and can therefore be
	skipped.

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
@@ -30,8 +30,8 @@
         self.co_stacksize = stacksize
         self.co_flags = flags
         self.co_code = code
-        self.co_consts_w = consts
-        self.co_names_w = [space.wrap(aname) for aname in names]
+        self.consts = consts
+        self.names = names
         self.co_varnames = varnames
         self.co_freevars = freevars
         self.co_cellvars = cellvars
@@ -72,11 +72,11 @@
     def _from_code(cls, space, code, hidden_applevel=False):
         """Initialize the code object from a real (CPython) one.
         """
-        newconsts_w = []
-        for num, const in enumerate(code.co_consts):
+        newconsts = []
+        for const in code.co_consts:
             if isinstance(const, CodeType):
                 const = cls._from_code(space, const, hidden_applevel)
-            newconsts_w.append(space.wrap(const))
+            newconsts.append(const)
         # stick the underlying CPython magic value, if the code object
         # comes from there
         return cls(space, code.co_argcount,
@@ -84,7 +84,7 @@
                       code.co_stacksize,
                       code.co_flags,
                       code.co_code,
-                      newconsts_w[:],
+                      newconsts,
                       list(code.co_names),
                       list(code.co_varnames),
                       code.co_filename,
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
@@ -420,6 +420,18 @@
             next_instr = block.handle(self, unroller)
             return next_instr
 
+    def getlocalvarname(self, index):
+        return self.pycode.co_varnames[index]
+
+    def getconstant_w(self, index):
+        return self.space.wrap(self.pycode.consts[index])
+
+    def getname_u(self, index):
+        return self.pycode.names[index]
+
+    def getname_w(self, index):
+        return Constant(self.pycode.names[index])
+
     def BAD_OPCODE(self, _, next_instr):
         raise FlowingError(self, "This operation is not RPython")
 


More information about the pypy-commit mailing list