Author: Ronan Lamy <[email protected]>
Branch: less-stringly-ops
Changeset: r66767:67c3af63e05a
Date: 2013-08-31 18:00 +0100
http://bitbucket.org/pypy/pypy/changeset/67c3af63e05a/
Log: Move implementation of FlowObjSpace.iter() to op.iter
diff --git a/rpython/flowspace/objspace.py b/rpython/flowspace/objspace.py
--- a/rpython/flowspace/objspace.py
+++ b/rpython/flowspace/objspace.py
@@ -207,14 +207,6 @@
def not_(self, w_obj):
return const(not self.frame.guessbool(self.bool(w_obj)))
- def iter(self, w_iterable):
- if isinstance(w_iterable, Constant):
- iterable = w_iterable.value
- if isinstance(iterable, unrolling_iterable):
- return const(iterable.get_unroller())
- w_iter = self.frame.do_operation("iter", w_iterable)
- return w_iter
-
def next(self, w_iter):
frame = self.frame
if isinstance(w_iter, Constant):
diff --git a/rpython/flowspace/operation.py b/rpython/flowspace/operation.py
--- a/rpython/flowspace/operation.py
+++ b/rpython/flowspace/operation.py
@@ -6,6 +6,7 @@
import __builtin__
import __future__
import operator
+from rpython.rlib.unroll import unrolling_iterable, _unroller
from rpython.tool.sourcetools import compile2
from rpython.flowspace.model import (Constant, WrapException, const, Variable,
SpaceOperation)
@@ -276,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('iter', 1, 'iter', pyfunc=iter)
add_operator('next', 1, 'next', pyfunc=next)
#add_operator('call', 3, 'call')
add_operator('get', 3, 'get', pyfunc=get, pure=True)
@@ -285,9 +285,25 @@
add_operator('userdel', 1, 'del', pyfunc=userdel)
add_operator('buffer', 1, 'buffer', pyfunc=buffer, pure=True) # see buffer.py
+class Iter(HLOperation):
+ opname = 'iter'
+ arity = 1
+ can_overflow = False
+ canraise = []
+ pyfunc = staticmethod(iter)
+
+ def constfold(self):
+ w_iterable, = self.args
+ if isinstance(w_iterable, Constant):
+ iterable = w_iterable.value
+ if isinstance(iterable, unrolling_iterable):
+ return const(iterable.get_unroller())
+op.iter = Iter
+
# Other functions that get directly translated to SpaceOperators
func2op[type] = op.type
func2op[operator.truth] = op.bool
+func2op[__builtin__.iter] = op.iter
if hasattr(__builtin__, 'next'):
func2op[__builtin__.next] = op.next
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit