Skip to content

Commit

Permalink
Showing 8 changed files with 22 additions and 87 deletions.
Original file line number Diff line number Diff line change
@@ -73,6 +73,6 @@

UnsafeGroup[] unsafe() default {};

String snippetIfNoBlock() default "";
String enumeratorSize() default "";

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

if(!method.snippetIfNoBlock().isEmpty()) {
sequence = new SnippetIfNoBlockNode(method.snippetIfNoBlock(), sequence);

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
@@ -18,17 +18,17 @@
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.profiles.ConditionProfile;

public class SnippetIfNoBlockNode extends RubyNode {
public class EnumeratorSizeNode extends RubyNode {

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

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

@Override
@@ -40,7 +40,7 @@ public Object execute(VirtualFrame frame) {
CompilerDirectives.transferToInterpreterAndInvalidate();
snippetNode = insert(new SnippetNode());
}
return snippetNode.execute(frame, this.snippet);
return snippetNode.execute(frame, snippet);
} else {
return method.execute(frame);
}
24 changes: 8 additions & 16 deletions truffle/src/main/java/org/jruby/truffle/core/array/ArrayNodes.java
Original file line number Diff line number Diff line change
@@ -95,14 +95,6 @@
import static org.jruby.truffle.core.array.ArrayHelpers.getSize;
import static org.jruby.truffle.core.array.ArrayHelpers.getStore;
import static org.jruby.truffle.core.array.ArrayHelpers.setStoreAndSize;
import static org.jruby.truffle.core.rubinius.ToEnumSnippets.ARRAY_DELETE_IF_TO_ENUM;
import static org.jruby.truffle.core.rubinius.ToEnumSnippets.ARRAY_EACH_TO_ENUM;
import static org.jruby.truffle.core.rubinius.ToEnumSnippets.ARRAY_EACH_WITH_INDEX_TO_ENUM;
import static org.jruby.truffle.core.rubinius.ToEnumSnippets.ARRAY_MAP_BANG_TO_ENUM;
import static org.jruby.truffle.core.rubinius.ToEnumSnippets.ARRAY_MAP_TO_ENUM;
import static org.jruby.truffle.core.rubinius.ToEnumSnippets.ARRAY_REJECT_BANG_TO_ENUM;
import static org.jruby.truffle.core.rubinius.ToEnumSnippets.ARRAY_REJECT_TO_ENUM;
import static org.jruby.truffle.core.rubinius.ToEnumSnippets.ARRAY_SELECT_TO_ENUM;

@CoreClass("Array")
public abstract class ArrayNodes {
@@ -799,7 +791,7 @@ public Object deleteAt(DynamicObject array, int index,

}

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

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

}

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

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

}

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

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

}

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

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

}

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

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

}

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

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


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

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

}

@CoreMethod(names = "select", needsBlock = true, snippetIfNoBlock = ARRAY_SELECT_TO_ENUM)
@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,7 +51,6 @@
import java.util.Arrays;
import java.util.Map;

import static org.jruby.truffle.core.rubinius.ToEnumSnippets.HASH_EACH_TO_ENUM;

@CoreClass("Hash")
public abstract class HashNodes {
@@ -583,7 +582,7 @@ public Object delete(VirtualFrame frame, DynamicObject hash, Object key, Object

}

@CoreMethod(names = { "each", "each_pair" }, needsBlock = true, snippetIfNoBlock = HASH_EACH_TO_ENUM)
@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,7 +41,6 @@
import org.jruby.truffle.language.objects.AllocateObjectNode;
import org.jruby.truffle.language.objects.AllocateObjectNodeGen;

import static org.jruby.truffle.core.rubinius.ToEnumSnippets.RANGE_EACH_TO_ENUM;

@CoreClass("Range")
public abstract class RangeNodes {
@@ -84,7 +83,7 @@ public DynamicObject map(

}

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

@Child private CallDispatchHeadNode eachInternalCall;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -151,8 +151,6 @@
import java.util.Arrays;
import java.util.List;
import static org.jruby.truffle.core.rope.RopeConstants.EMPTY_ASCII_8BIT_ROPE;
import static org.jruby.truffle.core.rubinius.ToEnumSnippets.STRING_EACH_BYTE_TO_ENUM;
import static org.jruby.truffle.core.rubinius.ToEnumSnippets.STRING_EACH_CHAR_TO_ENUM;
import static org.jruby.truffle.core.string.StringOperations.encoding;
import static org.jruby.truffle.core.string.StringOperations.rope;

@@ -1022,7 +1020,7 @@ private boolean multiByteDowncase(Encoding encoding, byte[] bytes, int s, int en
}
}

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

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

}

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

0 comments on commit debe1af

Please sign in to comment.