use of ast.Expression.Catch in project L42 by ElvisResearchGroup.
the class DesugarW method castT.
private VarDecXE castT(Position pos, Type t, String y, String x) {
assert t instanceof Type;
Type nt = t;
String z = Functions.freshName("casted", usedVars);
List<Catch> ks = new ArrayList<>();
Type t2 = new Type(nt.getMdf(), Path.Any(), Doc.empty());
ks.add(new //case return captured
Expression.Catch1(//case return captured
pos, //case return captured
SignalKind.Return, //case return captured
t, //case return captured
z, //return it
new X(pos, z)));
ks.add(new //else
Expression.Catch1(//else
pos, //else
SignalKind.Return, //else
t2, //else
z, // exception void
new Signal(SignalKind.Exception, Expression._void.instance)));
RoundBlock block = Desugar.getBlock(pos, new Signal(SignalKind.Return, new X(pos, x)), ks, Desugar.errorMsg("CastT-Should be unreachable code"));
return new VarDecXE(false, Optional.of(t), y, block);
}
use of ast.Expression.Catch 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.Catch in project L42 by ElvisResearchGroup.
the class DesugarCatchDefault method liftBC.
protected BlockContent liftBC(BlockContent c) {
if (c.get_catch().isEmpty()) {
return super.liftBC(c);
}
List<Catch> ks = Map.of(this::liftK, c.get_catch());
Type oldR = this.lastReturn;
this.lastReturn = newR(ks);
try {
List<VarDec> liftVarDecs = liftVarDecs(c.getDecs());
return new BlockContent(liftVarDecs, ks);
} finally {
this.lastReturn = oldR;
}
}
use of ast.Expression.Catch 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.Catch in project L42 by ElvisResearchGroup.
the class DesugarW method with_C_A.
private Expression with_C_A(Position pos, List<String> xs, With.On on0, Expression continuation) {
List<String> ys = new ArrayList<String>();
for (String x : xs) {
ys.add(Functions.freshName(x, usedVars));
}
//(
List<VarDec> decs = new ArrayList<>();
//TODO:?? now is very strange and requires the mdf to propagate it to the locally introduced var?
//casts: every cast is a block content e+catch
{
int i = -1;
for (Type ti : on0.getTs()) {
i += 1;
String xi = xs.get(i);
String yi = ys.get(i);
decs.add(castT(pos, ti, yi, xi));
}
}
//catch exception Void recursive call
Catch k = Desugar.getK(pos, SignalKind.Exception, "", Type.immVoid, continuation);
//main expression with 'T' renaming
Expression e0 = on0.getInner();
{
int i = -1;
for (Type ti : on0.getTs()) {
i += 1;
String xi = xs.get(i);
String yi = ys.get(i);
e0 = renameT(e0, new Expression.X(pos, xi), ti, new Expression.X(pos, yi));
}
}
BlockContent content = new BlockContent(decs, Collections.singletonList(k));
List<BlockContent> contents = new ArrayList<BlockContent>();
contents.add(content);
contents.add(Desugar.getBlockContent(e0));
//void)
return new RoundBlock(pos, Doc.empty(), Expression._void.instance, contents);
}
Aggregations