Skip to content

Commit

Permalink
Showing 17 changed files with 71 additions and 26 deletions.
2 changes: 0 additions & 2 deletions spec/truffle/tags/core/array/collect_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/array/delete_if_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/array/each_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/array/map_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/array/reject_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/array/select_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/hash/each_pair_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:Hash#each_pair properly expands (or not) child class's 'each'-yielded args
fails:Hash#each_pair when no block is given returned Enumerator size returns the enumerable size
1 change: 0 additions & 1 deletion spec/truffle/tags/core/hash/each_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:Hash#each properly expands (or not) child class's 'each'-yielded args
fails:Hash#each when no block is given returned Enumerator size returns the enumerable size
1 change: 0 additions & 1 deletion spec/truffle/tags/core/string/each_byte_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/string/each_char_tags.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -73,4 +73,6 @@

UnsafeGroup[] unsafe() default {};

String enumeratorSize() default "";

}
Original file line number Diff line number Diff line change
@@ -263,7 +263,12 @@ private static CallTarget makeGenericMethod(RubyContext context, MethodDetails m
} else {
sequence = Translator.sequence(context, sourceSection, Arrays.asList(checkArity, methodNode));

if (method.returnsEnumeratorIfNoBlock()) {

if (!method.enumeratorSize().isEmpty()) {
assert !method.returnsEnumeratorIfNoBlock(): "Only one of enumeratorSize or returnsEnumeratorIfNoBlock can be specified";
// TODO BF 6-27-2015 Handle multiple method names correctly
sequence = new EnumeratorSizeNode(method.enumeratorSize(), method.names()[0], sequence);
} else if (method.returnsEnumeratorIfNoBlock()) {
// TODO BF 3-18-2015 Handle multiple method names correctly
sequence = new ReturnEnumeratorIfNoBlockNode(method.names()[0], sequence);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.builtins;

import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.SnippetNode;
import org.jruby.truffle.language.arguments.RubyArguments;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.profiles.ConditionProfile;

public class EnumeratorSizeNode extends RubyNode {

@Child private RubyNode method;
@Child private SnippetNode snippetNode;
private final ConditionProfile noBlockProfile = ConditionProfile.createBinaryProfile();
private final String snippet;

public EnumeratorSizeNode(String enumeratorSize, String methodName, RubyNode method) {
super(method.getContext(), method.getEncapsulatingSourceSection());
this.method = method;
this.snippet = "to_enum(:" + methodName + ") { " + enumeratorSize + " }";
}

@Override
public Object execute(VirtualFrame frame) {
final DynamicObject block = RubyArguments.getBlock(frame);

if (noBlockProfile.profile(block == null)) {
if (snippetNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
snippetNode = insert(new SnippetNode());
}
return snippetNode.execute(frame, snippet);
} else {
return method.execute(frame);
}
}

}
Original file line number Diff line number Diff line change
@@ -791,7 +791,7 @@ public Object deleteAt(DynamicObject array, int index,

}

@CoreMethod(names = "each", needsBlock = true, returnsEnumeratorIfNoBlock = true)
@CoreMethod(names = "each", needsBlock = true, enumeratorSize = "size")
@ImportStatic(ArrayGuards.class)
public abstract static class EachNode extends YieldingCoreMethodNode {

@@ -827,7 +827,7 @@ public Object eachOther(VirtualFrame frame, DynamicObject array, DynamicObject b

}

@CoreMethod(names = "each_with_index", needsBlock = true, returnsEnumeratorIfNoBlock = true)
@CoreMethod(names = "each_with_index", needsBlock = true, enumeratorSize = "size")
@ImportStatic(ArrayGuards.class)
public abstract static class EachWithIndexNode extends YieldingCoreMethodNode {

@@ -1196,7 +1196,7 @@ public Object injectSymbolHelper(VirtualFrame frame, DynamicObject array, Dynami

}

@CoreMethod(names = { "map", "collect" }, needsBlock = true, returnsEnumeratorIfNoBlock = true)
@CoreMethod(names = { "map", "collect" }, needsBlock = true, enumeratorSize = "size")
@ImportStatic(ArrayGuards.class)
public abstract static class MapNode extends YieldingCoreMethodNode {

@@ -1230,7 +1230,7 @@ public Object map(VirtualFrame frame, DynamicObject array, DynamicObject block,

}

@CoreMethod(names = { "map!", "collect!" }, needsBlock = true, returnsEnumeratorIfNoBlock = true, raiseIfFrozenSelf = true)
@CoreMethod(names = { "map!", "collect!" }, needsBlock = true, enumeratorSize = "size", raiseIfFrozenSelf = true)
@ImportStatic(ArrayGuards.class)
public abstract static class MapInPlaceNode extends YieldingCoreMethodNode {

@@ -1742,7 +1742,7 @@ public DynamicObject pushMany(VirtualFrame frame, DynamicObject array, Object va

}

@CoreMethod(names = "reject", needsBlock = true, returnsEnumeratorIfNoBlock = true)
@CoreMethod(names = "reject", needsBlock = true, enumeratorSize = "size")
@ImportStatic(ArrayGuards.class)
public abstract static class RejectNode extends YieldingCoreMethodNode {

@@ -1781,7 +1781,7 @@ public Object rejectOther(VirtualFrame frame, DynamicObject array, DynamicObject

}

@CoreMethod(names = "delete_if" , needsBlock = true, returnsEnumeratorIfNoBlock = true, raiseIfFrozenSelf = true)
@CoreMethod(names = "delete_if" , needsBlock = true, enumeratorSize = "size", raiseIfFrozenSelf = true)
@ImportStatic(ArrayGuards.class)
public abstract static class DeleteIfNode extends YieldingCoreMethodNode {

@@ -1799,7 +1799,7 @@ protected RejectInPlaceNode createRejectInPlaceNode() {
}


@CoreMethod(names = "reject!", needsBlock = true, returnsEnumeratorIfNoBlock = true, raiseIfFrozenSelf = true)
@CoreMethod(names = "reject!", needsBlock = true, enumeratorSize = "size", raiseIfFrozenSelf = true)
@ImportStatic(ArrayGuards.class)
public abstract static class RejectInPlaceNode extends YieldingCoreMethodNode {

@@ -1881,7 +1881,7 @@ public DynamicObject replace(DynamicObject array, DynamicObject other,

}

@CoreMethod(names = "select", needsBlock = true, returnsEnumeratorIfNoBlock = true)
@CoreMethod(names = "select", needsBlock = true, enumeratorSize = "size")
@ImportStatic(ArrayGuards.class)
public abstract static class SelectNode extends YieldingCoreMethodNode {

Original file line number Diff line number Diff line change
@@ -51,6 +51,7 @@
import java.util.Arrays;
import java.util.Map;


@CoreClass("Hash")
public abstract class HashNodes {

@@ -581,7 +582,7 @@ public Object delete(VirtualFrame frame, DynamicObject hash, Object key, Object

}

@CoreMethod(names = { "each", "each_pair" }, needsBlock = true)
@CoreMethod(names = { "each", "each_pair" }, needsBlock = true, enumeratorSize = "size")
@ImportStatic(HashGuards.class)
public abstract static class EachNode extends YieldingCoreMethodNode {

Original file line number Diff line number Diff line change
@@ -41,6 +41,7 @@
import org.jruby.truffle.language.objects.AllocateObjectNode;
import org.jruby.truffle.language.objects.AllocateObjectNodeGen;


@CoreClass("Range")
public abstract class RangeNodes {

@@ -82,7 +83,7 @@ public DynamicObject map(

}

@CoreMethod(names = "each", needsBlock = true, lowerFixnumSelf = true, returnsEnumeratorIfNoBlock = true)
@CoreMethod(names = "each", needsBlock = true, lowerFixnumSelf = true, enumeratorSize = "size")
public abstract static class EachNode extends YieldingCoreMethodNode {

@Child private CallDispatchHeadNode eachInternalCall;
Original file line number Diff line number Diff line change
@@ -1020,7 +1020,7 @@ private boolean multiByteDowncase(Encoding encoding, byte[] bytes, int s, int en
}
}

@CoreMethod(names = "each_byte", needsBlock = true, returnsEnumeratorIfNoBlock = true)
@CoreMethod(names = "each_byte", needsBlock = true, enumeratorSize = "bytesize")
public abstract static class EachByteNode extends YieldingCoreMethodNode {

@Specialization
@@ -1044,7 +1044,7 @@ public DynamicObject eachByte(VirtualFrame frame, DynamicObject string, DynamicO

}

@CoreMethod(names = "each_char", needsBlock = true, returnsEnumeratorIfNoBlock = true)
@CoreMethod(names = "each_char", needsBlock = true, enumeratorSize = "size")
@ImportStatic(StringGuards.class)
public abstract static class EachCharNode extends YieldingCoreMethodNode {

0 comments on commit a222bf9

Please sign in to comment.