Ejemplo n.º 1
0
 def pTrT(self, pt, rt):
     assert pt.tMfamily == T.mfTuple and len(pt.tMindx) == 2
     leftT = H.intersection2(T.mvtNat, pt.tMindx[0])
     rightT = H.intersection2(T.mvtNat, pt.tMindx[1])
     grofT = H.intersection2(T.mvtNat, rt)  # mvtEmpty if fail
     if grofT == T.mvtEmpty or leftT == T.mvtEmpty or rightT == T.mvtEmpty:
         return T.mvtAny, T.mvtEmpty
     left = leftT.tMsubset[0] if leftT.tMsubset != None else None
     right = rightT.tMsubset[0] if rightT.tMsubset != None else None
     grof = grofT.tMsubset[0] if grofT.tMsubset != None else None
     if left != None and right != None:
         if grof != None and grof != left: return T.mvtAny, T.mvtEmpty
         if left >= right:
             grof = left
         else:
             return T.mvtAny, T.mvtEmpty
             #grofT=T.mvtEmpty # which isA Nat
     elif left != None and grof != None:  # and right==None
         if grof != left: return T.mvtEmpty, T.mvtEmpty
         return T.MtVal(T.mfTuple, (leftT, rightT), None), grofT
     elif right != None and grof != None:  # and left==None
         left = grof
         if left < right: return T.mvtAny, T.mvtEmpty
     else:
         return T.MtVal(T.mfTuple, (leftT, rightT), None), grofT
     # left, right and grofT defined, maybe grof
     return T.tupleFixUp(T.MtVal(T.mfTuple,(leftT,rightT),((left,right),)))[1],\
            T.typeWithVal(T.mvtNat,grof)
Ejemplo n.º 2
0
 def pTrT(self, pt, rt):  #
     assert pt.tMfamily == T.mfTuple  #and rt.tMfamily==T.mfList
     # we cheat and only work if all elements same base type
     t = T.tNoSub(pt.tMindx[0])  # first and only type
     assert all(H.isA(tt, t) != None for tt in pt.tMindx)
     if pt.tMsubset == None: return pt, T.MtVal(T.mfList, t, None)
     return pt,\
            T.MtVal(T.mfList,t,tuple((conv(pt.tMsubset[0][i],pt.tMindx[i],t)\
                                      for i in range(len(pt.tMindx)))))
Ejemplo n.º 3
0
 def pTrT(self, pt, rt):
     assert pt.tMfamily == T.mfTuple and len(pt.tMindx) == 2
     leftT = H.intersection2(T.mvtNat, pt.tMindx[0])
     rightT = H.intersection2(T.mvtNat, pt.tMindx[1])
     diffT = H.intersection2(T.mvtNat, rt)
     left = leftT.tMsubset[0] if leftT.tMsubset != None else None
     right = rightT.tMsubset[0] if rightT.tMsubset != None else None
     diff = diffT.tMsubset[0] if diffT.tMsubset != None else None
     if left != None and right != None:
         if diff != None: assert diff == left - right
         diff = left - right
     elif left != None and diff != None:  # and right==None
         right = left - diff
     elif right != None and diff != None:  # and left==None
         left = right + diff
     else:
         return T.MtVal(T.mfTuple, (leftT, rightT), None), diffT
     if diff < 0: return T.mvtAny, T.mvtEmpty  # Nat has no negative
     return T.tupleFixUp(T.MtVal(T.mfTuple,(leftT,rightT),((left,right),)))[1],\
            T.typeWithVal(T.mvtNat,diff)
