@SuppressWarnings("rawtypes") @TruffleBoundary <E extends TruffleLanguage> E getLanguage(Class<E> languageClass) { checkDisposed(); if (languageClass != spi.getClass()) { throw new IllegalArgumentException("Invalid access to language " + languageClass + "."); } return languageClass.cast(spi); }
@SuppressWarnings("rawtypes") @TruffleBoundary <E extends TruffleLanguage> E getLanguage(Class<E> languageClass) { checkDisposed(); if (languageClass != getSpi().getClass()) { throw new IllegalArgumentException("Invalid access to language " + languageClass + "."); } return languageClass.cast(getSpi()); }
/** * Looks additional service up. An environment for a particular {@link TruffleLanguage * language} may also be associated with additional services. One can request * implementations of such services by calling this method with the type identifying the * requested service and its API. * * Services that can be obtained via this method include * {@link com.oracle.truffle.api.instrumentation.Instrumenter} and others. * * @param <T> type of requested service * @param type class of requested service * @return instance of T or <code>null</code> if there is no such service available * @since 0.12 */ @TruffleBoundary public <T> T lookup(Class<T> type) { checkDisposed(); for (Object obj : services) { if (type.isInstance(obj)) { return type.cast(obj); } } return null; }
/** * Looks additional service up. An environment for a particular {@link TruffleLanguage * language} may also be associated with additional services. One can request * implementations of such services by calling this method with the type identifying the * requested service and its API. * * Services that can be obtained via this method include * {@link com.oracle.truffle.api.instrumentation.Instrumenter} and others. * * @param <T> type of requested service * @param type class of requested service * @return instance of T or <code>null</code> if there is no such service available * @since 0.12 */ @TruffleBoundary public <T> T lookup(Class<T> type) { checkDisposed(); for (Object obj : services) { if (type.isInstance(obj)) { return type.cast(obj); } } return null; }
/** * 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); }
/** * 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); }
/** * Returns a {@link TruffleFile} for given {@link URI}. * * @param uri the {@link URI} to create {@link TruffleFile} for * @return {@link TruffleFile} * @since 1.0 */ @TruffleBoundary public TruffleFile getTruffleFile(URI uri) { checkDisposed(); try { return new TruffleFile(fileSystem, fileSystem.parsePath(uri)); } catch (UnsupportedOperationException e) { throw new FileSystemNotFoundException("FileSystem for: " + uri.getScheme() + " scheme is not supported."); } }
/** * Allows it to be determined if this {@link org.graalvm.polyglot.Context} can execute code * written in a language with a given MIME type. * * @see Source#getMimeType() * @see #parse(Source, String...) * * @return a boolean that indicates if the MIME type is supported * @since 0.11 */ @TruffleBoundary public boolean isMimeTypeSupported(String mimeType) { checkDisposed(); return AccessAPI.engineAccess().isMimeTypeSupported(vmObject, mimeType); }
/** * Allows it to be determined if this {@link org.graalvm.polyglot.Context} can execute code * written in a language with a given MIME type. * * @see Source#getMimeType() * @see #parse(Source, String...) * * @return a boolean that indicates if the MIME type is supported * @since 0.11 */ @TruffleBoundary public boolean isMimeTypeSupported(String mimeType) { checkDisposed(); return AccessAPI.engineAccess().isMimeTypeSupported(vmObject, mimeType); }
/** * Standard output writer provided by * {@link org.graalvm.polyglot.Context.Builder#out(OutputStream)} this language is being * executed in. * * @return writer, never <code>null</code> * @since 0.8 or earlier */ @TruffleBoundary public OutputStream out() { checkDisposed(); return out; }
/** * Standard error writer provided by * {@link org.graalvm.polyglot.Context.Builder#err(OutputStream)} this language is being * executed in. * * @return writer, never <code>null</code> * @since 0.8 or earlier */ @TruffleBoundary public OutputStream err() { checkDisposed(); return err; }
/** * Configuration arguments passed from an outer language context to an inner language * context. Inner language contexts can be created using {@link #newContextBuilder()}. * * @see TruffleContext to create inner contexts. * @see TruffleContext.Builder#config(String, Object) to pass configuration objects to the * inner context. * @since 0.11 */ @TruffleBoundary public Map<String, Object> getConfig() { checkDisposed(); return config; }
/** * Configuration arguments passed from an outer language context to an inner language * context. Inner language contexts can be created using {@link #newContextBuilder()}. * * @see TruffleContext to create inner contexts. * @see TruffleContext.Builder#config(String, Object) to pass configuration objects to the * inner context. * @since 0.11 */ @TruffleBoundary public Map<String, Object> getConfig() { checkDisposed(); return config; }
/** * Standard output writer provided by * {@link org.graalvm.polyglot.Context.Builder#out(OutputStream)} this language is being * executed in. * * @return writer, never <code>null</code> * @since 0.8 or earlier */ @TruffleBoundary public OutputStream out() { checkDisposed(); return out; }
/** * Standard error writer provided by * {@link org.graalvm.polyglot.Context.Builder#err(OutputStream)} this language is being * executed in. * * @return writer, never <code>null</code> * @since 0.8 or earlier */ @TruffleBoundary public OutputStream err() { checkDisposed(); return err; }
/** * Input stream provided by {@link org.graalvm.polyglot.Context.Builder#in(InputStream)} * this language is being executed in. * * @return reader, never <code>null</code> * @since 0.8 or earlier */ @TruffleBoundary public InputStream in() { checkDisposed(); return in; }
/** * Input stream provided by {@link org.graalvm.polyglot.Context.Builder#in(InputStream)} * this language is being executed in. * * @return reader, never <code>null</code> * @since 0.8 or earlier */ @TruffleBoundary public InputStream in() { checkDisposed(); return in; }