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 TsBlock method tsBlockBase.
default default TOut tsBlockBase(TIn in, Block s) {
//Phase| p| G |- (ds ks e0 [_]) ~>(ds' ks' e'0 [T])
// : T <= T' | Tr'.capture(p,ks') U Tr U Tr0
List<Block.Dec> ds = s.getDecs();
List<Block.On> ks = s.getOns();
//G'=G/dom(ds)
TIn in1 = in.removeGDs(ds);
//G'[ks]
TIn in2 = in1.gKs(ks);
//Phase| p| G'[ks] |- ds ~> ds' |Tr' | G0
TOutDs _dsOut = dsType(in2, ds);
if (!_dsOut.isOk()) {
TErr err = _dsOut.toError();
if (!err.kind.needContext) {
return err;
}
//was locked by error safety[cite the line number of the catch]
return err;
}
TOkDs dsOk = _dsOut.toOkDs();
//Phase| p| G'| Tr' |- ks~> ks' : Ts <= T' | Tr
TOutKs _ksOut = ksType(in1, dsOk.trAcc, ks);
if (!_ksOut.isOk()) {
return _ksOut.toError();
}
TOkKs ksOk = _ksOut.toOkKs();
//now resolved
ks = ksOk.ks;
//Phase| p| G'[G0\dom(G')] |- e0~>e'0:T0 <=T' | Tr0
G G0LessG1 = dsOk.g.removeGXs(in1.g.keySet());
TOut _e0Out = type(in1.addGG(G0LessG1).withE(s.getE(), in.expected));
if (!_e0Out.isOk()) {
return _e0Out.toError();
}
TOk e0Ok = _e0Out.toOk();
//T= mostGeneralMdf({T0.mdf,Ts.mdfs}) T'.P //set of Mdfs admits no single most general mdf
Set<Mdf> mdfs = new HashSet<>();
for (Type nt : ksOk.ts) {
mdfs.add(nt.getMdf());
}
mdfs.add(e0Ok.computed.getMdf());
Mdf tMdf = TypeManipulation._mostGeneralMdf(mdfs);
if (tMdf == null) {
return new TErr(in, "", e0Ok.computed, ErrorKind.NoMostGeneralMdf);
}
Type t = new Type(tMdf, in.expected.getPath(), Doc.empty());
assert null == TypeSystem.subtype(in.p, t, in.expected);
Block annotated = new Block(s.getDoc(), dsOk.ds, e0Ok.annotated, ksOk.ks, s.getP());
TOk res = new TOk(in, annotated, t);
// result Tr: Tr'.capture(p,ks') U Tr U Tr0
Tr trCaptured = dsOk.trAcc;
for (On k : ks) {
trCaptured = trCaptured.trCapture(in.p, k);
}
Tr trUnion = trCaptured.trUnion(ksOk.trAcc).trUnion(e0Ok);
res = res.trUnion(trUnion);
return res;
}
use of ast.ExpCore.Block 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;
}
use of ast.ExpCore.Block in project L42 by ElvisResearchGroup.
the class PlgWrapperGenerator method updateTemplateUsing.
private static MethodWithType updateTemplateUsing(UsingInfo ui, MethodWithType mwt) {
MCall e = templateUsingExc;
MethodType mt = mwt.getMt();
ExpCore.Block b = (Block) e.getEs().get(0);
if (mwt.getMt().getExceptions().isEmpty()) {
b = b.withOns(Collections.emptyList());
}
ExpCore.Using u = (Using) b.getDecs().get(0).getInner();
//parameter expressions
ExpCore.MCall p0 = (MCall) u.getEs().get(0);
//e#mcall.inner<-mwt.retType.path
e = e.withInner(ExpCore.EPath.wrap(mt.getReturnType().getPath()));
//u=u.withS(ui.usingMs);
List<ExpCore> ues = new ArrayList<>();
if (mt.getMdf() != Mdf.Class) {
ues.add(p0.withInner(new ExpCore.X(mwt.getP(), "this")));
}
{
int i = -1;
for (String x : mwt.getMs().getNames()) {
i++;
ExpCore pi = new ExpCore.X(mwt.getP(), x);
boolean needAddBinaryRepr = true;
Type ti = mwt.getMt().getTs().get(i);
if (ti.equals(Type.immLibrary)) {
needAddBinaryRepr = false;
}
if (ti.getMdf() == Mdf.Class) {
needAddBinaryRepr = false;
}
if (needAddBinaryRepr) {
pi = p0.withInner(pi);
}
ues.add(pi);
}
}
u = new Using(u.getPath(), ui.usingMs, u.getDoc(), ues, u.getInner());
String errorS = "plugin string: " + ui.plgInfo.plgString + "\n" + "plugin part: " + ui.plgInfo.plgName + "\n" + "method name: " + mwt.getMs() + "\n" + "java method: " + ui.plgInfo.plgClass.getName() + "." + ui.usingMs + "\n";
//u.inner#mcall.es(0)<-EncodingHelper.wrapStringU()
List<ExpCore> errorEs = Collections.singletonList(EncodingHelper.wrapStringU(errorS));
Signal tmpS = (Signal) u.getInner();
MCall tmpMc = ((MCall) tmpS.getInner()).withEs(errorEs);
u = u.withInner(tmpS.withInner(tmpMc));
b = b.withDecs(Collections.singletonList(b.getDecs().get(0).withInner(u)));
//--
if (!mwt.getMt().getExceptions().isEmpty()) {
On on = b.getOns().get(0);
Dec k0 = ((Block) on.getInner()).getDecs().get(0);
List<Dec> ks = new ArrayList<>();
{
int i = -1;
for (Type ti : mt.getExceptions()) {
i++;
MCall mci = ((MCall) k0.getInner()).withInner(ExpCore.EPath.wrap(ti.getPath()));
ks.add(k0.withInner(mci).withX(k0.getX() + i));
}
}
on = on.withInner(((Block) on.getInner()).withDecs(ks));
b = b.withOns(Collections.singletonList(on));
//k0=b.k(0).inner#block.decs(0)
//k0 add more on need
//ki.inner#mcall.inner<-Pi
}
if (ui.isVoid) {
b = b.withDecs(Collections.singletonList(b.getDecs().get(0).withT(Optional.of(Type.immVoid))));
}
if (!ui.isVoid && !mwt.getMt().getReturnType().equals(Type.immLibrary)) {
e = e.withEs(Collections.singletonList(b));
mwt = mwt.withInner(e);
} else {
mwt = mwt.withInner(b);
}
return mwt;
}
use of ast.ExpCore.Block in project L42 by ElvisResearchGroup.
the class MethodPathCloneVisitor method visit.
public ExpCore visit(Block s) {
HashMap<String, Ast.Type> aux = new HashMap<>(this.varEnv);
try {
for (Dec d : s.getDecs()) {
if (d.getT().isPresent()) {
this.varEnv.put(d.getX(), d.getT().get());
}
//TODO:??? GuessTypeCore._of(this.varEnv,d.getInner());
}
List<Dec> newDecs = liftDecs(s.getDecs());
List<On> newOns = new ArrayList<>();
for (On on : s.getOns()) {
this.varEnv.put(on.getX(), on.getT());
newOns.add(liftO(on));
this.varEnv.remove(on.getX());
}
return new Block(s.getDoc(), newDecs, lift(s.getInner()), newOns, s.getP());
} finally {
this.varEnv = aux;
}
}
Aggregations