Author: Armin Rigo <ar...@tunes.org> Branch: kill-someobject Changeset: r57928:956082ef4b0a Date: 2012-10-08 15:04 +0200 http://bitbucket.org/pypy/pypy/changeset/956082ef4b0a/
Log: (fijal, arigo) - Fix the remaining test comparing two tuples with a different annotatation - Kill <= and friends on tuples diff --git a/pypy/rpython/rtuple.py b/pypy/rpython/rtuple.py --- a/pypy/rpython/rtuple.py +++ b/pypy/rpython/rtuple.py @@ -21,7 +21,6 @@ _gen_eq_function_cache = {} -_gen_cmp_function_cache = {} _gen_hash_function_cache = {} _gen_str_function_cache = {} @@ -46,49 +45,6 @@ _gen_eq_function_cache[key] = ll_eq return ll_eq -import os -def gen_cmp_function(items_r, op_funcs, eq_funcs, strict): - """generates <= and >= comparison ll_op for tuples - cmp_funcs is a tuple of (strict_comp, equality) functions - works for != with strict==True - """ - cmp_funcs = zip(op_funcs,eq_funcs) - autounrolling_funclist = unrolling_iterable(enumerate(cmp_funcs)) - key = tuple(cmp_funcs), strict - try: - return _gen_cmp_function_cache[key] - except KeyError: - def ll_cmp(t1, t2): - cmp_res = True - for i, (cmpfn, eqfn) in autounrolling_funclist: - attrname = 'item%d' % i - item1 = getattr(t1, attrname) - item2 = getattr(t2, attrname) - cmp_res = cmpfn(item1, item2) - if cmp_res: - # a strict compare is true we shortcut - return True - eq_res = eqfn(item1, item2) - if not eq_res: - # not strict and not equal we fail - return False - # Everything's equal here - if strict: - return False - else: - return True - _gen_cmp_function_cache[key] = ll_cmp - return ll_cmp - -def gen_gt_function(items_r, strict): - gt_funcs = [r_item.get_ll_gt_function() or operator.gt for r_item in items_r] - eq_funcs = [r_item.get_ll_eq_function() or operator.eq for r_item in items_r] - return gen_cmp_function( items_r, gt_funcs, eq_funcs, strict ) - -def gen_lt_function(items_r, strict): - lt_funcs = [r_item.get_ll_lt_function() or operator.lt for r_item in items_r] - eq_funcs = [r_item.get_ll_eq_function() or operator.eq for r_item in items_r] - return gen_cmp_function( items_r, lt_funcs, eq_funcs, strict ) def gen_hash_function(items_r): # based on CPython @@ -206,18 +162,6 @@ def get_ll_eq_function(self): return gen_eq_function(self.items_r) - def get_ll_ge_function(self): - return gen_gt_function(self.items_r, False) - - def get_ll_gt_function(self): - return gen_gt_function(self.items_r, True) - - def get_ll_le_function(self): - return gen_lt_function(self.items_r, False) - - def get_ll_lt_function(self): - return gen_lt_function(self.items_r, True) - def get_ll_hash_function(self): return gen_hash_function(self.items_r) @@ -292,30 +236,12 @@ rtype_inplace_add = rtype_add def rtype_eq((r_tup1, r_tup2), hop): - v_tuple1, v_tuple2 = hop.inputargs(r_tup1, r_tup2) - ll_eq = r_tup1.get_ll_eq_function() + s_tup = annmodel.unionof(*hop.args_s) + r_tup = hop.rtyper.getrepr(s_tup) + v_tuple1, v_tuple2 = hop.inputargs(r_tup, r_tup) + ll_eq = r_tup.get_ll_eq_function() return hop.gendirectcall(ll_eq, v_tuple1, v_tuple2) - def rtype_ge((r_tup1, r_tup2), hop): - v_tuple1, v_tuple2 = hop.inputargs(r_tup1, r_tup2) - ll_ge = r_tup1.get_ll_ge_function() - return hop.gendirectcall(ll_ge, v_tuple1, v_tuple2) - - def rtype_gt((r_tup1, r_tup2), hop): - v_tuple1, v_tuple2 = hop.inputargs(r_tup1, r_tup2) - ll_gt = r_tup1.get_ll_gt_function() - return hop.gendirectcall(ll_gt, v_tuple1, v_tuple2) - - def rtype_le((r_tup1, r_tup2), hop): - v_tuple1, v_tuple2 = hop.inputargs(r_tup1, r_tup2) - ll_le = r_tup1.get_ll_le_function() - return hop.gendirectcall(ll_le, v_tuple1, v_tuple2) - - def rtype_lt((r_tup1, r_tup2), hop): - v_tuple1, v_tuple2 = hop.inputargs(r_tup1, r_tup2) - ll_lt = r_tup1.get_ll_lt_function() - return hop.gendirectcall(ll_lt, v_tuple1, v_tuple2) - def rtype_ne(tup1tup2, hop): v_res = tup1tup2.rtype_eq(hop) return hop.genop('bool_not', [v_res], resulttype=Bool) diff --git a/pypy/rpython/test/test_rtuple.py b/pypy/rpython/test/test_rtuple.py --- a/pypy/rpython/test/test_rtuple.py +++ b/pypy/rpython/test/test_rtuple.py @@ -311,51 +311,6 @@ res = self.interpret(fn, [1, 49]) assert res is True - TUPLES = [ - ((1,2), (2,3), -1), - ((1,2), (1,3), -1), - ((1,2), (1,1), 1), - ((1,2), (1,2), 0), - ((1.,2.),(2.,3.), -1), - ((1.,2.),(1.,3.), -1), - ((1.,2.),(1.,1.), 1), - ((1.,2.),(1.,2.), 0), - ((1,2.),(2,3.), -1), - ((1,2.),(1,3.), -1), - ((1,2.),(1,1.), 1), - ((1,2.),(1,2.), 0), -## ((1,"def"),(1,"abc"), -1), -## ((1.,"abc"),(1.,"abc"), 0), - ] - - def test_tuple_comparison(self): - def f_lt( a, b, c, d ): - return (a,b) < (c,d) - def f_le( a, b, c, d ): - return (a,b) <= (c,d) - def f_gt( a, b, c, d ): - return (a,b) > (c,d) - def f_ge( a, b, c, d ): - return (a,b) >= (c,d) - def test_lt( a,b,c,d,resu ): - res = self.interpret(f_lt,[a,b,c,d]) - assert res == (resu == -1), "Error (%s,%s)<(%s,%s) is %s(%s)" % (a,b,c,d,res,resu) - def test_le( a,b,c,d,resu ): - res = self.interpret(f_le,[a,b,c,d]) - assert res == (resu <= 0), "Error (%s,%s)<=(%s,%s) is %s(%s)" % (a,b,c,d,res,resu) - def test_gt( a,b,c,d,resu ): - res = self.interpret(f_gt,[a,b,c,d]) - assert res == ( resu == 1 ), "Error (%s,%s)>(%s,%s) is %s(%s)" % (a,b,c,d,res,resu) - def test_ge( a,b,c,d,resu ): - res = self.interpret(f_ge,[a,b,c,d]) - assert res == ( resu >= 0 ), "Error (%s,%s)>=(%s,%s) is %s(%s)" % (a,b,c,d,res,resu) - - for (a,b),(c,d),resu in self.TUPLES: - yield test_lt, a,b,c,d, resu - yield test_gt, a,b,c,d, resu - yield test_le, a,b,c,d, resu - yield test_ge, a,b,c,d, resu - def test_tuple_hash_2(self): from pypy.rlib.objectmodel import compute_hash def f(n): _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit