Top Description Methods
org.graalvm.polyglot.tck

public Interface LanguageProvider

Known Direct Implementers
org.graalvm.polyglot.tck.LanguageProviderSnippets.JsSnippets, org.graalvm.polyglot.tck.LanguageProviderSnippets.RSnippets, org.graalvm.polyglot.tck.LanguageProviderSnippets.TypeDescriptorSnippets
Imports
java.util.Collection, .Collections, .Map, .ServiceLoader, org.graalvm.polyglot.Context, .Source, .Value

The LanguageProvider provides factory methods for language data types, expressions, statements and scripts used for testing language inter-operability. The LanguageProvider implementations are loaded by the ServiceLoader and should be registered in the 'META-INF/services/org.graalvm.polyglot.tck.LanguageProvider'. See Test Compatibility Kit for details how to add a new language provider and execute tests.
Since
0.30

Method Summary

Modifier and TypeMethod and Description
public default Map<String, String>

Returns:

The (key, value) pairs of language option to add to the context.
additionalOptions
()

Allows language providers to provide language options during the creation of the test context.

public Collection<? extends Snippet>

Returns:

factories creating the language expressions
createExpressions
(Context
the context for a guest language code literal evaluation
context
)

Creates a collection of functions representing language expressions to test.

public Value

Returns:

the Value representing the identity function
createIdentityFunction
(Context
the context for a guest language code literal evaluation
context
)

Creates an identity function.

public default Snippet

Returns:

the Snippet representing the identity function
createIdentityFunctionSnippet
(Context
the context for a guest language code literal evaluation
context
)

Creates a Snippet for an identity function.

public default Collection<? extends InlineSnippet>

Returns:

A collection of inline code snippets.
createInlineScripts
(Context
the context for a guest language code literal evaluation
context
)

Creates a collection of inline code snippets.

public Collection<? extends Source>

Returns:

the scripts
createInvalidSyntaxScripts
(Context
the context for a guest language code literal evaluation
context
)

Creates a collection of scripts containing a syntax error.

public Collection<? extends Snippet>

Returns:

the language scripts
createScripts
(Context
the context for a guest language code literal evaluation
context
)

Creates a collection of simple scripts used for instrumentation testing.

public Collection<? extends Snippet>

Returns:

factories creating the language statements
createStatements
(Context
the context for a guest language code literal evaluation
context
)

Creates a collection of functions representing language statements to test.

public Collection<? extends Snippet>

Returns:

factories creating the language data types
createValueConstructors
(Context
the context for a guest language code literal evaluation
context
)

Creates a collection of functions creating language data types.

public String

Returns:

the language identification
getId
()

Returns an identification of a provider.

Method Detail

additionalOptionsback to summary
public default Map<String, String> additionalOptions()

Allows language providers to provide language options during the creation of the test context. LanguageProviders are only allowed to set options of the language they represent (Options starting with getId()). Attempts to set options other than their own language will throw IllegalArgumentException on test context creation.

Returns:Map<String, String>

The (key, value) pairs of language option to add to the context.

Since
22.3
createExpressionsback to summary
public Collection<? extends Snippet> createExpressions(Context context)

Creates a collection of functions representing language expressions to test. For each language operator create a function performing given operator and assign a correct TypeDescriptors to its parameters and return type. The parameter types and return type can be one of the predefined TypeDescriptors, an array with component type, an executable with required parameter types or an union type.

The JavaScript sample implementation creating a plus operator:

LanguageProviderSnippets#JsSnippets#createExpressions
LanguageProviderSnippets#JsSnippets#createExpressions

The R sample implementation creating a plus operator:

LanguageProviderSnippets#RSnippets#createExpressions
LanguageProviderSnippets#RSnippets#createExpressions
Parameters
context:Context

the context for a guest language code literal evaluation

Returns:Collection<? extends Snippet>

factories creating the language expressions

Since
0.30
createIdentityFunctionback to summary
public Value createIdentityFunction(Context context)

Creates an identity function. The identity function just returns its argument.

The JavaScript sample implementation:

LanguageProviderSnippets#JsSnippets#createIdentityFunction
LanguageProviderSnippets#JsSnippets#createIdentityFunction

The R sample implementation:

