private static String langId(LanguageInfo languageInfo) { if (languageInfo == null) { return null; } else { return languageInfo.getId(); } }
@Override public LanguageInfo createLanguage(Object vmObject, String id, String name, String version, String defaultMimeType, Set<String> mimeTypes, boolean internal, boolean interactive) { return new LanguageInfo(vmObject, id, name, version, defaultMimeType, mimeTypes, internal, interactive); }
@Override public Object getEngineObject(LanguageInfo languageInfo) { return languageInfo.getEngineObject(); }
private static Object evalInContext(SuspendedEvent ev, Node node, MaterializedFrame frame, String code) { RootNode rootNode = node.getRootNode(); if (rootNode == null) { throw new IllegalArgumentException("Cannot evaluate in context using a node that is not yet adopated using a RootNode."); } LanguageInfo info = rootNode.getLanguageInfo(); if (info == null) { throw new IllegalArgumentException("Cannot evaluate in context using a without an associated TruffleLanguage."); } if (!info.isInteractive()) { throw new IllegalStateException("Can not evaluate in a non-interactive language."); } final Source source = Source.newBuilder(info.getId(), code, "eval in context").build(); ExecutableNode fragment = ev.getSession().getDebugger().getEnv().parseInline(source, node, frame); if (fragment != null) { ev.getInsertableNode().setParentOf(fragment); return fragment.execute(frame); } else { return Debugger.ACCESSOR.evalInContext(source, node, frame); } }
@Override boolean isInstrumentableSource(Source source) { String mimeType = source.getMimeType(); if (mimeType == null) { return false; } return languageInfo.getMimeTypes().contains(mimeType); }
@Override public TruffleLanguage<?> getLanguageSpi(LanguageInfo languageInfo) { return languageInfo.getSpi(); }
@Override public void onLanguageContextInitialized(TruffleContext context, LanguageInfo language) { if (!language.isInternal()) { nonInternalLanguageContextInitialized = true; } }
@Override public void setLanguageSpi(LanguageInfo languageInfo, TruffleLanguage<?> spi) { languageInfo.setSpi(spi); }
@Override boolean isInstrumentableSource(Source source) { String mimeType = source.getMimeType(); if (mimeType == null) { return false; } return languageInfo.getMimeTypes().contains(mimeType); }
/** * Returns the language instance associated with this executable node. The language instance is * intended for internal use in languages and is only accessible if the concrete type of the * language is known. Public information about the language can be accessed using * {@link #getLanguageInfo()}. The language is <code>null</code> if the executable node is not * associated with a <code>null</code> language. * * @see #getLanguageInfo() * @since 0.31 */ @SuppressWarnings("rawtypes") public final <C extends TruffleLanguage> C getLanguage(Class<C> languageClass) { if (languageInfo == null) { return null; } TruffleLanguage<?> language = languageInfo.getSpi(); if (language.getClass() != languageClass) { if (!languageClass.isInstance(language) || languageClass == TruffleLanguage.class || !TruffleLanguage.class.isAssignableFrom(languageClass)) { CompilerDirectives.transferToInterpreter(); throw new ClassCastException("Illegal language class specified. Expected " + language.getClass().getName() + "."); } } return languageClass.cast(language); }
private static String langId(LanguageInfo languageInfo) { if (languageInfo == null) { return null; } else { return languageInfo.getId(); } }
@Override public Object getEngineObject(LanguageInfo languageInfo) { return languageInfo.getEngineObject(); }
LanguageShared lang = new LanguageShared(this, languageCache, languageIndex++); languageList.add(lang); for (String mimeType : lang.language.getMimeTypes()) { langInfos.put(mimeType, lang.language);
@Override public LanguageInfo createLanguage(Object vmObject, String id, String name, String version, Set<String> mimeTypes, boolean internal) { return new LanguageInfo(vmObject, id, name, version, mimeTypes, internal); }
@Override public Object lookupSymbol(Object vmObject, Env env, LanguageInfo language, String symbolName) { PolyglotLanguageContext context = (PolyglotLanguageContext) vmObject; int index = context.context.engine.idToLanguage.get(language.getId()).index; return context.context.contexts[index].lookupGuest(symbolName); }
/** * Creates new root node given an language environment and frame descriptor. The language * instance is obtainable while {@link TruffleLanguage#createContext(Env)} or * {@link TruffleLanguage#parse(ParsingRequest)} is executed. If no language environment is * available, then <code>null</code> can be passed. Please note that root nodes with * <code>null</code> language are considered not instrumentable and have no access to the * {@link #getLanguage(Class) language} or its public {@link #getLanguageInfo() information}. * * @param language the language this root node is associated with * @since 0.25 */ protected RootNode(TruffleLanguage<?> language, FrameDescriptor frameDescriptor) { super(language); CompilerAsserts.neverPartOfCompilation(); if (this.languageInfo != null) { this.sourceVM = Node.ACCESSOR.engineSupport().getVMFromLanguageObject(this.languageInfo.getEngineObject()); } else { this.sourceVM = getCurrentVM(); } this.frameDescriptor = frameDescriptor == null ? new FrameDescriptor() : frameDescriptor; }
@SuppressWarnings({"unchecked", "rawtypes"}) static Map<String, Object>[] toMap(Map<LanguageInfo, Map<String, HeapSummary>> summaries) { List<Map<String, Object>> heapHisto = new ArrayList<>(summaries.size()); for (Entry<LanguageInfo, Map<String, HeapSummary>> objectsByLanguage : summaries.entrySet()) { LanguageInfo language = objectsByLanguage.getKey(); for (Entry<String, HeapSummary> objectsByMetaObject : objectsByLanguage.getValue().entrySet()) { HeapSummary mi = objectsByMetaObject.getValue(); Map<String, Object> metaObjMap = new HashMap<>(); metaObjMap.put("language", language.getId()); metaObjMap.put("name", objectsByMetaObject.getKey()); metaObjMap.put("totalInstances", mi.getTotalInstances()); metaObjMap.put("totalBytes", mi.getTotalBytes()); metaObjMap.put("aliveInstances", mi.getAliveInstances()); metaObjMap.put("aliveBytes", mi.getAliveBytes()); heapHisto.add(metaObjMap); } } return heapHisto.toArray(new Map[0]); }
/** * Creates new root node given an language environment and frame descriptor. The language * instance is obtainable while {@link TruffleLanguage#createContext(Env)} or * {@link TruffleLanguage#parse(ParsingRequest)} is executed. If no language environment is * available, then <code>null</code> can be passed. Please note that root nodes with * <code>null</code> language are considered not instrumentable and have no access to the * {@link #getLanguage(Class) language} or its public {@link #getLanguageInfo() information}. * * @param language the language this root node is associated with * @since 0.25 */ protected RootNode(TruffleLanguage<?> language, FrameDescriptor frameDescriptor) { super(language); CompilerAsserts.neverPartOfCompilation(); if (this.language != null) { this.sourceVM = Node.ACCESSOR.engineSupport().getVMFromLanguageObject(Node.ACCESSOR.languageSupport().getLanguageInfo(this.language).getEngineObject()); } else { this.sourceVM = getCurrentVM(); } this.frameDescriptor = frameDescriptor == null ? new FrameDescriptor() : frameDescriptor; }
void checkAccess(PolyglotLanguage accessingLanguage) { context.engine.checkState(); if (context.closed) { throw new PolyglotIllegalStateException("The Context is already closed."); } boolean accessPermitted = language.isHost() || language.cache.isInternal() || context.allowedPublicLanguages.contains(language.info.getId()) || (accessingLanguage != null && accessingLanguage.dependsOn(language)); if (!accessPermitted) { throw new PolyglotIllegalStateException(String.format("Access to language '%s' is not permitted. ", language.getId())); } RuntimeException initError = language.initError; if (initError != null) { throw new PolyglotIllegalStateException(String.format("Initialization error: %s", initError.getMessage()), initError); } }
void checkAccess(PolyglotLanguage accessingLanguage) { context.engine.checkState(); if (context.closed) { throw new PolyglotIllegalStateException("The Context is already closed."); } boolean accessPermitted = language.isHost() || language.cache.isInternal() || context.config.allowedPublicLanguages.contains(language.info.getId()) || (accessingLanguage != null && accessingLanguage.dependsOn(language)); if (!accessPermitted) { throw new PolyglotIllegalArgumentException(String.format("Access to language '%s' is not permitted. ", language.getId())); } RuntimeException initError = language.initError; if (initError != null) { throw new PolyglotIllegalStateException(String.format("Initialization error: %s", initError.getMessage()), initError); } }