[pypy-svn] r77318 - in pypy/trunk/pypy: interpreter module/pypyjit/test objspace/std

fijal at codespeak.net fijal at codespeak.net
Thu Sep 23 22:26:06 CEST 2010


Author: fijal
Date: Thu Sep 23 22:26:03 2010
New Revision: 77318

Modified:
   pypy/trunk/pypy/interpreter/baseobjspace.py
   pypy/trunk/pypy/interpreter/pyopcode.py
   pypy/trunk/pypy/module/pypyjit/test/test_pypy_c.py
   pypy/trunk/pypy/objspace/std/objspace.py
Log:
A slight simplification of unpackiterable handling. also provide a second
version of unpackiterable that provides possibility to unroll (called
from unpack_sequence opcode). Corresponding pypy_c_jit test


Modified: pypy/trunk/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/trunk/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/trunk/pypy/interpreter/baseobjspace.py	Thu Sep 23 22:26:03 2010
@@ -12,6 +12,7 @@
 from pypy.rlib.timer import DummyTimer, Timer
 from pypy.rlib.rarithmetic import r_uint
 from pypy.rlib import jit
+from pypy.tool.sourcetools import func_with_new_name
 import os, sys, py
 
 __all__ = ['ObjSpace', 'OperationError', 'Wrappable', 'W_Root']
@@ -749,12 +750,17 @@
                                 (i, plural)))
         return items
 
+    unpackiterable_unroll = jit.unroll_safe(func_with_new_name(unpackiterable,
+                                            'unpackiterable_unroll'))
+
     def fixedview(self, w_iterable, expected_length=-1):
         """ A fixed list view of w_iterable. Don't modify the result
         """
         return make_sure_not_resized(self.unpackiterable(w_iterable,
                                                          expected_length)[:])
 
+    fixedview_unroll = fixedview
+
     def listview(self, w_iterable, expected_length=-1):
         """ A non-fixed view of w_iterable. Don't modify the result
         """

Modified: pypy/trunk/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/trunk/pypy/interpreter/pyopcode.py	(original)
+++ pypy/trunk/pypy/interpreter/pyopcode.py	Thu Sep 23 22:26:03 2010
@@ -637,7 +637,7 @@
 
     def UNPACK_SEQUENCE(self, itemcount, next_instr):
         w_iterable = self.popvalue()
-        items = self.space.fixedview(w_iterable, itemcount)
+        items = self.space.fixedview_unroll(w_iterable, itemcount)
         self.pushrevvalues(itemcount, items)
 
     def STORE_ATTR(self, nameindex, next_instr):

Modified: pypy/trunk/pypy/module/pypyjit/test/test_pypy_c.py
==============================================================================
--- pypy/trunk/pypy/module/pypyjit/test/test_pypy_c.py	(original)
+++ pypy/trunk/pypy/module/pypyjit/test/test_pypy_c.py	Thu Sep 23 22:26:03 2010
@@ -869,6 +869,24 @@
                 return intimg[i - 1]
             ''', maxops, ([tc], res))
 
+    def test_unpackiterable(self):
+        self.run_source('''
+        from array import array
+
+        def main():
+            i = 0
+            t = array('l', (1, 2))
+            while i < 2000:
+                a, b = t
+                i += 1
+            return 3
+
+        ''', 100, ([], 3))
+        bytecode, = self.get_by_bytecode("UNPACK_SEQUENCE")
+        # we allocate virtual ref and frame, we don't want block
+        assert len(bytecode.get_opnames('call_may_force')) == 0
+        
+
     def test_intbound_simple(self):
         ops = ('<', '>', '<=', '>=', '==', '!=')
         nbr = (3, 7)

Modified: pypy/trunk/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/objspace.py	(original)
+++ pypy/trunk/pypy/objspace/std/objspace.py	Thu Sep 23 22:26:03 2010
@@ -7,7 +7,7 @@
 from pypy.objspace.std import (builtinshortcut, stdtypedef, frame, model,
                                transparent, callmethod, proxyobject)
 from pypy.objspace.descroperation import DescrOperation, raiseattrerror
-from pypy.rlib.objectmodel import instantiate, r_dict
+from pypy.rlib.objectmodel import instantiate, r_dict, specialize
 from pypy.rlib.debug import make_sure_not_resized
 from pypy.rlib.rarithmetic import base_int
 from pypy.rlib.objectmodel import we_are_translated
@@ -350,7 +350,8 @@
             raise self._wrap_expected_length(expected_length, len(t))
         return t
 
-    def fixedview(self, w_obj, expected_length=-1):
+    @specialize.arg(3)
+    def fixedview(self, w_obj, expected_length=-1, unroll=False):
         """ Fast paths
         """
         if isinstance(w_obj, W_TupleObject):
@@ -358,18 +359,26 @@
         elif isinstance(w_obj, W_ListObject):
             t = w_obj.wrappeditems[:]
         else:
-            return ObjSpace.fixedview(self, w_obj, expected_length)
+            if unroll:
+                return make_sure_not_resized(ObjSpace.unpackiterable_unroll(
+                    self, w_obj, expected_length)[:])
+            else:
+                return make_sure_not_resized(ObjSpace.unpackiterable(
+                    self, w_obj, expected_length)[:])
         if expected_length != -1 and len(t) != expected_length:
             raise self._wrap_expected_length(expected_length, len(t))
         return t
 
+    def fixedview_unroll(self, w_obj, expected_length=-1):
+        return self.fixedview(w_obj, expected_length, unroll=True)
+
     def listview(self, w_obj, expected_length=-1):
         if isinstance(w_obj, W_ListObject):
             t = w_obj.wrappeditems
         elif isinstance(w_obj, W_TupleObject):
             t = w_obj.wrappeditems[:]
         else:
-            return ObjSpace.listview(self, w_obj, expected_length)
+            return ObjSpace.unpackiterable(self, w_obj, expected_length)
         if expected_length != -1 and len(t) != expected_length:
             raise self._wrap_expected_length(expected_length, len(t))
         return t



More information about the Pypy-commit mailing list