Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: f0a21fe3abe0
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 58e1df004520
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Apr 24, 2016

  1. Copy the full SHA
    b946ac6 View commit details
  2. Copy the full SHA
    58e1df0 View commit details
Original file line number Diff line number Diff line change
@@ -48,6 +48,7 @@
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.ExactMath;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
@@ -63,6 +64,7 @@
import org.jruby.truffle.core.time.ReadTimeZoneNode;
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.SnippetNode;
import org.jruby.truffle.language.control.RaiseException;
import org.jruby.truffle.language.objects.AllocateObjectNode;
import org.jruby.truffle.language.objects.AllocateObjectNodeGen;
@@ -258,15 +260,30 @@ public TimeSFromArrayPrimitiveNode(RubyContext context, SourceSection sourceSect
allocateObjectNode = AllocateObjectNodeGen.create(context, sourceSection, null, null);
}

@Specialization
@Specialization(guards = {"!fromutc", "!isNil(utcoffset)"})
public DynamicObject timeSFromArray(VirtualFrame frame, DynamicObject timeClass, int sec, int min, int hour, int mday, int month, int year,
int nsec, int isdst, boolean fromutc, DynamicObject utcoffset,
@Cached("new()") SnippetNode snippetNode) {

DynamicObject envZon = null;
if (!fromutc && utcoffset == nil()) {
envZon = (DynamicObject) readTimeZoneNode.execute(frame);
}

final int millis = cast(snippetNode.execute(frame, "(offset * 1000).to_i", "offset", utcoffset));

return buildTime(timeClass, sec, min, hour, mday, month, year, nsec, isdst, fromutc, utcoffset, envZon, millis);
}

@Specialization(guards = "(fromutc || !isDynamicObject(utcoffset)) || isNil(utcoffset)")
public DynamicObject timeSFromArray(VirtualFrame frame, DynamicObject timeClass, int sec, int min, int hour, int mday, int month, int year,
int nsec, int isdst, boolean fromutc, Object utcoffset) {

DynamicObject envZon = null;
if (!fromutc && utcoffset == nil()) {
envZon = (DynamicObject) readTimeZoneNode.execute(frame);
}
return buildTime(timeClass, sec, min, hour, mday, month, year, nsec, isdst, fromutc, utcoffset, envZon);
return buildTime(timeClass, sec, min, hour, mday, month, year, nsec, isdst, fromutc, utcoffset, envZon, -1);
}

@Specialization(guards = "!isInteger(sec) || !isInteger(nsec)")
@@ -277,7 +294,7 @@ public DynamicObject timeSFromArrayFallback(VirtualFrame frame, DynamicObject ti

@TruffleBoundary
private DynamicObject buildTime(DynamicObject timeClass, int sec, int min, int hour, int mday, int month, int year,
int nsec, int isdst, boolean fromutc, Object utcoffset, DynamicObject envZon) {
int nsec, int isdst, boolean fromutc, Object utcoffset, DynamicObject envZon, int millis) {
if (sec < 0 || sec > 59 ||
min < 0 || min > 59 ||
hour < 0 || hour > 23 ||
@@ -317,7 +334,6 @@ private DynamicObject buildTime(DynamicObject timeClass, int sec, int min, int h
relativeOffset = true;
zoneToStore = nil();
} else if (utcoffset instanceof DynamicObject) {
final int millis = cast(ruby("(offset * 1000).to_i", "offset", utcoffset));
zone = DateTimeZone.forOffsetMillis(millis);
relativeOffset = true;
zoneToStore = nil();
Original file line number Diff line number Diff line change
@@ -11,14 +11,22 @@

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.profiles.ConditionProfile;
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.SnippetNode;
import org.jruby.truffle.language.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.language.dispatch.DoesRespondDispatchHeadNode;
import org.jruby.truffle.language.dispatch.RespondToNode;

public class ReadUserKeywordsHashNode extends RubyNode {

private final int minArgumentCount;

@Child private DoesRespondDispatchHeadNode respondToToHashNode;
@Child private CallDispatchHeadNode callToHashNode;

private final ConditionProfile notEnoughArgumentsProfile = ConditionProfile.createBinaryProfile();
private final ConditionProfile lastArgumentIsHashProfile = ConditionProfile.createBinaryProfile();

@@ -42,8 +50,16 @@ public Object execute(VirtualFrame frame) {

CompilerDirectives.bailout("Ruby keyword arguments aren't optimized yet");

if ((boolean) ruby("last_arg.respond_to?(:to_hash)", "last_arg", lastArgument)) {
final Object converted = ruby("last_arg.to_hash", "last_arg", lastArgument);
if (respondToToHashNode == null) {
respondToToHashNode = insert(new DoesRespondDispatchHeadNode(getContext(), false));
}

if (respondToToHashNode.doesRespondTo(frame, "to_hash", lastArgument)) {
if (callToHashNode == null) {
callToHashNode = insert(CallDispatchHeadNode.createMethodCall());
}

final Object converted = callToHashNode.call(frame, lastArgument, "to_hash", null);

if (RubyGuards.isRubyHash(converted)) {
RubyArguments.setArgument(frame.getArguments(), argumentCount - 1, converted);