[pypy-svn] r13731 - in pypy/dist/pypy/rpython: . test
tismer at codespeak.net
tismer at codespeak.net
Thu Jun 23 18:59:01 CEST 2005
Author: tismer
Date: Thu Jun 23 18:59:00 2005
New Revision: 13731
Modified:
pypy/dist/pypy/rpython/rlist.py
pypy/dist/pypy/rpython/test/test_rlist.py
Log:
made eq/ne work for instances.
refactored comparison.
next thing is to support "contains" and "index"
Modified: pypy/dist/pypy/rpython/rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/rlist.py (original)
+++ pypy/dist/pypy/rpython/rlist.py Thu Jun 23 18:59:00 2005
@@ -2,11 +2,12 @@
from pypy.annotation import model as annmodel
from pypy.objspace.flow.model import Constant
from pypy.rpython.lltype import *
-from pypy.rpython.rmodel import Repr, TyperError, IntegerRepr
+from pypy.rpython.rmodel import Repr, TyperError, IntegerRepr, inputconst
from pypy.rpython import rrange
from pypy.rpython.rslice import SliceRepr
from pypy.rpython.rslice import startstop_slice_repr, startonly_slice_repr
from pypy.rpython.rstr import string_repr, ll_streq
+from pypy.rpython.rclass import InstanceRepr
# ____________________________________________________________
#
@@ -74,6 +75,17 @@
result.items[i] = r_item.convert_const(x)
return result
+ def get_eqfunc(self):
+ if self.item_repr == string_repr:
+ func = ll_streq
+ elif isinstance(self.item_repr.lowleveltype, Primitive):
+ func = None
+ elif isinstance(self.item_repr, InstanceRepr):
+ func = None
+ else:
+ raise TyperError, 'comparison not implemented for %r' % self
+ return inputconst(Void, func)
+
def rtype_len(self, hop):
v_lst, = hop.inputargs(self)
return hop.gendirectcall(ll_len, v_lst)
@@ -191,17 +203,11 @@
def rtype_eq((self, _), hop):
v_lst1, v_lst2 = hop.inputargs(self, self)
- if self.item_repr == string_repr:
- func = ll_streq
- elif isinstance(self.item_repr.lowleveltype, Primitive):
- func = None
- else:
- raise TyperError, 'comparison not implemented for %r' % self
- cmp = hop.inputconst(Void, func)
- return hop.gendirectcall(ll_listeq, v_lst1, v_lst2, cmp)
+ return hop.gendirectcall(ll_listeq, v_lst1, v_lst2, self.get_eqfunc())
- def rtype_ne(both, hop):
- flag = both.rtype_eq(hop)
+ def rtype_ne((self, _), hop):
+ v_lst1, v_lst2 = hop.inputargs(self, self)
+ flag = hop.gendirectcall(ll_listeq, v_lst1, v_lst2, self.get_eqfunc())
return hop.genop('bool_not', [flag], resulttype=Bool)
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 18:59:00 2005
@@ -249,3 +249,23 @@
for case in False, True:
res = ev_fn(i, j, case)
assert res is fn(i, j, case)
+
+class Foo: pass
+
+class Bar(Foo): pass
+
+def test_list_compareinst():
+ def fn(i, j, neg=False):
+ foo1 = Foo()
+ foo2 = Foo()
+ bar1 = Bar()
+ s1 = [[foo1], [foo2], [bar1]]
+ s2 = s1[:]
+ if neg: return s1[i] != s2[i]
+ return s1[i] == s2[j]
+ ev_fn = make_interpreter(fn, [0, 0, False])#, view=True)
+ for i in range(3):
+ for j in range(3):
+ 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