use of ast.Ast.Type in project L42 by ElvisResearchGroup.
the class AlternativeMethodTypes method _mVpNoRec.
static MethodType _mVpNoRec(MethodType mt, int parNum) {
//Ts0 mut P Ts2->T;Ps in methTypes(p,P,ms)
//Ts'=mutToCapsule(Ts0) lent P mutToCapsule(Ts2) //this implies not fwd_or_fwd%_in Ts0,Ts2
//(mVp)-------------------------------------------------------------------
//Ts'->toLent(T);Ps in methTypes(p,P,ms)
Type pN = mt.getTs().get(parNum);
if (pN.getMdf() != Mdf.Mutable) {
return null;
}
Type retT = mt.getReturnType();
retT = _toLent(retT);
if (retT == null) {
return null;
}
List<Type> ts = Map.of(t -> mutToCapsule(t), mt.getTs());
ts.set(parNum, pN.withMdf(Mdf.Lent));
MethodType res = mt.withReturnType(retT).withTs(ts).withMdf(mutToCapsule(mt.getMdf()));
if (WellFormednessCore.methodTypeWellFormed(res)) {
return res;
}
return null;
}
use of ast.Ast.Type in project L42 by ElvisResearchGroup.
the class GuessTypeCore method guessedDs.
public static List<Dec> guessedDs(Program p, G in, List<Dec> toGuess) {
//G'
List<Dec> res = new ArrayList<>();
for (Dec di : toGuess) {
if (di.getT().isPresent()) {
res.add(di);
continue;
}
Type nti = _guessDecType(p, in, di);
assert nti != null;
res.add(di.withT(Optional.of(nti)));
}
return res;
}
use of ast.Ast.Type in project L42 by ElvisResearchGroup.
the class TIn method toLent.
public This toLent() {
//toLent(G)(x)=toLent(G(x)) //thus undefined where toLent undefined
Map<String, Map.Entry<Boolean, Type>> newG = new HashMap<>(g);
for (String xi : gDom()) {
Type ti = g(xi);
assert ti != null;
ti = TypeManipulation._toLent(ti);
if (ti == null) {
continue;
}
if (ti.getMdf() == Mdf.Immutable) {
newG.put(xi, p(gVar(xi), ti));
} else {
newG.put(xi, p(false, ti));
}
}
return this.withG(newG);
}
use of ast.Ast.Type in project L42 by ElvisResearchGroup.
the class TIn method addGds.
public This addGds(Program p, List<ExpCore.Block.Dec> ds) {
Map<String, Map.Entry<Boolean, Type>> newG = new HashMap<>(g);
for (ExpCore.Block.Dec d : ds) {
assert !g.containsKey(d.getX());
Type nt = d.getT().get();
assert !d.isVar() || !TypeManipulation.fwd_or_fwdP_in(nt.getMdf());
assert !d.isVar() || nt.getMdf() != Mdf.Capsule;
newG.put(d.getX(), p(d.isVar(), nt));
}
return this.withG(newG);
}
use of ast.Ast.Type in project L42 by ElvisResearchGroup.
the class TsBlock method kTypeCatch.
// T0 is the declared caught type, which contributes only a path
// T1 is the actual caught type, based on the types which can be thrown in context
// T2 is the type of the expression, based on x being bound T1
default default TOutK kTypeCatch(TIn in, Tr tr1, On k) {
if (k.getKind() == SignalKind.Return && tr1.returns.isEmpty()) {
return new TErr(in, "No returns in scope", null, ErrorKind.NoMostGeneralMdf);
}
Mdf mdf1 = TypeManipulation._mostGeneralMdf(k.getKind(), tr1);
if (mdf1 == null) {
return new TErr(in, "Contrasting mdf expected for return", null, ErrorKind.NoMostGeneralMdf);
}
Type T1 = k.getT().withMdf(mdf1);
TOut _out = type(in.addG(k.getX(), false, T1).withE(k.getE(), in.expected));
if (!_out.isOk()) {
return _out.toError();
}
TOk out = _out.toOk();
TOkK res = new TOkK(Tr.instance.trUnion(out), k.withE(out.annotated).withT(T1), out.computed);
return res;
/* Phase| p| G| Tr' |- catch throw T0 x e ~> catch throw T1.P x e' :T2 <= T | Tr
mdf1 = mostGeneralMdf(throw,Tr') //set of Mdfs admits no single most general mdf, or mdfs is empty
//inconsistent set of thrown things, which do not share a most
//general modifier [list of line numbers of the throws]
T1 = mdf1 resolve (p, T0).P //resolve can fail
not catchRethrow(catch throw T1 x e)
Phase| p| G[x:T1]|- e ~> e' : T2 <= T | Tr
*/
}
Aggregations