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));
}
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;
}
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);
}