use of org.graalvm.polyglot.tck.LanguageProvider in project graal by oracle.
the class IdentityFunctionTest method createIdentitySnippet.
static Snippet createIdentitySnippet(String lang) {
LanguageProvider tli = context.getInstalledProviders().get(lang);
Value value = tli.createIdentityFunction(context.getContext());
if (!value.canExecute()) {
throw new AssertionError(String.format("Result of createIdentityFunction for tck provider %s did not return an executable value. Returned value '%s'.", lang, value));
}
return (Snippet.newBuilder("identity", tli.createIdentityFunction(context.getContext()), ANY).parameterTypes(ANY).resultVerifier(new ResultVerifier() {
public void accept(SnippetRun snippetRun) throws PolyglotException {
final PolyglotException exception = snippetRun.getException();
if (exception != null) {
throw exception;
}
Value parameter = snippetRun.getParameters().get(0);
TypeDescriptor parameterType = TypeDescriptor.forValue(parameter);
TypeDescriptor resultType = TypeDescriptor.forValue(snippetRun.getResult());
if (!resultType.isAssignable(parameterType) || !resultType.isAssignable(resultType)) {
throw new AssertionError(String.format("Identity function return type must parameter type. Expected %s got %s.", parameterType, resultType));
}
}
}).build());
}
use of org.graalvm.polyglot.tck.LanguageProvider in project graal by oracle.
the class TestContext method getInstalledProviders.
Map<String, ? extends LanguageProvider> getInstalledProviders() {
checkState(State.NEW, State.INITIALIZED);
if (providers == null) {
state = State.INITIALIZING;
try {
final Map<String, LanguageProvider> tmpProviders = new HashMap<>();
final Set<String> languages = getContext().getEngine().getLanguages().keySet();
for (LanguageProvider provider : ServiceLoader.load(LanguageProvider.class)) {
final String id = provider.getId();
if (languages.contains(id) || isHost(provider)) {
tmpProviders.put(id, provider);
}
}
providers = Collections.unmodifiableMap(tmpProviders);
} finally {
state = State.INITIALIZED;
}
}
return providers;
}
Aggregations