Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[1.9] Fix remaining language/method_spec failures in interpreter.

  • Loading branch information...
commit 1c457721e55ecfca9641b0c4a52bb86d033ce2c2 1 parent 0bf229b
@headius headius authored yokolet committed
View
6 spec/tags/1.9/ruby/language/method_tags.txt
@@ -1,6 +0,0 @@
-fails:Calling a method accepts additional arguments after splat expansion
-fails:Calling a method accepts multiple splat expansions in the same argument list
-fails:Calling a method expands an array to arguments grouped in parentheses
-fails:Calling a method expands an array to arguments grouped in parentheses and ignores any rest arguments in the array
-fails:Calling a method expands an array to arguments grouped in parentheses and sets not specified arguments to nil
-fails:Calling a method expands an array to arguments grouped in parentheses which in turn takes rest arguments
View
10 src/org/jruby/ast/ArgsCatNode.java
@@ -34,6 +34,7 @@
import java.util.List;
import org.jruby.Ruby;
+import org.jruby.RubyArray;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.javasupport.util.RuntimeHelpers;
import org.jruby.lexer.yacc.ISourcePosition;
@@ -78,15 +79,8 @@ public Node getSecondNode() {
@Override
public IRubyObject interpret(Ruby runtime, ThreadContext context, IRubyObject self, Block aBlock) {
IRubyObject args = firstNode.interpret(runtime, context, self, aBlock);
-
IRubyObject secondInterpret = secondNode.interpret(runtime, context, self, aBlock);
- IRubyObject secondArgs;
- if (runtime.is1_9()) {
- secondArgs = RuntimeHelpers.splatValue19(secondInterpret);
- } else {
- secondArgs = RuntimeHelpers.splatValue(secondInterpret);
- }
- return RuntimeHelpers.ensureRubyArray(runtime, args).concat(secondArgs);
+ return RuntimeHelpers.argsCat(args, secondInterpret);
}
}
View
2  src/org/jruby/ast/FCallNode.java
@@ -48,7 +48,7 @@
* Represents a method call with self as an implicit receiver.
*/
public class FCallNode extends Node implements INameNode, IArgumentNode, BlockAcceptingNode {
- private Node argsNode;
+ protected Node argsNode;
protected Node iterNode;
public CallSite callAdapter;
View
5 src/org/jruby/compiler/ASTCompiler.java
@@ -698,10 +698,9 @@ public void compileArgsCat(Node node, BodyCompiler context, boolean expr) {
ArgsCatNode argsCatNode = (ArgsCatNode) node;
compile(argsCatNode.getFirstNode(), context,true);
- context.ensureRubyArray();
compile(argsCatNode.getSecondNode(), context,true);
- splatCurrentValue(context);
- context.concatArrays();
+ context.argsCat();
+
// TODO: don't require pop
if (!expr) context.consumeCurrentValue();
}
View
5 src/org/jruby/compiler/BodyCompiler.java
@@ -637,6 +637,11 @@ public void compileSequencedConditional(
public void argsPush();
/**
+ * Pass two stack elements, converting the first to an array, to the "argsCat" utility method.
+ */
+ public void argsCat();
+
+ /**
* Load the specified encoding.
*/
public void loadEncoding(Encoding encoding);
View
4 src/org/jruby/compiler/impl/BaseBodyCompiler.java
@@ -2861,6 +2861,10 @@ public void argsPush() {
invokeUtilityMethod("argsPush", sig(RubyArray.class, RubyArray.class, IRubyObject.class));
}
+ public void argsCat() {
+ invokeUtilityMethod("argsCat", sig(RubyArray.class, IRubyObject.class, IRubyObject.class));
+ }
+
public void loadEncoding(Encoding encoding) {
script.getCacheCompiler().cacheEncoding(this, encoding);
}
View
35 src/org/jruby/evaluator/AssignmentVisitor.java
@@ -50,30 +50,39 @@ public static IRubyObject assign(Ruby runtime, ThreadContext context, IRubyObjec
public static IRubyObject multiAssign(Ruby runtime, ThreadContext context, IRubyObject self, MultipleAsgn19Node node, RubyArray value, boolean checkArity) {
// Assign the values.
int valueLen = value.getLength();
- int varLen = node.getPre() == null ? 0 : node.getPre().size();
+ int varLen = node.getPreCount() + node.getPostCount();
- int j = 0;
- for (; j < valueLen && j < varLen; j++) {
- node.getPre().get(j).assign(runtime, context, self, value.eltInternal(j), Block.NULL_BLOCK, checkArity);
+ if (checkArity && varLen < valueLen) {
+ throw runtime.newArgumentError("Wrong # of arguments (" + valueLen + " for " + varLen + ")");
}
- if (checkArity && j < varLen) {
- throw runtime.newArgumentError("Wrong # of arguments (" + valueLen + " for " + varLen + ")");
+ int assigned = 0;
+ for (assigned = 0; assigned < node.getPreCount(); assigned++) {
+ if (assigned >= valueLen) {
+ node.getPre().get(assigned).assign(runtime, context, self, runtime.getNil(), Block.NULL_BLOCK, false);
+ } else {
+ node.getPre().get(assigned).assign(runtime, context, self, value.eltInternal(assigned), Block.NULL_BLOCK, false);
+ }
}
Node restArgument = node.getRest();
if (restArgument != null) {
- if (varLen < valueLen) {
- restArgument.assign(runtime, context, self, value.subseqLight(varLen, valueLen), Block.NULL_BLOCK, checkArity);
+ int restLen = valueLen - varLen;
+ if (restLen > 0) {
+ restArgument.assign(runtime, context, self, value.subseqLight(assigned, restLen), Block.NULL_BLOCK, false);
+ assigned += restLen;
} else {
- restArgument.assign(runtime, context, self, RubyArray.newEmptyArray(runtime), Block.NULL_BLOCK, checkArity);
+ restArgument.assign(runtime, context, self, RubyArray.newEmptyArray(runtime), Block.NULL_BLOCK, false);
}
- } else if (checkArity && valueLen < varLen) {
- throw runtime.newArgumentError("Wrong # of arguments (" + valueLen + " for " + varLen + ")");
}
- while (j < varLen) {
- node.getPre().get(j++).assign(runtime, context, self, runtime.getNil(), Block.NULL_BLOCK, checkArity);
+ for (int i = 0; i < node.getPostCount(); i++) {
+ assigned += i;
+ if (assigned >= valueLen) {
+ node.getPost().get(i).assign(runtime, context, self, runtime.getNil(), Block.NULL_BLOCK, false);
+ } else {
+ node.getPost().get(i).assign(runtime, context, self, value.eltInternal(assigned), Block.NULL_BLOCK, false);
+ }
}
return value;
View
12 src/org/jruby/javasupport/util/RuntimeHelpers.java
@@ -2224,6 +2224,18 @@ public static RubyArray argsPush(RubyArray first, IRubyObject second) {
return ((RubyArray)first.dup()).append(second);
}
+ public static RubyArray argsCat(IRubyObject first, IRubyObject second) {
+ Ruby runtime = first.getRuntime();
+ IRubyObject secondArgs;
+ if (runtime.is1_9()) {
+ secondArgs = RuntimeHelpers.splatValue19(second);
+ } else {
+ secondArgs = RuntimeHelpers.splatValue(second);
+ }
+
+ return ((RubyArray)RuntimeHelpers.ensureRubyArray(runtime, first).dup()).concat(secondArgs);
+ }
+
public static String encodeParameterList(ArgsNode argsNode) {
StringBuilder builder = new StringBuilder();
View
11 src/org/jruby/parser/ParserSupport.java
@@ -1410,12 +1410,19 @@ public Node new_args(ISourcePosition position, ListNode pre, ListNode optional,
// Zero-Argument declaration
if (optional == null && rest == null && post == null && block == null) {
if (pre == null || pre.size() == 0) return new ArgsNoArgNode(position);
- if (pre.size() == 1) return new ArgsPreOneArgNode(position, pre);
- if (pre.size() == 2) return new ArgsPreTwoArgNode(position, pre);
+ if (pre.size() == 1 && !hasAssignableArgs(pre)) return new ArgsPreOneArgNode(position, pre);
+ if (pre.size() == 2 && !hasAssignableArgs(pre)) return new ArgsPreTwoArgNode(position, pre);
}
return new ArgsNode(position, pre, optional, rest, post, block);
}
+ private boolean hasAssignableArgs(ListNode list) {
+ for (Node node : list.childNodes()) {
+ if (node instanceof AssignableNode) return true;
+ }
+ return false;
+ }
+
public Node newAlias(ISourcePosition position, Node newNode, Node oldNode) {
return new AliasNode(position, newNode, oldNode);
}
Please sign in to comment.
Something went wrong with that request. Please try again.