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

Commits on Jan 7, 2016

  1. Copy the full SHA
    21665b0 View commit details
  2. Copy the full SHA
    bdbffc9 View commit details
  3. [Truffle] Weird behaviour with multiple assignment with a splatted ni…

    …l on the rhs is the last variables spec.
    chrisseaton committed Jan 7, 2016
    Copy the full SHA
    9dc5c59 View commit details
4 changes: 0 additions & 4 deletions spec/truffle/tags/language/variables_tags.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -33,10 +33,11 @@
@NodeChild("child")
public abstract class SplatCastNode extends RubyNode {

public static enum NilBehavior {
public enum NilBehavior {
EMPTY_ARRAY,
ARRAY_WITH_NIL,
NIL
NIL,
CONVERT
}

private final NilBehavior nilBehavior;
@@ -58,17 +59,20 @@ public SplatCastNode(RubyContext context, SourceSection sourceSection, NilBehavi
conversionMethod = context.getSymbol(useToAry ? "to_ary" : "to_a");
}

protected abstract RubyNode getChild();
public abstract RubyNode getChild();

@Specialization(guards = "isNil(nil)")
public DynamicObject splat(Object nil) {
public Object splatNil(VirtualFrame frame, Object nil) {
switch (nilBehavior) {
case EMPTY_ARRAY:
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), null, 0);

case ARRAY_WITH_NIL:
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), new Object[]{nil()}, 1);

case CONVERT:
return toA.call(frame, nil, "to_a", null);

default: {
throw new UnsupportedOperationException();
}
Original file line number Diff line number Diff line change
@@ -54,10 +54,7 @@
import org.jruby.truffle.nodes.dispatch.RubyCallNode;
import org.jruby.truffle.nodes.exceptions.*;
import org.jruby.truffle.nodes.globals.*;
import org.jruby.truffle.nodes.literal.BooleanLiteralNode;
import org.jruby.truffle.nodes.literal.FloatLiteralNode;
import org.jruby.truffle.nodes.literal.LiteralNode;
import org.jruby.truffle.nodes.literal.StringLiteralNode;
import org.jruby.truffle.nodes.literal.*;
import org.jruby.truffle.nodes.locals.*;
import org.jruby.truffle.nodes.methods.*;
import org.jruby.truffle.nodes.objects.*;
@@ -2162,17 +2159,42 @@ public RubyNode visitMultipleAsgnNode(org.jruby.ast.MultipleAsgnNode node) {

final List<RubyNode> sequence = new ArrayList<>();

SplatCastNode.NilBehavior nilBehavior;

if (translatingNextExpression) {
nilBehavior = SplatCastNode.NilBehavior.EMPTY_ARRAY;
} else {
if (rhsTranslated instanceof SplatCastNode && ((SplatCastNodeGen) rhsTranslated).getChild() instanceof NilNode) {
rhsTranslated = ((SplatCastNodeGen) rhsTranslated).getChild();
nilBehavior = SplatCastNode.NilBehavior.CONVERT;
} else {
nilBehavior = SplatCastNode.NilBehavior.ARRAY_WITH_NIL;
}
}

final String tempRHSName = environment.allocateLocalTemp("rhs");
final RubyNode writeTempRHS = environment.findLocalVarNode(tempRHSName, sourceSection).makeWriteNode(rhsTranslated);
sequence.add(writeTempRHS);

final SplatCastNode rhsSplatCast = SplatCastNodeGen.create(context, sourceSection,
translatingNextExpression ? SplatCastNode.NilBehavior.EMPTY_ARRAY : SplatCastNode.NilBehavior.ARRAY_WITH_NIL,
false, environment.findLocalVarNode(tempRHSName, sourceSection));
nilBehavior,
true, environment.findLocalVarNode(tempRHSName, sourceSection));

sequence.add(translateDummyAssignment(node.getRest(), rhsSplatCast));
final String tempRHSSplattedName = environment.allocateLocalTemp("rhs");
final RubyNode writeTempSplattedRHS = environment.findLocalVarNode(tempRHSSplattedName, sourceSection).makeWriteNode(rhsSplatCast);
sequence.add(writeTempSplattedRHS);

result = new ElidableResultNode(context, sourceSection, SequenceNode.sequence(context, sourceSection, sequence), environment.findLocalVarNode(tempRHSName, sourceSection));
sequence.add(translateDummyAssignment(node.getRest(), environment.findLocalVarNode(tempRHSSplattedName, sourceSection)));

final RubyNode assignmentResult;

if (nilBehavior == SplatCastNode.NilBehavior.CONVERT) {
assignmentResult = environment.findLocalVarNode(tempRHSSplattedName, sourceSection);
} else {
assignmentResult = environment.findLocalVarNode(tempRHSName, sourceSection);
}

result = new ElidableResultNode(context, sourceSection, SequenceNode.sequence(context, sourceSection, sequence), assignmentResult);
} else if (node.getPre() == null
&& node.getPost() == null
&& node.getRest() != null
@@ -2707,7 +2729,7 @@ public RubyNode visitSplatNode(org.jruby.ast.SplatNode node) {
final SourceSection sourceSection = translate(node.getPosition());

final RubyNode value = translateNodeOrNil(sourceSection, node.getValue());
final RubyNode ret = SplatCastNodeGen.create(context, sourceSection, SplatCastNode.NilBehavior.EMPTY_ARRAY, false, value);
final RubyNode ret = SplatCastNodeGen.create(context, sourceSection, SplatCastNode.NilBehavior.CONVERT, false, value);
return addNewlineIfNeeded(node, ret);
}