Skip to content

Commit

Permalink
Merge branch 'master' into truffle-head
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed May 7, 2015
2 parents 4ab6c57 + 4fc6836 commit e87a864
Show file tree
Hide file tree
Showing 87 changed files with 406 additions and 1,147 deletions.
4 changes: 2 additions & 2 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@
<dependency>
<groupId>com.github.jnr</groupId>
<artifactId>jnr-posix</artifactId>
<version>3.0.12</version>
<version>3.0.13-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.github.jnr</groupId>
<artifactId>jnr-constants</artifactId>
<version>0.8.7</version>
<version>0.8.8-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.github.jnr</groupId>
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -1586,7 +1586,8 @@ public IRubyObject eachSlice(ThreadContext context, int size, Block block) {
makeShared();

// don't expose shared array to ruby
final boolean specificArity = (block.arity().isFixed()) && (block.arity().required() != 1);
Signature signature = block.getSignature();
final boolean specificArity = signature.isFixed() && signature.required() != 1;

for (; localRealLength >= size; localRealLength -= size) {
block.yield(context, window);
Expand Down
24 changes: 18 additions & 6 deletions core/src/main/java/org/jruby/RubyEnumerable.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ public static IRubyObject callEach(Ruby runtime, ThreadContext context, IRubyObj
arity, callback, context));
}

public static IRubyObject callEach19(Ruby runtime, ThreadContext context, IRubyObject self,
Signature signature, BlockCallback callback) {
return Helpers.invoke(context, self, "each", CallBlock19.newCallClosure(self, runtime.getEnumerable(),
signature, callback, context));
}

@Deprecated
public static IRubyObject callEach19(Ruby runtime, ThreadContext context, IRubyObject self,
Arity arity, BlockCallback callback) {
return Helpers.invoke(context, self, "each", CallBlock19.newCallClosure(self, runtime.getEnumerable(),
Expand Down Expand Up @@ -140,10 +147,10 @@ public static IRubyObject count18(ThreadContext context, IRubyObject self, final

@JRubyMethod(name = "count")
public static IRubyObject count(ThreadContext context, IRubyObject self, final Block block) {
return countCommon(context, self, block, block.arity());
return countCommon(context, self, block);
}

private static IRubyObject countCommon(ThreadContext context, IRubyObject self, final Block block, Arity callbackArity) {
private static IRubyObject countCommon(ThreadContext context, IRubyObject self, final Block block) {
final Ruby runtime = context.runtime;
final int result[] = new int[] { 0 };

Expand Down Expand Up @@ -802,7 +809,7 @@ private static IRubyObject collectCommon19(ThreadContext context, IRubyObject se
if (block.isGiven()) {
final RubyArray result = runtime.newArray();

callEach19(runtime, context, self, block.arity(), new BlockCallback() {
callEach19(runtime, context, self, block.getSignature(), new BlockCallback() {
public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
IRubyObject larg;
boolean newAry = false;
Expand Down Expand Up @@ -1593,10 +1600,15 @@ public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {

@JRubyMethod(name = "any?")
public static IRubyObject any_p(ThreadContext context, IRubyObject self, final Block block) {
return any_pCommon(context, self, block, block.arity());
return any_pCommon(context, self, block);
}


@Deprecated
public static IRubyObject any_pCommon(ThreadContext context, IRubyObject self, final Block block, Arity callbackArity) {
return any_pCommon(context, self, block);
}

public static IRubyObject any_pCommon(ThreadContext context, IRubyObject self, final Block block) {
final Ruby runtime = context.runtime;

try {
Expand Down Expand Up @@ -1942,7 +1954,7 @@ public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
IRubyObject packedArgs = packEnumValues(runtime, largs);
IRubyObject v;
if(arg.state.isNil()) {
if (arg.categorize.getBlock().arity().getValue() == 1) {
if (arg.categorize.getBlock().getSignature().arityValue() == 1) {
// if chunk's categorize block has arity one, we pass it the packed args
v = arg.categorize.callMethod(ctx, "call", packedArgs);
} else {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyFixnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import org.jruby.compiler.Constantizable;
import org.jruby.runtime.Arity;
import org.jruby.runtime.Block;
import org.jruby.runtime.BlockBody;
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.marshal.UnmarshalStream;
Expand Down Expand Up @@ -287,7 +287,7 @@ public IRubyObject times(ThreadContext context, Block block) {
boolean checkArity = block.type.checkArity;

if (block.getBody().getArgumentType() == BlockBody.ZERO_ARGS ||
block.arity() == Arity.NO_ARGUMENTS) {
block.getSignature() == Signature.NO_ARGUMENTS) {
if (checkArity) {
// must pass arg
IRubyObject nil = runtime.getNil();
Expand Down
7 changes: 4 additions & 3 deletions core/src/main/java/org/jruby/RubyHash.java
Original file line number Diff line number Diff line change
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.invokedynamic.MethodNames;
Expand Down Expand Up @@ -742,7 +743,7 @@ public IRubyObject default_proc() {
*
*/
private void checkDefaultProcArity(IRubyObject proc) {
int n = ((RubyProc)proc).getBlock().arity().getValue();
int n = ((RubyProc)proc).getBlock().getSignature().arityValue();

if(((RubyProc)proc).getBlock().type == Block.Type.LAMBDA && n != 2 && (n >= 0 || n < -3)) {
if(n < 0) n = -n-1;
Expand Down Expand Up @@ -1325,7 +1326,7 @@ private void iteratorVisitAll(Visitor visitor) {
*
*/
public RubyHash eachCommon(final ThreadContext context, final Block block) {
if (block.arity() == Arity.TWO_ARGUMENTS) {
if (block.getSignature() == Signature.TWO_ARGUMENTS) {
iteratorVisitAll(new Visitor() {
@Override
public void visit(IRubyObject key, IRubyObject value) {
Expand Down Expand Up @@ -1879,7 +1880,7 @@ public IRubyObject any_p(ThreadContext context, Block block) {

if (!block.isGiven()) return context.runtime.getTrue();

if (block.arity().getValue() > 1)
if (block.getSignature().arityValue() > 1)
return any_p_i_fast(context, block);

return any_p_i(context, block);
Expand Down
53 changes: 14 additions & 39 deletions core/src/main/java/org/jruby/RubyKernel.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,22 @@
public class RubyKernel {
public final static Class<?> IRUBY_OBJECT = IRubyObject.class;

public static abstract class MethodMissingMethod extends JavaMethodNBlock {
public MethodMissingMethod(RubyModule implementationClass) {
public static class MethodMissingMethod extends JavaMethodNBlock {
private final Visibility visibility;
private final CallType callType;

public MethodMissingMethod(RubyModule implementationClass, Visibility visibility, CallType callType) {
super(implementationClass, Visibility.PRIVATE, CallConfiguration.FrameFullScopeNone);

this.callType = callType;
this.visibility = visibility;
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
return methodMissing(context, self, clazz, name, args, block);
return RubyKernel.methodMissing(context, self, name, visibility, callType, args, block);
}

public abstract IRubyObject methodMissing(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block);

}
public static RubyModule createKernelModule(Ruby runtime) {
RubyModule module = runtime.defineModule("Kernel");
Expand All @@ -120,40 +124,11 @@ public static RubyModule createKernelModule(Ruby runtime) {

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

runtime.setPrivateMethodMissing(new MethodMissingMethod(module) {
@Override
public IRubyObject methodMissing(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
return RubyKernel.methodMissing(context, self, name, PRIVATE, CallType.NORMAL, args, block);
}
});

runtime.setProtectedMethodMissing(new MethodMissingMethod(module) {
@Override
public IRubyObject methodMissing(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
return RubyKernel.methodMissing(context, self, name, PROTECTED, CallType.NORMAL, args, block);
}
});

runtime.setVariableMethodMissing(new MethodMissingMethod(module) {
@Override
public IRubyObject methodMissing(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
return RubyKernel.methodMissing(context, self, name, PUBLIC, CallType.VARIABLE, args, block);
}
});

runtime.setSuperMethodMissing(new MethodMissingMethod(module) {
@Override
public IRubyObject methodMissing(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
return RubyKernel.methodMissing(context, self, name, PUBLIC, CallType.SUPER, args, block);
}
});

runtime.setNormalMethodMissing(new MethodMissingMethod(module) {
@Override
public IRubyObject methodMissing(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
return RubyKernel.methodMissing(context, self, name, PUBLIC, CallType.NORMAL, args, block);
}
});
runtime.setPrivateMethodMissing(new MethodMissingMethod(module, PRIVATE, CallType.NORMAL));
runtime.setProtectedMethodMissing(new MethodMissingMethod(module, PROTECTED, CallType.NORMAL));
runtime.setVariableMethodMissing(new MethodMissingMethod(module, PUBLIC, CallType.VARIABLE));
runtime.setSuperMethodMissing(new MethodMissingMethod(module, PUBLIC, CallType.SUPER));
runtime.setNormalMethodMissing(new MethodMissingMethod(module, PUBLIC, CallType.NORMAL));

recacheBuiltinMethods(runtime);

Expand Down
17 changes: 9 additions & 8 deletions core/src/main/java/org/jruby/RubyProc.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.lexer.yacc.SimpleSourcePosition;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.Arity;
import org.jruby.runtime.Binding;
import org.jruby.runtime.Block;
import org.jruby.runtime.BlockBody;
Expand All @@ -48,6 +47,7 @@
import org.jruby.runtime.IRBlockBody;
import org.jruby.runtime.MethodBlock;
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.marshal.DataType;
Expand Down Expand Up @@ -239,25 +239,26 @@ public IRubyObject call(ThreadContext context, IRubyObject[] args) {
* arity of one, etc.)
*/
public static IRubyObject[] prepareArgs(ThreadContext context, Block.Type type, BlockBody blockBody, IRubyObject[] args) {
// FIXME: Arity marked for death
Arity arity = blockBody.arity();
if (arity == null) return args;
Signature signature = blockBody.getSignature();

// FIXME: which blocks have no signature (and no arity before that?)
if (signature == null) return args;

if (args == null) return IRubyObject.NULL_ARRAY;

if (type == Block.Type.LAMBDA) {
blockBody.getSignature().checkArity(context.runtime, args);
signature.checkArity(context.runtime, args);
return args;
}

boolean isFixed = arity.isFixed();
int required = arity.required();
boolean isFixed = signature.isFixed();
int required = signature.required();
int actual = args.length;
boolean restKwargs = blockBody instanceof IRBlockBody && ((IRBlockBody) blockBody).getSignature().hasKwargs();

// FIXME: This is a hot mess. restkwargs factors into destructing a single element array as well. I just weaved it into this logic.
// for procs and blocks, single array passed to multi-arg must be spread
if ((arity != Arity.ONE_ARGUMENT && required != 0 && (isFixed || arity != Arity.OPTIONAL) || restKwargs) &&
if ((signature != Signature.ONE_ARGUMENT && required != 0 && (isFixed || signature != Signature.OPTIONAL) || restKwargs) &&
actual == 1 && args[0].respondsTo("to_ary")) {
args = args[0].convertToArray().toJavaArray();
actual = args.length;
Expand Down
11 changes: 1 addition & 10 deletions core/src/main/java/org/jruby/ast/AssignableNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@
***** END LICENSE BLOCK *****/
package org.jruby.ast;

import org.jruby.ast.types.IArityNode;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.runtime.Arity;

/**
* Base class of any node which can be assigned to.
*/
public abstract class AssignableNode extends Node implements IArityNode {
public abstract class AssignableNode extends Node {
private Node valueNode;

public AssignableNode(ISourcePosition position) {
Expand Down Expand Up @@ -67,11 +65,4 @@ public Node getValueNode() {
public void setValueNode(Node valueNode) {
this.valueNode = valueNode == null ? NilImplicitNode.NIL : valueNode;
}

/**
* Almost all assignables are only assigned a single value.
*/
public Arity getArity() {
return Arity.singleArgument();
}
}
5 changes: 0 additions & 5 deletions core/src/main/java/org/jruby/ast/ForNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ public Node getIterNode() {
return iterNode;
}

@Override
public int getArgumentType() {
return BlockBody.asArgumentType(BlockBody.getArgumentTypeWackyHack(this));
}

/**
* Accept for the visitor pattern.
* @param iVisitor the visitor
Expand Down
11 changes: 1 addition & 10 deletions core/src/main/java/org/jruby/ast/InstVarNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,14 @@

import java.util.List;

import org.jruby.ast.types.IArityNode;
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.runtime.Arity;

/**
* Represents an instance variable accessor.
*/
public class InstVarNode extends Node implements IArityNode, INameNode {
public class InstVarNode extends Node implements INameNode {
private String name;

public InstVarNode(ISourcePosition position, String name) {
Expand All @@ -62,13 +60,6 @@ public NodeType getNodeType() {
public <T> T accept(NodeVisitor<T> iVisitor) {
return iVisitor.visitInstVarNode(this);
}

/**
* A variable accessor takes no arguments.
*/
public Arity getArity() {
return Arity.noArguments();
}

/**
* Gets the name.
Expand Down
4 changes: 0 additions & 4 deletions core/src/main/java/org/jruby/ast/IterNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ public IterNode(ISourcePosition position, ArgsNode args, Node body, StaticScope
this.scope = scope;
}

public int getArgumentType() {
return BlockBody.asArgumentType(varNode.getNodeType());
}

public NodeType getNodeType() {
return NodeType.ITERNODE;
}
Expand Down
Loading

0 comments on commit e87a864

Please sign in to comment.