Search in sources :

Example 1 with X

use of ast.Expression.X 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 X

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

the class DesugarW method castT.

private VarDecXE castT(Position pos, Type t, String y, String x) {
    assert t instanceof Type;
    Type nt = t;
    String z = Functions.freshName("casted", usedVars);
    List<Catch> ks = new ArrayList<>();
    Type t2 = new Type(nt.getMdf(), Path.Any(), Doc.empty());
    ks.add(new //case return captured
    Expression.Catch1(//case return captured
    pos, //case return captured
    SignalKind.Return, //case return captured
    t, //case return captured
    z, //return it
    new X(pos, z)));
    ks.add(new //else
    Expression.Catch1(//else
    pos, //else
    SignalKind.Return, //else
    t2, //else
    z, // exception void
    new Signal(SignalKind.Exception, Expression._void.instance)));
    RoundBlock block = Desugar.getBlock(pos, new Signal(SignalKind.Return, new X(pos, x)), ks, Desugar.errorMsg("CastT-Should be unreachable code"));
    return new VarDecXE(false, Optional.of(t), y, block);
}
Also used : Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) Signal(ast.Expression.Signal) Expression(ast.Expression) Catch(ast.Expression.Catch) ArrayList(java.util.ArrayList) X(ast.Expression.X) RoundBlock(ast.Expression.RoundBlock) VarDecXE(ast.Ast.VarDecXE)

Example 3 with X

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

the class DesugarW method withDesugarGetDefaultCatch.

private Catch withDesugarGetDefaultCatch(Position pos, SignalKind kind, Expression eClose) {
    String propagated1 = Functions.freshName("propagated", usedVars);
    Expression blockPropagate1 = Desugar.getBlock(pos, eClose, new Signal(kind, new X(pos, propagated1)));
    Type t = Type.immAny;
    Expression.Catch1 k1 = new Expression.Catch1(pos, kind, t, propagated1, blockPropagate1);
    return new DesugarCatchDefault.CatchToComplete(k1);
}
Also used : Signal(ast.Expression.Signal) Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) Expression(ast.Expression) Catch1(ast.Expression.Catch1) X(ast.Expression.X) Catch1(ast.Expression.Catch1)

Example 4 with X

use of ast.Expression.X 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 5 with X

use of ast.Expression.X 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)

Aggregations

Expression (ast.Expression)15 X (ast.Expression.X)15 ArrayList (java.util.ArrayList)10 VarDecXE (ast.Ast.VarDecXE)7 Catch (ast.Expression.Catch)7 MethodSelectorX (ast.Ast.MethodSelectorX)6 Type (ast.Ast.Type)6 VarDec (ast.Ast.VarDec)6 MethodWithType (ast.Expression.ClassB.MethodWithType)6 Parameters (ast.Ast.Parameters)5 VarDecE (ast.Ast.VarDecE)5 RoundBlock (ast.Expression.RoundBlock)5 BlockContent (ast.Expression.BlockContent)3 MCall (ast.Expression.MCall)3 Signal (ast.Expression.Signal)3 MethodType (ast.Ast.MethodType)2 Position (ast.Ast.Position)2 Catch1 (ast.Expression.Catch1)2 FieldDec (ast.Ast.FieldDec)1 MethodSelector (ast.Ast.MethodSelector)1