Skip to content

Commit

Permalink
[Truffle] Return with block spec passes.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Oct 2, 2014
1 parent 39c9ca5 commit 5073469
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
21 changes: 20 additions & 1 deletion core/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java
Expand Up @@ -1838,7 +1838,7 @@ public InjectNode(InjectNode prev) {
}

@Specialization(guards = "isObject")
public Object inject(VirtualFrame frame, RubyArray array, Object initial, RubyProc block) {
public Object injectObject(VirtualFrame frame, RubyArray array, Object initial, RubyProc block) {
int count = 0;

final Object[] store = (Object[]) array.getStore();
Expand All @@ -1862,6 +1862,25 @@ public Object inject(VirtualFrame frame, RubyArray array, Object initial, RubyPr
return accumulator;
}

@Specialization
public Object inject(VirtualFrame frame, RubyArray array, Object initial, RubyProc block) {
notDesignedForCompilation();

final Object[] store = array.slowToArray();

if (store.length < 2) {
throw new UnsupportedOperationException();
}

Object accumulator = initial;

for (int n = 0; n < array.getSize(); n++) {
accumulator = yield(frame, block, accumulator, store[n]);
}

return accumulator;
}

@Specialization
public Object inject(VirtualFrame frame, RubyArray array, RubySymbol symbol, UndefinedPlaceholder unused) {
notDesignedForCompilation();
Expand Down
1 change: 0 additions & 1 deletion spec/truffle/tags/language/return_tags.txt
@@ -1,3 +1,2 @@
fails:The return keyword invoked with a method call without parentheses with a block returns the value returned from the method call
fails:The return keyword in a Thread raises a LocalJumpError if used to exit a thread
fails:The return keyword within define_method stops at the method when the return is used directly

0 comments on commit 5073469

Please sign in to comment.