/** * Returns the current language context entered on the current thread. If a * {@link TruffleLanguage language} instance is available, a * {@link TruffleLanguage#getContextReference() context reference} should be used instead for * performance reasons. An {@link IllegalStateException} is thrown if the language is not yet * initialized or not executing on this thread. If invoked on the fast-path then * <code>languageClass</code> must be a compilation final value. * * @param <C> the context type * @param <T> the language type * @param languageClass the exact language class needs to be provided for the lookup. * @see TruffleLanguage#getContextReference() * @since 0.27 */ protected static <C, T extends TruffleLanguage<C>> C getCurrentContext(Class<T> languageClass) { return AccessAPI.engineAccess().getCurrentContext(languageClass); }
/** * Returns the current context associated with the language this reference was created with. * If a context is accessed during {@link TruffleLanguage#createContext(Env) context * creation} or in the language class constructor an {@link IllegalStateException} is * thrown. This methods is designed to be called safely from compiled code paths. * <p> * Please note that the current context might vary between * {@link RootNode#execute(VirtualFrame) executions} if resources or code is shared between * multiple contexts. * * @since 0.25 */ @SuppressWarnings("unchecked") public C get() { return (C) AccessAPI.engineAccess().getCurrentContext(languageShared); }
/** * Returns the current language context entered on the current thread. If a * {@link TruffleLanguage language} instance is available, a * {@link TruffleLanguage#getContextReference() context reference} should be used instead for * performance reasons. An {@link IllegalStateException} is thrown if the language is not yet * initialized or not executing on this thread. If invoked on the fast-path then * <code>languageClass</code> must be a compilation final value. * * @param <C> the context type * @param <T> the language type * @param languageClass the exact language class needs to be provided for the lookup. * @see TruffleLanguage#getContextReference() * @since 0.27 */ protected static <C, T extends TruffleLanguage<C>> C getCurrentContext(Class<T> languageClass) { return AccessAPI.engineAccess().getCurrentContext(languageClass); }
/** * Returns the current context associated with the language this reference was created with. * If a context is accessed during {@link TruffleLanguage#createContext(Env) context * creation} or in the language class constructor an {@link IllegalStateException} is * thrown. This methods is designed to be called safely from compiled code paths. * <p> * Please note that the current context might vary between * {@link RootNode#execute(VirtualFrame) executions} if resources or code is shared between * multiple contexts. * * @since 0.25 */ @SuppressWarnings("unchecked") public C get() { return (C) AccessAPI.engineAccess().getCurrentContext(languageShared); }