Search in sources :

Example 6 with Block

use of ast.ExpCore.Block in project L42 by ElvisResearchGroup.

the class Executor method subst.

public static ExpCore subst(ExpCore ctxVal, Redex.Subst r) {
    Block e1 = r.getThat();
    int i = r.getSubstIndex();
    ExpCore val = e1.getDecs().get(i).getInner();
    String x = e1.getDecs().get(i).getX();
    ArrayList<Block.Dec> decs = new ArrayList<Block.Dec>(e1.getDecs());
    decs.remove(i);
    Block e2 = new Block(e1.getDoc(), decs, e1.getInner(), e1.getOns(), e1.getP());
    ExpCore result = ReplaceX.of(e2, val, x);
    return ReplaceCtx.of(ctxVal, result);
}
Also used : ExpCore(ast.ExpCore) Dec(ast.ExpCore.Block.Dec) ArrayList(java.util.ArrayList) Block(ast.ExpCore.Block)

Example 7 with Block

use of ast.ExpCore.Block in project L42 by ElvisResearchGroup.

the class TsBlock method tsBlockBase.

default default TOut tsBlockBase(TIn in, Block s) {
    //Phase| p| G |- (ds  ks  e0  [_]) ~>(ds' ks' e'0 [T]) 
    //     : T <= T' | Tr'.capture(p,ks') U Tr U Tr0
    List<Block.Dec> ds = s.getDecs();
    List<Block.On> ks = s.getOns();
    //G'=G/dom(ds)
    TIn in1 = in.removeGDs(ds);
    //G'[ks]
    TIn in2 = in1.gKs(ks);
    //Phase| p| G'[ks] |- ds ~> ds' |Tr' | G0
    TOutDs _dsOut = dsType(in2, ds);
    if (!_dsOut.isOk()) {
        TErr err = _dsOut.toError();
        if (!err.kind.needContext) {
            return err;
        }
        //was locked by error safety[cite the line number of the catch]
        return err;
    }
    TOkDs dsOk = _dsOut.toOkDs();
    //Phase| p| G'| Tr' |- ks~> ks' : Ts <= T' | Tr
    TOutKs _ksOut = ksType(in1, dsOk.trAcc, ks);
    if (!_ksOut.isOk()) {
        return _ksOut.toError();
    }
    TOkKs ksOk = _ksOut.toOkKs();
    //now resolved
    ks = ksOk.ks;
    //Phase| p| G'[G0\dom(G')] |- e0~>e'0:T0 <=T' | Tr0
    G G0LessG1 = dsOk.g.removeGXs(in1.g.keySet());
    TOut _e0Out = type(in1.addGG(G0LessG1).withE(s.getE(), in.expected));
    if (!_e0Out.isOk()) {
        return _e0Out.toError();
    }
    TOk e0Ok = _e0Out.toOk();
    //T= mostGeneralMdf({T0.mdf,Ts.mdfs}) T'.P //set of Mdfs admits no single most general mdf
    Set<Mdf> mdfs = new HashSet<>();
    for (Type nt : ksOk.ts) {
        mdfs.add(nt.getMdf());
    }
    mdfs.add(e0Ok.computed.getMdf());
    Mdf tMdf = TypeManipulation._mostGeneralMdf(mdfs);
    if (tMdf == null) {
        return new TErr(in, "", e0Ok.computed, ErrorKind.NoMostGeneralMdf);
    }
    Type t = new Type(tMdf, in.expected.getPath(), Doc.empty());
    assert null == TypeSystem.subtype(in.p, t, in.expected);
    Block annotated = new Block(s.getDoc(), dsOk.ds, e0Ok.annotated, ksOk.ks, s.getP());
    TOk res = new TOk(in, annotated, t);
    // result Tr: Tr'.capture(p,ks') U Tr U Tr0
    Tr trCaptured = dsOk.trAcc;
    for (On k : ks) {
        trCaptured = trCaptured.trCapture(in.p, k);
    }
    Tr trUnion = trCaptured.trUnion(ksOk.trAcc).trUnion(e0Ok);
    res = res.trUnion(trUnion);
    return res;
}
Also used : Dec(ast.ExpCore.Block.Dec) Mdf(ast.Ast.Mdf) Type(ast.Ast.Type) Block(ast.ExpCore.Block) On(ast.ExpCore.Block.On) HashSet(java.util.HashSet)

