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/coerce/ToIntNode.java
	truffle/src/main/java/org/jruby/truffle/nodes/core/DirNodes.java
	truffle/src/main/java/org/jruby/truffle/nodes/core/FileNodes.java
	truffle/src/main/java/org/jruby/truffle/nodes/core/FloatNodes.java
	truffle/src/main/java/org/jruby/truffle/nodes/core/ModuleNodes.java
	truffle/src/main/java/org/jruby/truffle/nodes/objects/FreezeNode.java
	truffle/src/main/java/org/jruby/truffle/nodes/objects/IsFrozenNode.java
	truffle/src/main/java/org/jruby/truffle/nodes/rubinius/StringPrimitiveNodes.java
  • Loading branch information
chrisseaton committed Apr 18, 2015
2 parents 865c26c + 3735705 commit bff6243
Show file tree
Hide file tree
Showing 167 changed files with 2,430 additions and 1,465 deletions.
2 changes: 1 addition & 1 deletion core/pom.xml
Expand Up @@ -10,7 +10,7 @@
<artifactId>jruby-core</artifactId>
<name>JRuby Core</name>
<properties>
<version.ruby>2.2.1</version.ruby>
<version.ruby>2.2.2</version.ruby>
<prawn.dir>${test.dir}/prawn</prawn.dir>
<spec.tags.dir>${spec.dir}/tags</spec.tags.dir>
<pkg.dir>${build.dir}/pkg</pkg.dir>
Expand Down
10 changes: 9 additions & 1 deletion core/src/main/java/org/jruby/AbstractRubyMethod.java
Expand Up @@ -35,6 +35,7 @@
import org.jruby.anno.JRubyMethod;
import org.jruby.ext.jruby.JRubyLibrary;
import org.jruby.internal.runtime.methods.DynamicMethod;
import org.jruby.internal.runtime.methods.IRMethodArgs;
import org.jruby.internal.runtime.methods.ProcMethod;
import org.jruby.internal.runtime.methods.UndefinedMethod;
import org.jruby.runtime.Block;
Expand Down Expand Up @@ -81,7 +82,14 @@ public DynamicMethod getMethod() {
*/
@JRubyMethod(name = "arity")
public RubyFixnum arity() {
return getRuntime().newFixnum(method.getArity().getValue());
int value;
if (method instanceof IRMethodArgs) {
value = ((IRMethodArgs) method).getSignature().arityValue();
} else {
value = method.getArity().getValue();
}

return getRuntime().newFixnum(value);
}

@JRubyMethod(name = "eql?", required = 1)
Expand Down
14 changes: 12 additions & 2 deletions core/src/main/java/org/jruby/IncludedModuleWrapper.java
Expand Up @@ -208,7 +208,17 @@ public IRubyObject getAutoloadConstant(String name) {

@Override
protected DynamicMethod searchMethodCommon(String name) {
// try us and superclasses (from prepend)
return origin.searchMethodInner(name);
// IncludedModuleWrapper needs to search prepended modules too, but not included ones.
RubyModule module = this;
for (; module.isPrepended(); module = module.getSuperClass()) {
DynamicMethod method = module.getMethods().get(name);
if (method != null) return method.isNull() ? null : method;
}

// Last non-prepended module should be our regular module, do one last search.
DynamicMethod method = module.getMethods().get(name);
if (method != null) return method.isNull() ? null : method;

return null;
}
}
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/RubyArray.java
Expand Up @@ -51,6 +51,7 @@
import org.jruby.runtime.ClassIndex;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.Signature;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.encoding.EncodingCapable;
Expand Down Expand Up @@ -4026,7 +4027,7 @@ public IRubyObject find(ThreadContext context, IRubyObject ifnone, Block block)
}

public IRubyObject find_index(ThreadContext context, Block block) {
if (!isBuiltin("each")) return RubyEnumerable.find_indexCommon(context, this, block, Arity.OPTIONAL);
if (!isBuiltin("each")) return RubyEnumerable.find_indexCommon(context, this, block, Signature.OPTIONAL);

for (int i = 0; i < realLength; i++) {
if (block.yield(context, eltOk(i)).isTrue()) return context.runtime.newFixnum(i);
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/RubyBignum.java
Expand Up @@ -76,6 +76,7 @@ public static RubyClass createBignumClass(Ruby runtime) {
public RubyBignum(Ruby runtime, BigInteger value) {
super(runtime, runtime.getBignum());
this.value = value;
setFrozen(true);
}

@Override
Expand Down
42 changes: 37 additions & 5 deletions core/src/main/java/org/jruby/RubyDir.java
Expand Up @@ -387,10 +387,24 @@ public static IRubyObject foreach(ThreadContext context, IRubyObject recv, IRuby
public static IRubyObject foreach19(ThreadContext context, IRubyObject recv, IRubyObject arg, Block block) {
RubyString pathString = RubyFile.get_path(context, arg);

return foreachCommon(context, recv, context.runtime, pathString, block);
return foreachCommon(context, recv, context.runtime, pathString, null, block);
}

private static IRubyObject foreachCommon(ThreadContext context, IRubyObject recv, Ruby runtime, RubyString _path, Block block) {
@JRubyMethod(name = "foreach", meta = true)
public static IRubyObject foreach19(ThreadContext context, IRubyObject recv, IRubyObject path, IRubyObject enc, Block block) {
RubyString pathString = RubyFile.get_path(context, path);
RubyEncoding encoding;

if (enc instanceof RubyEncoding) {
encoding = (RubyEncoding) enc;
} else {
throw context.runtime.newTypeError(enc, context.runtime.getEncoding());
}

return foreachCommon(context, recv, context.runtime, pathString, encoding, block);
}

private static IRubyObject foreachCommon(ThreadContext context, IRubyObject recv, Ruby runtime, RubyString _path, RubyEncoding encoding, Block block) {
if (block.isGiven()) {
RubyClass dirClass = runtime.getDir();
RubyDir dir = (RubyDir) dirClass.newInstance(context, new IRubyObject[]{_path}, block);
Expand All @@ -399,7 +413,11 @@ private static IRubyObject foreachCommon(ThreadContext context, IRubyObject recv
return runtime.getNil();
}

return enumeratorize(runtime, recv, "foreach", _path);
if (encoding == null) {
return enumeratorize(runtime, recv, "foreach", _path);
} else {
return enumeratorize(runtime, recv, "foreach", new IRubyObject[]{_path, encoding});
}
}

/** Returns the current directory. */
Expand Down Expand Up @@ -508,22 +526,36 @@ public IRubyObject close() {
/**
* Executes the block once for each entry in the directory.
*/
public IRubyObject each(ThreadContext context, Block block) {
public IRubyObject each(ThreadContext context, Encoding enc, Block block) {
checkDir();

String[] contents = snapshot;
for (pos = 0; pos < contents.length; pos++) {
block.yield(context, getRuntime().newString(contents[pos]));
block.yield(context, RubyString.newString(context.runtime, contents[pos], enc));
}

return this;
}

/**
* Executes the block once for each entry in the directory.
*/
public IRubyObject each(ThreadContext context, Block block) {
return each(context, context.runtime.getDefaultInternalEncoding(), block);
}

@JRubyMethod(name = "each")
public IRubyObject each19(ThreadContext context, Block block) {
return block.isGiven() ? each(context, block) : enumeratorize(context.runtime, this, "each");
}

@JRubyMethod(name = "each")
public IRubyObject each19(ThreadContext context, IRubyObject encoding, Block block) {
if (!(encoding instanceof RubyEncoding)) throw context.runtime.newTypeError(encoding, context.runtime.getEncoding());

return block.isGiven() ? each(context, ((RubyEncoding)encoding).getEncoding(), block) : enumeratorize(context.runtime, this, "each", encoding);
}

@Override
@JRubyMethod
public IRubyObject inspect() {
Expand Down

0 comments on commit bff6243

Please sign in to comment.