Search in sources :

Example 6 with Program

use of programReduction.Program in project L42 by ElvisResearchGroup.

the class Executor method meta1Prop.

protected ClassB meta1Prop(Program p, ClassB cb, NestedClass m) {
    log("---meta1Prop--");
    //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));
}
Also used : ExpCore(ast.ExpCore) Program(programReduction.Program) PData(facade.PData) ClassB(ast.ExpCore.ClassB)

Example 7 with Program

use of programReduction.Program in project L42 by ElvisResearchGroup.

the class TestHelper method getProgram.

public static Program getProgram(/*List<Path> paths,*/
String[] code) {
    Program p0 = Program.emptyLibraryProgram();
    Integer outerCount = code.length;
    for (String s : code) {
        Expression e = Parser.parse("This" + outerCount, s);
        --outerCount;
        ClassB ec = (ClassB) Desugar.of(e).accept(new InjectionOnCore());
        p0 = p0.evilPush(ec);
    }
    return p0;
}
Also used : Program(programReduction.Program) Expression(ast.Expression) ClassB(ast.ExpCore.ClassB) InjectionOnCore(sugarVisitors.InjectionOnCore)

Example 8 with Program

use of programReduction.Program in project L42 by ElvisResearchGroup.

the class RenameAlsoDefinition method potentiallyRenameMethodImplementedHeader.

private MethodWithType potentiallyRenameMethodImplementedHeader(MethodWithType mi) {
    assert mi.getMt().isRefine();
    ClassB currentCb = this.getLocator().getLastCb();
    Program ep = p;
    for (ClassB cbi : this.getLocator().getCbs()) {
        ep = ep.evilPush(cbi);
    }
    //List<Path> supers = Program.getAllSupertypes(ep, currentCb);
    Path origin = Functions.originDecOf(ep, mi.getMs(), currentCb);
    Locator original = this.getLocator().copy();
    boolean isOut = original.moveInPath(origin);
    if (isOut) {
        return mi;
    }
    for (Locator pMx : maps.selectors) {
        assert pMx.kind() == Kind.Method;
        MethodSelector s = pMx.getLastMember().match(nc -> {
            throw Assertions.codeNotReachable();
        }, mimpl -> mimpl.getS(), mt -> mt.getMs());
        if (!mi.getMs().equals(s)) {
            continue;
        }
        Locator renamed = pMx.copy();
        renamed.toFormerNodeLocator();
        if (!original.equals(renamed)) {
            return mi;
        }
        MethodSelector ms2 = (MethodSelector) pMx.getAnnotation();
        return mi.withMs(ms2);
    }
    return mi;
}
Also used : Path(ast.Ast.Path) Locator(auxiliaryGrammar.Locator) MethodSelector(ast.Ast.MethodSelector) Program(programReduction.Program) ClassB(ast.ExpCore.ClassB)

Example 9 with Program

use of programReduction.Program in project L42 by ElvisResearchGroup.

the class Executor method stepStar.

public static ExpCore stepStar(Executor executer, ExpCore e) {
    final Program emptyP = Program.emptyLibraryProgram();
    int iteration = 0;
    dbgRecordNext(e);
    executer.log("--------------------" + (iteration += 1));
    //TestHelper.dbgCompact(e);
    try {
        while (true) {
            assert coreVisitors.CheckNoVarDeclaredTwice.of((ClassB) e);
            e = NormalizeBlocks.of(e);
            e = executer.step(new PData(emptyP), e);
            dbgRecordNext(e);
            assert coreVisitors.CheckNoVarDeclaredTwice.of((ClassB) e);
            executer.log("--------------------" + (iteration += 1));
        //TestHelper.dbgCompact(e);
        }
    }//catch(ErrorMessage.NormalForm mess){ return mess.getE();}
     catch (ErrorMessage.CtxExtractImpossible mess) {
        assert e instanceof ClassB;
        if (!L42.trustPluginsAndFinalProgram) {
            ClassB ct = (ClassB) e;
            Program p1 = emptyP.evilPush(ct);
            //I think this is all old code?
            assert false;
        //Configuration.typeSystem.checkCt( emptyP, ct);
        /*if(!p1.checkComplete()){//also check is star
        throw new ErrorMessage.MalformedFinalResult(ct,
          "Some class can not be completely typed as is still incomplete or refers to incomplete classes"
            +ErrorFormatter.reportPlaceOfMetaError(p1,ct)
            );
        }*/
        }
        return e;
    }
}
Also used : Program(programReduction.Program) ErrorMessage(ast.ErrorMessage) PData(facade.PData) ClassB(ast.ExpCore.ClassB)

Example 10 with Program

use of programReduction.Program in project L42 by ElvisResearchGroup.

the class TestLibrary method test.

@Test()
public void test() {
    Program p = TestProgram.p(sProg);
    ClassB cb1Pre = (ClassB) Desugar.of(Parser.parse(null, s1)).accept(new InjectionOnCore());
    cb1Pre = new programReduction.Norm().norm(p.evilPush(cb1Pre));
    TOut out;
    try {
        out = TypeSystem.instance().type(TIn.top(Phase.Coherent, p, cb1Pre));
    } catch (NotOkToStar coh) {
        assert s2 == ErrorKind.LibraryNotCoherent;
        return;
    }
    if (s2 instanceof ErrorKind) {
        assert !out.isOk();
        ErrorKind kind = out.toError().kind;
        assert kind == s2;
    } else {
        assert out.isOk() : "";
        ClassB cb1 = (ClassB) out.toOk().annotated;
        ClassB cbExpected = s2 == sameAsFormer ? cb1Pre : (ClassB) Desugar.of(Parser.parse(null, (String) s2)).accept(new InjectionOnCore());
        TestHelper.assertEqualExp(cb1, cbExpected);
    }
}
Also used : TestProgram(programReduction.TestProgram) Program(programReduction.Program) NotOkToStar(ast.ErrorMessage.NotOkToStar) ClassB(ast.ExpCore.ClassB) InjectionOnCore(sugarVisitors.InjectionOnCore) Test(org.junit.Test)

Aggregations

Program (programReduction.Program)25 ClassB (ast.ExpCore.ClassB)16 MethodWithType (ast.ExpCore.ClassB.MethodWithType)8 Path (ast.Ast.Path)6 ExpCore (ast.ExpCore)6 ArrayList (java.util.ArrayList)6 InjectionOnCore (sugarVisitors.InjectionOnCore)6 Ast (ast.Ast)5 MethodSelector (ast.Ast.MethodSelector)5 Type (ast.Ast.Type)5 Functions (auxiliaryGrammar.Functions)5 PData (facade.PData)5 List (java.util.List)5 Optional (java.util.Optional)5 Member (ast.ExpCore.ClassB.Member)4 CloneVisitorWithProgram (coreVisitors.CloneVisitorWithProgram)4 Collectors (java.util.stream.Collectors)4 Doc (ast.Ast.Doc)3 Mdf (ast.Ast.Mdf)3 ErrorMessage (ast.ErrorMessage)3