Search in sources :

Example 1 with Redex

use of ast.Redex in project L42 by ElvisResearchGroup.

the class ExtractCtxVal method visit.

public Ctx<Redex> visit(Block s) {
    Ctx<Redex> res = checkRedex(s);
    if (res != null) {
        return res;
    }
    for (int i = 0; i < s.getDecs().size(); i++) {
        //final restrictions
        int ii = i;
        Dec di = s.getDecs().get(i);
        boolean isDv = new IsValue(p).validDv(di);
        Redex isGarbage = null;
        if (isDv && di.getInner() instanceof Block) {
            Block diB = (Block) di.getInner();
            isGarbage = IsValue.nestedGarbage(diB);
        }
        if (isGarbage != null) {
            List<Block.Dec> ds = new ArrayList<Block.Dec>(s.getDecs());
            ds.set(ii, di.withInner(new WalkBy()));
            return new Ctx<Redex>(s.withDecs(ds), isGarbage);
        }
        if (isDv) {
            continue;
        }
        //otherwise, i is the first non dv
        return lift(di.getInner().accept(this), ctx -> {
            List<Block.Dec> es = new ArrayList<Block.Dec>(s.getDecs());
            es.set(ii, es.get(ii).withInner(ctx));
            return s.withDecs(es);
        });
    }
    if (!s.getOns().isEmpty()) {
        return null;
    }
    return lift(s.getInner().accept(this), ctx -> s.withInner(ctx));
}
Also used : Dec(ast.ExpCore.Block.Dec) Redex(ast.Redex) Ctx(auxiliaryGrammar.Ctx) ArrayList(java.util.ArrayList) Block(ast.ExpCore.Block) WalkBy(ast.ExpCore.WalkBy)

Example 2 with Redex

use of ast.Redex in project L42 by ElvisResearchGroup.

the class ExtractCtxVal method visit.

public Ctx<Redex> visit(MCall s) {
    Ctx<Redex> res = checkRedex(s);
    if (res != null) {
        return res;
    }
    if (!IsValue.of(p, s.getInner())) {
        return lift(s.getInner().accept(this), ctx -> s.withInner(ctx));
    }
    for (ExpCore ei : s.getEs()) {
        if (IsValue.of(p, ei)) {
            continue;
        }
        return lift(ei.accept(this), ctx -> {
            List<ExpCore> es = new ArrayList<ExpCore>(s.getEs());
            es.set(es.indexOf(ei), ctx);
            return s.withEs(es);
        });
    }
    return null;
}
Also used : ExpCore(ast.ExpCore) Redex(ast.Redex) ArrayList(java.util.ArrayList)

Example 3 with Redex

use of ast.Redex in project L42 by ElvisResearchGroup.

the class ExtractCtxVal method visit.

public Ctx<Redex> visit(Using s) {
    Ctx<Redex> res = checkRedex(s);
    if (res != null) {
        return res;
    }
    for (ExpCore ei : s.getEs()) {
        if (IsValue.of(p, ei)) {
            continue;
        }
        return lift(ei.accept(this), ctx -> {
            List<ExpCore> es = new ArrayList<ExpCore>(s.getEs());
            es.set(es.indexOf(ei), ctx);
            return s.withEs(es);
        });
    }
    return lift(s.getInner().accept(this), s::withInner);
}
Also used : ExpCore(ast.ExpCore) Assertions(tools.Assertions) Functions(auxiliaryGrammar.Functions) Redex(ast.Redex) ArrayList(java.util.ArrayList)

Aggregations

Redex (ast.Redex)3 ArrayList (java.util.ArrayList)3 ExpCore (ast.ExpCore)2 Block (ast.ExpCore.Block)1 Dec (ast.ExpCore.Block.Dec)1 WalkBy (ast.ExpCore.WalkBy)1 Ctx (auxiliaryGrammar.Ctx)1 Functions (auxiliaryGrammar.Functions)1 Assertions (tools.Assertions)1