[pypy-svn] r39347 - in pypy/dist/pypy: annotation annotation/test rpython rpython/test

cfbolz at codespeak.net cfbolz at codespeak.net
Sat Feb 24 00:27:42 CET 2007


Author: cfbolz
Date: Sat Feb 24 00:27:38 2007
New Revision: 39347

Modified:
   pypy/dist/pypy/annotation/test/test_annrpython.py
   pypy/dist/pypy/annotation/unaryop.py
   pypy/dist/pypy/rpython/rmodel.py
   pypy/dist/pypy/rpython/test/test_rlist.py
Log:
support for iterator.next methods.


Modified: pypy/dist/pypy/annotation/test/test_annrpython.py
==============================================================================
--- pypy/dist/pypy/annotation/test/test_annrpython.py	(original)
+++ pypy/dist/pypy/annotation/test/test_annrpython.py	Sat Feb 24 00:27:38 2007
@@ -443,6 +443,14 @@
         s = a.build_types(snippet.simple_iter, [list])
         assert isinstance(s, annmodel.SomeIterator)
         
+    def test_simple_iter_next(self):
+        def f(x):
+            i = iter(range(x))
+            return i.next()
+        a = self.RPythonAnnotator()
+        s = a.build_types(f, [int])
+        assert isinstance(s, annmodel.SomeInteger)
+
     def test_simple_iter_dict(self):
         a = self.RPythonAnnotator()
         t = somedict(annmodel.SomeInteger(), annmodel.SomeInteger())

Modified: pypy/dist/pypy/annotation/unaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/unaryop.py	(original)
+++ pypy/dist/pypy/annotation/unaryop.py	Sat Feb 24 00:27:38 2007
@@ -506,6 +506,7 @@
     def next(itr):
         return itr.s_container.getanyitem(*itr.variant)
     next.can_only_throw = _can_only_throw
+    method_next = next
 
 
 class __extend__(SomeInstance):

Modified: pypy/dist/pypy/rpython/rmodel.py
==============================================================================
--- pypy/dist/pypy/rpython/rmodel.py	(original)
+++ pypy/dist/pypy/rpython/rmodel.py	Sat Feb 24 00:27:38 2007
@@ -272,6 +272,9 @@
         v_iter, = hop.inputargs(self)
         return v_iter
 
+    def rtype_method_next(self, hop):
+        return self.rtype_next(self, hop)
+
 
 class __extend__(annmodel.SomeIterator):
     # NOTE: SomeIterator is for iterators over any container, not just list

Modified: pypy/dist/pypy/rpython/test/test_rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rlist.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rlist.py	Sat Feb 24 00:27:38 2007
@@ -283,6 +283,35 @@
         res = self.interpret(dummyfn, [])
         assert res == 25
 
+    def test_iterate_next(self):
+        def dummyfn():
+            total = 0
+            it = iter([1, 3, 5, 7, 9])
+            while 1:
+                try:
+                    x = it.next()
+                except StopIteration:
+                    break
+                total += x
+            return total
+        res = self.interpret(dummyfn, [])
+        assert res == 25
+        def dummyfn():
+            total = 0
+            l = [1, 3, 5, 7]
+            l.append(9)
+            it = iter(l)
+            while 1:
+                try:
+                    x = it.next()
+                except StopIteration:
+                    break
+                total += x
+            return total
+        res = self.interpret(dummyfn, [])
+        assert res == 25
+
+
     def test_recursive(self):
         def dummyfn(N):
             l = []



More information about the Pypy-commit mailing list