Search in sources :

Example 6 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 7 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)

Example 8 with Type

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

the class TsOperations method tsClassB.

default default TOut tsClassB(TIn in, ClassB s) {
    //D |- L ~> L' : imm Library <= T | emptyTr
    //D.p|-imm Library <= T
    //D.Phase  |- D.p.evilPush(L) ~> L'
    Type t = Path.Library().toImmNT();
    ErrorKind subErr = TypeSystem.subtype(in.p, t, in.expected);
    if (subErr != null) {
        TErr out = new TErr(in, "-----------", t, subErr);
        return out;
    }
    TOut out = typeLib(in.withP(in.p.evilPush(s)));
    if (out.isOk()) {
        return new TOk(in, out.toOk().annotated, t);
    }
    return out.toError().enrich(in);
}
Also used : Type(ast.Ast.Type)

Example 9 with Type

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

the class TsOperations method tsSignal.

default default TOut tsSignal(TIn in, Signal s) {
    //D |- throw[_,_] e~> throw[T0,T3] e' : T0 <= T0 | Tr
    //  T1 = resolve(D.p,guessType(D.G,e))// Note, resolves and guessTypes can go in error, and need to become a type error here
    //  if throw=exception, T2= imm T1.P and Tr=Ts;Ps,P
    //  if throw=error,     T2= imm T1.P and Tr=Ts;Ps
    //  if throw=return,    T2= (fwd T1) and Tr=(Ts,T3);Ps 
    //  D|- e~>  e' :  T3 <=T2|Ts;Ps
    Type T1 = GuessTypeCore._of(in.p, in, s.getInner());
    Type T2;
    if (s.getKind() != SignalKind.Return) {
        T2 = T1.getPath().toImmNT();
    } else {
        T2 = TypeManipulation.fwd(T1);
    }
    TOut innerT = type(in.withE(s.getInner(), T2));
    if (!innerT.isOk()) {
        return innerT.toError();
    }
    TOk res = innerT.toOk();
    Type T3 = res.computed;
    if (s.getKind() == SignalKind.Return) {
        res = res.returnsAdd(T3);
    }
    if (s.getKind() == SignalKind.Exception) {
        res = res.exceptionsAdd(T3.getPath());
    }
    s = s.withInner(res.annotated).withTypeIn(T3).withTypeOut(in.expected);
    return res.withAC(s, in.expected);
}
Also used : Type(ast.Ast.Type)

Example 10 with Type

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

the class SumMethods method isReplacedParOk.

static boolean isReplacedParOk(int index, MethodType mt1, MethodType mt2) {
    if (mt2.getTs().isEmpty()) {
        return false;
    }
    Type p1 = mt2.getTs().get(index);
    Type r = mt1.getReturnType();
    return p1.equals(r);
}
Also used : Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType)

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