Ejemplo n.º 4
0
 def pTrT(self, pt, rt):
     assert pt.tMfamily == T.mfTuple and len(pt.tMindx) == 2
     leftT = H.intersection2(T.mvtNat, pt.tMindx[0])
     rightT = H.intersection2(T.mvtNat, pt.tMindx[1])
     prodT = H.intersection2(T.mvtNat, rt)
     left = leftT.tMsubset[0] if leftT.tMsubset != None else None
     right = rightT.tMsubset[0] if rightT.tMsubset != None else None
     prod = prodT.tMsubset[0] if prodT.tMsubset != None else None
     if left != None and right != None:
         if prod != None: assert prod == left * right
         prod = left * right
     elif left != None and prod != None:  # and right==None
         if left == 0: return T.mvtAny, T.mvtEmpty
         right = prod // left
     elif right != None and prod != None:  # and left==None
         if right == 0: return T.mvtAny, T.mvtEmpty
         left = prod // right
     else:
         return T.MtVal(T.mfTuple, (leftT, rightT), None), prodT
     if prod != left * right: return T.mvtAny, T.mvtEmpty
     return T.tupleFixUp(T.MtVal(T.mfTuple,(leftT,rightT),((left,right),)))[1],\
            T.typeWithVal(T.mvtNat,prod)
Ejemplo n.º 5
0
 def pTrT(self, pt, rt):
     if pt.tMsubset == None: return pt, rt
     assert pt.tMfamily == T.mfTuple
     # we cheat and only work if all elements same base type
     hd = pt.tMindx[0]  # first type is in hd
     tl = pt.tMindx[1]  # an mfTuple with 0 or more members
     t = T.tNoSub(hd)  # first and only type
     for tt in tl.tMindx:
         t = H.union2(t, T.tNoSub(tt))
     return pt,\
            T.MtVal(T.mfList,t,(((H.conv(hd.tMsubset[0],hd,t),)+\
            tuple((H.conv(tl.tMindx[i].tMsubset[0],tl.tMindx[i],t)\
                                      for i in range(len(tl.tMindx))))),))
Ejemplo n.º 6
0
 def __init__(self,shadowing,shadowLevel,ast,up,myChildId,closR,rsltT=T.mvtAny):
     super().__init__(shadowing,shadowLevel,ast,up,myChildId,closR,rsltT)
     assert isinstance(ast,A.AstTuple)
     if self.curType.tMfamily==T.mfTuple: 
         assert len(self.ast.members)==len(self.curType.tMindx)
     elif H.isEqual(self.curType,T.mvtAny): # convert Any to tuple of Anys
         self.curType = T.MtVal(T.mfTuple,len(self.ast.members)*(T.mvtAny,),None)
     else:
         assert False # we can probably handle other things FIXME
     # at this point curType is a tuple type
     self.members = tuple(newEt(self.ast.members[i],self,i,self.closR,\
             self.curType.tMindx[i]) for i in range(len(self.ast.members)))
     self.level = 1+max((m.level for m in self.members))
     if len(closR.levels) <= self.level: closR.levels.append(set())
     if self.rcvd!={}: closR.levels[self.level].add(self)
Ejemplo n.º 7
0
def intersection2Base(t1, t2):  # 2 MtVal, not subset
    assert t1.tMsubset == None and t2.tMsubset == None
    #if t1==T.mvtEmpty or t2==T.mvtEmpty: return T.mvtEmpty # not needed
    isA12 = isABase(t1, t2)
    if isA12 != None: return t1
    isA21 = isABase(t2, t1)
    if isA21 != None: return t2
    if t1.tMfamily == T.mfTuple:  # intersect componentwise
        if t2.tMfamily != T.mfTuple or len(t1.tMindx) != len(t2.tMindx):
            return T.mvtEmpty
        intsecs = tuple(intersection2Base(T.tNoSub(t1.tMindx[i]),T.tNoSub(t2.tMindx[i]))\
                for i in range(len(t1.tMindx)))
        if any(intsecs[i] == T.mvtEmpty for i in range(len(intsecs))):
            return T.mvtEmpty
        return T.MtVal(T.mfTuple, intsecs, None)
    return None  #T.mvtEmpty # need to handle more complex cases FIXME
Ejemplo n.º 8
0
 def pTrT(self, pt, rt):
     assert pt.tMfamily == T.mfTuple and len(pt.tMindx) == 2
     self.rt = H.intersectionList([pt.tMindx[0], pt.tMindx[1], rt])
     ch, self.pt = T.tupleFixUp(T.MtVal(T.mfTuple, (self.rt, self.rt),
                                        None))
     return self.pt, self.rt