Skip to content

Commit

Permalink
Showing 6 changed files with 22 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.NotProvided;
import org.jruby.truffle.language.RubyNode;

public class IsRubiniusUndefinedNode extends RubyNode {
@@ -25,7 +26,7 @@ public IsRubiniusUndefinedNode(RubyContext context, SourceSection sourceSection,

@Override
public boolean executeBoolean(VirtualFrame frame) {
return isRubiniusUndefined(child.execute(frame));
return child.execute(frame) == NotProvided.INSTANCE;
}

@Override
Original file line number Diff line number Diff line change
@@ -53,11 +53,6 @@ public long duration(double duration) {
return validate((long) (duration * 1000));
}

@Specialization(guards = "isRubiniusUndefined(duration)")
public long duration(DynamicObject duration) {
return noDuration(NotProvided.INSTANCE);
}

@Specialization(guards = "isNil(duration)")
public long durationNil(DynamicObject duration) {
if (acceptsNil) {
@@ -67,7 +62,7 @@ public long durationNil(DynamicObject duration) {
}
}

@Specialization(guards = { "!isRubiniusUndefined(duration)", "!isNil(duration)" })
@Specialization(guards = "!isNil(duration)")
public long duration(VirtualFrame frame, DynamicObject duration) {
if (floatCastNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
Original file line number Diff line number Diff line change
@@ -303,7 +303,7 @@ public abstract static class GetOrUndefinedNode extends CoreMethodArrayArguments
public GetOrUndefinedNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
getIndexNode = GetIndexNodeFactory.create(context, sourceSection, null);
getIndexNode.setUndefinedValue(context.getCoreLibrary().getRubiniusUndefined());
getIndexNode.setUndefinedValue(NotProvided.INSTANCE);
}

@Specialization
Original file line number Diff line number Diff line change
@@ -509,8 +509,8 @@ public GetIndexNode(RubyContext context, SourceSection sourceSection) {
allocateObjectNode = AllocateObjectNode.create();
}

@Specialization(guards = "wasNotProvided(length) || isRubiniusUndefined(length)")
public Object getIndex(VirtualFrame frame, DynamicObject string, int index, Object length) {
@Specialization
public Object getIndex(VirtualFrame frame, DynamicObject string, int index, NotProvided length) {
// Check for the only difference from str[index, 1]
if (index == rope(string).characterLength()) {
outOfBounds.enter();
@@ -519,24 +519,26 @@ public Object getIndex(VirtualFrame frame, DynamicObject string, int index, Obje
return getSubstringNode().execute(frame, string, index, 1);
}

@Specialization(guards = { "!isRubyRange(index)", "!isRubyRegexp(index)", "!isRubyString(index)", "wasNotProvided(length) || isRubiniusUndefined(length)" })
public Object getIndex(VirtualFrame frame, DynamicObject string, Object index, Object length, @Cached("new()") SnippetNode snippetNode) {
@Specialization(guards = { "!isRubyRange(index)", "!isRubyRegexp(index)", "!isRubyString(index)" })
public Object getIndex(VirtualFrame frame, DynamicObject string, Object index, NotProvided length, @Cached("new()") SnippetNode snippetNode) {
return getIndex(frame, string, (int)snippetNode.execute(frame, "Rubinius::Type.rb_num2int(v)", "v", index), length);
}

@Specialization(guards = { "isIntRange(range)", "wasNotProvided(length) || isRubiniusUndefined(length)" })
public Object sliceIntegerRange(VirtualFrame frame, DynamicObject string, DynamicObject range, Object length) {
@Specialization(guards = "isIntRange(range)")
public Object sliceIntegerRange(VirtualFrame frame, DynamicObject string, DynamicObject range, NotProvided length) {
return sliceRange(frame, string, Layouts.INT_RANGE.getBegin(range), Layouts.INT_RANGE.getEnd(range), Layouts.INT_RANGE.getExcludedEnd(range));
}

@Specialization(guards = { "isLongRange(range)", "wasNotProvided(length) || isRubiniusUndefined(length)" })
public Object sliceLongRange(VirtualFrame frame, DynamicObject string, DynamicObject range, Object length) {
@Specialization(guards = "isLongRange(range)")
public Object sliceLongRange(VirtualFrame frame, DynamicObject string, DynamicObject range, NotProvided length) {
// TODO (nirvdrum 31-Mar-15) The begin and end values should be properly lowered, only if possible.
return sliceRange(frame, string, (int) Layouts.LONG_RANGE.getBegin(range), (int) Layouts.LONG_RANGE.getEnd(range), Layouts.LONG_RANGE.getExcludedEnd(range));
}

@Specialization(guards = {"isObjectRange(range)", "wasNotProvided(length) || isRubiniusUndefined(length)"})
public Object sliceObjectRange(VirtualFrame frame, DynamicObject string, DynamicObject range, Object length, @Cached("new()") SnippetNode snippetNode1, @Cached("new()") SnippetNode snippetNode2) {
@Specialization(guards = "isObjectRange(range)")
public Object sliceObjectRange(VirtualFrame frame, DynamicObject string, DynamicObject range, NotProvided length,
@Cached("new()") SnippetNode snippetNode1,
@Cached("new()") SnippetNode snippetNode2) {
// TODO (nirvdrum 31-Mar-15) The begin and end values may return Fixnums beyond int boundaries and we should handle that -- Bignums are always errors.
final int coercedBegin = (int)snippetNode1.execute(frame, "Rubinius::Type.rb_num2int(v)", "v", Layouts.OBJECT_RANGE.getBegin(range));
final int coercedEnd = (int)snippetNode2.execute(frame, "Rubinius::Type.rb_num2int(v)", "v", Layouts.OBJECT_RANGE.getEnd(range));
@@ -593,12 +595,12 @@ public Object slice(VirtualFrame frame, DynamicObject string, Object start, Obje
return slice(frame, string, (int)snippetNode1.execute(frame, "Rubinius::Type.rb_num2int(v)", "v", start), (int)snippetNode2.execute(frame, "Rubinius::Type.rb_num2int(v)", "v", length));
}

@Specialization(guards = {"isRubyRegexp(regexp)", "wasNotProvided(capture) || isRubiniusUndefined(capture)"})
@Specialization(guards = "isRubyRegexp(regexp)")
public Object slice1(
VirtualFrame frame,
DynamicObject string,
DynamicObject regexp,
Object capture,
NotProvided capture,
@Cached("createMethodCallIgnoreVisibility()") CallDispatchHeadNode callNode,
@Cached("create()") RegexpSetLastMatchPrimitiveNode setLastMatchNode) {
return sliceCapture(frame, string, regexp, 0, callNode, setLastMatchNode);
@@ -626,8 +628,8 @@ public Object sliceCapture(
return array[1];
}

@Specialization(guards = {"wasNotProvided(length) || isRubiniusUndefined(length)", "isRubyString(matchStr)"})
public Object slice2(VirtualFrame frame, DynamicObject string, DynamicObject matchStr, Object length) {
@Specialization(guards = "isRubyString(matchStr)")
public Object slice2(VirtualFrame frame, DynamicObject string, DynamicObject matchStr, NotProvided length) {
if (includeNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
includeNode = insert(DispatchHeadNodeFactory.createMethodCall(getContext()));
@@ -656,11 +658,6 @@ private StringSubstringPrimitiveNode getSubstringNode() {
return substringNode;
}

@Override
protected boolean isRubiniusUndefined(Object object) {
return object == coreLibrary().getRubiniusUndefined();
}

}

@CoreMethod(names = "ascii_only?")
Original file line number Diff line number Diff line change
@@ -97,10 +97,6 @@ protected boolean isNil(Object value) {
return value == nil();
}

protected boolean isRubiniusUndefined(Object value) {
return value == coreLibrary().getRubiniusUndefined();
}

// Helpers methods for terseness

protected DynamicObject nil() {
Original file line number Diff line number Diff line change
@@ -68,6 +68,7 @@
import org.jruby.truffle.core.string.StringOperations;
import org.jruby.truffle.core.string.StringUtils;
import org.jruby.truffle.language.LexicalScope;
import org.jruby.truffle.language.NotProvided;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.RubyRootNode;
import org.jruby.truffle.language.RubySourceSection;
@@ -3171,7 +3172,7 @@ public RubyNode visitUntilNode(UntilParseNode node) {
public RubyNode visitVCallNode(VCallParseNode node) {
final RubySourceSection sourceSection = translate(node.getPosition());
if (node.getName().equals("undefined") && getSourcePath(sourceSection).startsWith(corePath())) { // translate undefined
final RubyNode ret = new ObjectLiteralNode(context, sourceSection.toSourceSection(source), context.getCoreLibrary().getRubiniusUndefined());
final RubyNode ret = new ObjectLiteralNode(context, sourceSection.toSourceSection(source), NotProvided.INSTANCE);
return addNewlineIfNeeded(node, ret);
}

0 comments on commit 8e56bac

Please sign in to comment.