Skip to content

Commit

Permalink
[Truffle] Implement zsuper with rest, when there are no other arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed May 19, 2015
1 parent 901b9d5 commit fa26543
Show file tree
Hide file tree
Showing 38 changed files with 45 additions and 71 deletions.
4 changes: 0 additions & 4 deletions spec/truffle/tags/language/super_tags.txt
@@ -1,8 +1,4 @@
fails:The super keyword passes along modified rest args when they weren't originally empty
fails:The super keyword passes along modified rest args when they were originally empty
fails:The super keyword raises a RuntimeError when called with implicit arguments from a method defined with define_method
fails:The super keyword calls method_missing when a superclass method is not found
fails:The super keyword without explicit arguments passes rest arguments
fails:The super keyword without explicit arguments passes rest arguments including any modifications
fails:The super keyword without explicit arguments passes arguments and rest arguments
fails:The super keyword without explicit arguments passes arguments and rest arguments including any modifications
2 changes: 0 additions & 2 deletions spec/truffle/tags/library/set/divide_tags.txt

This file was deleted.

3 changes: 0 additions & 3 deletions spec/truffle/tags/library/set/sortedset/classify_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/library/set/sortedset/collect_tags.txt

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions spec/truffle/tags/library/set/sortedset/delete_if_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/library/set/sortedset/delete_tags.txt

This file was deleted.

4 changes: 0 additions & 4 deletions spec/truffle/tags/library/set/sortedset/divide_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/library/set/sortedset/each_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/library/set/sortedset/empty_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/library/set/sortedset/eql_tags.txt

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/library/set/sortedset/exclusion_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/library/set/sortedset/flatten_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/library/set/sortedset/hash_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/library/set/sortedset/include_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/library/set/sortedset/initialize_tags.txt

This file was deleted.

3 changes: 0 additions & 3 deletions spec/truffle/tags/library/set/sortedset/keep_if_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/library/set/sortedset/length_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/library/set/sortedset/map_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/library/set/sortedset/member_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/library/set/sortedset/merge_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/library/set/sortedset/plus_tags.txt

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions spec/truffle/tags/library/set/sortedset/reject_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/library/set/sortedset/replace_tags.txt

This file was deleted.

4 changes: 0 additions & 4 deletions spec/truffle/tags/library/set/sortedset/select_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/library/set/sortedset/size_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/library/set/sortedset/subset_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/library/set/sortedset/superset_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/library/set/sortedset/to_a_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/library/set/sortedset/union_tags.txt

This file was deleted.

Expand Up @@ -186,6 +186,8 @@ private Object[] executeKeywordOptimizedArguments(VirtualFrame frame) {
}

private Object[] splat(Object argument) {
// TODO CS 19-May-15 this is a terrible mess and needs to go

// TODO(CS): what happens if isn't just one argument, or it isn't an Array?

if (!(argument instanceof RubyArray)) {
Expand Down
Expand Up @@ -16,17 +16,21 @@
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.array.ArrayUtils;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyProc;

public class GeneralSuperReCallNode extends AbstractGeneralSuperCallNode {

private final boolean inBlock;
private final boolean isSplatted;
@Children private final RubyNode[] reloadNodes;
@Child private RubyNode block;

public GeneralSuperReCallNode(RubyContext context, SourceSection sourceSection, boolean inBlock, RubyNode[] reloadNodes, RubyNode block) {
public GeneralSuperReCallNode(RubyContext context, SourceSection sourceSection, boolean inBlock, boolean isSplatted, RubyNode[] reloadNodes, RubyNode block) {
super(context, sourceSection);
this.inBlock = inBlock;
this.isSplatted = isSplatted;
this.reloadNodes = reloadNodes;
this.block = block;
}
Expand All @@ -49,12 +53,19 @@ public final Object execute(VirtualFrame frame) {
originalArguments = frame.getArguments();
}

final Object[] superArguments = new Object[reloadNodes.length];
Object[] superArguments = new Object[reloadNodes.length];

for (int n = 0; n < superArguments.length; n++) {
superArguments[n] = reloadNodes[n].execute(frame);
}

if (isSplatted) {
CompilerDirectives.transferToInterpreter();
assert superArguments.length == 1;
assert superArguments[0] instanceof RubyArray;
superArguments = ((RubyArray) superArguments[0]).slowToArray();
}

Object blockObject;

if (block != null) {
Expand Down
Expand Up @@ -284,10 +284,14 @@ public RubyNode visitZSuperNode(org.jruby.ast.ZSuperNode node) {
blockNode = null;
}

final SequenceNode reloadSequence = (SequenceNode) new ReloadArgumentsTranslator(
currentNode, context, source, this).visitArgsNode(argsNode);
final ReloadArgumentsTranslator reloadTranslator = new ReloadArgumentsTranslator(
currentNode, context, source, this);

return new GeneralSuperReCallNode(context, sourceSection, environment.isBlock(),
final SequenceNode reloadSequence = (SequenceNode) reloadTranslator.visitArgsNode(argsNode);

return new GeneralSuperReCallNode(context, sourceSection,
environment.isBlock(),
reloadTranslator.isSplatted(),
reloadSequence.getSequence(),
blockNode);
}
Expand Down
Expand Up @@ -34,7 +34,7 @@ public class ReloadArgumentsTranslator extends Translator {

private final BodyTranslator methodBodyTranslator;

private int index;
private boolean isSplatted = false;

public ReloadArgumentsTranslator(Node currentNode, RubyContext context, Source source, BodyTranslator methodBodyTranslator) {
super(currentNode, context, source);
Expand All @@ -47,18 +47,27 @@ public RubyNode visitArgsNode(org.jruby.ast.ArgsNode node) {

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

if (node.getPre() != null) {
for (org.jruby.ast.Node arg : node.getPre().childNodes()) {
sequence.add(arg.accept(this));
index++;
if (node.getPreCount() > 0 || node.getOptArgs() != null) {
if (node.getPre() != null) {
for (org.jruby.ast.Node arg : node.getPre().childNodes()) {
sequence.add(arg.accept(this));
}
}

if (node.getOptArgs() != null) {
for (org.jruby.ast.Node arg : node.getOptArgs().childNodes()) {
sequence.add(arg.accept(this));
}
}
}

if (node.getOptArgs() != null) {
for (org.jruby.ast.Node arg : node.getOptArgs().childNodes()) {
sequence.add(arg.accept(this));
index++;
if (node.hasRestArg()) {
// TODO CS 19-May-15 - documented in failing specs as well
//System.err.println("warning: " + node.getPosition());
}
} else if (node.hasRestArg()) {
sequence.add(visitArgumentNode(node.getRestArgNode()));

isSplatted = true;
}

return SequenceNode.sequenceNoFlatten(context, sourceSection, sequence);
Expand Down Expand Up @@ -89,4 +98,8 @@ protected String getIdentifier() {
return methodBodyTranslator.getIdentifier();
}

public boolean isSplatted() {
return isSplatted;
}

}

0 comments on commit fa26543

Please sign in to comment.