public Optional<CompiledScript> compile(final String script, final Optional<String> language) throws ScriptException {
        final String lang = language.orElse("gremlin-groovy");
        try {
            final GremlinScriptEngine scriptEngine = gremlinScriptEngineManager.getEngineByName(lang);
            if (scriptEngine instanceof Compilable)
                return Optional.of(((Compilable) scriptEngine).compile(script));
            else
                return Optional.empty();
        } catch (UnsupportedOperationException uoe) {
            return Optional.empty();
        }
    }
Attempts to compile a script and cache it in the request {@link javax.script.ScriptEngine}.  This is only
possible if the {@link javax.script.ScriptEngine} implementation implements {@link Compilable}.
In the event that the requested {@link javax.script.ScriptEngine} does not implement it, the method will
return empty.
gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutor.java