[pypy-svn] r13934 - in pypy/dist/pypy/rpython: . test
hpk at codespeak.net
hpk at codespeak.net
Sun Jun 26 13:42:56 CEST 2005
Author: hpk
Date: Sun Jun 26 13:42:55 2005
New Revision: 13934
Modified:
pypy/dist/pypy/rpython/rtuple.py
pypy/dist/pypy/rpython/test/test_rtuple.py
Log:
(arigo, hpk)
contains for constant tuples delegating to ConstantDict's
Modified: pypy/dist/pypy/rpython/rtuple.py
==============================================================================
--- pypy/dist/pypy/rpython/rtuple.py (original)
+++ pypy/dist/pypy/rpython/rtuple.py Sun Jun 26 13:42:55 2005
@@ -64,10 +64,27 @@
hop.gendirectcall(rlist.ll_setitem_nonneg, vlist, cindex, vitem)
return vlist
-#class __extend__(pairtype(TupleRepr, Repr)):
-# def rtype_contains((r_tup, r_item), hop):
-# XXX
-
+class __extend__(pairtype(TupleRepr, Repr)):
+ def rtype_contains((r_tup, r_item), hop):
+ v_tup = hop.args_v[0]
+ if not isinstance(v_tup, Constant):
+ raise TyperError("contains() on non-const tuple")
+ t = v_tup.value
+ typ = type(t[0])
+ for x in t[1:]:
+ if type(x) is not typ:
+ raise TyperError("contains() on mixed-type tuple "
+ "constant %r" % (v_tup,))
+ d = {}
+ for x in t:
+ d[x] = None
+ hop2 = hop.copy()
+ _, _ = hop2.r_s_popfirstarg()
+ v_dict = Constant(d)
+ s_dict = hop.rtyper.annotator.bookkeeper.immutablevalue(d)
+ hop2.v_s_insertfirstarg(v_dict, s_dict)
+ return hop2.dispatch()
+
class __extend__(pairtype(TupleRepr, IntegerRepr)):
def rtype_getitem((r_tup, r_int), hop):
Modified: pypy/dist/pypy/rpython/test/test_rtuple.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rtuple.py (original)
+++ pypy/dist/pypy/rpython/test/test_rtuple.py Sun Jun 26 13:42:55 2005
@@ -70,7 +70,6 @@
assert res == 123
def test_constant_tuple_contains():
- py.test.skip("tuple contains not implemented")
def f(i):
t1 = (1, 2, 3, 4)
return i in t1
More information about the Pypy-commit
mailing list