Exemple #1
0
def ProcessDepFields(depfields,res,rtype,mode='real'):
    if len(depfields.comps.__dict__) == 0:
        return res
    else:
        oldlength = len(depfields.comps.__dict__)
        todelete = []
        for l in depfields.comps.__dict__:
            Resolved = ComputeDepType(res,depfields.comps.__getattribute__(l),rtype.poss)
            #print(show(Resolved))
            if 'not a label' in show(Resolved):  #Is this condition still used?
                pass
            elif Resolved == None:
                pass
            else:
                if mode=='real':
                    res.addfield(l,Resolved.in_poss(rtype.poss).create())
                    todelete.append(l)
                elif mode=='hyp':
                    res.addfield(l,Resolved.create_hypobj())
                    todelete.append(l)
                else:
                    print(mode+' not recognized as option for ProcessDepFields')
        for l in todelete:
            del depfields.comps.__dict__[l]
        if len(depfields.comps.__dict__) < oldlength:
            return ProcessDepFields(depfields,res,rtype,mode)
        else:
            if ttracing('create') or ttracing('create_hypobj'):
                print('Unresolved dependency in '+show(rtype))
            return None
Exemple #2
0
def ProcessDepFields(depfields, res, rtype, mode='real'):
    if len(depfields.comps.__dict__) == 0:
        return res
    else:
        oldlength = len(depfields.comps.__dict__)
        todelete = []
        for l in depfields.comps.__dict__:
            Resolved = ComputeDepType(res, depfields.comps.__getattribute__(l),
                                      rtype.poss)
            #print(show(Resolved))
            if 'not a label' in show(Resolved):  #Is this condition still used?
                pass
            elif Resolved == None:
                pass
            else:
                if mode == 'real':
                    res.addfield(l, Resolved.in_poss(rtype.poss).create())
                    todelete.append(l)
                elif mode == 'hyp':
                    res.addfield(l, Resolved.create_hypobj())
                    todelete.append(l)
                else:
                    print(mode +
                          ' not recognized as option for ProcessDepFields')
        for l in todelete:
            del depfields.comps.__dict__[l]
        if len(depfields.comps.__dict__) < oldlength:
            return ProcessDepFields(depfields, res, rtype, mode)
        else:
            if ttracing('create') or ttracing('create_hypobj'):
                print('Unresolved dependency in ' + show(rtype))
            return None
Exemple #3
0
def QueryField(l, r, T, M):
    if ttracing('QueryField'):
        print('QueryField args: ', show([l, r, T, M]))
    TInField = T.comps.__getattribute__(l)
    Obj = r.__getattribute__(l)
    # if isinstance(Obj,HypObj):
    #     M = _M
    if isinstance(TInField, TypeClass):
        return (Obj, TInField.in_poss(M))
    #TInField.in_poss(M).query(Obj)
    else:
        TResolved = ComputeDepType(r, TInField, M)
        if ttracing('TResolved'):
            print('TResolved is: ', show((Obj, TResolved.in_poss(M))))
        return (Obj, TResolved.in_poss(M))
Exemple #4
0
 def appc_m(self,arg,M):
     if self.validate_arg_m(arg,M):
         return self.app(arg)
     else:
         if ttracing('appc_m'):
             print (self.show()+'('+show(arg)+'): badly typed function application')
         return None            
Exemple #5
0
 def appc_m(self,arg,M):
     if self.validate_arg_m(arg,M):
         return self.app(arg)
     else:
         if ttracing('appc_m'):
             print (self.show()+'('+show(arg)+'): badly typed function application')
         return None            
Exemple #6
0
def ti_apply(Tf, Targ):
    if isinstance(Tf, FunType) \
        and Targ.subtype_of(Tf.comps.domain):
        return Tf.comps.range
    else:
        if ttracing('ti_apply'):
            print('Not a well-typed function application: '+ show(Tf) + show(Targ))
        return None
