Search in sources :

Example 1 with VarDecE

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

the class Desugar method visit1Step.

public MCall visit1Step(SquareCall s) {
    //we can assumethe receivers are normalized after DesugarContext
    //assert s.getReceiver() instanceof Ast.Atom:      s.getReceiver();
    //but nor really, since vars accesses are replaced by meth calls. In that case is fine to not have an atom.
    //(b=r.builder() b.a() b.b() b.c() .... b)
    List<VarDec> vd = new ArrayList<>();
    Expression k = getMCall(s.getP(), s.getReceiver(), "#seqBuilder", getPs());
    String x = Functions.freshName("b", usedVars);
    X b = new X(s.getP(), x);
    vd.add(new VarDecXE(false, Optional.empty(), x, k));
    for (Parameters ps : s.getPss()) {
        vd.add(new VarDecE(getMCall(s.getP(), b, "#add", ps)));
    }
    Expression inner = getBlock(s.getP(), vd, b);
    Parameters ps = new Parameters(Optional.empty(), Collections.singletonList("seqBuilder"), Collections.singletonList(inner));
    return getMCall(s.getP(), s.getReceiver(), "#from", ps);
}
Also used : Parameters(ast.Ast.Parameters) Expression(ast.Expression) VarDec(ast.Ast.VarDec) ArrayList(java.util.ArrayList) X(ast.Expression.X) MethodSelectorX(ast.Ast.MethodSelectorX) VarDecE(ast.Ast.VarDecE) VarDecXE(ast.Ast.VarDecXE)

Example 2 with VarDecE

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

the class DesugarW method visit.

public Expression visit(SquareWithCall s) {
    //we can assumethe receivers are normalized after DesugarContext
    assert s.getReceiver() instanceof Ast.Atom : s;
    //(b=r.builder() b.a() b.b() b.c() .... b)
    List<VarDec> vd = new ArrayList<>();
    Expression k = Desugar.getMCall(s.getP(), s.getReceiver(), "#seqBuilder", Desugar.getPs());
    String x = Functions.freshName("b", usedVars);
    X b = new X(s.getP(), x);
    vd.add(new VarDecXE(false, Optional.empty(), x, k));
    Expression ew = s.getWith().accept(this);
    ew = ew.accept(new CloneVisitor() {

        @Override
        public Expression visit(Expression.UseSquare u) {
            SquareCall sq = (SquareCall) u.getInner();
            //inner, hide external one to prevent use (was a bug before)
            List<VarDec> vd = new ArrayList<>();
            for (Parameters ps : sq.getPss()) {
                vd.add(new VarDecE(Desugar.getMCall(s.getP(), b, "#add", ps)));
            }
            return Desugar.getBlock(s.getP(), vd, Expression._void.instance);
        }
    });
    vd.add(new VarDecE(ew));
    Expression inner = Desugar.getBlock(s.getP(), vd, b);
    Parameters ps = new Parameters(Optional.empty(), Collections.singletonList("seqBuilder"), Collections.singletonList(inner));
    return Desugar.getMCall(s.getP(), s.getReceiver(), "#from", ps);
}
Also used : Parameters(ast.Ast.Parameters) ArrayList(java.util.ArrayList) VarDecE(ast.Ast.VarDecE) Expression(ast.Expression) VarDec(ast.Ast.VarDec) X(ast.Expression.X) SquareCall(ast.Expression.SquareCall) VarDecXE(ast.Ast.VarDecXE)

Example 3 with VarDecE

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

the class DesugarW method withNext.

private static Expression.BlockContent withNext(Position pos, int index, List<String> xs) {
    Expression eStart = Desugar.getMCall(pos, new X(pos, xs.get(index)), "#next", Desugar.getPs());
    List<VarDec> decs = new ArrayList<>();
    for (String x : xs.subList(index + 1, xs.size())) {
        Expression ei = Desugar.getMCall(pos, new X(pos, x), "#next", Desugar.getPs());
        ei = withE1CatchExceptionOnVoidE2elseE3(pos, ei, Expression._void.instance, Expression._void.instance);
        decs.add(new VarDecE(ei));
    }
    for (String x : xs) {
        Expression ei = Desugar.getMCall(pos, new X(pos, x), "#checkEnd", Desugar.getPs());
        ei = withE1CatchExceptionOnVoidE2elseE3(pos, ei, Expression._void.instance, Expression._void.instance);
        decs.add(new VarDecE(ei));
    }
    Expression eCatch = Desugar.getBlock(pos, decs, new Signal(SignalKind.Exception, Expression._void.instance));
    Expression.Catch k = Desugar.getK(pos, SignalKind.Exception, "", Type.immVoid, eCatch);
    return Desugar.getBlockContent(eStart, k);
}
Also used : Signal(ast.Expression.Signal) Expression(ast.Expression) VarDec(ast.Ast.VarDec) X(ast.Expression.X) ArrayList(java.util.ArrayList) VarDecE(ast.Ast.VarDecE) Catch(ast.Expression.Catch)

Example 4 with VarDecE

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

the class Desugar method getBlockContent.

public static Expression.BlockContent getBlockContent(Expression e, Expression.Catch k) {
    List<VarDec> single = new ArrayList<VarDec>();
    single.add(new VarDecE(e));
    return new Expression.BlockContent(single, Collections.singletonList(k));
}
Also used : VarDec(ast.Ast.VarDec) ArrayList(java.util.ArrayList) VarDecE(ast.Ast.VarDecE)

Example 5 with VarDecE

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

the class Desugar method getBlock.

static RoundBlock getBlock(Position p, Expression xe, List<Expression.Catch> ks, 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, ks));
    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

VarDecE (ast.Ast.VarDecE)12 VarDec (ast.Ast.VarDec)10 ArrayList (java.util.ArrayList)10 Expression (ast.Expression)9 RoundBlock (ast.Expression.RoundBlock)5 X (ast.Expression.X)5 VarDecXE (ast.Ast.VarDecXE)4 MethodSelectorX (ast.Ast.MethodSelectorX)3 Parameters (ast.Ast.Parameters)3 Catch (ast.Expression.Catch)2 BlockContent (ast.Expression.BlockContent)1 CurlyBlock (ast.Expression.CurlyBlock)1 Signal (ast.Expression.Signal)1 SquareCall (ast.Expression.SquareCall)1 With (ast.Expression.With)1 On (ast.Expression.With.On)1