@Override public void collectEnvServices(Set<Object> collectTo, Object languageShared, TruffleLanguage<?> language) { InstrumentationHandler instrumentationHandler = (InstrumentationHandler) engineAccess().getInstrumentationHandler(languageShared); Instrumenter instrumenter = instrumentationHandler.forLanguage(language); collectTo.add(instrumenter); AllocationReporter allocationReporter = instrumentationHandler.getAllocationReporter(AccessorInstrumentHandler.langAccess().getLanguageInfo(language)); collectTo.add(allocationReporter); }
static <T extends TruffleLanguage<?>> T findLanguageByClass(Object vm, Class<T> languageClass) { Env env = SPI.findEnv(vm, languageClass, true); TruffleLanguage<?> language = NODES.getLanguageSpi(API.getLanguageInfo(env)); return languageClass.cast(language); }
/** * Creates new executable node with a given language instance. The language instance is * obtainable while {@link TruffleLanguage#parse(InlineParsingRequest)} is executed. * * @param language the language this executable node is associated with * @since 0.31 */ protected ExecutableNode(TruffleLanguage<?> language) { CompilerAsserts.neverPartOfCompilation(); if (language != null) { this.languageInfo = Node.ACCESSOR.languageSupport().getLanguageInfo(language); if (languageInfo == null) { throw new IllegalArgumentException("Truffle language instance is not initialized."); } } else { this.languageInfo = null; } }
/** * Parses source snippet of the node's language at the provided node location. The result is * an AST fragment represented by {@link ExecutableNode} that accepts frames valid at the * provided node location, or <code>null</code> when inline parsing is not supported by the * language. * * @param source a source snippet to parse at the provided node location * @param node a context location where the source is parsed at, must not be * <code>null</code> * @param frame a frame location where the source is parsed at, can be <code>null</code> * @return the executable fragment representing the parsed result, or <code>null</code> * @since 0.31 */ public ExecutableNode parseInline(Source source, Node node, MaterializedFrame frame) { if (node == null) { throw new IllegalArgumentException("Node must not be null."); } TruffleLanguage.Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(vmObject, source.getLanguage(), source.getMimeType()); // Assert that the languages match: assert AccessorInstrumentHandler.langAccess().getLanguageInfo(env) == node.getRootNode().getLanguageInfo(); ExecutableNode fragment = AccessorInstrumentHandler.langAccess().parseInline(env, source, node, frame); if (fragment != null) { TruffleLanguage<?> languageSPI = AccessorInstrumentHandler.langAccess().getSPI(env); fragment = new GuardedExecutableNode(languageSPI, fragment, frame); } return fragment; }
/** * Parses source snippet of the node's language at the provided node location. The result is * an AST fragment represented by {@link ExecutableNode} that accepts frames valid at the * provided node location, or <code>null</code> when inline parsing is not supported by the * language. * * @param source a source snippet to parse at the provided node location * @param node a context location where the source is parsed at, must not be * <code>null</code> * @param frame a frame location where the source is parsed at, can be <code>null</code> * @return the executable fragment representing the parsed result, or <code>null</code> * @since 0.31 */ public ExecutableNode parseInline(Source source, Node node, MaterializedFrame frame) { if (node == null) { throw new IllegalArgumentException("Node must not be null."); } TruffleLanguage.Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(vmObject, source.getLanguage(), source.getMimeType()); // Assert that the languages match: assert AccessorInstrumentHandler.langAccess().getLanguageInfo(env) == node.getRootNode().getLanguageInfo(); ExecutableNode fragment = AccessorInstrumentHandler.langAccess().parseInline(env, source, node, frame); if (fragment != null) { TruffleLanguage<?> languageSPI = AccessorInstrumentHandler.langAccess().getSPI(env); fragment = new GuardedExecutableNode(languageSPI, fragment, frame); } return fragment; }
/** * 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; }
/** * Returns public information about the language. The language can be assumed equal if the * instances of the language info instance are the same. To access internal details of the * language within the language implementation use {@link #getLanguage(Class)}. * * @since 0.31 */ public final LanguageInfo getLanguageInfo() { if (language != null) { return Node.ACCESSOR.languageSupport().getLanguageInfo(language); } else { return null; } }
FindContextNodeImpl(Env env) { this.env = env; this.languageShared = (LanguageShared) NODES.getEngineObject(LANGUAGE.getLanguageInfo(env)); }
static Iterable<Scope> findTopScopes(TruffleLanguage.Env env) { Iterable<Scope> langScopes = AccessorInstrumentHandler.langAccess().findTopScopes(env); assert langScopes != null : AccessorInstrumentHandler.langAccess().getLanguageInfo(env).getId(); return langScopes; }
@SuppressWarnings("unchecked") @Override public TruffleLanguage<C> getTruffleLanguage() { return (TruffleLanguage<C>) NODES.getLanguageSpi(LANGUAGE.getLanguageInfo(env)); } }
LanguageClientInstrumenter(TruffleLanguage<?> language) { this.language = language; this.languageInfo = AccessorInstrumentHandler.langAccess().getLanguageInfo(language); }
static Iterable<Scope> findTopScopes(TruffleLanguage.Env env) { Iterable<Scope> langScopes = AccessorInstrumentHandler.langAccess().findTopScopes(env); assert langScopes != null : AccessorInstrumentHandler.langAccess().getLanguageInfo(env).getId(); return langScopes; }