Search in sources :

Example 1 with Ctx

use of auxiliaryGrammar.Ctx in project L42 by ElvisResearchGroup.

the class Move method visit.

public Ctx<List<Block.Dec>> visit(Block s) {
    List<Block.Dec> dvs = new ArrayList<Block.Dec>();
    List<Block.Dec> ds = new ArrayList<Block.Dec>();
    List<Block.Dec> dvs1 = new ArrayList<Block.Dec>();
    List<Block.Dec> dvs2 = new ArrayList<Block.Dec>();
    for (Block.Dec d : s.getDecs()) {
        if (ds.isEmpty() && !IsCtx.of(d.getInner())) {
            dvs.add(d);
        } else {
            assert ds.isEmpty() || !IsCtx.of(d.getInner());
            ds.add(d);
        }
    }
    Ctx<List<Block.Dec>> nestedCtx = null;
    if (ds.isEmpty()) {
        nestedCtx = s.getInner().accept(this);
    } else {
        nestedCtx = ds.get(0).getInner().accept(this);
    }
    HashSet<String> richXs = new HashSet<String>();
    richXs.add(x);
    for (Block.Dec dv : nestedCtx.hole) {
        richXs.addAll(FreeVariables.of(dv.getInner()));
    }
    split(dvs, dvs1, dvs2, richXs);
    Block s2 = null;
    if (ds.isEmpty()) {
        s2 = s.withInner(nestedCtx.ctx);
    } else {
        ds.set(0, ds.get(0).withInner(nestedCtx.ctx));
        dvs2.addAll(ds);
        s2 = s;
    }
    s2 = s2.withDecs(dvs2);
    dvs1.addAll(nestedCtx.hole);
    return new Ctx<List<Block.Dec>>(s2, dvs1);
}
Also used : Dec(ast.ExpCore.Block.Dec) Dec(ast.ExpCore.Block.Dec) Ctx(auxiliaryGrammar.Ctx) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Example 2 with Ctx

use of auxiliaryGrammar.Ctx 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 3 with Ctx

use of auxiliaryGrammar.Ctx in project L42 by ElvisResearchGroup.

the class ExtractCtxUpToX method visit.

public Ctx<Block> visit(Block s) {
    int xPos = s.domDecs().indexOf(x);
    if (xPos != -1 && IsCtx.of(s)) {
        return new Ctx<Block>(new WalkBy(), s);
    }
    List<Block.Dec> newDecs = new ArrayList<Block.Dec>();
    Ctx<Block> res = null;
    for (Block.Dec dec : s.getDecs()) {
        if (!IsCtx.of(dec.getInner())) {
            newDecs.add(dec);
            continue;
        }
        res = dec.getInner().accept(this);
        newDecs.add(dec.withInner(res.ctx));
    }
    if (res != null) {
        res.ctx = s.withDecs(newDecs);
        return res;
    }
    assert IsCtx.of(s.getInner());
    assert s.getOns().isEmpty();
    res = s.getInner().accept(this);
    res.ctx = s.withInner(res.ctx);
    return res;
}
Also used : Ctx(auxiliaryGrammar.Ctx) ArrayList(java.util.ArrayList) Block(ast.ExpCore.Block) WalkBy(ast.ExpCore.WalkBy)

Aggregations

Ctx (auxiliaryGrammar.Ctx)3 ArrayList (java.util.ArrayList)3 Block (ast.ExpCore.Block)2 Dec (ast.ExpCore.Block.Dec)2 WalkBy (ast.ExpCore.WalkBy)2 Redex (ast.Redex)1 HashSet (java.util.HashSet)1 List (java.util.List)1