[pypy-commit] pypy iterator-in-rpython: make the test pass - lltype only for now

fijal noreply at buildbot.pypy.org
Sun Jul 8 20:58:31 CEST 2012


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: iterator-in-rpython
Changeset: r56007:c4822d35a07e
Date: 2012-07-08 20:58 +0200
http://bitbucket.org/pypy/pypy/changeset/c4822d35a07e/

Log:	make the test pass - lltype only for now

diff --git a/pypy/annotation/unaryop.py b/pypy/annotation/unaryop.py
--- a/pypy/annotation/unaryop.py
+++ b/pypy/annotation/unaryop.py
@@ -663,12 +663,16 @@
     def iter(ins):
         s_iterable = ins._true_getattr('__iter__')
         bk = getbookkeeper()
-        return bk.emulate_pbc_call(bk.position_key, s_iterable, [])
+        # record for calltables
+        bk.emulate_pbc_call(bk.position_key, s_iterable, [])
+        return s_iterable.call(bk.build_args("simple_call", []))
 
     def next(ins):
         s_next = ins._true_getattr('next')
         bk = getbookkeeper()
-        return bk.emulate_pbc_call(bk.position_key, s_next, [])
+        # record for calltables
+        bk.emulate_pbc_call(bk.position_key, s_next, [])
+        return s_next.call(bk.build_args("simple_call", []))
 
 class __extend__(SomeBuiltin):
     def _can_only_throw(bltn, *args):
diff --git a/pypy/rpython/rclass.py b/pypy/rpython/rclass.py
--- a/pypy/rpython/rclass.py
+++ b/pypy/rpython/rclass.py
@@ -378,11 +378,11 @@
     def rtype_is_true(self, hop):
         raise NotImplementedError
 
-    def rtype_iter(self, hop):
+    def _emulate_call(self, hop, meth_name):
         vinst, = hop.inputargs(self)
         clsdef = hop.args_s[0].classdef
-        s_unbound_attr = clsdef.find_attribute('__iter__').getvalue()
-        s_attr = clsdef.lookup_filter(s_unbound_attr, '__iter__',
+        s_unbound_attr = clsdef.find_attribute(meth_name).getvalue()
+        s_attr = clsdef.lookup_filter(s_unbound_attr, meth_name,
                                       hop.args_s[0].flags)
         if s_attr.is_constant():
             xxx # does that even happen?
@@ -396,8 +396,11 @@
         hop2.args_s = [s_attr]
         return hop2.dispatch()
 
+    def rtype_iter(self, hop):
+        return self._emulate_call(hop, '__iter__')
+
     def rtype_next(self, hop):
-        xxx
+        return self._emulate_call(hop, 'next')
 
     def ll_str(self, i):
         raise NotImplementedError
diff --git a/pypy/rpython/test/test_rclass.py b/pypy/rpython/test/test_rclass.py
--- a/pypy/rpython/test/test_rclass.py
+++ b/pypy/rpython/test/test_rclass.py
@@ -958,28 +958,6 @@
                 found.append(op.args[1].value)
         assert found == ['mutate_c']
 
-    def test_iter(self):
-        class Iterable(object):
-            def __init__(self):
-                self.counter = 0
-            
-            def __iter__(self):
-                return self
-
-            def next(self):
-                if self.counter == 5:
-                    raise StopIteration
-                self.counter += 1
-                return self.counter - 1
-
-        def f():
-            i = Iterable()
-            s = 0
-            for elem in i:
-                s += elem
-            return s
-
-        assert self.interpret(f, []) == f()
 
 class TestLLtype(BaseTestRclass, LLRtypeMixin):
 
@@ -1165,6 +1143,29 @@
                                       'cast_pointer': 1,
                                       'setfield': 1}
 
+    def test_iter(self):
+        class Iterable(object):
+            def __init__(self):
+                self.counter = 0
+            
+            def __iter__(self):
+                return self
+
+            def next(self):
+                if self.counter == 5:
+                    raise StopIteration
+                self.counter += 1
+                return self.counter - 1
+
+        def f():
+            i = Iterable()
+            s = 0
+            for elem in i:
+                s += elem
+            return s
+
+        assert self.interpret(f, []) == f()
+
 
 class TestOOtype(BaseTestRclass, OORtypeMixin):
 


More information about the pypy-commit mailing list