Search in sources :

Example 6 with VarDecXE

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

the class CheckVarUsedAreInScope method visit.

public Expression visit(With s) {
    Set<String> aux = this.xs;
    this.xs = new HashSet<String>(aux);
    List<VarDecXE> is = Map.of(this::liftVarDecXE, s.getIs());
    for (VarDecXE vd : is) {
        this.xs.add(vd.getX());
    }
    List<VarDecXE> es = Map.of(this::liftVarDecXE, s.getDecs());
    for (VarDecXE vd : es) {
        this.xs.add(vd.getX());
    }
    try {
        return new With(s.getP(), s.getXs(), is, es, Map.of(this::liftO, s.getOns()), Map.of(this::lift, s.getDefaultE()));
    } finally {
        this.xs = aux;
    }
}
Also used : VarDecXE(ast.Ast.VarDecXE)

Example 7 with VarDecXE

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

the class Desugar method getBlock.

static RoundBlock getBlock(Position p, String x, Expression xe, Expression inner) {
    List<Expression.BlockContent> bc = new ArrayList<>();
    List<VarDec> decs = new ArrayList<VarDec>();
    decs.add(new VarDecXE(false, Optional.empty(), x, xe));
    bc.add(new Expression.BlockContent(decs, Collections.emptyList()));
    return new RoundBlock(p, Doc.empty(), inner, bc);
}
Also used : Expression(ast.Expression) VarDec(ast.Ast.VarDec) ArrayList(java.util.ArrayList) RoundBlock(ast.Expression.RoundBlock) VarDecXE(ast.Ast.VarDecXE)

Example 8 with VarDecXE

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

the class InjectionOnSugar method visit.

@Override
public Expression visit(Block s) {
    Doc docs = s.getDoc();
    Expression inner = lift(s.getInner());
    List<VarDec> decs = new ArrayList<VarDec>();
    for (int i = 0; i < s.getDecs().size(); i++) {
        Optional<Type> t = s.getDecs().get(i).getT();
        String x = s.getDecs().get(i).getX();
        Expression e = lift(s.getDecs().get(i).getInner());
        decs.add(new VarDecXE(s.getDecs().get(i).isVar(), t, x, e));
    }
    List<Expression.Catch> _catch = injectionCatch(s.getOns());
    List<Expression.BlockContent> contents = new ArrayList<>();
    if (!decs.isEmpty() || !_catch.isEmpty()) {
        contents.add(new Expression.BlockContent(decs, _catch));
    }
    Expression.Position pos = s.getP();
    Expression.RoundBlock result = new Expression.RoundBlock(pos, docs, inner, contents);
    //assert WellFormedness.blockCheck(result);, no it can actually get wrong?
    return result;
}
Also used : ArrayList(java.util.ArrayList) Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) Expression(ast.Expression) VarDec(ast.Ast.VarDec) Doc(ast.Ast.Doc) VarDecXE(ast.Ast.VarDecXE)

Example 9 with VarDecXE

use of ast.Ast.VarDecXE 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 10 with VarDecXE

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

the class Desugar method blockInferVar.

private RoundBlock blockInferVar(RoundBlock s) {
    if (s.getContents().isEmpty()) {
        return s;
    }
    HashMap<String, Type> localVarEnv = new HashMap<String, Type>(this.varEnv);
    List<VarDec> newDecs = new ArrayList<VarDec>();
    for (VarDec _dec : s.getContents().get(0).getDecs()) {
        if (!(_dec instanceof VarDecXE)) {
            newDecs.add(_dec);
            continue;
        }
        VarDecXE dec = (VarDecXE) _dec;
        if (dec.getT().isPresent()) {
            Type ti = dec.getT().get();
            localVarEnv.put(dec.getX(), ti);
            newDecs.add(dec);
            continue;
        }
        localVarEnv.put(dec.getX(), null);
        newDecs.add(dec.withT(Optional.ofNullable(t)));
    }
    return blockWithDec(s, newDecs);
}
Also used : Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) MethodType(ast.Ast.MethodType) HashMap(java.util.HashMap) VarDec(ast.Ast.VarDec) ArrayList(java.util.ArrayList) VarDecXE(ast.Ast.VarDecXE)

Aggregations

VarDecXE (ast.Ast.VarDecXE)15 ArrayList (java.util.ArrayList)12 Expression (ast.Expression)11 VarDec (ast.Ast.VarDec)9 X (ast.Expression.X)7 RoundBlock (ast.Expression.RoundBlock)6 Type (ast.Ast.Type)5 VarDecE (ast.Ast.VarDecE)4 Parameters (ast.Ast.Parameters)3 MethodWithType (ast.Expression.ClassB.MethodWithType)3 MethodSelectorX (ast.Ast.MethodSelectorX)2 MethodType (ast.Ast.MethodType)2 BlockContent (ast.Expression.BlockContent)2 Catch (ast.Expression.Catch)2 Doc (ast.Ast.Doc)1 Position (ast.Ast.Position)1 VarDecCE (ast.Ast.VarDecCE)1 Loop (ast.Expression.Loop)1 MCall (ast.Expression.MCall)1 Signal (ast.Expression.Signal)1