[pypy-svn] r50251 - in pypy/branch/astcompilertests/pypy: interpreter/astcompiler objspace/std

arigo at codespeak.net arigo at codespeak.net
Wed Jan 2 11:24:08 CET 2008


Author: arigo
Date: Wed Jan  2 11:24:08 2008
New Revision: 50251

Modified:
   pypy/branch/astcompilertests/pypy/interpreter/astcompiler/pyassem.py
   pypy/branch/astcompilertests/pypy/interpreter/astcompiler/pycodegen.py
   pypy/branch/astcompilertests/pypy/objspace/std/listobject.py
   pypy/branch/astcompilertests/pypy/objspace/std/objspace.py
Log:
We never generated LIST_APPEND so far.  Fix this and add a shortcut
in the stdobjspace to make it faster.


Modified: pypy/branch/astcompilertests/pypy/interpreter/astcompiler/pyassem.py
==============================================================================
--- pypy/branch/astcompilertests/pypy/interpreter/astcompiler/pyassem.py	(original)
+++ pypy/branch/astcompilertests/pypy/interpreter/astcompiler/pyassem.py	Wed Jan  2 11:24:08 2008
@@ -1064,6 +1064,7 @@
         'FOR_ITER': 1,
         'WITH_CLEANUP': 3,
         'LOOKUP_METHOD': 1,
+        'LIST_APPEND': -2,
         }
     # use pattern match
     patterns = [

Modified: pypy/branch/astcompilertests/pypy/interpreter/astcompiler/pycodegen.py
==============================================================================
--- pypy/branch/astcompilertests/pypy/interpreter/astcompiler/pycodegen.py	(original)
+++ pypy/branch/astcompilertests/pypy/interpreter/astcompiler/pycodegen.py	Wed Jan  2 11:24:08 2008
@@ -604,13 +604,11 @@
     def visitListComp(self, node):
         self.set_lineno(node)
         # setup list
-        append = "$append%d" % self.__list_count
+        tmpname = "$list%d" % self.__list_count
         self.__list_count = self.__list_count + 1
         self.emitop_int('BUILD_LIST', 0)
         self.emit('DUP_TOP')
-        self.emitop('LOAD_ATTR', 'append')
-        self._implicitNameOp('STORE', append)
-
+        self._implicitNameOp('STORE', tmpname)
 
         stack = []
         i = 0
@@ -626,10 +624,9 @@
             self.genexpr_cont_stack.pop()
             i += 1
 
-        self._implicitNameOp('LOAD', append)
+        self._implicitNameOp('LOAD', tmpname)
         node.expr.accept( self )
-        self.emitop_int('CALL_FUNCTION', 1)
-        self.emit('POP_TOP')
+        self.emit('LIST_APPEND')
 
         for start, cont, anchor in stack:
             if cont:
@@ -640,7 +637,7 @@
                 self.nextBlock(skip_one)
             self.emitop_block('JUMP_ABSOLUTE', start)
             self.startBlock(anchor)
-        self._implicitNameOp('DELETE', append)
+        self._implicitNameOp('DELETE', tmpname)
 
         self.__list_count = self.__list_count - 1
 

Modified: pypy/branch/astcompilertests/pypy/objspace/std/listobject.py
==============================================================================
--- pypy/branch/astcompilertests/pypy/objspace/std/listobject.py	(original)
+++ pypy/branch/astcompilertests/pypy/objspace/std/listobject.py	Wed Jan  2 11:24:08 2008
@@ -23,6 +23,9 @@
         items = [space.unwrap(w_item) for w_item in w_list.wrappeditems]# XXX generic mixed types unwrap
         return list(items)
 
+    def append(w_list, w_item):
+        w_list.wrappeditems.append(w_item)
+
 
 registerimplementation(W_ListObject)
 

Modified: pypy/branch/astcompilertests/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/branch/astcompilertests/pypy/objspace/std/objspace.py	(original)
+++ pypy/branch/astcompilertests/pypy/objspace/std/objspace.py	Wed Jan  2 11:24:08 2008
@@ -103,6 +103,14 @@
                         w_result = f.space.getitem(w_1, w_2)
                     f.pushvalue(w_result)
 
+            def LIST_APPEND(f, *ignored):
+                w = f.popvalue()
+                v = f.popvalue()
+                if type(v) is W_ListObject:
+                    v.append(w)
+                else:
+                    f.space.call_method(v, 'append', w)
+
             if self.config.objspace.opcodes.CALL_LIKELY_BUILTIN:
                 def CALL_LIKELY_BUILTIN(f, oparg, *ignored):
                     from pypy.module.__builtin__ import OPTIMIZED_BUILTINS, Module



More information about the Pypy-commit mailing list