Author: Ronan Lamy <ronan.l...@gmail.com> Branch: var-in-Some Changeset: r71591:8fe91928ab37 Date: 2014-05-19 17:45 +0100 http://bitbucket.org/pypy/pypy/changeset/8fe91928ab37/
Log: register annotators for the base case of comparison operators diff --git a/rpython/annotator/binaryop.py b/rpython/annotator/binaryop.py --- a/rpython/annotator/binaryop.py +++ b/rpython/annotator/binaryop.py @@ -58,6 +58,18 @@ r.set_knowntypedata(knowntypedata) return r +def _make_cmp_annotator_default(cmp_op): + @cmp_op.register(SomeObject, SomeObject) + def default_annotate(obj1, obj2): + s_1, s_2 = obj1.ann, obj2.ann + if s_1.is_immutable_constant() and s_2.is_immutable_constant(): + return immutablevalue(cmp_op.pyfunc(s_1.const, s_2.const)) + else: + return s_Bool + +for cmp_op in [op.lt, op.le, op.eq, op.ne, op.gt, op.ge]: + _make_cmp_annotator_default(cmp_op) + class __extend__(pairtype(SomeObject, SomeObject)): def union((obj1, obj2)): @@ -86,42 +98,6 @@ inplace_floordiv.can_only_throw = [ZeroDivisionError] inplace_mod.can_only_throw = [ZeroDivisionError] - def lt((obj1, obj2)): - if obj1.is_immutable_constant() and obj2.is_immutable_constant(): - return immutablevalue(obj1.const < obj2.const) - else: - return s_Bool - - def le((obj1, obj2)): - if obj1.is_immutable_constant() and obj2.is_immutable_constant(): - return immutablevalue(obj1.const <= obj2.const) - else: - return s_Bool - - def eq((obj1, obj2)): - if obj1.is_immutable_constant() and obj2.is_immutable_constant(): - return immutablevalue(obj1.const == obj2.const) - else: - return s_Bool - - def ne((obj1, obj2)): - if obj1.is_immutable_constant() and obj2.is_immutable_constant(): - return immutablevalue(obj1.const != obj2.const) - else: - return s_Bool - - def gt((obj1, obj2)): - if obj1.is_immutable_constant() and obj2.is_immutable_constant(): - return immutablevalue(obj1.const > obj2.const) - else: - return s_Bool - - def ge((obj1, obj2)): - if obj1.is_immutable_constant() and obj2.is_immutable_constant(): - return immutablevalue(obj1.const >= obj2.const) - else: - return s_Bool - def cmp((obj1, obj2)): if obj1.is_immutable_constant() and obj2.is_immutable_constant(): return immutablevalue(cmp(obj1.const, obj2.const)) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit