Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 19ea763cf046^
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c6ea19519f4a
Choose a head ref
  • 14 commits
  • 30 files changed
  • 1 contributor

Commits on May 20, 2016

  1. Copy the full SHA
    19ea763 View commit details
  2. Copy the full SHA
    9eff0d6 View commit details
  3. Copy the full SHA
    577a894 View commit details
  4. Copy the full SHA
    9c1996e View commit details
  5. [Truffle] Initialize Readline on startup rather than on require with …

    …a primitive.
    
    The primitive system is a bit too fickle for this use case.
    nirvdrum committed May 20, 2016
    Copy the full SHA
    4b5cc11 View commit details
  6. Copy the full SHA
    7bce6df View commit details
  7. Copy the full SHA
    78bc610 View commit details

Commits on May 23, 2016

  1. [Truffle] Moved readline state out to be per-context.

    I'm really not sure how well this will work cross-contexts, but perhaps if readline is being source by something other than STDIN this will be valuable. It's cleaner in any event.
    nirvdrum committed May 23, 2016
    Copy the full SHA
    7e08ef6 View commit details
  2. Copy the full SHA
    958a00a View commit details
  3. Copy the full SHA
    1df90e2 View commit details
  4. Copy the full SHA
    2dc2648 View commit details
  5. Copy the full SHA
    fae1b48 View commit details
  6. Copy the full SHA
    4e74d73 View commit details
  7. Copy the full SHA
    c6ea195 View commit details
Showing with 588 additions and 0 deletions.
  1. +64 −0 lib/ruby/truffle/truffle/readline.rb
  2. +2 −0 spec/truffle/tags/library/readline/basic_quote_characters_tags.txt
  3. +2 −0 spec/truffle/tags/library/readline/completer_quote_characters_tags.txt
  4. +2 −0 spec/truffle/tags/library/readline/completer_word_break_characters_tags.txt
  5. +2 −0 spec/truffle/tags/library/readline/completion_append_character_tags.txt
  6. +2 −0 spec/truffle/tags/library/readline/completion_case_fold_tags.txt
  7. +3 −0 spec/truffle/tags/library/readline/completion_proc_tags.txt
  8. +1 −0 spec/truffle/tags/library/readline/constants_tags.txt
  9. +1 −0 spec/truffle/tags/library/readline/emacs_editing_mode_tags.txt
  10. +2 −0 spec/truffle/tags/library/readline/filename_quote_characters_tags.txt
  11. +3 −0 spec/truffle/tags/library/readline/history/delete_at_tags.txt
  12. +2 −0 spec/truffle/tags/library/readline/history/each_tags.txt
  13. +3 −0 spec/truffle/tags/library/readline/history/element_reference_tags.txt
  14. +4 −0 spec/truffle/tags/library/readline/history/element_set_tags.txt
  15. +1 −0 spec/truffle/tags/library/readline/history/empty_tags.txt
  16. +1 −0 spec/truffle/tags/library/readline/history/length_tags.txt
  17. +1 −0 spec/truffle/tags/library/readline/history/pop_tags.txt
  18. +1 −0 spec/truffle/tags/library/readline/history/push_tags.txt
  19. +3 −0 spec/truffle/tags/library/readline/history/shift_tags.txt
  20. +1 −0 spec/truffle/tags/library/readline/history/size_tags.txt
  21. +1 −0 spec/truffle/tags/library/readline/readline_tags.txt
  22. +1 −0 spec/truffle/tags/library/readline/vi_editing_mode_tags.txt
  23. +1 −0 spec/truffle/truffle.mspec
  24. +8 −0 truffle/src/main/java/org/jruby/truffle/RubyContext.java
  25. +7 −0 truffle/src/main/java/org/jruby/truffle/core/CoreLibrary.java
  26. +2 −0 truffle/src/main/java/org/jruby/truffle/core/string/CoreStrings.java
  27. +7 −0 truffle/src/main/java/org/jruby/truffle/language/RubyBaseNode.java
  28. +86 −0 truffle/src/main/java/org/jruby/truffle/stdlib/readline/ConsoleHolder.java
  29. +135 −0 truffle/src/main/java/org/jruby/truffle/stdlib/readline/ReadlineHistoryNodes.java
  30. +239 −0 truffle/src/main/java/org/jruby/truffle/stdlib/readline/ReadlineNodes.java