Example 8 with Block

use of ast.ExpCore.Block in project L42 by ElvisResearchGroup.

the class ExtractCtxUpToX method visit.

public Ctx<Block> visit(Block s) {
    int xPos = s.domDecs().indexOf(x);
    if (xPos != -1 && IsCtx.of(s)) {
        return new Ctx<Block>(new WalkBy(), s);
    }
    List<Block.Dec> newDecs = new ArrayList<Block.Dec>();
    Ctx<Block> res = null;
    for (Block.Dec dec : s.getDecs()) {
        if (!IsCtx.of(dec.getInner())) {
            newDecs.add(dec);
            continue;
        }
        res = dec.getInner().accept(this);
        newDecs.add(dec.withInner(res.ctx));
    }
    if (res != null) {
        res.ctx = s.withDecs(newDecs);
        return res;
    }
    assert IsCtx.of(s.getInner());
    assert s.getOns().isEmpty();
    res = s.getInner().accept(this);
    res.ctx = s.withInner(res.ctx);
    return res;
}
Also used : Ctx(auxiliaryGrammar.Ctx) ArrayList(java.util.ArrayList) Block(ast.ExpCore.Block) WalkBy(ast.ExpCore.WalkBy)

Example 9 with Block

use of ast.ExpCore.Block in project L42 by ElvisResearchGroup.

the class PlgWrapperGenerator method updateTemplateUsing.

private static MethodWithType updateTemplateUsing(UsingInfo ui, MethodWithType mwt) {
    MCall e = templateUsingExc;
    MethodType mt = mwt.getMt();
    ExpCore.Block b = (Block) e.getEs().get(0);
    if (mwt.getMt().getExceptions().isEmpty()) {
        b = b.withOns(Collections.emptyList());
    }
    ExpCore.Using u = (Using) b.getDecs().get(0).getInner();
    //parameter expressions
    ExpCore.MCall p0 = (MCall) u.getEs().get(0);
    //e#mcall.inner<-mwt.retType.path
    e = e.withInner(ExpCore.EPath.wrap(mt.getReturnType().getPath()));
    //u=u.withS(ui.usingMs);
    List<ExpCore> ues = new ArrayList<>();
    if (mt.getMdf() != Mdf.Class) {
        ues.add(p0.withInner(new ExpCore.X(mwt.getP(), "this")));
    }
    {
        int i = -1;
        for (String x : mwt.getMs().getNames()) {
            i++;
            ExpCore pi = new ExpCore.X(mwt.getP(), x);
            boolean needAddBinaryRepr = true;
            Type ti = mwt.getMt().getTs().get(i);
            if (ti.equals(Type.immLibrary)) {
                needAddBinaryRepr = false;
            }
            if (ti.getMdf() == Mdf.Class) {
                needAddBinaryRepr = false;
            }
            if (needAddBinaryRepr) {
                pi = p0.withInner(pi);
            }
            ues.add(pi);
        }
    }
    u = new Using(u.getPath(), ui.usingMs, u.getDoc(), ues, u.getInner());
    String errorS = "plugin string: " + ui.plgInfo.plgString + "\n" + "plugin part: " + ui.plgInfo.plgName + "\n" + "method name: " + mwt.getMs() + "\n" + "java method: " + ui.plgInfo.plgClass.getName() + "." + ui.usingMs + "\n";
    //u.inner#mcall.es(0)<-EncodingHelper.wrapStringU()
    List<ExpCore> errorEs = Collections.singletonList(EncodingHelper.wrapStringU(errorS));
    Signal tmpS = (Signal) u.getInner();
    MCall tmpMc = ((MCall) tmpS.getInner()).withEs(errorEs);
    u = u.withInner(tmpS.withInner(tmpMc));
    b = b.withDecs(Collections.singletonList(b.getDecs().get(0).withInner(u)));
    //--
    if (!mwt.getMt().getExceptions().isEmpty()) {
        On on = b.getOns().get(0);
        Dec k0 = ((Block) on.getInner()).getDecs().get(0);
        List<Dec> ks = new ArrayList<>();
        {
            int i = -1;
            for (Type ti : mt.getExceptions()) {
                i++;
                MCall mci = ((MCall) k0.getInner()).withInner(ExpCore.EPath.wrap(ti.getPath()));
                ks.add(k0.withInner(mci).withX(k0.getX() + i));
            }
        }
        on = on.withInner(((Block) on.getInner()).withDecs(ks));
        b = b.withOns(Collections.singletonList(on));
    //k0=b.k(0).inner#block.decs(0)
    //k0 add more on need
    //ki.inner#mcall.inner<-Pi
    }
    if (ui.isVoid) {
        b = b.withDecs(Collections.singletonList(b.getDecs().get(0).withT(Optional.of(Type.immVoid))));
    }
    if (!ui.isVoid && !mwt.getMt().getReturnType().equals(Type.immLibrary)) {
        e = e.withEs(Collections.singletonList(b));
        mwt = mwt.withInner(e);
    } else {
        mwt = mwt.withInner(b);
    }
    return mwt;
}
Also used : MethodType(ast.Ast.MethodType) ExpCore(ast.ExpCore) Block(ast.ExpCore.Block) Dec(ast.ExpCore.Block.Dec) Using(ast.ExpCore.Using) ArrayList(java.util.ArrayList) Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Signal(ast.ExpCore.Signal) Using(ast.ExpCore.Using) MCall(ast.ExpCore.MCall) Block(ast.ExpCore.Block) MCall(ast.ExpCore.MCall) On(ast.ExpCore.Block.On)