LanguageProviderSnippets#RSnippets#createIdentityFunction
LanguageProviderSnippets#RSnippets#createIdentityFunction
Parameters
context:Context

the context for a guest language code literal evaluation

Returns:Value

the Value representing the identity function

Since
0.30
createIdentityFunctionSnippetback to summary
public default Snippet createIdentityFunctionSnippet(Context context)

Creates a Snippet for an identity function. The identity function just returns its argument. This method allows an implementor to override the default identity function verification. In most cases it's not needed to implement this method and it's enough to implement createIdentityFunction.

The implementor can delegate to the default identity function verifier obtained by ResultVerifier#getIdentityFunctionDefaultResultVerifier().

Parameters
context:Context

the context for a guest language code literal evaluation

Returns:Snippet

the Snippet representing the identity function

Since
19.1.0
createInlineScriptsback to summary
public default Collection<? extends InlineSnippet> createInlineScripts(Context context)

Creates a collection of inline code snippets.

This method is optional, it should be implemented if TruffleLanguage.parse(InlineParsingRequest) is implemented. It returns an empty list by default.

The JavaScript sample implementation creating inline code snippets:

LanguageProviderSnippets#JsSnippets#createInlineScripts
LanguageProviderSnippets#JsSnippets#createInlineScripts
Parameters
context:Context

the context for a guest language code literal evaluation

Returns:Collection<? extends InlineSnippet>

A collection of inline code snippets.

Since
0.32
createInvalidSyntaxScriptsback to summary
public Collection<? extends Source> createInvalidSyntaxScripts(Context context)

Creates a collection of scripts containing a syntax error.

The JavaScript sample implementation:

LanguageProviderSnippets#JsSnippets#createInvalidSyntaxScripts
LanguageProviderSnippets#JsSnippets#createInvalidSyntaxScripts
Parameters
context:Context

the context for a guest language code literal evaluation

Returns:Collection<? extends Source>

the scripts

Since
0.30
createScriptsback to summary
public Collection<? extends Snippet> createScripts(Context context)

Creates a collection of simple scripts used for instrumentation testing. Each script is represented as a function performing the script. The function must have no formal parameters but may return a result which can be asserted by ResultVerifier.

The JavaScript sample implementation:

LanguageProviderSnippets#JsSnippets#createScripts
LanguageProviderSnippets#JsSnippets#createScripts
Parameters
context:Context

the context for a guest language code literal evaluation

Returns:Collection<? extends Snippet>

the language scripts

Since
0.30
createStatementsback to summary
public Collection<? extends Snippet> createStatements(Context context)

Creates a collection of functions representing language statements to test. For each control flow statement create a function performing given statement and assign a correct TypeDescriptors to its parameters and return type. The parameter types and return type can be one of the predefined TypeDescriptors, an array with component type, an executable with required parameter types or an union type.

The JavaScript sample implementation creating the if statement:

LanguageProviderSnippets#JsSnippets#createStatements
LanguageProviderSnippets#JsSnippets#createStatements

The R sample implementation creating the if statement:

LanguageProviderSnippets#RSnippets#createStatements
LanguageProviderSnippets#RSnippets#createStatements
Parameters
context:Context

the context for a guest language code literal evaluation

Returns:Collection<? extends Snippet>

factories creating the language statements

Since
0.30
createValueConstructorsback to summary
public Collection<? extends Snippet> createValueConstructors(Context context)

Creates a collection of functions creating language data types. For each language data type create a function returning a value of given type and assign a correct TypeDescriptor to it. The TypeDescriptor can be one of the predefined TypeDescriptors, an array with component type, an executable with required parameter types or an intersection type.

The JavaScript sample implementation creating a boolean type:

LanguageProviderSnippets#JsSnippets#createValueConstructors
LanguageProviderSnippets#JsSnippets#createValueConstructors

The R sample implementation creating a boolean type:

LanguageProviderSnippets#RSnippets#createValueConstructors
LanguageProviderSnippets#RSnippets#createValueConstructors
Parameters
context:Context

the context for a guest language code literal evaluation

Returns:Collection<? extends Snippet>

factories creating the language data types

Since
0.30
getIdback to summary
public String getId()

Returns an identification of a provider. The common pattern is to use the identification of the tested language.

Returns:String

the language identification

Since
0.30