Search in sources :

Example 1 with Signal

use of ast.Expression.Signal 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 2 with Signal

use of ast.Expression.Signal 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 3 with Signal

use of ast.Expression.Signal 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)3 Signal (ast.Expression.Signal)3 X (ast.Expression.X)3 Type (ast.Ast.Type)2 Catch (ast.Expression.Catch)2 MethodWithType (ast.Expression.ClassB.MethodWithType)2 ArrayList (java.util.ArrayList)2 VarDec (ast.Ast.VarDec)1 VarDecE (ast.Ast.VarDecE)1 VarDecXE (ast.Ast.VarDecXE)1 Catch1 (ast.Expression.Catch1)1 RoundBlock (ast.Expression.RoundBlock)1