Example #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(int1, int2, "RPython cannot prove that these " + \
                            "integers are of the same signedness")
                knowntype = t1
            elif t1 is int:
                if int1.nonneg == False:
                    raise UnionError(int1, int2, "RPython cannot prove that these " + \
                            "integers are of the same signedness")
                knowntype = t2
            else:
                raise UnionError(int1, int2)
        return SomeInteger(nonneg=int1.nonneg and int2.nonneg,
                           knowntype=knowntype)
Example #2
0
 def union((iter1, iter2)):
     s_cont = unionof(iter1.s_container, iter2.s_container)
     if iter1.variant != iter2.variant:
         raise UnionError(
             iter1, iter2,
             "RPython cannot unify incompatible iterator variants")
     return SomeIterator(s_cont, *iter1.variant)
Example #3
0
 def union((flt1, flt2)):
     if not TLS.allow_int_to_float:
         # in this mode, if one of the two is actually the
         # subclass SomeInteger, complain
         if isinstance(flt1, SomeInteger) or isinstance(flt2, SomeInteger):
             raise UnionError(flt1, flt2)
     return SomeFloat()
Example #4
0
 def union((bltn1, bltn2)):
     if (bltn1.analyser != bltn2.analyser or
             bltn1.methodname != bltn2.methodname):
         raise UnionError(bltn1, bltn2)
     s_self = unionof(bltn1.s_self, bltn2.s_self)
     return SomeBuiltinMethod(bltn1.analyser, s_self,
             methodname=bltn1.methodname)
Example #5
0
 def union((tup1, tup2)):
     if len(tup1.items) != len(tup2.items):
         raise UnionError(tup1, tup2, "RPython cannot unify tuples of "
                 "different length: %d versus %d" % \
                 (len(tup1.items), len(tup2.items)))
     else:
         unions = [unionof(x, y) for x, y in zip(tup1.items, tup2.items)]
         return SomeTuple(items=unions)
Example #6
0
 def union((s_wrf1, s_wrf2)):
     if s_wrf1.classdef is None:
         basedef = s_wrf2.classdef  # s_wrf1 is known to be dead
     elif s_wrf2.classdef is None:
         basedef = s_wrf1.classdef  # s_wrf2 is known to be dead
     else:
         basedef = s_wrf1.classdef.commonbase(s_wrf2.classdef)
         if basedef is None:  # no common base class! complain...
             raise UnionError(s_wrf1, s_wrf2)
     return SomeWeakRef(basedef)
Example #7
0
    def merge(self, other):
        if self is not other:
            if getattr(TLS, 'no_side_effects_in_union', 0):
                raise UnionError(self, other)

            if other.dont_change_any_more:
                if self.dont_change_any_more:
                    raise TooLateForChange
                else:
                    # lists using 'other' don't expect it to change any more,
                    # so we try merging into 'other', which will give
                    # TooLateForChange if it actually tries to make
                    # things more general
                    self, other = other, self

            self.immutable &= other.immutable
            if other.must_not_resize:
                if self.resized:
                    raise ListChangeUnallowed("list merge with a resized")
                self.must_not_resize = True
            if other.mutated:
                self.mutate()
            if other.resized:
                self.resize()
            if other.range_step != self.range_step:
                self.setrangestep(self._step_map[type(self.range_step),
                                                 type(other.range_step)])
            self.itemof.update(other.itemof)
            read_locations = self.read_locations.copy()
            other_read_locations = other.read_locations.copy()
            self.read_locations.update(other.read_locations)
            s_value = self.s_value
            s_other_value = other.s_value
            s_new_value = unionof(s_value, s_other_value)
            if s_new_value != s_value:
                if self.dont_change_any_more:
                    raise TooLateForChange
            self.patch()    # which should patch all refs to 'other'
            if s_new_value != s_value:
                self.s_value = s_new_value
                # reflow from reading points
                for position_key in read_locations:
                    self.bookkeeper.annotator.reflowfromposition(position_key) 
            if s_new_value != s_other_value:
                # reflow from reading points
                for position_key in other_read_locations:
                    other.bookkeeper.annotator.reflowfromposition(position_key)
Example #8
0
 def union((ins1, ins2)):
     if ins1.classdef is None or ins2.classdef is None:
         # special case only
         basedef = None
     else:
         basedef = ins1.classdef.commonbase(ins2.classdef)
         if basedef is None:
             raise UnionError(ins1, ins2, "RPython cannot unify instances "
                     "with no common base class")
     flags = ins1.flags
     if flags:
         flags = flags.copy()
         for key, value in flags.items():
             if key not in ins2.flags or ins2.flags[key] != value:
                 del flags[key]
     return SomeInstance(basedef,
                         can_be_None=ins1.can_be_None or ins2.can_be_None,
                         flags=flags)
Example #9
0
 def union((ins1, ins2)):
     if ins1.classdef is None or ins2.classdef is None:
         # special case only
         basedef = None
     else:
         basedef = ins1.classdef.commonbase(ins2.classdef)
         if basedef is None:
             print "\n\nUnionError will be thrown, basically there are 2 or more classes that are on a same context (variable, function args, or function return) that aren't compatible. Here are their __dict__:"
             print '\n', ins1.classdef.classdesc.classdict
             print '\n', ins2.classdef.classdesc.classdict, '\n'
             raise UnionError(ins1, ins2, "RPython cannot unify instances "
                     "with no common base class")
     flags = ins1.flags
     if flags:
         flags = flags.copy()
         for key, value in flags.items():
             if key not in ins2.flags or ins2.flags[key] != value:
                 del flags[key]
     return SomeInstance(basedef,
                         can_be_None=ins1.can_be_None or ins2.can_be_None,
                         flags=flags)
Example #10
0
 def union((obj1, obj2)):
     raise UnionError(obj1, obj2)
Example #11
0
 def union((p1, p2)):
     if p1.ll_ptrtype != p2.ll_ptrtype:
         raise UnionError(p1, p2)
     return SomePtr(p1.ll_ptrtype)
Example #12
0
 def union((s_obj, s_addr)):
     raise UnionError(s_obj, s_addr)
Example #13
0
 def union((p, obj)):
     raise UnionError(p, obj)
Example #14
0
 def union((s_wkd1, s_wkd2)):
     if s_wkd1.keyclassdef is not s_wkd2.keyclassdef:
         raise UnionError(s_wkd1, s_wkd2, "not the same key class!")
     if s_wkd1.valueclassdef is not s_wkd2.valueclassdef:
         raise UnionError(s_wkd1, s_wkd2, "not the same value class!")
     return SomeWeakKeyDict(s_wkd1.keyclassdef, s_wkd1.valueclassdef)
Example #15
0
 def union((s_wvd1, s_wvd2)):
     if s_wvd1.valueclassdef is not s_wvd2.valueclassdef:
         raise UnionError(s_wvd1, s_wvd2, "not the same class!")
     s_key = annmodel.unionof(s_wvd1.s_key, s_wvd2.s_key)
     return SomeWeakValueDict(s_key, s_wvd1.valueclassdef)