Exemple #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)
Exemple #2
0
 def __init__(self,shadowing,shadowLevel,ast,up,myChildId,closR,rsltT=T.mvtAny):
     super().__init__(shadowing,shadowLevel,ast,up,myChildId,closR,rsltT)
     if self.ast.constType=='Number':
         v = D.Decimal(self.ast.const)
         self.curType = T.typeWithVal(T.mvtDecimal,v)
     else:
         assert False # FIXME
     self.up.receive(self.myChildId,self.curType)
     if self.rcvd!={}: closR.levels[self.level].add(self) # we shouldn't receive, should we?
Exemple #3
0
def intersection2(t1, t2):
    t1NS = T.tNoSub(t1)
    t2NS = T.tNoSub(t2)
    base = intersection2Base(t1NS, t2NS)
    if base == T.mvtEmpty:
        return T.mvtEmpty  # shouldn't need this if isA works??
    # subsets must be converted to base and be equal there
    if t1.tMsubset == None and t2.tMsubset == None: return base
    updown1 = isA(base, t1NS)
    updown2 = isA(base, t2NS)
    if updown1 == None or updown2 == None: return T.mvtEmpty  # val not in base
    if t1.tMsubset == None:  # so t2.tMsubset!=None
        return T.typeWithVal(base, updown2[1](t2.tMsubset[0]))
    elif t2.tMsubset == None:
        return T.typeWithVal(base, updown1[1](t1.tMsubset[0]))
    else:  # 2 values
        v2 = updown2[1](t2.tMsubset[0])  # possible base value
        v1 = updown1[1](t1.tMsubset[0])
        return T.mvtEmpty if not T.vEqual(base, v1, v2) else T.typeWithVal(
            base, v1)
Exemple #4
0
 def pTrT(self, pt, rt):
     assert pt.tMfamily == T.mfTuple and len(pt.tMindx) == 2
     if pt.tMindx[1].tMsubset == None: return pt, rt
     assert pt.tMindx[1].tMfamily == T.mfType and len(
         pt.tMindx[1].tMsubset) == 1
     reqT = pt.tMindx[1].tMsubset[0]
     updown = H.isA(pt.tMindx[0], reqT)
     if updown == None:
         assert pt.tMindx[0].tMsubset == None
         r = L.bind(pt).tMindx[0].set(reqT)
     else:
         if pt.tMindx[0].tMsubset == None:
             r = L.bind(pt).tMindx[0].set(reqT)
         else:
             up, down = updown
             val = up(pt.tMindx[0].tMsubset[0])
             r = L.bind(pt).tMindx[0].set(T.typeWithVal(reqT, val))
             r = T.tupleFixUp(r)[1]
     return r, r.tMindx[0]
Exemple #5
0
 def __init__(self,shadowing,shadowLevel,ast,up,myChildId,closR,rsltT=T.mvtAny):
     super().__init__(shadowing,shadowLevel,ast,up,myChildId,closR,rsltT)
     if isinstance(self.up,FakeEt): self.up.setChild(self) # hack
     assert isinstance(ast,A.AstClosure)
     self.curType = H.intersection2(rsltT,T.typeWithVal(T.mvtProcAnyAny,self))
     if H.isA(self.up.kidsType(self.myChildId),self.curType)==None:
         self.up.receive(self.myChildId,self.curType)
     # Ids seen but not newId:
     # Set all extIds to current values. Note that they must all have values "soon".
     # The closure is only callable after all values filled in. We register self with any
     # such "forward/future" references.
     self.extIds = {k:IdTypeReg(needIdType(k,self.closR),[]) for k in self.ast.extIds}
     self.gotAllEIs = True
     # if a closure is being evaluated then the closure it is lexically in is running,
     # and has all extIds defined. So if not defined it must be in closureRun's myIds
     for k,ei in self.extIds.items():
         if ei.mtval.tMsubset==None or len(ei.mtval.tMsubset)!=1:
             self.closR.myIds[k].registry.append(self) # reg has ids and inner closures
             self.gotAllEIs = False
     self.level = 0
Exemple #6
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)
Exemple #7
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)
Exemple #8
0
 def vToAny(v):  # v will be value of type t1
     ##assert T.vEqual(t1,t1.tMsubset[0],v)
     return T.typeWithVal(t1, v)  ##T.Mval(t1,v)