Search in sources :

Example 1 with LanguageProvider

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());
}
Also used : LanguageProvider(org.graalvm.polyglot.tck.LanguageProvider) ResultVerifier(org.graalvm.polyglot.tck.ResultVerifier) TypeDescriptor(org.graalvm.polyglot.tck.TypeDescriptor) Value(org.graalvm.polyglot.Value) PolyglotException(org.graalvm.polyglot.PolyglotException)

Example 2 with LanguageProvider

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;
}
Also used : LanguageProvider(org.graalvm.polyglot.tck.LanguageProvider) HashMap(java.util.HashMap)

Aggregations

LanguageProvider (org.graalvm.polyglot.tck.LanguageProvider)2 HashMap (java.util.HashMap)1 PolyglotException (org.graalvm.polyglot.PolyglotException)1 Value (org.graalvm.polyglot.Value)1 ResultVerifier (org.graalvm.polyglot.tck.ResultVerifier)1 TypeDescriptor (org.graalvm.polyglot.tck.TypeDescriptor)1