Search in sources :

Example 6 with Language

use of org.graalvm.polyglot.Language in project graal by oracle.

the class Launcher method printLanguages.

private static void printLanguages(Engine engine, boolean printWhenEmpty) {
    if (engine.getLanguages().isEmpty()) {
        if (printWhenEmpty) {
            System.out.println("  Installed Languages: none");
        }
    } else {
        System.out.println("  Installed Languages:");
        List<Language> languages = new ArrayList<>(engine.getLanguages().size());
        int nameLength = 0;
        for (Language language : engine.getLanguages().values()) {
            languages.add(language);
            nameLength = max(nameLength, language.getName().length());
        }
        languages.sort(Comparator.comparing(Language::getId));
        String langFormat = "    %-" + nameLength + "s%s version %s%n";
        for (Language language : languages) {
            String host;
            host = "";
            String version = language.getVersion();
            if (version == null || version.length() == 0) {
                version = "";
            }
            System.out.printf(langFormat, language.getName().isEmpty() ? "Unnamed" : language.getName(), host, version);
        }
    }
}
Also used : Language(org.graalvm.polyglot.Language) ArrayList(java.util.ArrayList)

Example 7 with Language

use of org.graalvm.polyglot.Language in project graal by oracle.

the class PolyglotLauncher method printHelp.

@Override
protected void printHelp(OptionCategory maxCategory) {
    Engine engine = Engine.create();
    // @formatter:off
    printVersion(engine);
    System.out.println();
    System.out.println("Usage: polyglot [OPTION]... [FILE] [ARGS]...");
    List<Language> languages = sortedLanguages(engine);
    System.out.print("Available languages: ");
    String sep = "";
    for (Language language : languages) {
        System.out.print(sep);
        System.out.print(language.getId());
        sep = ", ";
    }
    System.out.println();
    System.out.println("Basic Options:");
    printOption("--language <lang>", "Specifies the main language.");
    printOption("--file [<lang>:]FILE", "Additional file to execute.");
    printOption("--eval [<lang>:]CODE", "Evaluates code snippets, for example, '--eval js:42'.");
    printOption("--shell", "Start a multi language shell.");
// @formatter:on
}
Also used : Language(org.graalvm.polyglot.Language) Engine(org.graalvm.polyglot.Engine)

Example 8 with Language

use of org.graalvm.polyglot.Language in project graal by oracle.

the class EvalLauncher method printHelp.

private static void printHelp(OptionCategory maxCategory) {
    Engine engine = Engine.create();
    System.out.println(BASIC_HELP);
    System.out.println("Engine options: ");
    for (OptionDescriptor descriptor : engine.getOptions()) {
        printOption(maxCategory, descriptor);
    }
    System.out.println("Language options: ");
    for (String languageId : engine.getLanguages().keySet()) {
        Language language = engine.getLanguage(languageId);
        for (OptionDescriptor descriptor : language.getOptions()) {
            printOption(maxCategory, descriptor);
        }
    }
    System.out.println("Tool options: ");
    for (String instrumentId : engine.getInstruments().keySet()) {
        Instrument instrument = engine.getInstrument(instrumentId);
        for (OptionDescriptor descriptor : instrument.getOptions()) {
            printOption(maxCategory, descriptor);
        }
    }
}
Also used : Language(org.graalvm.polyglot.Language) OptionDescriptor(org.graalvm.options.OptionDescriptor) Instrument(org.graalvm.polyglot.Instrument) Engine(org.graalvm.polyglot.Engine)

Example 9 with Language

use of org.graalvm.polyglot.Language in project graal by oracle.

the class AbstractLanguageLauncher method printVersion.

protected void printVersion(Engine engine) {
    String languageId = getLanguageId();
    Language language = engine.getLanguages().get(languageId);
    if (language == null) {
        throw abort(String.format("Unknown language: '%s'!", languageId));
    }
    String implementationName = language.getImplementationName();
    if (implementationName == null || implementationName.length() == 0) {
        String languageName = language.getName();
        if (languageName == null || languageName.length() == 0) {
            languageName = languageId;
        }
        implementationName = "Graal " + languageName;
    }
    System.out.println(String.format("%s %s (GraalVM %s)", implementationName, language.getVersion(), engine.getVersion()));
}
Also used : Language(org.graalvm.polyglot.Language)

Example 10 with Language

use of org.graalvm.polyglot.Language in project graal by oracle.

the class PolyglotEngineImpl method requirePublicLanguage.

@Override
public Language requirePublicLanguage(String id) {
    checkState();
    Language language = idToPublicLanguage.get(id);
    if (language == null) {
        String misspelledGuess = matchSpellingError(idToPublicLanguage.keySet(), id);
        String didYouMean = "";
        if (misspelledGuess != null) {
            didYouMean = String.format("Did you mean '%s'? ", misspelledGuess);
        }
        throw new PolyglotIllegalStateException(String.format("A language with id '%s' is not installed. %sInstalled languages are: %s.", id, didYouMean, getLanguages().keySet()));
    }
    return language;
}
Also used : Language(org.graalvm.polyglot.Language)

Aggregations

Language (org.graalvm.polyglot.Language)13 Engine (org.graalvm.polyglot.Engine)6 ArrayList (java.util.ArrayList)3 OptionDescriptor (org.graalvm.options.OptionDescriptor)3 Instrument (org.graalvm.polyglot.Instrument)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Test (org.junit.Test)2 TruffleLanguage (com.oracle.truffle.api.TruffleLanguage)1 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)1 LanguageInfo (com.oracle.truffle.api.nodes.LanguageInfo)1 RootNode (com.oracle.truffle.api.nodes.RootNode)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 PrintWriter (java.io.PrintWriter)1 Field (java.lang.reflect.Field)1