Exemple #7
0
 def pathvalue(self, path):
     splits=deque(path.split("."))
     if (len(splits) == 1):
         if splits[0] in dir(self.comps):
             return self.comps.__getattribute__(splits[0])
         else:
             if ttracing('pathvalue'):
                 print(splits[0]+' not a label in '+self.show())
             return None
     else:
         addr = splits.popleft()
         if 'pathvalue' not in dir(self.comps.__getattribute__(addr)):
             if ttracing('pathvalue'):
                 print('No paths into '+show(self.comps.__getattribute__(addr)))
             return None
         else:
             return self.comps.__getattribute__(addr).pathvalue(".".join(splits))
Exemple #8
0
def ti_apply(Tf, Targ):
    if isinstance(Tf, FunType) \
        and Targ.subtype_of(Tf.comps.domain):
        return Tf.comps.range
    else:
        if ttracing('ti_apply'):
            print('Not a well-typed function application: '+ show(Tf) + show(Targ))
        return None
Exemple #9
0
 def pathvalue(self, path):
     splits=deque(path.split("."))
     if (len(splits) == 1):
         if splits[0] in dir(self.comps):
             return self.comps.__getattribute__(splits[0])
         else:
             if ttracing('pathvalue'):
                 print(splits[0]+' not a label in '+self.show())
             return None
     else:
         addr = splits.popleft()
         if 'pathvalue' not in dir(self.comps.__getattribute__(addr)):
             if ttracing('pathvalue'):
                 print('No paths into '+show(self.comps.__getattribute__(addr)))
             return None
         else:
             return self.comps.__getattribute__(addr).pathvalue(".".join(splits))
Exemple #10
0
def merge_dep_types(f1,f2):
    if isinstance(f1,Type) and isinstance(f1,Type):
        return f1.merge(f2)
    elif isinstance(f1,Fun) and isinstance(f2,Fun):
        var = gensym('v')
        return Fun(var, f1.domain_type.merge(f2.domain_type),
                   merge_dep_types(f1.body.subst(f1.var,var),f2.body.subst(f2.var,var)))
    else:
        if ttracing('merge_dep_types'):
            print(show(f1)+' and '+show(f2)+' cannot be merged.')
        return None
Exemple #11
0
def merge_dep_types(f1,f2):
    if isinstance(f1,Type) and isinstance(f1,Type):
        return f1.merge(f2)
    elif isinstance(f1,Fun) and isinstance(f2,Fun):
        var = gensym('v')
        return Fun(var, f1.domain_type.merge(f2.domain_type),
                   merge_dep_types(f1.body.subst(f1.var,var),f2.body.subst(f2.var,var)))
    else:
        if ttracing('merge_dep_types'):
            print(show(f1)+' and '+show(f2)+' cannot be merged.')
        return None
Exemple #12
0
def subtype_of_dep_types(f1,f2):
    if isinstance(f1,Type) and isinstance(f2,Type):
        return f1.subtype_of(f2)
    elif isinstance(f1,Fun):
        f1inst = f1.app(f1.domain_type.create_hypobj())
        return subtype_of_dep_types(f1inst,f2)
    elif isinstance(f2,Fun):
        f2inst = f2.app(f2.domain_type.create_hypobj())
        return subtype_of_dep_types(f1,f2inst)
    else:
        if ttracing('subtype_of_dep_types'):
            print(show(f1)+ ' and '+show(f2)+' cannot be compared for subtyping.')
        return None
Exemple #13
0
def subtype_of_dep_types(f1,f2):
    if isinstance(f1,Type) and isinstance(f2,Type):
        return f1.subtype_of(f2)
    elif isinstance(f1,Fun):
        f1inst = f1.app(f1.domain_type.create_hypobj())
        return subtype_of_dep_types(f1inst,f2)
    elif isinstance(f2,Fun):
        f2inst = f2.app(f2.domain_type.create_hypobj())
        return subtype_of_dep_types(f1,f2inst)
    else:
        if ttracing('subtype_of_dep_types'):
            print(show(f1)+ ' and '+show(f2)+' cannot be compared for subtyping.')
        return None
