use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.
the class Executor method metaMethod.
protected ClassB metaMethod(Program p, ClassB cb, Member m) {
log("---meta2--");
//get cb-->ct
//get p'
Program p1 = p.evilPush(cb);
//extract e
ExpCore e = m.getInner();
//extract cb
Ctx<ClassB> ctxC = ExtractCtxCompiled.of(e);
//run cb1-->cb2
ClassB cb2 = (ClassB) step(new PData(p1), ctxC.hole);
ExpCore e2 = ReplaceCtx.of(ctxC.ctx, cb2);
//compose cb with new member
return cb.withMember(m.withInner(e2));
}
use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.
the class TestSum method test.
@Test
public void test() {
TestHelper.configureForTest();
ClassB cb1 = getClassB(_cb1);
ClassB cb2 = getClassB(_cb2);
ClassB expected = getClassB(_expected);
if (!isError) {
ClassB res = _Sum.sum(Program.emptyLibraryProgram(), cb1, cb2);
TestHelper.assertEqualExp(expected, res);
} else {
try {
_Sum.sum(Program.emptyLibraryProgram(), cb1, cb2);
fail("error expected");
} catch (Resources.Error err) {
ClassB res = (ClassB) err.unbox;
TestHelper.assertEqualExp(expected, res);
}
}
}
use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.
the class RemoveCode method addDep.
private static ClassB addDep(ClassB accumulator, List<Ast.C> path, ClassB originalCb) {
if (path.isEmpty()) {
return mergeNestedHolderWithDep(accumulator, originalCb);
}
Ast.C firstName = path.get(0);
//either fistName does not exist in accumulator, and we call removeAllButPath
//or we have to continue recursivelly.
Optional<Member> optM = Functions.getIfInDom(accumulator.getMs(), firstName);
NestedClass originalNc = (NestedClass) Functions.getIfInDom(originalCb.getMs(), firstName).get();
ClassB newInner;
if (!optM.isPresent()) {
newInner = removeAllButPath(path.subList(1, path.size()), (ClassB) originalNc.getInner());
} else {
NestedClass accumulatorNc = (NestedClass) optM.get();
newInner = addDep((ClassB) accumulatorNc.getInner(), path.subList(1, path.size()), (ClassB) originalNc.getInner());
}
NestedClass nc = originalNc.withInner(newInner);
List<Member> ms = new ArrayList<>(accumulator.getMs());
Functions.replaceIfInDom(ms, nc);
return accumulator.withMs(ms);
}
use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.
the class TranslateExpression method visit.
//not a propagator visitor.
@Override
public Void visit(ExpCore.EPath s) {
Path ss = s.getInner();
if (ss.isPrimitive()) {
if (ss.equals(Path.Any())) {
res.append("platformSpecific.javaTranslation.Resources.Any.type");
}
if (ss.equals(Path.Library())) {
res.append("platformSpecific.javaTranslation.Resources.Library.type");
}
if (ss.equals(Path.Void())) {
res.append("platformSpecific.javaTranslation.Resources.Void.type");
}
return null;
}
ClassB cbs = Resources.getP().extractClassB(ss);
if (cbs.getPhase() == Phase.Coherent && IsCompiled.of(cbs)) {
res.append(Resources.nameOf(ss) + ".type ");
} else {
Position pos = Resources.getP().get(ss.outerNumber()).getP();
int hash = System.identityHashCode(pos);
String cs = s.toString();
int dotPos = cs.indexOf(".");
assert dotPos >= 0;
cs = cs.substring(dotPos);
res.append("platformSpecific.javaTranslation.Resources.fromHash(" + hash + ",\"" + cs + "\")");
}
return null;
}
use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.
the class TestPop method test.
@Test
public void test() {
ClassB cb1 = getClassB(_cb1);
ClassB expected = getClassB(_expected);
if (!isError) {
ClassB res = Pop.pop(cb1);
TestHelper.assertEqualExp(expected, res);
} else {
try {
Pop.pop(cb1);
fail("error expected");
} catch (Resources.Error err) {
ClassB res = (ClassB) err.unbox;
TestHelper.assertEqualExp(expected, res);
}
}
}
Aggregations