Search in sources :

Example 51 with Type

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

the class AlternativeMethodTypes method _mRead.

static MethodType _mRead(MethodType mt) {
    //mutToCapsuleAndFwdToRead(Ts)->read P0;Ps in methTypes(p,P,ms)
    if (!TypeManipulation.fwd_or_fwdP_in(mt.getTs())) {
        return null;
    }
    Type retT = mt.getReturnType();
    if (retT.getMdf() != Mdf.MutablePFwd) {
        return null;
    }
    retT = retT.withMdf(Mdf.Readable);
    List<Type> ts = Map.of(t -> mutToCapsuleAndFwdToRead(t), mt.getTs());
    MethodType res = mt.withReturnType(retT).withTs(ts).withMdf(mutToCapsuleAndFwdToRead(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 52 with Type

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

the class InjectionOnSugar method visit.

@Override
public Expression visit(Block s) {
    Doc docs = s.getDoc();
    Expression inner = lift(s.getInner());
    List<VarDec> decs = new ArrayList<VarDec>();
    for (int i = 0; i < s.getDecs().size(); i++) {
        Optional<Type> t = s.getDecs().get(i).getT();
        String x = s.getDecs().get(i).getX();
        Expression e = lift(s.getDecs().get(i).getInner());
        decs.add(new VarDecXE(s.getDecs().get(i).isVar(), t, x, e));
    }
    List<Expression.Catch> _catch = injectionCatch(s.getOns());
    List<Expression.BlockContent> contents = new ArrayList<>();
    if (!decs.isEmpty() || !_catch.isEmpty()) {
        contents.add(new Expression.BlockContent(decs, _catch));
    }
    Expression.Position pos = s.getP();
    Expression.RoundBlock result = new Expression.RoundBlock(pos, docs, inner, contents);
    //assert WellFormedness.blockCheck(result);, no it can actually get wrong?
    return result;
}
Also used : ArrayList(java.util.ArrayList) Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) Expression(ast.Expression) VarDec(ast.Ast.VarDec) Doc(ast.Ast.Doc) VarDecXE(ast.Ast.VarDecXE)

Example 53 with Type

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

the class Desugar method generateExposer.

//left cfExposer generating exposer since is different from generateExposer code for # and capsule
/*static private void cfExposer(Expression.Position pos,FieldDec f,Doc doc, List<Member> result) {
    NormType tt=f.getT().match(nt->Functions.toComplete(nt), hType->hType);
    MethodType mti=new MethodType(false,Mdf.Mutable,Collections.emptyList(),tt,Collections.emptyList());
    MethodSelector msi=MethodSelector.of("#"+f.getName(),Collections.emptyList());
    result.add(new MethodWithType(doc, msi, mti, Optional.empty(),pos));
  }*/
private static MethodWithType generateExposer(Expression.Position pos, FieldDec f, Doc doc) {
    Type tt = TypeManipulation.noFwd(f.getT());
    if (tt.getMdf() == Mdf.Capsule) {
        tt = tt.withMdf(Mdf.Lent);
    }
    MethodType mti = new MethodType(false, Mdf.Mutable, Collections.emptyList(), tt, Collections.emptyList());
    MethodSelector msi = MethodSelector.of("#" + f.getName(), Collections.emptyList());
    MethodWithType mwt = new MethodWithType(doc, msi, mti, Optional.empty(), pos);
    return mwt;
}
Also used : MethodType(ast.Ast.MethodType) Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) MethodType(ast.Ast.MethodType) MethodSelector(ast.Ast.MethodSelector) MethodWithType(ast.Expression.ClassB.MethodWithType)

Example 54 with Type

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

the class Desugar method liftKs.

protected List<Catch> liftKs(List<Catch> ks) {
    List<Catch> result = new ArrayList<>();
    String x = Functions.freshName("catched", usedVars);
    for (Catch k : ks) {
        if (k instanceof DesugarCatchDefault.CatchToComplete) {
            Catch k2 = this.liftK(((DesugarCatchDefault.CatchToComplete) k).catch1);
            result.add(new DesugarCatchDefault.CatchToComplete((Catch1) k2));
            continue;
        }
        k.match(k1 -> result.add(liftK(k1)), kM -> {
            for (Type t : kM.getTs()) {
                result.add(liftK(new Expression.Catch1(kM.getP(), kM.getKind(), t, x, kM.getInner())));
            }
            return false;
        }, kP -> {
            for (Type t : kP.getTs()) {
                Expression inner = kP.getInner();
                inner = new Expression.FCall(kP.getP(), inner, Doc.empty(), new ast.Ast.Parameters(Optional.of(new X(kP.getP(), x)), Collections.emptyList(), Collections.emptyList()));
                inner = new Expression.Signal(kP.getKind(), inner);
                result.add(liftK(new Expression.Catch1(kP.getP(), SignalKind.Exception, t, x, inner)));
            }
            return false;
        });
    }
    return result;
}
Also used : Parameters(ast.Ast.Parameters) Catch(ast.Expression.Catch) ArrayList(java.util.ArrayList) Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) MethodType(ast.Ast.MethodType) Expression(ast.Expression) Catch1(ast.Expression.Catch1) FCall(ast.Expression.FCall) X(ast.Expression.X) MethodSelectorX(ast.Ast.MethodSelectorX)

Example 55 with Type

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

the class Desugar method visit.

public Expression visit(Using s) {
    Type aux = this.t;
    this.t = Type.immVoid;
    Parameters ps = liftPs(s.getPs());
    this.t = aux;
    return new Using(liftP(s.getPath()), s.getName(), s.getDocs(), ps, lift(s.getInner()));
}
Also used : Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) MethodType(ast.Ast.MethodType) Parameters(ast.Ast.Parameters) Using(ast.Expression.Using)

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