Example 10 with Block

use of ast.ExpCore.Block in project L42 by ElvisResearchGroup.

the class MethodPathCloneVisitor method visit.

public ExpCore visit(Block s) {
    HashMap<String, Ast.Type> aux = new HashMap<>(this.varEnv);
    try {
        for (Dec d : s.getDecs()) {
            if (d.getT().isPresent()) {
                this.varEnv.put(d.getX(), d.getT().get());
            }
        //TODO:??? GuessTypeCore._of(this.varEnv,d.getInner());
        }
        List<Dec> newDecs = liftDecs(s.getDecs());
        List<On> newOns = new ArrayList<>();
        for (On on : s.getOns()) {
            this.varEnv.put(on.getX(), on.getT());
            newOns.add(liftO(on));
            this.varEnv.remove(on.getX());
        }
        return new Block(s.getDoc(), newDecs, lift(s.getInner()), newOns, s.getP());
    } finally {
        this.varEnv = aux;
    }
}
Also used : Type(ast.Ast.Type) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Dec(ast.ExpCore.Block.Dec) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Block(ast.ExpCore.Block) On(ast.ExpCore.Block.On)

Aggregations

Block (ast.ExpCore.Block)11 ArrayList (java.util.ArrayList)7 ExpCore (ast.ExpCore)6 Dec (ast.ExpCore.Block.Dec)5 On (ast.ExpCore.Block.On)5 Type (ast.Ast.Type)4 WalkBy (ast.ExpCore.WalkBy)4 MethodType (ast.Ast.MethodType)2 MethodWithType (ast.ExpCore.ClassB.MethodWithType)2 Signal (ast.ExpCore.Signal)2 Ctx (auxiliaryGrammar.Ctx)2 Ast (ast.Ast)1 Doc (ast.Ast.Doc)1 Mdf (ast.Ast.Mdf)1 SignalKind (ast.Ast.SignalKind)1 MCall (ast.ExpCore.MCall)1 Using (ast.ExpCore.Using)1 Expression (ast.Expression)1 Catch (ast.Expression.Catch)1 Redex (ast.Redex)1