64 changes: 64 additions & 0 deletions lib/ruby/truffle/truffle/readline.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This
# code is released under a tri EPL/GPL/LGPL license. You can use it,
# redistribute it and/or modify it under the terms of the:
#
# Eclipse Public License version 1.0
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

Readline = Truffle::Readline

module Readline

HISTORY = Object.new

module_function

%i[
basic_quote_characters
basic_quote_characters=
completer_quote_characters
completer_quote_characters=
completer_word_break_characters
completer_word_break_characters=
completion_append_character
completion_proc
emacs_editing_mode
emacs_editing_mode?
filename_quote_characters
filename_quote_characters=
vi_editing_mode
vi_editing_mode?
set_screen_size
].each do |method_name|
define_method(method_name) do
raise NotImplementedError.new("#{method_name}() function is unimplemented on this machine")
end
end

def input=(input)
# TODO (nirvdrum 20-May-16): This should do something functional.
nil
end

def output=(output)
# TODO (nirvdrum 20-May-16): This should do something functional.
nil
end

end

class << Readline::HISTORY

include Enumerable
include Truffle::ReadlineHistory

def empty?
size == 0
end

def to_s
'HISTORY'
end

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fails:Readline.basic_quote_characters returns not nil
fails:Readline.basic_quote_characters= returns the passed string
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fails:Readline.completer_quote_characters returns nil
fails:Readline.completer_quote_characters= returns the passed string
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fails:Readline.completer_word_break_characters returns nil
fails:Readline.completer_word_break_characters= returns the passed string
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fails:Readline.completion_append_character returns not nil
fails:Readline.completion_append_character= returns the first character of the passed string
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fails:Readline.completion_case_fold returns nil
fails:Readline.completion_case_fold= returns the passed boolean
3 changes: 3 additions & 0 deletions spec/truffle/tags/library/readline/completion_proc_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fails:Readline.completion_proc returns nil
fails:Readline.completion_proc= returns the passed Proc
fails:Readline.completion_proc= returns an ArgumentError if not given an Proc or #call
1 change: 1 addition & 0 deletions spec/truffle/tags/library/readline/constants_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fails:Readline::VERSION is defined and is a non-empty String
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fails:Readline.emacs_editing_mode returns nil
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fails:Readline.filename_quote_characters returns nil
fails:Readline.filename_quote_characters= returns the passed string
3 changes: 3 additions & 0 deletions spec/truffle/tags/library/readline/history/delete_at_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fails:Readline::HISTORY.delete_at deletes and returns the history entry at the specified index
fails:Readline::HISTORY.delete_at raises an IndexError when the given index is greater than the history size
fails:Readline::HISTORY.delete_at taints the returned strings
2 changes: 2 additions & 0 deletions spec/truffle/tags/library/readline/history/each_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fails:Readline::HISTORY.each yields each item in the history
fails:Readline::HISTORY.each yields tainted Objects
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fails:Readline::HISTORY.[] returns tainted objects
fails:Readline::HISTORY.[] returns the history item at the passed index
fails:Readline::HISTORY.[] raises an IndexError when there is no item at the passed index
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fails:Readline::HISTORY.[]= returns the new value for the passed index
fails:Readline::HISTORY.[]= raises an IndexError when there is no item at the passed positive index
fails:Readline::HISTORY.[]= sets the item at the given index
fails:Readline::HISTORY.[]= raises an IndexError when there is no item at the passed negative index
1 change: 1 addition & 0 deletions spec/truffle/tags/library/readline/history/empty_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fails:Readline::HISTORY.empty? returns true when the history is empty
1 change: 1 addition & 0 deletions spec/truffle/tags/library/readline/history/length_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fails:Readline::HISTORY.length returns the size of the history
1 change: 1 addition & 0 deletions spec/truffle/tags/library/readline/history/pop_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fails:Readline::HISTORY.pop returns and removes the last item from the history
1 change: 1 addition & 0 deletions spec/truffle/tags/library/readline/history/push_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fails:Readline::HISTORY.push pushes all passed Objects into the history
3 changes: 3 additions & 0 deletions spec/truffle/tags/library/readline/history/shift_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fails:Readline::HISTORY.shift returns nil when the history is empty
fails:Readline::HISTORY.shift returns and removes the first item from the history
fails:Readline::HISTORY.shift taints the returned strings
1 change: 1 addition & 0 deletions spec/truffle/tags/library/readline/history/size_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fails:Readline::HISTORY.size returns the size of the history
1 change: 1 addition & 0 deletions spec/truffle/tags/library/readline/readline_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fails:Readline.readline taints the returned strings
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fails:Readline.vi_editing_mode returns nil
1 change: 1 addition & 0 deletions spec/truffle/truffle.mspec
Original file line number Diff line number Diff line change
@@ -124,6 +124,7 @@ class MSpecScript
MSpec.disable_feature :continuation_library
MSpec.disable_feature :fork
MSpec.enable_feature :encoding
MSpec.enable_feature :readline

