[pypy-commit] pypy less-stringly-ops: Move implementation of FlowObjSpace.next() to op.next

rlamy noreply at buildbot.pypy.org
Mon Sep 2 21:36:52 CEST 2013


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: less-stringly-ops
Changeset: r66770:d0d7f7735df4
Date: 2013-09-01 11:37 +0100
http://bitbucket.org/pypy/pypy/changeset/d0d7f7735df4/

Log:	Move implementation of FlowObjSpace.next() to op.next

diff --git a/rpython/flowspace/objspace.py b/rpython/flowspace/objspace.py
--- a/rpython/flowspace/objspace.py
+++ b/rpython/flowspace/objspace.py
@@ -18,7 +18,6 @@
         bootstrap_generator)
 from rpython.flowspace.pygraph import PyGraph
 from rpython.flowspace.specialcase import SPECIAL_CASES
-from rpython.rlib.unroll import unrolling_iterable, _unroller
 from rpython.rlib import rstackovf
 
 
@@ -202,22 +201,6 @@
     def not_(self, w_obj):
         return const(not self.frame.guessbool(self.bool(w_obj)))
 
-    def next(self, w_iter):
-        frame = self.frame
-        if isinstance(w_iter, Constant):
-            it = w_iter.value
-            if isinstance(it, _unroller):
-                try:
-                    v, next_unroller = it.step()
-                except IndexError:
-                    raise const(StopIteration())
-                else:
-                    frame.replace_in_stack(it, next_unroller)
-                    return const(v)
-        w_item = frame.do_operation("next", w_iter)
-        frame.guessexception([StopIteration, RuntimeError], force=True)
-        return w_item
-
 
     def getattr(self, w_obj, w_name):
         # handling special things like sys
diff --git a/rpython/flowspace/operation.py b/rpython/flowspace/operation.py
--- a/rpython/flowspace/operation.py
+++ b/rpython/flowspace/operation.py
@@ -277,7 +277,6 @@
 add_operator('cmp', 2, 'cmp', pyfunc=cmp, pure=True)   # rich cmps preferred
 add_operator('coerce', 2, 'coerce', pyfunc=coerce, pure=True)
 add_operator('contains', 2, 'contains', pure=True)
-add_operator('next', 1, 'next', pyfunc=next)
 #add_operator('call', 3, 'call')
 add_operator('get', 3, 'get', pyfunc=get, pure=True)
 add_operator('set', 3, 'set', pyfunc=set)
@@ -300,6 +299,31 @@
                 return const(iterable.get_unroller())
 op.iter = Iter
 
+class Next(HLOperation):
+    opname = 'next'
+    arity = 1
+    can_overflow = False
+    canraise = []
+    pyfunc = staticmethod(next)
+
+    def eval(self, frame):
+        w_iter, = self.args
+        if isinstance(w_iter, Constant):
+            it = w_iter.value
+            if isinstance(it, _unroller):
+                try:
+                    v, next_unroller = it.step()
+                except IndexError:
+                    raise const(StopIteration())
+                else:
+                    frame.replace_in_stack(it, next_unroller)
+                    return const(v)
+        w_item = frame.do_op(self)
+        frame.guessexception([StopIteration, RuntimeError], force=True)
+        return w_item
+op.next = Next
+
+
 # Other functions that get directly translated to SpaceOperators
 func2op[type] = op.type
 func2op[operator.truth] = op.bool


More information about the pypy-commit mailing list