Search in sources :

Example 1 with BlockContent

use of ast.Expression.BlockContent in project L42 by ElvisResearchGroup.

the class DesugarW method with_E_handleIs.

private Expression with_E_handleIs(Position pos, List<VarDecXE> is, Expression b) {
    //case e in 6 pages
    //xs is dom(Is)
    List<String> xs = new ArrayList<>();
    for (VarDecXE i : is) {
        xs.add(i.getX());
    }
    //di ki is block content =nexti(xs)
    List<BlockContent> bc = new ArrayList<>();
    for (int i = 0; i < xs.size(); i++) {
        bc.add(withNext(pos, i, xs));
    }
    //inner =di ki s b[xs:=xs.#inner()]
    for (String xi : xs) {
        b = XInE.of(new X(pos, xi), Desugar.getMCall(pos, new X(pos, xi), "#inner", Desugar.getPs()), b);
    }
    RoundBlock inner = new RoundBlock(pos, Doc.empty(), b, bc);
    Catch k = Desugar.getK(pos, SignalKind.Exception, "", Type.immVoid, Expression._void.instance);
    inner = Desugar.getBlock(pos, new Loop(inner), Collections.singletonList(k), Expression._void.instance);
    Expression result = withDeclareIts(is, inner);
    //accept
    return result;
}
Also used : Loop(ast.Expression.Loop) Expression(ast.Expression) Catch(ast.Expression.Catch) ArrayList(java.util.ArrayList) BlockContent(ast.Expression.BlockContent) X(ast.Expression.X) RoundBlock(ast.Expression.RoundBlock) VarDecXE(ast.Ast.VarDecXE)

Example 2 with BlockContent

use of ast.Expression.BlockContent in project L42 by ElvisResearchGroup.

the class DesugarCatchDefault method liftBC.

protected BlockContent liftBC(BlockContent c) {
    if (c.get_catch().isEmpty()) {
        return super.liftBC(c);
    }
    List<Catch> ks = Map.of(this::liftK, c.get_catch());
    Type oldR = this.lastReturn;
    this.lastReturn = newR(ks);
    try {
        List<VarDec> liftVarDecs = liftVarDecs(c.getDecs());
        return new BlockContent(liftVarDecs, ks);
    } finally {
        this.lastReturn = oldR;
    }
}
Also used : Type(ast.Ast.Type) Catch(ast.Expression.Catch) VarDec(ast.Ast.VarDec) BlockContent(ast.Expression.BlockContent)

Example 3 with BlockContent

use of ast.Expression.BlockContent in project L42 by ElvisResearchGroup.

the class DesugarVars method visit.

public Expression visit(CurlyBlock s) {
    Expression inner;
    if (s.getContents().size() == 1 && s.getContents().get(0).get_catch().isEmpty() && s.getContents().get(0).getDecs().size() == 1 && s.getContents().get(0).getDecs().get(0) instanceof VarDecE) {
        inner = ((VarDecE) s.getContents().get(0).getDecs().get(0)).getInner();
    } else {
        inner = new RoundBlock(s.getP(), s.getDoc(), Expression._void.instance, s.getContents());
    }
    inner = inner.accept(this);
    List<VarDec> vd = Collections.singletonList((VarDec) new VarDecE(inner));
    BlockContent o = new BlockContent(vd, Collections.emptyList());
    return new CurlyBlock(s.getP(), Doc.empty(), Collections.singletonList(o));
}
Also used : Expression(ast.Expression) CurlyBlock(ast.Expression.CurlyBlock) VarDec(ast.Ast.VarDec) BlockContent(ast.Expression.BlockContent) RoundBlock(ast.Expression.RoundBlock) VarDecE(ast.Ast.VarDecE)

Example 4 with BlockContent

use of ast.Expression.BlockContent in project L42 by ElvisResearchGroup.

the class DesugarW method with_C_A.

private Expression with_C_A(Position pos, List<String> xs, With.On on0, Expression continuation) {
    List<String> ys = new ArrayList<String>();
    for (String x : xs) {
        ys.add(Functions.freshName(x, usedVars));
    }
    //(
    List<VarDec> decs = new ArrayList<>();
    //TODO:?? now is very strange and requires the mdf to propagate it to the locally introduced var?
    //casts: every cast is a block content e+catch
    {
        int i = -1;
        for (Type ti : on0.getTs()) {
            i += 1;
            String xi = xs.get(i);
            String yi = ys.get(i);
            decs.add(castT(pos, ti, yi, xi));
        }
    }
    //catch exception Void recursive call
    Catch k = Desugar.getK(pos, SignalKind.Exception, "", Type.immVoid, continuation);
    //main expression with 'T' renaming
    Expression e0 = on0.getInner();
    {
        int i = -1;
        for (Type ti : on0.getTs()) {
            i += 1;
            String xi = xs.get(i);
            String yi = ys.get(i);
            e0 = renameT(e0, new Expression.X(pos, xi), ti, new Expression.X(pos, yi));
        }
    }
    BlockContent content = new BlockContent(decs, Collections.singletonList(k));
    List<BlockContent> contents = new ArrayList<BlockContent>();
    contents.add(content);
    contents.add(Desugar.getBlockContent(e0));
    //void)
    return new RoundBlock(pos, Doc.empty(), Expression._void.instance, contents);
}
Also used : Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) Expression(ast.Expression) Catch(ast.Expression.Catch) VarDec(ast.Ast.VarDec) ArrayList(java.util.ArrayList) BlockContent(ast.Expression.BlockContent) RoundBlock(ast.Expression.RoundBlock) X(ast.Expression.X)

Example 5 with BlockContent

use of ast.Expression.BlockContent in project L42 by ElvisResearchGroup.

the class ToAst method visitCurlyBlock.

@Override
public Expression visitCurlyBlock(CurlyBlockContext ctx) {
    Doc doc = parseDoc(ctx.docsOpt());
    List<BlockContent> contents = new ArrayList<BlockContent>();
    for (BbContext b : ctx.bb()) {
        List<VarDec> decs = new ArrayList<VarDec>();
        for (DContext d : b.d()) {
            decs.add(parseVDec(d));
        }
        assert b.ks() != null;
        List<Catch> _catch = parseKs(b.ks());
        contents.add(new BlockContent(decs, _catch));
    }
    return new Expression.CurlyBlock(position(ctx), doc, contents);
}
Also used : Catch(ast.Expression.Catch) VarDec(ast.Ast.VarDec) BlockContent(ast.Expression.BlockContent) Doc(ast.Ast.Doc)

Aggregations

BlockContent (ast.Expression.BlockContent)6 VarDec (ast.Ast.VarDec)5 Catch (ast.Expression.Catch)5 Expression (ast.Expression)4 RoundBlock (ast.Expression.RoundBlock)3 Doc (ast.Ast.Doc)2 Type (ast.Ast.Type)2 X (ast.Expression.X)2 ArrayList (java.util.ArrayList)2 VarDecE (ast.Ast.VarDecE)1 VarDecXE (ast.Ast.VarDecXE)1 MethodWithType (ast.Expression.ClassB.MethodWithType)1 CurlyBlock (ast.Expression.CurlyBlock)1 Loop (ast.Expression.Loop)1