use of ast.Expression.X in project L42 by ElvisResearchGroup.
the class DesugarW method with_E_handleIs.
private Expression with_E_handleIs(Position pos, List<VarDecXE> is, Expression b) {
//case e in 6 pages
//xs is dom(Is)
List<String> xs = new ArrayList<>();
for (VarDecXE i : is) {
xs.add(i.getX());
}
//di ki is block content =nexti(xs)
List<BlockContent> bc = new ArrayList<>();
for (int i = 0; i < xs.size(); i++) {
bc.add(withNext(pos, i, xs));
}
//inner =di ki s b[xs:=xs.#inner()]
for (String xi : xs) {
b = XInE.of(new X(pos, xi), Desugar.getMCall(pos, new X(pos, xi), "#inner", Desugar.getPs()), b);
}
RoundBlock inner = new RoundBlock(pos, Doc.empty(), b, bc);
Catch k = Desugar.getK(pos, SignalKind.Exception, "", Type.immVoid, Expression._void.instance);
inner = Desugar.getBlock(pos, new Loop(inner), Collections.singletonList(k), Expression._void.instance);
Expression result = withDeclareIts(is, inner);
//accept
return result;
}
use of ast.Expression.X in project L42 by ElvisResearchGroup.
the class Desugar method visit.
public Expression visit(BinOp s) {
Op op = s.getOp();
if (op == Op.ColonEqual) {
//TODO: set the right expect type?
return s.withRight(lift(s.getRight()));
}
if (op.kind == Ast.OpKind.EqOp) {
//go from, for example a++=b into a:=a ++b
Op op2 = Op.fromString(s.getOp().inner.substring(0, s.getOp().inner.length() - 1));
BinOp s2 = s.withOp(op2);
//NO!s2=s2.withLeft(getMCall(s.getP(),s.getLeft(),"#inner",getPs()));
return visit(new BinOp(s.getP(), s.getLeft(), Op.ColonEqual, Doc.empty(), s2));
}
if (op.negated) {
BinOp s2 = s.withOp(op.nonNegatedVersion());
return visit(getMCall(s.getP(), s2, desugarName(Op.Bang.inner), getPs()));
}
if (op.normalized) {
return visit(getMCall(s.getP(), s.getLeft(), desugarName(s.getOp().inner), getPs(s.getRight())));
}
String x = Functions.freshName("opNorm", usedVars);
BinOp s2 = new BinOp(s.getP(), s.getRight(), op.normalizedVersion(), s.getDoc(), new Expression.X(s.getP(), x));
return visit(getBlock(s.getP(), x, s.getLeft(), s2));
}
use of ast.Expression.X in project L42 by ElvisResearchGroup.
the class Desugar method liftKs.
protected List<Catch> liftKs(List<Catch> ks) {
List<Catch> result = new ArrayList<>();
String x = Functions.freshName("catched", usedVars);
for (Catch k : ks) {
if (k instanceof DesugarCatchDefault.CatchToComplete) {
Catch k2 = this.liftK(((DesugarCatchDefault.CatchToComplete) k).catch1);
result.add(new DesugarCatchDefault.CatchToComplete((Catch1) k2));
continue;
}
k.match(k1 -> result.add(liftK(k1)), kM -> {
for (Type t : kM.getTs()) {
result.add(liftK(new Expression.Catch1(kM.getP(), kM.getKind(), t, x, kM.getInner())));
}
return false;
}, kP -> {
for (Type t : kP.getTs()) {
Expression inner = kP.getInner();
inner = new Expression.FCall(kP.getP(), inner, Doc.empty(), new ast.Ast.Parameters(Optional.of(new X(kP.getP(), x)), Collections.emptyList(), Collections.emptyList()));
inner = new Expression.Signal(kP.getKind(), inner);
result.add(liftK(new Expression.Catch1(kP.getP(), SignalKind.Exception, t, x, inner)));
}
return false;
});
}
return result;
}
use of ast.Expression.X 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);
}
use of ast.Expression.X in project L42 by ElvisResearchGroup.
the class Desugar method visit.
public Expression visit(CurlyBlock s) {
assert s.getContents().size() == 1;
assert s.getContents().get(0).get_catch().isEmpty();
assert s.getContents().get(0).getDecs().size() == 1;
assert s.getContents().get(0).getDecs().get(0) instanceof VarDecE;
Expression inner = ((VarDecE) s.getContents().get(0).getDecs().get(0)).getInner();
String y = Functions.freshName("result", this.usedVars);
Expression.Catch k = getK(s.getP(), SignalKind.Return, y, this.t, new X(s.getP(), y));
Expression termination = Desugar.errorMsg("CurlyBlock-Should be unreachable code");
RoundBlock outer = getBlock(s.getP(), inner, Collections.singletonList(k), termination);
return visit(outer);
}
Aggregations