/** * Looks up symbol in the top-most scope of the language. Returns <code>null</code> if no * symbol was found. * <p> * The returned object can either be <code>TruffleObject</code> (e.g. a native object from * the other language) to support interoperability between languages, {@link String} or one * of the Java primitive wrappers ( {@link Integer}, {@link Double}, {@link Byte}, * {@link Boolean}, etc.). * <p> * * @param language the language too lookup. must not be null. * @param symbolName the name of the symbol in the top-most scope. * @since 0.27 * @deprecated deprecated without replacement. the language * {@link Context#getBindings(String) bindings} may be exposed to the language * using the polyglot bindings. */ @TruffleBoundary @Deprecated public Object lookupSymbol(@SuppressWarnings("hiding") LanguageInfo language, String symbolName) { return AccessAPI.engineAccess().lookupSymbol(vmObject, this, language, symbolName); }
@Override public Env createEnv(Object vmObject, TruffleLanguage<?> language, OutputStream stdOut, OutputStream stdErr, InputStream stdIn, Map<String, Object> config, OptionValues options, String[] applicationArguments, FileSystem fileSystem) { Env env = new Env(vmObject, language, stdOut, stdErr, stdIn, config, options, applicationArguments, fileSystem); LinkedHashSet<Object> collectedServices = new LinkedHashSet<>(); LanguageInfo info = language.languageInfo; AccessAPI.instrumentAccess().collectEnvServices(collectedServices, API.nodes().getEngineObject(info), language); env.services = new ArrayList<>(collectedServices); return env; }
/** * Set arguments of the scope. * <p> * The properties representing the arguments needs to have deterministic iteration order, * argument declaration order is recommended. * * @param arguments arguments of the scope * @since 0.30 */ @SuppressWarnings("hiding") public Builder arguments(Object arguments) { assert arguments == null || TruffleLanguage.AccessAPI.interopAccess().isTruffleObject(arguments) : Objects.toString(arguments); this.arguments = arguments; return this; }
return AccessAPI.engineAccess().createThread(vmObject, runnable, context != null ? context.impl : null, group, stackSize);
return AccessAPI.engineAccess().createThread(vmObject, runnable, context != null ? context.impl : null);
/** * Find a hierarchy of local scopes enclosing the given {@link Node node}. Unless the node is in * a global scope, it is expected that there is at least one scope provided, that corresponds to * the enclosing function. The language might provide additional block scopes, closure scopes, * etc. Global top scopes are provided by {@link #findTopScopes(java.lang.Object)}. The scope * hierarchy should correspond with the scope nesting, from the inner-most to the outer-most. * The scopes are expected to contain variables valid at the given node. * <p> * Scopes may depend on the information provided by the frame. <br/> * Lexical scopes are returned when <code>frame</code> argument is <code>null</code>. * <p> * When not overridden, the enclosing {@link RootNode}'s scope with variables read from its * {@link FrameDescriptor}'s {@link FrameSlot}s is provided by default. * <p> * The * {@link com.oracle.truffle.api.instrumentation.TruffleInstrument.Env#findLocalScopes(com.oracle.truffle.api.nodes.Node, com.oracle.truffle.api.frame.Frame)} * provides result of this method to instruments. * * @param context the current context of the language * @param node a node to find the enclosing scopes for. The node, is inside a {@link RootNode} * associated with this language. * @param frame The current frame the node is in, or <code>null</code> for lexical access when * the program is not running, or is not suspended at the node's location. * @return an iterable with scopes in their nesting order from the inner-most to the outer-most. * @since 0.30 */ protected Iterable<Scope> findLocalScopes(C context, Node node, Frame frame) { assert node != null; return AccessAPI.engineAccess().createDefaultLexicalScope(node, frame); }
/** * Enters this context and returns an object representing the previous context. Calls to enter * must be followed by a call to {@link #leave(Object)} in a finally block and the previous * context must be passed as an argument. It is allowed to enter a context multiple times from * the same thread. If the context is currently not entered by any thread then it is allowed be * entered by an arbitrary thread. Entering the context from two or more different threads at * the same time is possible, unless one of the loaded languages denies access to the thread, in * which case an {@link IllegalStateException} is thrown. The result of the enter function is * unspecified and must only be passed to {@link #leave(Object)}. The result value must not be * stored permanently. * <p> * Entering a language context is designed for compilation and is most efficient if the * {@link TruffleContext context} instance is compilation final. * * <p> * Example usage: {@link TruffleContextSnippets#executeInContext} * * @see #leave(Object) * @since 0.27 */ public Object enter() { Object prev = AccessAPI.engineAccess().enterInternalContext(impl); assert verifyEnter(prev); return prev; }
/** * Find a hierarchy of local scopes enclosing the given {@link Node node}. Unless the node is in * a global scope, it is expected that there is at least one scope provided, that corresponds to * the enclosing function. The language might provide additional block scopes, closure scopes, * etc. Global top scopes are provided by {@link #findTopScopes(java.lang.Object)}. The scope * hierarchy should correspond with the scope nesting, from the inner-most to the outer-most. * The scopes are expected to contain variables valid at the given node. * <p> * Scopes may depend on the information provided by the frame. <br/> * Lexical scopes are returned when <code>frame</code> argument is <code>null</code>. * <p> * When not overridden, the enclosing {@link RootNode}'s scope with variables read from its * {@link FrameDescriptor}'s {@link FrameSlot}s is provided by default. * <p> * The * {@link com.oracle.truffle.api.instrumentation.TruffleInstrument.Env#findLocalScopes(com.oracle.truffle.api.nodes.Node, com.oracle.truffle.api.frame.Frame)} * provides result of this method to instruments. * * @param context the current context of the language * @param node a node to find the enclosing scopes for. The node, is inside a {@link RootNode} * associated with this language. * @param frame The current frame the node is in, or <code>null</code> for lexical access when * the program is not running, or is not suspended at the node's location. * @return an iterable with scopes in their nesting order from the inner-most to the outer-most. * @since 0.30 */ protected Iterable<Scope> findLocalScopes(C context, Node node, Frame frame) { assert node != null; return AccessAPI.engineAccess().createDefaultLexicalScope(node, frame); }
/** * Enters this context and returns an object representing the previous context. Calls to enter * must be followed by a call to {@link #leave(Object)} in a finally block and the previous * context must be passed as an argument. It is allowed to enter a context multiple times from * the same thread. If the context is currently not entered by any thread then it is allowed be * entered by an arbitrary thread. Entering the context from two or more different threads at * the same time is possible, unless one of the loaded languages denies access to the thread, in * which case an {@link IllegalStateException} is thrown. The result of the enter function is * unspecified and must only be passed to {@link #leave(Object)}. The result value must not be * stored permanently. * <p> * Entering a language context is designed for compilation and is most efficient if the * {@link TruffleContext context} instance is compilation final. * * <p> * Example usage: {@link TruffleContextSnippets#executeInContext} * * @see #leave(Object) * @since 0.27 */ public Object enter() { Object prev = AccessAPI.engineAccess().enterInternalContext(impl); assert verifyEnter(prev); return prev; }
/** * Returns an additional service provided by the given language, specified by type. If an * language is not loaded, it will not be automatically loaded by requesting a service. In * order to ensure a language to be loaded at least one {@link Source} must be * {@link #parse(Source, String...) parsed} first. * * @param <S> the requested type * @param language the language to query * @param type the class of the requested type * @return the registered service or <code>null</code> if none is found * @since 0.26 */ @TruffleBoundary public <S> S lookup(LanguageInfo language, Class<S> type) { if (this.getSpi().languageInfo == language) { throw new IllegalArgumentException("Cannot request services from the current language."); } Env otherEnv = AccessAPI.engineAccess().getLanguageEnv(this, language); return otherEnv.getSpi().lookup(type); }
/** * Evaluates source of (potentially different) language. The {@link Source#getMimeType() * MIME type} is used to identify the {@link TruffleLanguage} to use to perform the * {@link #parse(com.oracle.truffle.api.TruffleLanguage.ParsingRequest)} . 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 * @since 0.8 or earlier */ @TruffleBoundary public CallTarget parse(Source source, String... argumentNames) { CompilerAsserts.neverPartOfCompilation(); checkDisposed(); return AccessAPI.engineAccess().parseForLanguage(vmObject, source, argumentNames); }
/** * Explicitely exports a symbol to the polyglot bindings object. The behavior of this method * is equivalent to sending a WRITE message to the {@link #getPolyglotBindings() polyglot * bindings} object. Exporting a symbol with a <code>null</code> value will remove the * symbol from the polyglot object. * <p> * The exported symbol value can either be a <code>TruffleObject</code> (e.g. a native * object from the other language) to support interoperability between languages, * {@link String} or one of the Java primitive wrappers ( {@link Integer}, {@link Double}, * {@link Byte}, {@link Boolean}, etc.). * * @param symbolName the name with which the symbol should be exported into the polyglot * scope * @param value the value to export for * @since 0.27 */ @TruffleBoundary public void exportSymbol(String symbolName, Object value) { AccessAPI.engineAccess().exportSymbol(vmObject, symbolName, value); }
/** * Returns an additional service provided by the given language, specified by type. If an * language is not loaded, it will not be automatically loaded by requesting a service. In * order to ensure a language to be loaded at least one {@link Source} must be * {@link #parse(Source, String...) parsed} first. * * @param <S> the requested type * @param language the language to query * @param type the class of the requested type * @return the registered service or <code>null</code> if none is found * @since 0.26 */ @TruffleBoundary public <S> S lookup(@SuppressWarnings("hiding") LanguageInfo language, Class<S> type) { if (this.language == language) { throw new IllegalArgumentException("Cannot request services from the current language."); } TruffleLanguage<?> otherSpi = AccessAPI.nodesAccess().getLanguageSpi(language); return otherSpi.lookup(type); }
/** * Converts a existing Java host object to a guest language value. If the value is already * an interop value, then no conversion will be performed. Otherwise, the returned wraps the * host object and provides support for the interop contract to access the java members. The * interpretation of converted objects is described in {@link Context#asValue(Object)}. * <p> * This method should be used exclusively to convert already allocated Java objects to a * guest language representation. To allocate new host objects users should use * {@link #lookupHostSymbol(String)} to lookup the class and then send a NEW interop message * to that object to instantiate it. This method does not respect configured * {@link org.graalvm.polyglot.Context.Builder#hostClassFilter(java.util.function.Predicate) * class filters}. * * @param hostObject the host object to convert * @since 1.0 */ public Object asGuestValue(Object hostObject) { return AccessAPI.engineAccess().toGuestValue(hostObject, vmObject); }
/** * Explicitely imports a symbol from the polyglot bindings. The behavior of this method is * equivalent to sending a READ message to the {@link #getPolyglotBindings() polyglot * bindings} object. Reading a symbol that does not exist will return <code>null</code>. * <p> * The returned symbol value can either be a <code>TruffleObject</code> (e.g. a native * object from the other language) to support interoperability between languages, * {@link String} or one of the Java primitive wrappers ( {@link Integer}, {@link Double}, * {@link Byte}, {@link Boolean}, etc.). * <p> * * @param symbolName the name of the symbol to search for * @return object representing the symbol or <code>null</code> if it does not exist * @since 0.8 or earlier */ @TruffleBoundary public Object importSymbol(String symbolName) { return AccessAPI.engineAccess().importSymbol(vmObject, this, symbolName); }
/** * Closes this context and disposes its resources. A context cannot be closed if it is currently * {@link #enter() entered} by any thread. If a closed context is attempted to be accessed or * entered, then an {@link IllegalStateException} is thrown. If the context is not closed * explicitly, then it is automatically closed together with the parent context. If an attempt * to close a context was successful then consecutive calls to close have no effect. * <p> * Only contexts created by {@link Builder#build()} can be explicitly closed. Other instances * throw {@link UnsupportedOperationException} on close attempts. * * @throws UnsupportedOperationException when not created by {@link Builder#build()}. * @since 0.27 */ @Override @TruffleBoundary public void close() { if (!closeable) { throw new UnsupportedOperationException("It's not possible to close a foreign context."); } AccessAPI.engineAccess().closeInternalContext(impl); }
/** * Closes this context and disposes its resources. A context cannot be closed if it is currently * {@link #enter() entered} by any thread. If a closed context is attempted to be accessed or * entered, then an {@link IllegalStateException} is thrown. If the context is not closed * explicitly, then it is automatically closed together with the parent context. If an attempt * to close a context was successful then consecutive calls to close have no effect. * <p> * Only contexts created by {@link Builder#build()} can be explicitly closed. Other instances * throw {@link UnsupportedOperationException} on close attempts. * * @throws UnsupportedOperationException when not created by {@link Builder#build()}. * @since 0.27 */ @Override @TruffleBoundary public void close() { if (!closeable) { throw new UnsupportedOperationException("It's not possible to close a foreign context."); } AccessAPI.engineAccess().closeInternalContext(impl); }
/** * Checks if a message of the given level would be logged by this logger. * * @param level the required logging level * @return true if message is loggable by this logger * @since 1.0 */ public boolean isLoggable(final Level level) { int value = getLevelNum(); if (level.intValue() < value || value == OFF_VALUE) { return false; } final Object currentContext = TruffleLanguage.AccessAPI.engineAccess().getCurrentOuterContext(); if (currentContext == null) { return false; } return isLoggableSlowPath(currentContext, level); }
/** * Evaluates source of (potentially different) language. The {@link Source#getMimeType() * MIME type} is used to identify the {@link TruffleLanguage} to use to perform the * {@link #parse(com.oracle.truffle.api.TruffleLanguage.ParsingRequest)} . 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 * @since 0.8 or earlier */ @TruffleBoundary public CallTarget parse(Source source, String... argumentNames) { CompilerAsserts.neverPartOfCompilation(); checkDisposed(); return AccessAPI.engineAccess().getEnvForLanguage(vmObject, source.getLanguage(), source.getMimeType()).spi.parse(source, null, null, argumentNames); }