Search in sources :

Example 1 with RoundBlock

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

the class Desugar method visit.

public Expression visit(While s) {
    Expression cond = Desugar.getMCall(s.getP(), s.getCond(), "#checkTrue", Desugar.getPs());
    RoundBlock b = Desugar.getBlock(s.getP(), cond, s.getThen());
    Loop l = new Loop(b);
    Type _void = Type.immVoid;
    Expression.Catch k = Desugar.getK(s.getP(), SignalKind.Exception, "", _void, Expression._void.instance);
    RoundBlock b2 = Desugar.getBlock(s.getP(), l, Collections.singletonList(k), Expression._void.instance);
    return b2.accept(this);
}
Also used : Loop(ast.Expression.Loop) Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) MethodType(ast.Ast.MethodType) Expression(ast.Expression) RoundBlock(ast.Expression.RoundBlock) Catch(ast.Expression.Catch)

Example 2 with RoundBlock

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

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

the class DesugarW method withDeclareIts.

private RoundBlock withDeclareIts(List<VarDecXE> is, RoundBlock inner) {
    if (is.isEmpty()) {
        return inner;
    }
    VarDecXE i0 = is.get(0);
    List<VarDecXE> is2 = is.subList(1, is.size());
    List<VarDec> decs = new ArrayList<VarDec>();
    decs.add(i0.withVar(false));
    RoundBlock conclusive = withDeclareItsNestedBlock(inner, i0, is2);
    return Desugar.getBlock(inner.getP(), decs, conclusive);
}
Also used : VarDec(ast.Ast.VarDec) ArrayList(java.util.ArrayList) RoundBlock(ast.Expression.RoundBlock) VarDecXE(ast.Ast.VarDecXE)

Example 4 with RoundBlock

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

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

the class DesugarVars method getFakeBlock.

private RoundBlock getFakeBlock(X x, X z, RoundBlock s, List<VarDec> varDecs, int d3First) {
    Position pos = Desugar.getPosition(s);
    List<Expression.BlockContent> fakeContent = new ArrayList<>();
    List<VarDec> fakeDecs = new ArrayList<VarDec>();
    if (d3First != -1) {
        //d3 not empty
        fakeDecs.addAll(varDecs.subList(d3First, varDecs.size()));
    }
    fakeContent.add(new Expression.BlockContent(fakeDecs, s.getContents().get(0).get_catch()));
    RoundBlock fake = s.withContents(fakeContent);
    fake = (RoundBlock) XEqOpInZEqOp.of(x, z, fake);
    fake = (RoundBlock) XInE.of(x, Desugar.getMCall(pos, z, "#inner", Desugar.getPs()), fake);
    return fake;
}
Also used : Position(ast.Ast.Position) Expression(ast.Expression) VarDec(ast.Ast.VarDec) ArrayList(java.util.ArrayList) BlockContent(ast.Expression.BlockContent) RoundBlock(ast.Expression.RoundBlock) BlockContent(ast.Expression.BlockContent)

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