Пример #1
0
    def union((int1, int2)):
        if int1.unsigned == int2.unsigned:
            knowntype = rarithmetic.compute_restype(int1.knowntype,
                                                    int2.knowntype)
        else:
            t1 = int1.knowntype
            if t1 is bool:
                t1 = int
            t2 = int2.knowntype
            if t2 is bool:
                t2 = int

            if t2 is int:
                if int2.nonneg == False:
                    raise UnionError, "Merging %s and a possibly negative int is not allowed" % t1
                knowntype = t1
            elif t1 is int:
                if int1.nonneg == False:
                    raise UnionError, "Merging %s and a possibly negative int is not allowed" % t2
                knowntype = t2
            else:
                raise UnionError, "Merging these types (%s, %s) is not supported" % (
                    t1, t2)
        return SomeInteger(nonneg=int1.nonneg and int2.nonneg,
                           knowntype=knowntype)
Пример #2
0
    def union((int1, int2)):
        if int1.unsigned == int2.unsigned:
            knowntype = rarithmetic.compute_restype(int1.knowntype,
                                                    int2.knowntype)
        else:
            t1 = int1.knowntype
            if t1 is bool:
                t1 = int
            t2 = int2.knowntype
            if t2 is bool:
                t2 = int

            if t2 is int:
                if int2.nonneg == False:
                    raise UnionError, "Merging %s and a possibly negative int is not allowed" % t1
                knowntype = t1
            elif t1 is int:
                if int1.nonneg == False:
                    raise UnionError, "Merging %s and a possibly negative int is not allowed" % t2
                knowntype = t2
            else:
                raise UnionError, "Merging these types (%s, %s) is not supported" % (
                    t1, t2)
        return SomeInteger(
            nonneg=int1.nonneg and int2.nonneg, knowntype=knowntype)
Пример #3
0
class __extend__(pairtype(SomeInteger, SomeInteger)):
    # unsignedness is considered a rare and contagious disease

    def union((int1, int2)):
        knowntype = rarithmetic.compute_restype(int1.knowntype, int2.knowntype)
        return SomeInteger(nonneg=int1.nonneg and int2.nonneg,
                           knowntype=knowntype)

    or_ = xor = add = mul = _clone(union, [])
    add_ovf = mul_ovf = _clone(union, [OverflowError])
    div = floordiv = mod = _clone(union, [ZeroDivisionError])
    div_ovf = floordiv_ovf = mod_ovf = _clone(
        union, [ZeroDivisionError, OverflowError])

    def truediv((int1, int2)):
        return SomeFloat()

    truediv.can_only_throw = [ZeroDivisionError]
    truediv_ovf = _clone(truediv, [ZeroDivisionError, OverflowError])

    inplace_div = div
    inplace_truediv = truediv

    def sub((int1, int2)):
        knowntype = rarithmetic.compute_restype(int1.knowntype, int2.knowntype)
        return SomeInteger(knowntype=knowntype)

    sub.can_only_throw = []
    sub_ovf = _clone(sub, [OverflowError])

    def and_((int1, int2)):
        knowntype = rarithmetic.compute_restype(int1.knowntype, int2.knowntype)
        return SomeInteger(nonneg=int1.nonneg or int2.nonneg,
                           knowntype=knowntype)

    and_.can_only_throw = []

    def lshift((int1, int2)):
        if isinstance(int1, SomeBool):
            return SomeInteger()
        else:
            return SomeInteger(knowntype=int1.knowntype)

    lshift.can_only_throw = []
    lshift_ovf = _clone(lshift, [OverflowError])

    def rshift((int1, int2)):
        if isinstance(int1, SomeBool):
            return SomeInteger(nonneg=True)
        else:
            return SomeInteger(nonneg=int1.nonneg, knowntype=int1.knowntype)

    rshift.can_only_throw = []

    def pow((int1, int2), obj3):
        knowntype = rarithmetic.compute_restype(int1.knowntype, int2.knowntype)
        return SomeInteger(nonneg=int1.nonneg, knowntype=knowntype)
Пример #4
0
def unify_scalar_tp(item1, item2):
    typecode = None
    if float in (item1.knowntype, item2.knowntype):
        typecode = 'd'
    else:
        item_knowntype = rarithmetic.compute_restype(item1.knowntype, item2.knowntype)
        for typecode, s_item in SomeArray.typecode_to_item.items():
            if s_item.knowntype == item_knowntype:
                break
    if typecode is None:
        raise AnnotatorError()
    return typecode
