use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.
the class PlgWrapperGenerator method isOkAsException.
private static void isOkAsException(Program p, Path csTop, Path pi) throws ClassUnfit, MethodUnfit {
Path op = _pathForOutside(csTop.getCBar().size(), pi);
if (op == null) {
checkForInside(p.top(), csTop, pi);
return;
}
ClassB l = p.extractClassB(op);
if (!hasExceptionIf(l)) {
throw new RefactorErrors.ClassUnfit().msg("Class " + op + " has no method #exceptionIf(binaryRepr)");
}
}
use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.
the class Translator method useFrom.
//this should take a class, strip out nested and 'from' it so that it is as at top level
static ClassB useFrom(ClassB ct, Path p) {
ArrayList<Member> ms = new ArrayList<Member>();
for (Member m : ct.getMs()) {
m.match(nc -> null, mi -> {
throw Assertions.codeNotReachable();
}, mt -> ms.add(From.from(mt, p)));
}
//for(PathMwt pmwt:ct.getStage().getInherited()){
for (PathMwt pmwt : Collections.<PathMwt>emptyList()) {
if (Functions.getIfInDom(ms, pmwt.getMwt().getMs()).isPresent()) {
continue;
}
ms.add(From.from(pmwt.getMwt(), p));
}
List<Path> sup = tools.Map.of(ti -> (Path) From.fromP(ti.getPath(), p), ct.getSupertypes());
//tools.Map.of(pi->(Path)From.fromP(pi,p),ct.getStage().getInheritedPaths());
List<Path> supAll = sup;
ClassB res = ct.withMs(ms).withSupertypes(tools.Map.of(pi -> pi.toImmNT(), sup));
return res;
}
use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.
the class Translator method add.
public static void add(int level, List<Ast.C> cs, ClassB cb, Map<String, ClassB> map, Program original) {
Ast.Path p = Ast.Path.outer(level, cs);
if (cb.getPhase() == Phase.Coherent && IsCompiled.of(cb)) {
//otherwise is "meta"
//assert cb.getStage().getInheritedPaths()!=null;
ClassB cbUF = useFrom(cb, p);
if (!cs.isEmpty()) {
//ok to ignore empty ones, since not complete?
map.put(Resources.nameOf(level, cs), cbUF);
}
} else {
//generate only for metaprogramming //Can be ignored now with typemap
/*ExpCore.ClassB cbMP = new ExpCore.ClassB(
Doc.factory("##@DebugInfo: is interface since (cb.getStage()!=Stage.Star :"
+(cb.getStage().getStage()!=Stage.Star)+") or since !IsCompiled.of(cb) :"+!IsCompiled.of(cb)+")"
),Doc.empty(),true,Collections.emptyList(),Collections.emptyList(),new Util.CachedStage());
cbMP.getStage().setInheritedPaths(Collections.emptyList());
cbMP.getStage().setInherited(Collections.emptyList());
assert cbMP.getStage().getInheritedPaths()!=null;
map.put(Resources.nameOf(level,cs),cbMP);
*/
}
for (Member m : cb.getMs()) {
if (!(m instanceof NestedClass)) {
continue;
}
NestedClass nc = (NestedClass) m;
if (!(nc.getInner() instanceof ClassB)) {
continue;
}
if (cs.isEmpty() && level > 0) {
if (nc.getInner() == original.get(level - 1)) {
continue;
}
//avoid generation of multiple versions of the same thing
}
ArrayList<Ast.C> newCs = new ArrayList<>(cs);
newCs.add(nc.getName());
add(level, newCs, (ClassB) nc.getInner(), map, original);
}
}
use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.
the class BigStep method executeAtomicStep.
protected ExpCore executeAtomicStep(PData p1, ExpCore _e1) {
if (!IsCompiled.of(_e1)) {
return step(p1, _e1);
}
return Resources.withPDo(p1, () -> {
ExpCore e1 = _e1;
boolean runned = false;
e1 = NormalizeBlocks.of(e1);
try {
while (!(e1 instanceof ClassB)) {
log(ToFormattedText.ofCompact(e1.accept(new InjectionOnSugar()), false));
e1 = step(p1, e1);
e1 = NormalizeBlocks.of(e1);
runned = true;
}
} catch (Throwable t) {
if (!runned) {
throw t;
}
}
log(ToFormattedText.ofCompact(e1.accept(new InjectionOnSugar()), false));
return e1;
});
}
use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.
the class CompiledStep method executeAtomicStep.
@Override
protected ExpCore executeAtomicStep(PData p1, ExpCore _e1, Ast.C nestedName) {
if (!IsCompiled.of(_e1)) {
return step(p1, _e1);
}
return Resources.withPDo(p1, () -> {
ExpCore e1 = NormalizeBlocks.of(_e1);
if (e1 instanceof ExpCore.Signal) {
throw new ErrorMessage.CtxExtractImpossible(e1, null);
}
Translator code = Timer.record("Translator.translateProgram", () -> Translator.translateProgram(p1.p, e1));
try {
L42.compilationRounds++;
System.out.println("Compilation Iteration-- " + nestedName + ":" + L42.compilationRounds + "");
Timer.activate("code.runMap");
Object o = code.runMap();
Timer.deactivate("code.runMap");
System.out.println("Compilation Iteration complete-- " + nestedName + ":" + L42.compilationRounds + "");
assert o instanceof ClassB;
return (ClassB) o;
} catch (Resources.Error err) {
Resources.cacheMessage(err);
return EncodingHelper.wrapResource(err);
} catch (Resources.Exception err) {
Resources.cacheMessage(err);
return EncodingHelper.wrapResource(err);
} catch (Resources.Return err) {
//it can happen if other stuff is wrong, in this way we can see the error.
Resources.cacheMessage(err);
return EncodingHelper.wrapResource(err);
}
});
}
Aggregations