Skip to content

Commit

Permalink
Merge branch 'master' into truffle-head
Browse files Browse the repository at this point in the history
Conflicts:
	truffle/src/main/java/org/jruby/truffle/nodes/RubyNode.java
	truffle/src/main/java/org/jruby/truffle/nodes/core/BignumNodes.java
	truffle/src/main/java/org/jruby/truffle/nodes/core/FixnumNodes.java
	truffle/src/main/java/org/jruby/truffle/nodes/core/FloatNodes.java
  • Loading branch information
chrisseaton committed Apr 9, 2015
2 parents 206d828 + ab47c74 commit ee6a4a1
Show file tree
Hide file tree
Showing 188 changed files with 9,077 additions and 1,434 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -13,7 +13,7 @@ Authors: Stefan Matthias Aust, Anders Bengtsson, Geert Bevin, Ola Bini,
Daiki Ueno, Matthias Veit, Jason Voegele, Sergey Yevtushenko, Robert Yokota,
and many gracious contributors from the community.

Project Contact: Thomas E Enebo <enebo@acm.org>
Project Contact: Thomas E Enebo <tom.enebo@gmail.com>

JRuby also uses code generously shared by the creator of the Ruby language,
Yukihiro Matsumoto <matz@netlab.co.jp>.
Expand Down
50 changes: 30 additions & 20 deletions core/src/main/java/org/jruby/RubyBasicObject.java
Expand Up @@ -583,33 +583,41 @@ public RubyClass getType() {

/**
* Does this object respond to the specified message? Uses a
* shortcut if it can be proved that respond_to? haven't been
* overridden.
* shortcut if it can be proved that respond_to? and respond_to_missing?
* haven't been overridden.
*/
@Override
public final boolean respondsTo(String name) {
Ruby runtime = getRuntime();

DynamicMethod method = getMetaClass().searchMethod("respond_to?");
if(method.equals(runtime.getRespondToMethod())) {
DynamicMethod respondTo = getMetaClass().searchMethod("respond_to?");
DynamicMethod respondToMissing = getMetaClass().searchMethod("respond_to_missing?");

if(respondTo.equals(runtime.getRespondToMethod()) && respondToMissing.equals(runtime.getRespondToMissingMethod())) {
// fastest path; builtin respond_to? which just does isMethodBound
return getMetaClass().isMethodBound(name, false);
} else if (!method.isUndefined()) {
// medium path, invoke user's respond_to? if defined
} else if (!(respondTo.isUndefined() && respondToMissing.isUndefined())) {
// medium path, invoke user's respond_to?/respond_to_missing? if defined
DynamicMethod method;
String methodName;
if (respondTo.isUndefined()) {
method = respondToMissing;
methodName = "respond_to_missing?";
} else {
method = respondTo;
methodName = "respond_to?";
}

// We have to check and enforce arity
Arity arity = method.getArity();
ThreadContext context = runtime.getCurrentContext();
if (arity.isFixed() && arity.required() == 1) {
return method.call(context, this, metaClass, "respond_to?", runtime.newSymbol(name)).isTrue();
return method.call(context, this, metaClass, methodName, runtime.newSymbol(name)).isTrue();
} else if (arity.isFixed() && arity.required() != 2) {
throw runtime.newArgumentError("respond_to? must accept 1 or 2 arguments (requires " + arity.getValue() + ")");
} else {

throw runtime.newArgumentError(methodName + " must accept 1 or 2 arguments (requires " + arity.getValue() + ")");
}

return method.call(context, this, metaClass, "respond_to?", runtime.newSymbol(name), runtime.newBoolean(true)).isTrue();

return method.call(context, this, metaClass, methodName, runtime.newSymbol(name), runtime.newBoolean(true)).isTrue();
} else {
// slowest path, full callMethod to hit method_missing if present, or produce error
return callMethod(runtime.getCurrentContext(), "respond_to?", runtime.newSymbol(name)).isTrue();
Expand Down Expand Up @@ -1489,11 +1497,12 @@ public IRubyObject removeInstanceVariable(String name) {
@Override
public List<Variable<IRubyObject>> getInstanceVariableList() {
Map<String, VariableAccessor> ivarAccessors = metaClass.getVariableAccessorsForRead();
ArrayList<Variable<IRubyObject>> list = new ArrayList<Variable<IRubyObject>>();
ArrayList<Variable<IRubyObject>> list = new ArrayList<Variable<IRubyObject>>(ivarAccessors.size());
for (Map.Entry<String, VariableAccessor> entry : ivarAccessors.entrySet()) {
Object value = entry.getValue().get(this);
if (value == null || !(value instanceof IRubyObject) || !IdUtil.isInstanceVariable(entry.getKey())) continue;
list.add(new VariableEntry<IRubyObject>(entry.getKey(), (IRubyObject)value));
final String key = entry.getKey();
final Object value = entry.getValue().get(this);
if (value == null || !(value instanceof IRubyObject) || !IdUtil.isInstanceVariable(key)) continue;
list.add(new VariableEntry<IRubyObject>(key, (IRubyObject) value));
}
return list;
}
Expand All @@ -1505,11 +1514,12 @@ public List<Variable<IRubyObject>> getInstanceVariableList() {
@Override
public List<String> getInstanceVariableNameList() {
Map<String, VariableAccessor> ivarAccessors = metaClass.getVariableAccessorsForRead();
ArrayList<String> list = new ArrayList<String>();
ArrayList<String> list = new ArrayList<String>(ivarAccessors.size());
for (Map.Entry<String, VariableAccessor> entry : ivarAccessors.entrySet()) {
Object value = entry.getValue().get(this);
if (value == null || !(value instanceof IRubyObject) || !IdUtil.isInstanceVariable(entry.getKey())) continue;
list.add(entry.getKey());
final String key = entry.getKey();
final Object value = entry.getValue().get(this);
if (value == null || !(value instanceof IRubyObject) || !IdUtil.isInstanceVariable(key)) continue;
list.add(key);
}
return list;
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyKernel.java
Expand Up @@ -118,7 +118,7 @@ public static RubyModule createKernelModule(Ruby runtime) {

module.defineAnnotatedMethods(RubyKernel.class);

module.setFlag(RubyObject.USER7_F, false); //Kernel is the only Module that doesn't need an implementor
module.setFlag(RubyObject.USER7_F, false); //Kernel is the only normal Module that doesn't need an implementor

runtime.setPrivateMethodMissing(new MethodMissingMethod(module) {
@Override
Expand Down

0 comments on commit ee6a4a1

Please sign in to comment.