Search in sources :

Example 26 with Type

use of ast.Ast.Type in project L42 by ElvisResearchGroup.

the class AlternativeMethodTypes method _mVpNoRec.

static MethodType _mVpNoRec(MethodType mt, int parNum) {
    //Ts0 mut P Ts2->T;Ps in methTypes(p,P,ms)
    //Ts'=mutToCapsule(Ts0) lent P mutToCapsule(Ts2) //this implies not fwd_or_fwd%_in Ts0,Ts2
    //(mVp)-------------------------------------------------------------------
    //Ts'->toLent(T);Ps in methTypes(p,P,ms)
    Type pN = mt.getTs().get(parNum);
    if (pN.getMdf() != Mdf.Mutable) {
        return null;
    }
    Type retT = mt.getReturnType();
    retT = _toLent(retT);
    if (retT == null) {
        return null;
    }
    List<Type> ts = Map.of(t -> mutToCapsule(t), mt.getTs());
    ts.set(parNum, pN.withMdf(Mdf.Lent));
    MethodType res = mt.withReturnType(retT).withTs(ts).withMdf(mutToCapsule(mt.getMdf()));
    if (WellFormednessCore.methodTypeWellFormed(res)) {
        return res;
    }
    return null;
}
Also used : MethodType(ast.Ast.MethodType) Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType)

Example 27 with Type

use of ast.Ast.Type in project L42 by ElvisResearchGroup.

the class GuessTypeCore method guessedDs.

public static List<Dec> guessedDs(Program p, G in, List<Dec> toGuess) {
    //G'
    List<Dec> res = new ArrayList<>();
    for (Dec di : toGuess) {
        if (di.getT().isPresent()) {
            res.add(di);
            continue;
        }
        Type nti = _guessDecType(p, in, di);
        assert nti != null;
        res.add(di.withT(Optional.of(nti)));
    }
    return res;
}
Also used : Type(ast.Ast.Type) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Dec(ast.ExpCore.Block.Dec) ArrayList(java.util.ArrayList)

Example 28 with Type

use of ast.Ast.Type in project L42 by ElvisResearchGroup.

the class TIn method toLent.

public This toLent() {
    //toLent(G)(x)=toLent(G(x)) //thus undefined where toLent undefined
    Map<String, Map.Entry<Boolean, Type>> newG = new HashMap<>(g);
    for (String xi : gDom()) {
        Type ti = g(xi);
        assert ti != null;
        ti = TypeManipulation._toLent(ti);
        if (ti == null) {
            continue;
        }
        if (ti.getMdf() == Mdf.Immutable) {
            newG.put(xi, p(gVar(xi), ti));
        } else {
            newG.put(xi, p(false, ti));
        }
    }
    return this.withG(newG);
}
Also used : Entry(java.util.Map.Entry) Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) HashMap(java.util.HashMap)

Example 29 with Type

use of ast.Ast.Type in project L42 by ElvisResearchGroup.

the class TIn method addGds.

public This addGds(Program p, List<ExpCore.Block.Dec> ds) {
    Map<String, Map.Entry<Boolean, Type>> newG = new HashMap<>(g);
    for (ExpCore.Block.Dec d : ds) {
        assert !g.containsKey(d.getX());
        Type nt = d.getT().get();
        assert !d.isVar() || !TypeManipulation.fwd_or_fwdP_in(nt.getMdf());
        assert !d.isVar() || nt.getMdf() != Mdf.Capsule;
        newG.put(d.getX(), p(d.isVar(), nt));
    }
    return this.withG(newG);
}
Also used : Entry(java.util.Map.Entry) Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Dec(ast.ExpCore.Block.Dec) HashMap(java.util.HashMap) Block(ast.ExpCore.Block)

Example 30 with Type

use of ast.Ast.Type in project L42 by ElvisResearchGroup.

the class TsBlock method kTypeCatch.

// T0 is the declared caught type, which contributes only a path
// T1 is the actual caught type, based on the types which can be thrown in context
// T2 is the type of the expression, based on x being bound T1
default default TOutK kTypeCatch(TIn in, Tr tr1, On k) {
    if (k.getKind() == SignalKind.Return && tr1.returns.isEmpty()) {
        return new TErr(in, "No returns in scope", null, ErrorKind.NoMostGeneralMdf);
    }
    Mdf mdf1 = TypeManipulation._mostGeneralMdf(k.getKind(), tr1);
    if (mdf1 == null) {
        return new TErr(in, "Contrasting mdf expected for return", null, ErrorKind.NoMostGeneralMdf);
    }
    Type T1 = k.getT().withMdf(mdf1);
    TOut _out = type(in.addG(k.getX(), false, T1).withE(k.getE(), in.expected));
    if (!_out.isOk()) {
        return _out.toError();
    }
    TOk out = _out.toOk();
    TOkK res = new TOkK(Tr.instance.trUnion(out), k.withE(out.annotated).withT(T1), out.computed);
    return res;
/*   Phase| p| G| Tr' |- catch throw T0 x e ~> catch throw T1.P x e' :T2 <= T | Tr
     mdf1 = mostGeneralMdf(throw,Tr') //set of Mdfs admits no single most general mdf, or mdfs is empty
     //inconsistent set of thrown things, which do not share a most
     //general modifier [list of line numbers of the throws]
     T1 = mdf1 resolve (p, T0).P //resolve can fail
     not catchRethrow(catch throw T1 x e)
     Phase| p| G[x:T1]|- e ~> e' : T2 <= T | Tr
*/
}
Also used : Type(ast.Ast.Type) Mdf(ast.Ast.Mdf)

Aggregations

Type (ast.Ast.Type)81 MethodType (ast.Ast.MethodType)50 MethodWithType (ast.ExpCore.ClassB.MethodWithType)28 MethodWithType (ast.Expression.ClassB.MethodWithType)24 ArrayList (java.util.ArrayList)24 Mdf (ast.Ast.Mdf)16 Expression (ast.Expression)15 Path (ast.Ast.Path)13 Doc (ast.Ast.Doc)11 Ast (ast.Ast)10 MethodSelector (ast.Ast.MethodSelector)10 HashMap (java.util.HashMap)10 MethodSelectorX (ast.Ast.MethodSelectorX)8 VarDecXE (ast.Ast.VarDecXE)8 ExpCore (ast.ExpCore)8 Catch (ast.Expression.Catch)8 X (ast.Expression.X)8 VarDec (ast.Ast.VarDec)7 Block (ast.ExpCore.Block)7 List (java.util.List)7