Exemple #14
0
 def subtype_of(self, T):
     if ttracing('subtype_of'):
         print('subtype_of args: ', show([self, T]))
     if T in self.supertype_cache:
         return True
     elif equal(self, T):
         return True
     else:
         a = self.create_hypobj()
         if T.query(a).min == 1:
             self.supertype_cache.append(T)
             return True
         else:
             return False
Exemple #15
0
def combine_dep_types(f1,f2):
    if isinstance(f1,Type) and isinstance(f2,Type):
        return f1.merge(f2)
    elif isinstance(f1,Fun) and isinstance(f2,Type):
        var = gensym('v')
        return Fun(var, f1.domain_type, combine_dep_types(f1.body.subst(f1.var,var),f2))
    elif isinstance(f1,Type) and isinstance(f2,Fun):
        var = gensym('v')
        return Fun(var, f2.domain_type, combine_dep_types(f1,f2.body.subst(f2.var,var)))
    elif isinstance(f1,Fun) and isinstance(f2,Fun):
        var1 = gensym('v')
        var2 = gensym('v')
        return Fun(var1, f1.domain_type,
                   Fun(var2, f2.domain_type, combine_dep_types(f1.body.subst(f1.var,var1),f2.body.subst(f2.var,var2))))
    else:
        if ttracing('combine_dep_types'):
            print(show(f1)+' and '+show(f2)+' cannot be combined.')
        return None
Exemple #16
0
def combine_dep_types(f1,f2):
    if isinstance(f1,Type) and isinstance(f2,Type):
        return f1.merge(f2)
    elif isinstance(f1,Fun) and isinstance(f2,Type):
        var = gensym('v')
        return Fun(var, f1.domain_type, combine_dep_types(f1.body.subst(f1.var,var),f2))
    elif isinstance(f1,Type) and isinstance(f2,Fun):
        var = gensym('v')
        return Fun(var, f2.domain_type, combine_dep_types(f1,f2.body.subst(f2.var,var)))
    elif isinstance(f1,Fun) and isinstance(f2,Fun):
        var1 = gensym('v')
        var2 = gensym('v')
        return Fun(var1, f1.domain_type,
                   Fun(var2, f2.domain_type, combine_dep_types(f1.body.subst(f1.var,var1),f2.body.subst(f2.var,var2))))
    else:
        if ttracing('combine_dep_types'):
            print(show(f1)+' and '+show(f2)+' cannot be combined.')
        return None
Exemple #17
0
 def query(self, a, c=[], oracle=None):
     if ttracing('query'):
         print('query args: ', show([self, a, c, oracle]))
     if check_stack('query', dict(a=a, c=c, oracle=oracle, self=self)):
         return PConstraint(0, 1)
     for m in self._query_methods:
         res = self.__getattribute__(m)(a, c, oracle)
         if res and (res.min > 0 or res.max < 1):
             if not c:
                 if a in self.witness_cache[0]:
                     self.witness_cache[1][self.witness_cache[0].index(
                         a)] = res
                 else:
                     if not isinstance(a, HypObj):
                         self.witness_cache[0].append(a)
                         self.witness_cache[1].append(res)
             return res
     if c or oracle:
         return self.query(a)
     else:
         return PConstraint(0, 1)
Exemple #18
0
def logtype_t(x, c):
    if ttracing('learn_witness_type'):
        print(show(x) + ' is a logical type and cannot learn new conditions')
Exemple #19
0
def logtype_t(x,c): 
    if ttracing('learn_witness_type'):
        print(show(x)+' is a logical type and cannot learn new conditions')
Exemple #20
0
 def judge_nonspec(self, n=1, max=None):
     if ttracing('judge_nonspec'):
         print(show(self) + ' is a variable type and cannot be judged')
Exemple #21
0
 def learn_witness_condition(self,c):
     if ttracing('learn_witness_condition'):
         print('Meet types are logical and cannot learn new conditions')
Exemple #22
0
 def learn_witness_condition(self, c):
     if ttracing('learn_witness_condition'):
         print('Record types cannot learn new witness conditions')
     return None
Exemple #23
0
 def learn_witness_condition(self, c):
     if ttracing('learn_witness_condition'):
         print('Meet types are logical and cannot learn new conditions')