[pypy-svn] r29578 - in pypy/dist/pypy/rpython: . test
arigo at codespeak.net
arigo at codespeak.net
Sun Jul 2 10:40:28 CEST 2006
Author: arigo
Date: Sun Jul 2 10:40:26 2006
New Revision: 29578
Modified:
pypy/dist/pypy/rpython/rlist.py
pypy/dist/pypy/rpython/test/test_rlist.py
Log:
get_ll_eq_function() for lists. This is to support things like
'list1 in list2'.
Modified: pypy/dist/pypy/rpython/rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/rlist.py (original)
+++ pypy/dist/pypy/rpython/rlist.py Sun Jul 2 10:40:26 2006
@@ -35,6 +35,7 @@
class AbstractBaseListRepr(Repr):
+ eq_func_cache = None
def recast(self, llops, v):
return llops.convertvar(v, self.item_repr, self.external_item_repr)
@@ -91,6 +92,17 @@
hop.exception_is_here()
return hop.gendirectcall(ll_listindex, v_lst, v_value, self.get_eqfunc())
+ def get_ll_eq_function(self):
+ result = self.eq_func_cache
+ if result is not None:
+ return result
+ def list_eq(l1, l2):
+ return ll_listeq(l1, l2, item_eq_func)
+ self.eq_func_cache = list_eq
+ # ^^^ do this first, before item_repr.get_ll_eq_function()
+ item_eq_func = self.item_repr.get_ll_eq_function()
+ return list_eq
+
class AbstractListRepr(AbstractBaseListRepr):
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 Sun Jul 2 10:40:26 2006
@@ -1015,6 +1015,14 @@
res = self.interpret(g, [3])
assert res == 77
+ def test_list_equality(self):
+ def dummyfn(n):
+ lst = [12] * n
+ assert lst == [12, 12, 12]
+ lst2 = [[12, 34], [5], [], [12, 12, 12], [5]]
+ assert lst in lst2
+ self.interpret(dummyfn, [3])
+
class TestLLtype(BaseTestRlist, LLRtypeMixin):
rlist = ll_rlist
More information about the Pypy-commit
mailing list