[pypy-svn] r13718 - in pypy/dist/pypy: annotation rpython rpython/test
tismer at codespeak.net
tismer at codespeak.net
Thu Jun 23 16:14:13 CEST 2005
Author: tismer
Date: Thu Jun 23 16:14:11 2005
New Revision: 13718
Modified:
pypy/dist/pypy/annotation/binaryop.py
pypy/dist/pypy/rpython/rlist.py
pypy/dist/pypy/rpython/test/test_rlist.py
Log:
list comparison works (just eq and ne needed)
Modified: pypy/dist/pypy/annotation/binaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/binaryop.py (original)
+++ pypy/dist/pypy/annotation/binaryop.py Thu Jun 23 16:14:11 2005
@@ -333,6 +333,11 @@
lst1.listdef.union(lst2.listdef)
return lst1
+ def eq((lst1, lst2)):
+ lst1.listdef.union(lst2.listdef)
+ return SomeBool()
+ ne = eq
+
class __extend__(pairtype(SomeList, SomeObject)):
Modified: pypy/dist/pypy/rpython/rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/rlist.py (original)
+++ pypy/dist/pypy/rpython/rlist.py Thu Jun 23 16:14:11 2005
@@ -179,6 +179,16 @@
hop.gendirectcall(ll_extend, v_lst1, v_lst2)
return v_lst1
+ def rtype_eq((self, _), hop):
+ v_lst1, v_lst2 = hop.inputargs(self, self)
+ return hop.gendirectcall(ll_listeq, v_lst1, v_lst2)
+
+ def rtype_ne((self, _), hop):
+ v_lst1, v_lst2 = hop.inputargs(self, self)
+ flag = hop.gendirectcall(ll_listeq, v_lst1, v_lst2)
+ return hop.genop('bool_not', [flag], resulttype=Bool)
+
+
# ____________________________________________________________
#
# Low-level methods. These can be run for testing, but are meant to
@@ -366,6 +376,25 @@
# ____________________________________________________________
#
+# Comparison.
+
+def ll_listeq(l1, l2):
+ len1 = len(l1.items)
+ len2 = len(l2.items)
+ if len1 != len2:
+ return False
+ j = 0
+ items1 = l1.items
+ items2 = l2.items
+ while j < len1:
+ if items1[j] != items2[j]:
+ return False
+ j += 1
+ return True
+
+
+# ____________________________________________________________
+#
# Irregular operations.
def ll_newlist(LISTPTR, length):
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 Thu Jun 23 16:14:11 2005
@@ -4,7 +4,7 @@
from pypy.rpython.rlist import *
from pypy.rpython.rslice import ll_newslice
from pypy.rpython.rint import signed_repr
-from pypy.rpython.test.test_llinterp import interpret
+from pypy.rpython.test.test_llinterp import interpret, make_interpreter
def sample_list():
@@ -221,3 +221,16 @@
return l1 is l2
res = interpret(dummyfn, [])
assert res is False
+
+def test_list_compare():
+ def fn(i, j, neg=False):
+ s1 = [[1, 2, 3], [4, 5, 1]]
+ s2 = [[1, 2, 3], [4, 5, 1], [1], [1, 2], [4, 5, 1, 6], [7, 1, 1, 8, 9, 10]]
+ if neg: return s1[i] != s2[i]
+ return s1[i] == s2[j]
+ ev_fn = make_interpreter(fn, [0, 0, False])
+ for i in range(2):
+ for j in range(6):
+ for case in False, True:
+ res = ev_fn(i, j, case)
+ assert res is fn(i, j, case)
More information about the Pypy-commit
mailing list