set :files, get(:language) + get(:core) + get(:library) + get(:truffle)
end
8 changes: 8 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/RubyContext.java
Original file line number Diff line number Diff line change
@@ -47,6 +47,7 @@
import org.jruby.truffle.platform.NativePlatform;
import org.jruby.truffle.platform.NativePlatformFactory;
import org.jruby.truffle.stdlib.CoverageManager;
import org.jruby.truffle.stdlib.readline.ConsoleHolder;
import org.jruby.truffle.tools.InstrumentationServerManager;
import org.jruby.truffle.tools.callgraph.CallGraph;
import org.jruby.truffle.tools.callgraph.SimpleWriter;
@@ -91,6 +92,7 @@ public class RubyContext extends ExecutionContext {
private final CallGraph callGraph;
private final PrintStream debugStandardOut;
private final CoverageManager coverageManager;
private final ConsoleHolder consoleHolder;

private final Object classVariableDefinitionLock = new Object();

@@ -174,6 +176,8 @@ public RubyContext(Ruby jrubyRuntime, TruffleLanguage.Env env) {
coverageManager = new CoverageManager(this, instrumenter);

coreLibrary.initializePostBoot();

consoleHolder = new ConsoleHolder();
}

public Object send(Object object, String methodName, DynamicObject block, Object... arguments) {
@@ -348,4 +352,8 @@ public CoreExceptions getCoreExceptions() {
return coreExceptions;
}

public ConsoleHolder getConsoleHolder() {
return consoleHolder;
}

}
7 changes: 7 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/core/CoreLibrary.java
Original file line number Diff line number Diff line change
@@ -110,6 +110,8 @@
import org.jruby.truffle.stdlib.psych.PsychEmitterNodesFactory;
import org.jruby.truffle.stdlib.psych.PsychParserNodesFactory;
import org.jruby.truffle.stdlib.psych.YAMLEncoding;
import org.jruby.truffle.stdlib.readline.ReadlineHistoryNodesFactory;
import org.jruby.truffle.stdlib.readline.ReadlineNodesFactory;
import org.jruby.util.cli.OutputStrings;
import java.io.File;
import java.io.IOException;
@@ -593,6 +595,8 @@ public CoreLibrary(RubyContext context) {
defineModule(truffleModule, "Process");
defineModule(truffleModule, "Binding");
defineModule(truffleModule, "POSIX");
defineModule(truffleModule, "Readline");
defineModule(truffleModule, "ReadlineHistory");
psychModule = defineModule("Psych");
psychParserClass = defineClass(psychModule, objectClass, "Parser");
final DynamicObject psychHandlerClass = defineClass(psychModule, objectClass, "Handler");
@@ -742,6 +746,8 @@ public void addCoreMethods() {
coreMethodNodeManager.addCoreMethodNodes(EtcNodesFactory.getFactories());
coreMethodNodeManager.addCoreMethodNodes(PsychParserNodesFactory.getFactories());
coreMethodNodeManager.addCoreMethodNodes(PsychEmitterNodesFactory.getFactories());
coreMethodNodeManager.addCoreMethodNodes(ReadlineNodesFactory.getFactories());
coreMethodNodeManager.addCoreMethodNodes(ReadlineHistoryNodesFactory.getFactories());
coreMethodNodeManager.addCoreMethodNodes(AtomicReferenceNodesFactory.getFactories());
coreMethodNodeManager.addCoreMethodNodes(TracePointNodesFactory.getFactories());
coreMethodNodeManager.addCoreMethodNodes(CoverageNodesFactory.getFactories());
@@ -932,6 +938,7 @@ public void initializePostBoot() {
throw new TruffleFatalException("couldn't load the post-boot code", e);
}
}

}

private void initializeRubiniusFFI() {
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ public class CoreStrings {
public final CoreString CANT_COMPRESS_NEGATIVE;
public final CoreString CLASS;
public final CoreString CLASS_VARIABLE;
public final CoreString EMPTY_STRING;
public final CoreString EXPRESSION;
public final CoreString FALSE;
public final CoreString GLOBAL_VARIABLE;
@@ -50,6 +51,7 @@ public CoreStrings(RubyContext context) {
CANT_COMPRESS_NEGATIVE = new CoreString(context, "can't compress negative numbers");
CLASS = new CoreString(context, "class");
CLASS_VARIABLE = new CoreString(context, "class variable");
EMPTY_STRING = new CoreString(context, "");
EXPRESSION = new CoreString(context, "expression");
FALSE = new CoreString(context, "false");
GLOBAL_VARIABLE = new CoreString(context, "global-variable");
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
import com.oracle.truffle.api.source.SourceSection;
import jnr.ffi.provider.MemoryManager;
import org.jcodings.Encoding;
import org.jcodings.specific.UTF8Encoding;
import org.jruby.truffle.Layouts;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.CoreLibrary;
@@ -86,6 +87,12 @@ protected DynamicObject getSymbol(Rope name) {
return getContext().getSymbolTable().getSymbol(name);
}

protected Encoding getDefaultInternalEncoding() {
return getContext().getJRubyRuntime().getDefaultInternalEncoding() == null ?
UTF8Encoding.INSTANCE :
getContext().getJRubyRuntime().getDefaultInternalEncoding();
}

protected DynamicObject createString(ByteList bytes) {
return StringOperations.createString(getContext(), bytes);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*
* This code is modified from the Readline JRuby extension module
* implementation with the following header:
*
* Version: EPL 1.0/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Eclipse Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.eclipse.org/legal/epl-v10.html
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* Copyright (C) 2006 Ola Bini <ola@ologix.com>
* Copyright (C) 2006 Damian Steer <pldms@mac.com>
* Copyright (C) 2008 Joseph LaFata <joe@quibb.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the EPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the EPL, the GPL or the LGPL.
*/
package org.jruby.truffle.stdlib.readline;

import jline.console.ConsoleReader;
import jline.console.completer.Completer;
import jline.console.history.History;
import jline.console.history.MemoryHistory;

import java.io.IOException;

public class ConsoleHolder {

private final ConsoleReader readline;
private final Completer currentCompleter;
private final History history;

public ConsoleHolder() {
try {
readline = new ConsoleReader();
} catch (IOException e) {
throw new UnsupportedOperationException("Couldn't initialize readline", e);
}

readline.setHistoryEnabled(false);
readline.setPaginationEnabled(true);
readline.setBellEnabled(true);

currentCompleter = new ReadlineNodes.RubyFileNameCompleter();
readline.addCompleter(currentCompleter);

history = new MemoryHistory();
readline.setHistory(history);
}

public ConsoleReader getReadline() {
return readline;
}

public Completer getCurrentCompleter() {
return currentCompleter;
}

public History getHistory() {
return history;
}

}
Loading