Search in sources :

Example 6 with VarDecE

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

the class Desugar method visit1Step.

public MCall visit1Step(Literal s) {
    //(b=r.builder() b.a() b.b() b.c() .... b)
    List<VarDec> vd = new ArrayList<>();
    Expression k = getMCall(s.getP(), s.getReceiver(), "#builder", getPs());
    String x = Functions.freshName("b", usedVars);
    X b = new X(s.getP(), x);
    vd.add(new VarDecXE(false, Optional.empty(), x, k));
    for (char ch : s.getInner().toCharArray()) {
        String name = Character.toString(ch);
        if (!Character.isAlphabetic(ch) && !Character.isDigit(ch)) {
            name = desugarSymbol(name);
        }
        vd.add(new VarDecE(getMCall(s.getP(), b, "#" + name, getPs())));
    }
    Expression inner = getBlock(s.getP(), vd, b);
    Parameters ps = new Parameters(Optional.empty(), Collections.singletonList("builder"), 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 7 with VarDecE

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

the class Desugar method visit.

public Expression visit(CurlyBlock s) {
    assert s.getContents().size() == 1;
    assert s.getContents().get(0).get_catch().isEmpty();
    assert s.getContents().get(0).getDecs().size() == 1;
    assert s.getContents().get(0).getDecs().get(0) instanceof VarDecE;
    Expression inner = ((VarDecE) s.getContents().get(0).getDecs().get(0)).getInner();
    String y = Functions.freshName("result", this.usedVars);
    Expression.Catch k = getK(s.getP(), SignalKind.Return, y, this.t, new X(s.getP(), y));
    Expression termination = Desugar.errorMsg("CurlyBlock-Should be unreachable code");
    RoundBlock outer = getBlock(s.getP(), inner, Collections.singletonList(k), termination);
    return visit(outer);
}
Also used : Expression(ast.Expression) X(ast.Expression.X) MethodSelectorX(ast.Ast.MethodSelectorX) RoundBlock(ast.Expression.RoundBlock) VarDecE(ast.Ast.VarDecE) Catch(ast.Expression.Catch)

Example 8 with VarDecE

use of ast.Ast.VarDecE 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 9 with VarDecE

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

the class DesugarW method oldWith_noUseKw.

private void oldWith_noUseKw(SquareWithCall s, X xX, List<VarDec> decs) {
    List<With.On> ons = s.getWith().getOns();
    List<With.On> onsPrime = new ArrayList<>();
    for (With.On on : ons) {
        onsPrime.add(on.withInner(withSquareAdd(s.getP(), xX, on.getInner())));
    }
    Optional<Expression> def = s.getWith().getDefaultE();
    Optional<Expression> defPrime = Map.of(e -> withSquareAdd(s.getP(), xX, e), def);
    With w = s.getWith().withOns(onsPrime).withDefaultE(defPrime);
    decs.add(new VarDecE(w));
}
Also used : Expression(ast.Expression) ArrayList(java.util.ArrayList) On(ast.Expression.With.On) VarDecE(ast.Ast.VarDecE) On(ast.Expression.With.On) With(ast.Expression.With)

Example 10 with VarDecE

use of ast.Ast.VarDecE 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)

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