use of ast.ExpCore.Block in project L42 by ElvisResearchGroup.
the class Executor method subst.
public static ExpCore subst(ExpCore ctxVal, Redex.Subst r) {
Block e1 = r.getThat();
int i = r.getSubstIndex();
ExpCore val = e1.getDecs().get(i).getInner();
String x = e1.getDecs().get(i).getX();
ArrayList<Block.Dec> decs = new ArrayList<Block.Dec>(e1.getDecs());
decs.remove(i);
Block e2 = new Block(e1.getDoc(), decs, e1.getInner(), e1.getOns(), e1.getP());
ExpCore result = ReplaceX.of(e2, val, x);
return ReplaceCtx.of(ctxVal, result);
}
use of ast.ExpCore.Block in project L42 by ElvisResearchGroup.
the class RenameVars method visit.
public ExpCore visit(Block s) {
List<On> k = Map.of(this::liftO, s.getOns());
List<On> newK = new ArrayList<>();
for (On on : k) {
String altK = toRename.get(on.getX());
if (altK != null) {
newK.add(on.withX(altK));
} else {
newK.add(on);
}
}
List<Block.Dec> decs = new ArrayList<>();
for (Block.Dec dec : s.getDecs()) {
String altxi = toRename.get(dec.getX());
if (altxi == null) {
decs.add(dec);
} else {
decs.add(dec.withX(altxi));
}
}
return new Block(s.getDoc(), Map.of(this::liftDec, decs), lift(s.getInner()), newK, s.getP());
}
use of ast.ExpCore.Block 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.ExpCore.Block in project L42 by ElvisResearchGroup.
the class ExtractThrow method visit.
public ExpCore visit(Block s) {
if (!s.getOns().isEmpty()) {
return new ExpCore.WalkBy();
}
for (int i = 0; i < s.getDecs().size(); i++) {
if (new IsValue(p).validDv(s.getDecs().get(i))) {
continue;
}
//otherwise, i is the first non dv
ExpCore res = s.getDecs().get(i).getInner().accept(this);
if (res instanceof ExpCore.WalkBy) {
return res;
}
Signal res_ = (Signal) res;
List<Block.Dec> decs = s.getDecs().subList(0, i);
Block newInner = new Block(s.getDoc(), decs, res_.getInner(), Collections.emptyList(), s.getP());
newInner = Functions.garbage(newInner, i);
return res_.withInner(newInner);
}
ExpCore res = s.getInner().accept(this);
if (res instanceof ExpCore.WalkBy) {
return res;
}
Signal res_ = (Signal) res;
Block newInner = s.withInner(res_.getInner());
return res_.withInner(newInner);
}
use of ast.ExpCore.Block in project L42 by ElvisResearchGroup.
the class HB method visit.
@Override
public ExpCore visit(Block s) {
ExpCore result = null;
for (Block.Dec di : s.getDecs()) {
result = acc(result, di.getInner().accept(this));
}
result = acc(result, s.getInner().accept(this));
if (result == null && onlyAroundHole) {
return null;
}
assert !onlyAroundHole || result instanceof WalkBy : onlyAroundHole + " " + result;
for (Block.Dec dec : s.getDecs()) {
if (xs.contains(dec.getX())) {
throw new ErrorMessage.VariableDeclaredMultipleTimes(dec.getX(), s.getP());
}
this.xs.add(dec.getX());
this.xsRes.add(dec.getX());
}
try {
if (!onlyAroundHole && !s.getOns().isEmpty()) {
for (On on : s.getOns()) {
if (xs.contains(on.getX())) {
throw new ErrorMessage.VariableDeclaredMultipleTimes(on.getX(), s.getP());
}
xs.add(on.getX());
xsRes.add(on.getX());
on.getInner().accept(this);
xs.remove(on.getX());
}
}
return result;
} finally {
for (Block.Dec dec : s.getDecs()) {
this.xs.remove(dec.getX());
}
}
}
Aggregations