Пример #5
0
def unify_scalar_tp(item1, item2):
    typecode = None
    if float in (item1.knowntype, item2.knowntype):
        typecode = 'd'
    else:
        item_knowntype = rarithmetic.compute_restype(item1.knowntype,
                                                     item2.knowntype)
        for typecode, s_item in SomeArray.typecode_to_item.items():
            if s_item.knowntype == item_knowntype:
                break
    if typecode is None:
        raise AnnotatorError()
    return typecode
Пример #6
0
 def inplace_pow((int1, int2)):
     knowntype = rarithmetic.compute_restype(int1.knowntype, int2.knowntype)
     return SomeInteger(nonneg = int1.nonneg,
                        knowntype=knowntype)
Пример #7
0
 def and_((int1, int2)):
     knowntype = rarithmetic.compute_restype(int1.knowntype, int2.knowntype)
     return SomeInteger(nonneg=int1.nonneg or int2.nonneg,
                        knowntype=knowntype)
Пример #8
0
 def sub((int1, int2)):
     knowntype = rarithmetic.compute_restype(int1.knowntype, int2.knowntype)
     return SomeInteger(knowntype=knowntype)
Пример #9
0
 def inplace_pow((int1, int2)):
     knowntype = rarithmetic.compute_restype(int1.knowntype, int2.knowntype)
     return SomeInteger(nonneg=int1.nonneg, knowntype=knowntype)
Пример #10
0
 def and_((int1, int2)):
     knowntype = rarithmetic.compute_restype(int1.knowntype, int2.knowntype)
     return SomeInteger(nonneg=int1.nonneg or int2.nonneg,
                        knowntype=knowntype)
Пример #11
0
 def sub((int1, int2)):
     knowntype = rarithmetic.compute_restype(int1.knowntype, int2.knowntype)
     return SomeInteger(knowntype=knowntype)
Пример #12
0
class __extend__(pairtype(SomeInteger, SomeInteger)):
    # unsignedness is considered a rare and contagious disease

    def union((int1, int2)):
        if int1.unsigned == int2.unsigned:
            knowntype = rarithmetic.compute_restype(int1.knowntype,
                                                    int2.knowntype)
        else:
            t1 = int1.knowntype
            if t1 is bool:
                t1 = int
            t2 = int2.knowntype
            if t2 is bool:
                t2 = int

            if t2 is int:
                if int2.nonneg == False:
                    raise UnionError, "Merging %s and a possibly negative int is not allowed" % t1
                knowntype = t1
            elif t1 is int:
                if int1.nonneg == False:
                    raise UnionError, "Merging %s and a possibly negative int is not allowed" % t2
                knowntype = t2
            else:
                raise UnionError, "Merging these types (%s, %s) is not supported" % (
                    t1, t2)
        return SomeInteger(nonneg=int1.nonneg and int2.nonneg,
                           knowntype=knowntype)

    or_ = xor = add = mul = _clone(union, [])
    add_ovf = mul_ovf = _clone(union, [OverflowError])
    div = floordiv = mod = _clone(union, [ZeroDivisionError])
    div_ovf = floordiv_ovf = mod_ovf = _clone(
        union, [ZeroDivisionError, OverflowError])

    def truediv((int1, int2)):
        return SomeFloat()

    truediv.can_only_throw = [ZeroDivisionError]
    truediv_ovf = _clone(truediv, [ZeroDivisionError, OverflowError])

    inplace_div = div
    inplace_truediv = truediv

    def sub((int1, int2)):
        knowntype = rarithmetic.compute_restype(int1.knowntype, int2.knowntype)
        return SomeInteger(knowntype=knowntype)

    sub.can_only_throw = []
    sub_ovf = _clone(sub, [OverflowError])

    def and_((int1, int2)):
        knowntype = rarithmetic.compute_restype(int1.knowntype, int2.knowntype)
        return SomeInteger(nonneg=int1.nonneg or int2.nonneg,
                           knowntype=knowntype)

    and_.can_only_throw = []

    def lshift((int1, int2)):
        if isinstance(int1, SomeBool):
            return SomeInteger()
        else:
            return SomeInteger(knowntype=int1.knowntype)

    lshift.can_only_throw = []
    lshift_ovf = _clone(lshift, [OverflowError])

    def rshift((int1, int2)):
        if isinstance(int1, SomeBool):
            return SomeInteger(nonneg=True)
        else:
            return SomeInteger(nonneg=int1.nonneg, knowntype=int1.knowntype)

    rshift.can_only_throw = []

    def pow((int1, int2), obj3):
        knowntype = rarithmetic.compute_restype(int1.knowntype, int2.knowntype)
        return SomeInteger(nonneg=int1.nonneg, knowntype=knowntype)