Search in sources :

Example 1 with SignalKind

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

the class TranslateExpression method getCatches.

private void getCatches(List<On> c, String asReturn, String kLab) {
    assert !c.isEmpty();
    SignalKind kind = c.get(0).getKind();
    boolean allEq = true;
    for (On on : c) {
        if (on.getKind() != kind) {
            allEq = false;
        }
    }
    //TODO: for now ok, then we will capture a more general exception on need.
    assert allEq;
    String kVar = Functions.freshName("K", TranslateExpression.labels);
    res.append("catch(platformSpecific.javaTranslation.Resources." + kind.name() + " " + kVar);
    res.append("){\n");
    for (On on : c) {
        getCatch(kVar, on, asReturn, kLab);
    }
    res.append("{}/*ensure termination*/throw " + kVar);
    res.append(";\n}\n");
}
Also used : SignalKind(ast.Ast.SignalKind) On(ast.ExpCore.Block.On)

Example 2 with SignalKind

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

the class ToAst method visitSignalExpr.

@Override
public Expression visitSignalExpr(SignalExprContext ctx) {
    Expression inner = ctx.eTop().accept(this);
    SignalKind kind = SignalKind.fromString(nameK(ctx.S()));
    return new Expression.Signal(kind, inner);
}
Also used : Expression(ast.Expression) SignalKind(ast.Ast.SignalKind)

Example 3 with SignalKind

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

the class InjectionOnCore method visit.

public ExpCore visit(Expression.RoundBlock s) {
    Doc doc = s.getDoc();
    assert s.getContents().size() <= 1 : s.getContents();
    List<Dec> decs = new ArrayList<Dec>();
    List<ExpCore.Block.On> ons = new ArrayList<ExpCore.Block.On>();
    ExpCore inner = s.getInner().accept(this);
    if (s.getContents().size() == 1) {
        Expression.BlockContent c = s.getContents().get(0);
        for (Ast.VarDec d : c.getDecs()) {
            assert d instanceof Ast.VarDecXE : d;
            Ast.VarDecXE sugarDec = (Ast.VarDecXE) d;
            //assert sugarDec.getT().isPresent() :sugarDec;
            Optional<Type> t = sugarDec.getT();
            String x = sugarDec.getX();
            ExpCore e = sugarDec.getInner().accept(this);
            decs.add(new Dec(sugarDec.isVar(), t, x, e));
        }
        //END FOR DECS
        ;
        for (Catch k : c.get_catch()) {
            assert k instanceof Expression.Catch1;
            Expression.Catch1 k1 = (Expression.Catch1) k;
            SignalKind kind = k1.getKind();
            String x = k1.getX();
            assert x.length() >= 1;
            ons.add(new ExpCore.Block.On(kind, x, k1.getT(), lift(k1.getInner()), k1.getP()));
        }
        return new Block(doc, decs, inner, ons, s.getP());
    }
    return new Block(doc, decs, inner, Collections.emptyList(), s.getP());
}
Also used : ExpCore(ast.ExpCore) Ast(ast.Ast) Catch(ast.Expression.Catch) ArrayList(java.util.ArrayList) Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) Expression(ast.Expression) Doc(ast.Ast.Doc) Block(ast.ExpCore.Block) SignalKind(ast.Ast.SignalKind)

Aggregations

SignalKind (ast.Ast.SignalKind)3 Expression (ast.Expression)2 Ast (ast.Ast)1 Doc (ast.Ast.Doc)1 MethodType (ast.Ast.MethodType)1 Type (ast.Ast.Type)1 ExpCore (ast.ExpCore)1 Block (ast.ExpCore.Block)1 On (ast.ExpCore.Block.On)1 Catch (ast.Expression.Catch)1 ArrayList (java.util.ArrayList)1