Search in sources :

Example 11 with RoundBlock

use of ast.Expression.RoundBlock 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 12 with RoundBlock

use of ast.Expression.RoundBlock 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 13 with RoundBlock

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

the class DesugarW method withE1CatchExceptionOnVoidE2elseE3.

private static RoundBlock withE1CatchExceptionOnVoidE2elseE3(Position pos, Expression e1, Expression e2, Expression e3) {
    Expression.Catch k = Desugar.getK(pos, SignalKind.Exception, "", Type.immVoid, e2);
    List<Expression.BlockContent> cs = new ArrayList<>();
    cs.add(Desugar.getBlockContent(e1, k));
    return new RoundBlock(pos, Doc.empty(), e3, cs);
}
Also used : Expression(ast.Expression) ArrayList(java.util.ArrayList) BlockContent(ast.Expression.BlockContent) RoundBlock(ast.Expression.RoundBlock) Catch(ast.Expression.Catch)

Example 14 with RoundBlock

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

the class Desugar method blockEtoXE.

private RoundBlock blockEtoXE(RoundBlock s) {
    if (s.getContents().isEmpty()) {
        return s;
    }
    List<VarDec> decs = s.getContents().get(0).getDecs();
    List<VarDec> newDecs = new ArrayList<VarDec>();
    for (VarDec _dec : decs) {
        if (!(_dec instanceof VarDecE)) {
            newDecs.add(_dec);
            continue;
        }
        VarDecE dec = (VarDecE) _dec;
        String x = Functions.freshName("unused", usedVars);
        //usedVars.add(x);
        VarDecXE newXE = new VarDecXE(false, Optional.of(Type.immVoid), x, dec.getInner());
        newDecs.add(newXE);
    }
    RoundBlock result = blockWithDec(s, newDecs);
    //assert L42.checkWellFormedness(result);
    return result;
}
Also used : VarDec(ast.Ast.VarDec) ArrayList(java.util.ArrayList) RoundBlock(ast.Expression.RoundBlock) VarDecE(ast.Ast.VarDecE) VarDecXE(ast.Ast.VarDecXE)

Example 15 with RoundBlock

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

the class Desugar method getBlock.

static RoundBlock getBlock(Position p, Expression xe, Expression inner) {
    List<Expression.BlockContent> bc = new ArrayList<>();
    List<VarDec> decs = new ArrayList<VarDec>();
    decs.add(new VarDecE(xe));
    bc.add(new Expression.BlockContent(decs, Collections.emptyList()));
    return new RoundBlock(p, Doc.empty(), inner, bc);
}
Also used : Expression(ast.Expression) VarDec(ast.Ast.VarDec) ArrayList(java.util.ArrayList) RoundBlock(ast.Expression.RoundBlock) VarDecE(ast.Ast.VarDecE)

Aggregations

RoundBlock (ast.Expression.RoundBlock)15 Expression (ast.Expression)12 ArrayList (java.util.ArrayList)12 VarDec (ast.Ast.VarDec)9 BlockContent (ast.Expression.BlockContent)7 VarDecXE (ast.Ast.VarDecXE)6 Catch (ast.Expression.Catch)6 VarDecE (ast.Ast.VarDecE)5 X (ast.Expression.X)5 Type (ast.Ast.Type)3 MethodWithType (ast.Expression.ClassB.MethodWithType)3 Loop (ast.Expression.Loop)2 MethodSelectorX (ast.Ast.MethodSelectorX)1 MethodType (ast.Ast.MethodType)1 Position (ast.Ast.Position)1 VarDecCE (ast.Ast.VarDecCE)1 CurlyBlock (ast.Expression.CurlyBlock)1 Signal (ast.Expression.Signal)1