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: 1ac0693f614e
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 332bea3c40a8
Choose a head ref
  • 2 commits
  • 6 files changed
  • 1 contributor

Commits on Apr 15, 2018

  1. Copy the full SHA
    77418b0 View commit details
  2. Fix spec:jrubyc. Blergh unexpected issue with AST INameNode only retu…

    …rning
    
    a sybol is toString will return ":foo" vs to_s which returns "foo".  So to_s
    we go for now.
    enebo committed Apr 15, 2018
    Copy the full SHA
    332bea3 View commit details
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ir/IRClosure.java
Original file line number Diff line number Diff line change
@@ -252,7 +252,7 @@ protected LocalVariable findExistingLocalVariable(RubySymbol name, int scopeDept

public LocalVariable getNewLocalVariable(RubySymbol name, int depth) {
if (depth == 0 && !(this instanceof IRFor)) {
LocalVariable lvar = new ClosureLocalVariable(name, 0, getStaticScope().addVariableThisScope(name.toString()));
LocalVariable lvar = new ClosureLocalVariable(name, 0, getStaticScope().addVariableThisScope(name.idString()));
localVars.put(name, lvar);
return lvar;
} else {
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/ir/persistence/IRReader.java
Original file line number Diff line number Diff line change
@@ -106,12 +106,12 @@ private static KeyValuePair<IRScope, Integer> decodeScopeHeader(IRManager manage
// FIXME: Replace since we are defining this...perhaps even make a persistence constructor
scope.setLabelIndices(indices);

decoder.addScope(scope);

// FIXME: This is odd, but ClosureLocalVariable wants it's defining closure...feels wrong.
// But because of this we have to push decoding lvars to the end of the scope info.
scope.setLocalVariables(decodeScopeLocalVariables(decoder, scope));

decoder.addScope(scope);

int instructionsOffset = decoder.decodeInt();

return new KeyValuePair<>(scope, instructionsOffset);
@@ -121,7 +121,7 @@ private static Map<RubySymbol, LocalVariable> decodeScopeLocalVariables(IRReader
int size = decoder.decodeInt();
Map<RubySymbol, LocalVariable> localVariables = new HashMap(size);
for (int i = 0; i < size; i++) {
RubySymbol name = decoder.decodeSymbol();
RubySymbol name = scope.getManager().getRuntime().newSymbol(decoder.decodeByteList());
int offset = decoder.decodeInt();

localVariables.put(name, scope instanceof IRClosure ?
Original file line number Diff line number Diff line change
@@ -189,6 +189,7 @@ public Map<String, Operand> getVars() {

@Override
public List<Instr> decodeInstructionsAt(IRScope scope, int offset) {
currentScope = scope;
vars = new HashMap<>();
buf.position(offset);

5 changes: 4 additions & 1 deletion core/src/main/java/org/jruby/ir/persistence/IRWriter.java
Original file line number Diff line number Diff line change
@@ -103,10 +103,13 @@ private static void persistScopeHeader(IRWriterEncoder file, IRScope scope) {
// FIXME: I hacked around our lvar types for now but this hsould be done in a less ad-hoc fashion.
private static void persistLocalVariables(IRScope scope, IRWriterEncoder file) {
Map<RubySymbol, LocalVariable> localVariables = scope.getLocalVariables();
if (RubyInstanceConfig.IR_WRITING_DEBUG) System.out.println("PERSISTING LVARS (" + localVariables.size() + ")");
file.encode(localVariables.size());
for (RubySymbol name: localVariables.keySet()) {
file.encode(name);
file.encode(localVariables.get(name).getOffset()); // No need to write depth..it is zero.
int offset = localVariables.get(name).getOffset();
if (RubyInstanceConfig.IR_WRITING_DEBUG) System.out.println(" NAME: " + name + "(0:" + offset + ")");
file.encode(offset); // No need to write depth..it is zero.
}
}

58 changes: 29 additions & 29 deletions lib/ruby/stdlib/jruby/compiler/java_class.rb
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ def generate_javac(files, options)

module VisitorBuilder
def visit(name, &block)
define_method :"visit_#{name}_node" do |node|
define_method :"visit_#{name.to_s}_node" do |node|
log "visit: #{node.node_type} - #{node}"
with_node(node) { instance_eval(&block) }
end
@@ -98,7 +98,7 @@ def add_annotation(nodes)

def add_interface(*ifc_nodes)
ifc_nodes.
map {|ifc| defined?(ifc.name) ? ifc.name : ifc.value}.
map {|ifc| defined?(ifc.name) ? ifc.name.to_s : ifc.value}.
each {|ifc| current_class.add_interface(ifc)}
end

@@ -200,7 +200,7 @@ def set_package(package)
end

def name_or_value(node)
return node.name if defined? node.name
return node.name.to_s if defined? node.name
return node.value if defined? node.value
raise "unknown node: #{node.inspect}"
end
@@ -229,51 +229,51 @@ def log(str)
current_method.java_signature = build_args_signature(node.pre)
end
node.pre && node.pre.child_nodes.each do |pre_arg|
current_method.args << pre_arg.name
current_method.args << pre_arg.name.to_s
end
node.opt_args && node.opt_args.child_nodes.each do |pre_arg|
current_method.args << pre_arg.name
current_method.args << pre_arg.name.to_s
end
node.post && node.post.child_nodes.each do |post_arg|
current_method.args << post_arg.name
current_method.args << post_arg.name.to_s
end
if node.has_rest_arg
current_method.args << node.rest_arg_node.name
current_method.args << node.rest_arg_node.name.to_s
end
if node.block
current_method.args << node.block.name
current_method.args << node.block.name.to_s
end

# if method still has no signature, generate one
unless current_method.java_signature
args_string = current_method.args.map { |arg| "Object #{arg}" }.join(',')
sig_string = "Object #{current_method.name}(#{args_string})"
sig_string = "Object #{current_method.name.to_s}(#{args_string})"
current_method.java_signature = build_signature(sig_string)
end
end

visit :class do
new_class(node.cpath.name)
new_class(node.cpath.name.to_s)
node.body_node.accept(self)
pop_class
end

visit :defn do
next if @class_stack.empty?
new_method(node.name)
new_method(node.name.to_s)
node.args_node.accept(self)
pop_method
end

visit :defs do
next if @class_stack.empty?
new_static_method(node.name)
new_static_method(node.name.to_s)
node.args_node.accept(self)
pop_method
end

visit :fcall do
case node.name
case node.name.to_s
when 'java_import'
add_imports node.args_node.child_nodes
when 'java_signature'
@@ -298,7 +298,7 @@ def log(str)
end

visit :vcall do
case node.name
case node.name.to_s
when 'private' # visibility modifier without args
set_method_visibility :private
when 'protected'
@@ -390,7 +390,7 @@ def initialize(name, imports = [], script_name = nil, annotations = [], requires
attr_accessor :methods, :fields, :annotations, :interfaces, :requires, :package, :sourcefile

def has_constructor?
!!methods.find { |method| constructor?(method.name, method.java_signature) }
!!methods.find { |method| constructor?(method.name.to_s, method.java_signature) }
end

def new_field(java_signature, annotations = [])
@@ -413,22 +413,22 @@ def method_visibility=(visibility); @method_visibility = visibility end

def private_method(name)
return if name.to_s.eql?('initialize')
method = methods.find { |method| method.name == name.to_s } || raise(NoMethodError.new("could not find method :#{name}"))
method = methods.find { |method| method.name.to_s == name.to_s } || raise(NoMethodError.new("could not find method :#{name}"))
method.visibility = :private
end

def protected_method(name)
method = methods.find { |method| method.name == name.to_s } || raise(NoMethodError.new("could not find method :#{name}"))
method = methods.find { |method| method.name.to_s == name.to_s } || raise(NoMethodError.new("could not find method :#{name}"))
method.visibility = :protected
end

def public_method(name)
method = methods.find { |method| method.name == name.to_s } || raise(NoMethodError.new("could not find method :#{name}"))
method = methods.find { |method| method.name.to_s == name.to_s } || raise(NoMethodError.new("could not find method :#{name}"))
method.visibility = :public
end

def constructor?(name, java_signature = nil)
name.eql?('initialize') || java_signature.is_a?(ConstructorSignatureNode)
name.to_s.eql?('initialize') || java_signature.is_a?(ConstructorSignatureNode)
end
private :constructor?

@@ -445,9 +445,9 @@ def static_init
return <<JAVA
static {
#{requires_string}
RubyClass metaclass = __ruby__.getClass(\"#{name}\");
if (metaclass == null) throw new NoClassDefFoundError(\"Could not load Ruby class: #{name}\");
metaclass.setRubyStaticAllocator(#{name}.class);
RubyClass metaclass = __ruby__.getClass(\"#{name.to_s}\");
if (metaclass == null) throw new NoClassDefFoundError(\"Could not load Ruby class: #{name.to_s}\");
metaclass.setRubyStaticAllocator(#{name.to_s}.class);
__metaclass__ = metaclass;
}
JAVA
@@ -493,7 +493,7 @@ def constructor_string
* @param ruby The JRuby instance this object will belong to
* @param metaclass The RubyClass representing the Ruby class of this object
*/
private #{name}(Ruby ruby, RubyClass metaclass) {
private #{name.to_s}(Ruby ruby, RubyClass metaclass) {
super(ruby, metaclass);
}
@@ -505,7 +505,7 @@ def constructor_string
* @param metaclass The RubyClass representing the Ruby class of this object
*/
public static IRubyObject __allocate__(Ruby ruby, RubyClass metaClass) {
return new #{name}(ruby, metaClass);
return new #{name.to_s}(ruby, metaClass);
}
JAVA

@@ -517,7 +517,7 @@ def constructor_string
* Ruby and RubyClass instances assocated with this class, and then invokes the
* no-argument 'initialize' method in Ruby.
*/
public #{name}() {
public #{name.to_s}() {
this(__ruby__, __metaclass__);
Helpers.invoke(__ruby__.getCurrentContext(), this, "initialize");
}
@@ -534,7 +534,7 @@ def to_s
#{imports_string}
#{annotations_string}
public class #{name} extends RubyObject #{interface_string} {
public class #{name.to_s} extends RubyObject #{interface_string} {
private static final Ruby __ruby__ = Ruby.getGlobalRuntime();
private static final RubyClass __metaclass__;
@@ -595,7 +595,7 @@ def to_s
declarator_string do
<<-JAVA
#{conversion_string(var_names)}
IRubyObject ruby_result = Helpers.invoke(__ruby__.getCurrentContext(), #{static ? '__metaclass__' : 'this'}, \"#{name}\"#{passed_args});
IRubyObject ruby_result = Helpers.invoke(__ruby__.getCurrentContext(), #{static ? '__metaclass__' : 'this'}, \"#{name.to_s}\"#{passed_args});
#{return_string}
JAVA
end
@@ -655,7 +655,7 @@ def typed_args

i = 0
@typed_args = java_signature.parameters.map do |a|
type = a.type.name
type = a.type.name.to_s
if a.variable_name
var_name = a.variable_name
else
@@ -717,7 +717,7 @@ def java_name
private

def has_java_signature!
raise "no java_signature has been set for method #{name}" unless java_signature
raise "no java_signature has been set for method #{name.to_s}" unless java_signature
end

end
2 changes: 1 addition & 1 deletion lib/ruby/stdlib/jruby/compiler/java_signature.rb
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ def initialize(string, ast)
end

def name
@ast.name
@ast.name.id_string
end

def as_java_type(string); self.class.as_java_type(string) end