public static final class TruffleLanguage.Env extends Object
TruffleLanguage. Each active
TruffleLanguage receives instance of the environment before any code is executed upon
it. The environment has knowledge of all active languages and can exchange symbols between
them.| Modifier and Type | Method and Description |
|---|---|
OutputStream |
err()
Standard error writer for
PolyglotEngine this language
is being executed in. |
Map<String,Object> |
getConfig()
Configuration arguments for this language.
|
Map<String,InstrumentInfo> |
getInstruments()
Returns a map instrument-id to instrument instance of all instruments that are installed
in the environment.
|
Map<String,LanguageInfo> |
getLanguages()
Returns a map mime-type to language instance of all languages that are installed in the
environment.
|
Object |
importSymbol(String globalName)
Asks the environment to go through other registered languages and find whether they
export global symbol of specified name.
|
Iterable<? extends Object> |
importSymbols(String globalName)
Returns an iterable collection of global symbols that are exported for a given name.
|
InputStream |
in()
Input associated with
PolyglotEngine this language is
being executed in. |
boolean |
isMimeTypeSupported(String mimeType)
Allows it to be determined if this
PolyglotEngine can
execute code written in a language with a given MIME type. |
<T> T |
lookup(Class<T> type)
Looks additional service up.
|
<S> S |
lookup(InstrumentInfo instrument,
Class<S> type)
Returns an additional service provided by this instrument, specified by type.
|
<S> S |
lookup(LanguageInfo language,
Class<S> type)
Returns an additional service provided by the given language, specified by type.
|
OutputStream |
out()
Standard output writer for
PolyglotEngine this language
is being executed in. |
CallTarget |
parse(Source source,
String... argumentNames)
Evaluates source of (potentially different) language.
|
public Object importSymbol(String globalName)
TruffleObject, or one of the wrappers of Java primitive types (
Integer, Double).globalName - the name of the symbol to search fornullpublic Iterable<? extends Object> importSymbols(String globalName)
interop
semantics e.g. the expected returned type is either
TruffleObject, or one of the wrappers of Java
primitive types (like Integer, Double).globalName - the name of the symbol to search forpublic boolean isMimeTypeSupported(String mimeType)
PolyglotEngine can
execute code written in a language with a given MIME type.Source.getMimeType(),
TruffleLanguage.Env.parse(Source, String...)public CallTarget parse(Source source, String... argumentNames)
MIME type is used to identify the TruffleLanguage to use to perform the
TruffleLanguage.parse(com.oracle.truffle.api.TruffleLanguage.ParsingRequest) . The names of
arguments are parameters for the resulting {#link CallTarget} that allow the
source to reference the actual parameters passed to
CallTarget.call(java.lang.Object...).source - the source to evaluateargumentNames - the names of CallTarget.call(java.lang.Object...) arguments
that can be referenced from the sourcepublic InputStream in()
PolyglotEngine this language is
being executed in.nullpublic OutputStream out()
PolyglotEngine this language
is being executed in.nullpublic OutputStream err()
PolyglotEngine this language
is being executed in.nullpublic <T> T lookup(Class<T> type)
language and a PolyglotEngine 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
Instrumenter and others.T - type of requested servicetype - class of requested servicenull if there is no such service availablepublic <S> S lookup(InstrumentInfo instrument, Class<S> type)
S - the requested typeinstrument - identification of the instrument to querytype - the class of the requested typenull if none is foundpublic <S> S lookup(LanguageInfo language, Class<S> type)
Source must be
parsed first.S - the requested typelanguage - the language to querytype - the class of the requested typenull if none is foundpublic Map<String,LanguageInfo> getLanguages()
looked up .public Map<String,InstrumentInfo> getInstruments()
looked up .public Map<String,Object> getConfig()
when constructing the
engine are accessible via this map.
This method (in combination with
PolyglotEngine.Builder.config(java.lang.String, java.lang.String, java.lang.Object)) provides a
straight-forward way to pass implementation-level arguments, as typically specified on a
command line, to the languages.
In contrast toString[] args = {"--kernel", "Kernel.som", "--instrument", "dyn-metrics"};PolyglotEngine.PolyglotEngine.Builderbuilder =PolyglotEngine.newBuilder(); builder.config(YourLang.MIME_TYPE, "CMD_ARGS", args);PolyglotEngineengine = builder.build();
global symbols the provided values are passed in exactly as specified, because these
configuration arguments are strictly at the implementation level and not language-level
objects.
These configuration arguments are available when
creating the language
context to make it possible to take them into account before the language gets ready for
execution. This is the most common way to access them:
class MyLanguage extendsTruffleLanguage<Context> { @Overrideprotected Context createContext(TruffleLanguage.Envenv) {String[] args = (String[]) env.getConfig().get("CMD_ARGS"); return new Context(args); } }