Search in sources :

Example 81 with ClassB

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)");
    }
}
Also used : Path(ast.Ast.Path) ClassUnfit(is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.ClassUnfit) ClassB(ast.ExpCore.ClassB)

Example 82 with ClassB

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;
}
Also used : Path(ast.Ast.Path) From(coreVisitors.From) Stage(ast.Ast.Stage) Arrays(java.util.Arrays) Program(programReduction.Program) Ast(ast.Ast) Configuration(facade.Configuration) Type(ast.Ast.Type) HashMap(java.util.HashMap) Assertions(tools.Assertions) ArrayList(java.util.ArrayList) CompilationError(platformSpecific.inMemoryCompiler.InMemoryJavaCompiler.CompilationError) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) ClassB(ast.ExpCore.ClassB) InterfaceHeader(ast.Ast.InterfaceHeader) Map(java.util.Map) Facade(reduction.Facade) PathMwt(ast.Util.PathMwt) MapClassLoader(platformSpecific.inMemoryCompiler.InMemoryJavaCompiler.MapClassLoader) Method(java.lang.reflect.Method) IsCompiled(coreVisitors.IsCompiled) NestedClass(ast.ExpCore.ClassB.NestedClass) Files(java.nio.file.Files) Path(ast.Ast.Path) Doc(ast.Ast.Doc) Phase(ast.ExpCore.ClassB.Phase) IOException(java.io.IOException) ExpCore(ast.ExpCore) Member(ast.ExpCore.ClassB.Member) Functions(auxiliaryGrammar.Functions) InvocationTargetException(java.lang.reflect.InvocationTargetException) Util(ast.Util) Consumer(java.util.function.Consumer) List(java.util.List) EmptyProgram(programReduction.Program.EmptyProgram) Paths(java.nio.file.Paths) Optional(java.util.Optional) SourceFile(platformSpecific.inMemoryCompiler.InMemoryJavaCompiler.SourceFile) Timer(profiling.Timer) InMemoryJavaCompiler(platformSpecific.inMemoryCompiler.InMemoryJavaCompiler) Collections(java.util.Collections) L42(facade.L42) ArrayList(java.util.ArrayList) Member(ast.ExpCore.ClassB.Member) PathMwt(ast.Util.PathMwt) ClassB(ast.ExpCore.ClassB)

Example 83 with ClassB

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);
    }
}
Also used : Ast(ast.Ast) Path(ast.Ast.Path) ArrayList(java.util.ArrayList) NestedClass(ast.ExpCore.ClassB.NestedClass) Member(ast.ExpCore.ClassB.Member) ClassB(ast.ExpCore.ClassB)

Example 84 with ClassB

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;
    });
}
Also used : ExpCore(ast.ExpCore) InjectionOnSugar(coreVisitors.InjectionOnSugar) ClassB(ast.ExpCore.ClassB)

Example 85 with ClassB

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);
        }
    });
}
Also used : ExpCore(ast.ExpCore) Translator(platformSpecific.javaTranslation.Translator) Resources(platformSpecific.javaTranslation.Resources) ClassB(ast.ExpCore.ClassB)

Aggregations

ClassB (ast.ExpCore.ClassB)107 ArrayList (java.util.ArrayList)33 Path (ast.Ast.Path)30 ExpCore (ast.ExpCore)25 Member (ast.ExpCore.ClassB.Member)25 EncodingHelper.ensureExtractClassB (auxiliaryGrammar.EncodingHelper.ensureExtractClassB)20 Program (programReduction.Program)20 Ast (ast.Ast)19 MethodWithType (ast.ExpCore.ClassB.MethodWithType)19 MethodSelector (ast.Ast.MethodSelector)18 NestedClass (ast.ExpCore.ClassB.NestedClass)18 List (java.util.List)17 ActionType (platformSpecific.fakeInternet.ActionType)16 Doc (ast.Ast.Doc)12 Type (ast.Ast.Type)12 ErrorMessage (ast.ErrorMessage)12 Optional (java.util.Optional)10 C (ast.Ast.C)9 MethodType (ast.Ast.MethodType)8 Phase (ast.ExpCore.ClassB.Phase)8