/** * Find a list of top scopes of a language. The iteration order corresponds with the scope * nesting, from the inner-most to the outer-most. * * @param languageId a language id. * @return a list of top scopes, can be empty when no top scopes are provided by the * language * @see TruffleLanguage#findTopScopes(java.lang.Object) * @since 0.30 */ public Iterable<Scope> findTopScopes(String languageId) { LanguageInfo languageInfo = getLanguages().get(languageId); if (languageInfo == null) { throw new IllegalArgumentException("Unknown language: " + languageId + ". Known languages are: " + getLanguages().keySet()); } final TruffleLanguage.Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(languageInfo); return findTopScopes(env); }
/** * Find a list of top scopes of a language. The iteration order corresponds with the scope * nesting, from the inner-most to the outer-most. * * @param languageId a language id. * @return a list of top scopes, can be empty when no top scopes are provided by the * language * @see TruffleLanguage#findTopScopes(java.lang.Object) * @since 0.30 */ public Iterable<Scope> findTopScopes(String languageId) { LanguageInfo languageInfo = getLanguages().get(languageId); if (languageInfo == null) { throw new IllegalArgumentException("Unknown language: " + languageId + ". Known languages are: " + getLanguages().keySet()); } final TruffleLanguage.Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(languageInfo); return findTopScopes(env); }
private static TruffleLanguage.Env getLangEnv(Node node) { LanguageInfo languageInfo = node.getRootNode().getLanguageInfo(); if (languageInfo == null) { throw new IllegalArgumentException("No language available for given node."); } return AccessorInstrumentHandler.engineAccess().getEnvForInstrument(languageInfo); }
/** * Evaluates source of (potentially different) language using the current context. The names of * arguments are parameters for the resulting {#link CallTarget} that allow the * <code>source</code> to reference the actual parameters passed to * {@link CallTarget#call(java.lang.Object...)}. * * @param source the source to evaluate * @param argumentNames the names of {@link CallTarget#call(java.lang.Object...)} arguments that * can be referenced from the source * @return the call target representing the parsed result * @throws IOException if the parsing or evaluation fails for some reason * @since 0.12 * @deprecated Use * {@link TruffleInstrument.Env#parseInline(com.oracle.truffle.api.source.Source, com.oracle.truffle.api.nodes.Node, com.oracle.truffle.api.frame.MaterializedFrame)} * with {@link #getInstrumentedNode()} instead. */ @Deprecated public CallTarget parseInContext(Source source, String... argumentNames) throws IOException { Node instrumentedNode = getInstrumentedNode(); LanguageInfo languageInfo = instrumentedNode.getRootNode().getLanguageInfo(); if (languageInfo == null) { throw new IllegalArgumentException("No language available for given node."); } Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(languageInfo); return AccessorInstrumentHandler.langAccess().parse(env, source, instrumentedNode, argumentNames); }
/** * Evaluates source of (potentially different) language using the current context. The names of * arguments are parameters for the resulting {#link CallTarget} that allow the * <code>source</code> to reference the actual parameters passed to * {@link CallTarget#call(java.lang.Object...)}. * * @param source the source to evaluate * @param argumentNames the names of {@link CallTarget#call(java.lang.Object...)} arguments that * can be referenced from the source * @return the call target representing the parsed result * @throws IOException if the parsing or evaluation fails for some reason * @since 0.12 * @deprecated Use * {@link TruffleInstrument.Env#parseInline(com.oracle.truffle.api.source.Source, com.oracle.truffle.api.nodes.Node, com.oracle.truffle.api.frame.MaterializedFrame)} * with {@link #getInstrumentedNode()} instead. */ @Deprecated public CallTarget parseInContext(Source source, String... argumentNames) throws IOException { Node instrumentedNode = getInstrumentedNode(); LanguageInfo languageInfo = instrumentedNode.getRootNode().getLanguageInfo(); if (languageInfo == null) { throw new IllegalArgumentException("No language available for given node."); } Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(languageInfo); return AccessorInstrumentHandler.langAccess().parse(env, source, instrumentedNode, argumentNames); }
/** * 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; }
/** * Uses the provided language to find a meta-object of a value, if any. The meta-object * represents a description of the object, reveals it's kind and it's features. Some * information that a meta-object might define includes the base object's type, interface, * class, methods, attributes, etc. When no meta-object is known, <code>null</code> is * returned. For the best results, use the {@link #findLanguage(java.lang.Object) value's * language}, if any. * * @param language a language * @param value a value to find the meta-object of, must be an interop type (i.e. either * implementing TruffleObject or be a primitive value) * @return the meta-object, or <code>null</code> * @see #findLanguage(java.lang.Object) * @since 0.27 */ public Object findMetaObject(LanguageInfo language, Object value) { AccessorInstrumentHandler.interopAccess().checkInteropType(value); final TruffleLanguage.Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(language); Object metaObject = AccessorInstrumentHandler.langAccess().findMetaObject(env, value); assert checkNullOrInterop(metaObject); return metaObject; }
/** * Uses the provided language to find a meta-object of a value, if any. The meta-object * represents a description of the object, reveals it's kind and it's features. Some * information that a meta-object might define includes the base object's type, interface, * class, methods, attributes, etc. When no meta-object is known, <code>null</code> is * returned. For the best results, use the {@link #findLanguage(java.lang.Object) value's * language}, if any. * * @param language a language * @param value a value to find the meta-object of, must be an interop type (i.e. either * implementing TruffleObject or be a primitive value) * @return the meta-object, or <code>null</code> * @see #findLanguage(java.lang.Object) * @since 0.27 */ public Object findMetaObject(LanguageInfo language, Object value) { AccessorInstrumentHandler.interopAccess().checkInteropType(value); final TruffleLanguage.Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(language); return AccessorInstrumentHandler.langAccess().findMetaObject(env, value); }
/** * Test if language context of the source of the event is initialized. * * @since 0.26 */ public boolean isLanguageContextInitialized() { CompilerAsserts.neverPartOfCompilation(); Node node = getInstrumentedNode(); if (node == null) { return true; } RootNode root = node.getRootNode(); if (root == null) { return true; } LanguageInfo languageInfo = root.getLanguageInfo(); Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(languageInfo); return AccessorInstrumentHandler.langAccess().isContextInitialized(env); }
/** * Evaluates source of (potentially different) language using the current context.The names * of arguments are parameters for the resulting {#link CallTarget} that allow the * <code>source</code> to reference the actual parameters passed to * {@link CallTarget#call(java.lang.Object...)}. * * @param source the source to evaluate * @param argumentNames the names of {@link CallTarget#call(java.lang.Object...)} arguments * that can be referenced from the source * @return the call target representing the parsed result * @throws IOException if the parsing or evaluation fails for some reason * @since 0.12 */ public CallTarget parse(Source source, String... argumentNames) throws IOException { TruffleLanguage.Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(vmObject, source.getLanguage(), source.getMimeType()); return AccessorInstrumentHandler.langAccess().parse(env, source, null, argumentNames); }
/** * Evaluates source of (potentially different) language using the current context.The names * of arguments are parameters for the resulting {#link CallTarget} that allow the * <code>source</code> to reference the actual parameters passed to * {@link CallTarget#call(java.lang.Object...)}. * * @param source the source to evaluate * @param argumentNames the names of {@link CallTarget#call(java.lang.Object...)} arguments * that can be referenced from the source * @return the call target representing the parsed result * @throws IOException if the parsing or evaluation fails for some reason * @since 0.12 */ public CallTarget parse(Source source, String... argumentNames) throws IOException { TruffleLanguage.Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(vmObject, source.getLanguage(), source.getMimeType()); return AccessorInstrumentHandler.langAccess().parse(env, source, null, argumentNames); }
/** * Uses the provided language to find a source location where a value is declared, if any. * For the best results, use the {@link #findLanguage(java.lang.Object) value's language}, * if any. * * @param language a language * @param value a value to get the source location for, must be an interop type (i.e. either * implementing TruffleObject or be a primitive value) * @return a source location of the object, or <code>null</code> * @see #findLanguage(java.lang.Object) * @since 0.27 */ public SourceSection findSourceLocation(LanguageInfo language, Object value) { AccessorInstrumentHandler.interopAccess().checkInteropType(value); final TruffleLanguage.Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(language); return AccessorInstrumentHandler.langAccess().findSourceLocation(env, value); }
/** * Test if language context of the source of the event is initialized. * * @since 0.26 */ public boolean isLanguageContextInitialized() { CompilerAsserts.neverPartOfCompilation(); Node node = getInstrumentedNode(); if (node == null) { return true; } RootNode root = node.getRootNode(); if (root == null) { return true; } LanguageInfo languageInfo = root.getLanguageInfo(); Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(languageInfo); return AccessorInstrumentHandler.langAccess().isContextInitialized(env); }
/** * Uses the provided language to print a string representation of this value. The behavior * of this method is undefined if a type unknown to the language is passed as a value. * * @param language a language * @param value a known value of that language, must be an interop type (i.e. either * implementing TruffleObject or be a primitive value) * @return a human readable string representation of the value. * @see #findLanguage(java.lang.Object) * @since 0.27 */ public String toString(LanguageInfo language, Object value) { AccessorInstrumentHandler.interopAccess().checkInteropType(value); final TruffleLanguage.Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(language); return AccessorInstrumentHandler.langAccess().toStringIfVisible(env, value, false); }
/** * Uses the provided language to find a source location where a value is declared, if any. * For the best results, use the {@link #findLanguage(java.lang.Object) value's language}, * if any. * * @param language a language * @param value a value to get the source location for, must be an interop type (i.e. either * implementing TruffleObject or be a primitive value) * @return a source location of the object, or <code>null</code> * @see #findLanguage(java.lang.Object) * @since 0.27 */ public SourceSection findSourceLocation(LanguageInfo language, Object value) { AccessorInstrumentHandler.interopAccess().checkInteropType(value); final TruffleLanguage.Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(language); return AccessorInstrumentHandler.langAccess().findSourceLocation(env, value); }
/** * Uses the provided language to print a string representation of this value. The behavior * of this method is undefined if a type unknown to the language is passed as a value. * * @param language a language * @param value a known value of that language, must be an interop type (i.e. either * implementing TruffleObject or be a primitive value) * @return a human readable string representation of the value. * @see #findLanguage(java.lang.Object) * @since 0.27 */ public String toString(LanguageInfo language, Object value) { AccessorInstrumentHandler.interopAccess().checkInteropType(value); final TruffleLanguage.Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(language); return AccessorInstrumentHandler.langAccess().toStringIfVisible(env, value, false); }
protected CallTarget parse(Source code, Node context, String... argumentNames) { RootNode rootNode = context.getRootNode(); return languageSupport().parse(engineSupport().getEnvForInstrument(rootNode.getLanguageInfo()), code, context, argumentNames); }
private void assertIsObjectOfLanguage(Object obj) throws Exception { enterTCK(); // hack to ensure entered PolyglotRuntime.Instrument instr = vm().getRuntime().getInstruments().get(TckInstrument.ID); TruffleLanguage.Env env = TruffleTCKAccessor.engineAccess().getEnvForInstrument(instr, null, mimeType()); assertTrue(obj.toString(), TruffleTCKAccessor.langAccess().isObjectOfLanguage(env, obj)); }
private static TruffleLanguage.Env getLangEnv(Node node) { LanguageInfo languageInfo = node.getRootNode().getLanguageInfo(); if (languageInfo == null) { throw new IllegalArgumentException("No language available for given node."); } return AccessorInstrumentHandler.engineAccess().getEnvForInstrument(languageInfo); }
protected CallTarget parse(Source code, Node context, String... argumentNames) { RootNode rootNode = context.getRootNode(); return languageSupport().parse(engineSupport().getEnvForInstrument(rootNode.getLanguageInfo()), code, context, argumentNames); }