Skip to content

Commit

Permalink
Showing 1 changed file with 12 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
package org.jruby.truffle.nodes.rubinius;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
@@ -46,7 +47,7 @@ public RubyTime timeSNow(VirtualFrame frame, RubyClass timeClass) {
return new RubyTime(timeClass, now(readTimeZoneNode.executeRubyString(frame)), nil());
}

@CompilerDirectives.TruffleBoundary
@TruffleBoundary
private DateTime now(RubyString timeZone) {
return DateTime.now(org.jruby.RubyTime.getTimeZoneFromTZString(getContext().getRuntime(), timeZone.toString()));
}
@@ -68,7 +69,7 @@ public RubyTime timeSDup(RubyTime other) {

}

@RubiniusPrimitive(name = "time_s_specific", needsSelf = false)
@RubiniusPrimitive(name = "time_s_specific", needsSelf = false, lowerFixnumParameters = { 0, 1 })
public static abstract class TimeSSpecificPrimitiveNode extends RubiniusPrimitiveNode {

@Child private ReadTimeZoneNode readTimeZoneNode;
@@ -78,48 +79,27 @@ public TimeSSpecificPrimitiveNode(RubyContext context, SourceSection sourceSecti
readTimeZoneNode = new ReadTimeZoneNode(context, sourceSection);
}

@Specialization(guards = {"isTrue(isUTC)", "isNil(offset)"})
public RubyTime timeSSpecificUTC(long seconds, long nanoseconds, boolean isUTC, Object offset) {
return timeSSpecificUTC((int) seconds, (int) nanoseconds, isUTC, offset);
}

@Specialization(guards = {"isTrue(isUTC)", "isNil(offset)"})
public RubyTime timeSSpecificUTC(long seconds, int nanoseconds, boolean isUTC, Object offset) {
return timeSSpecificUTC((int) seconds, nanoseconds, isUTC, offset);
}

@Specialization(guards = {"isTrue(isUTC)", "isNil(offset)"})
@Specialization(guards = { "isTrue(isUTC)", "isNil(offset)" })
public RubyTime timeSSpecificUTC(int seconds, int nanoseconds, boolean isUTC, Object offset) {
// TODO(CS): overflow checks needed?
final long milliseconds = seconds * 1_000L + (nanoseconds / 1_000_000);
return new RubyTime(getContext().getCoreLibrary().getTimeClass(), time(milliseconds), nil());
}


@Specialization(guards = {"!isTrue(isUTC)", "isNil(offset)"})
public RubyTime timeSSpecific(VirtualFrame frame, long seconds, long nanoseconds, boolean isUTC, Object offset) {
return timeSSpecific(frame, (int) seconds, (int) nanoseconds, isUTC, offset);
}

@Specialization(guards = {"!isTrue(isUTC)", "isNil(offset)"})
public RubyTime timeSSpecific(VirtualFrame frame, long seconds, int nanoseconds, boolean isUTC, Object offset) {
return timeSSpecific(frame, (int) seconds, nanoseconds, isUTC, offset);
}

@Specialization(guards = {"!isTrue(isUTC)", "isNil(offset)"})
@Specialization(guards = { "!isTrue(isUTC)", "isNil(offset)" })
public RubyTime timeSSpecific(VirtualFrame frame, int seconds, int nanoseconds, boolean isUTC, Object offset) {
// TODO(CS): overflow checks needed?
final long milliseconds = (long) seconds * 1_000 + ((long) nanoseconds / 1_000_000);
return new RubyTime(getContext().getCoreLibrary().getTimeClass(), time(milliseconds, readTimeZoneNode.executeRubyString(frame)), offset);
return new RubyTime(getContext().getCoreLibrary().getTimeClass(), localtime(milliseconds, readTimeZoneNode.executeRubyString(frame)), offset);
}

@CompilerDirectives.TruffleBoundary
public DateTime time(long milliseconds) {
@TruffleBoundary
private DateTime time(long milliseconds) {
return new DateTime(milliseconds, DateTimeZone.UTC);
}

@CompilerDirectives.TruffleBoundary
private DateTime time(long milliseconds, RubyString timeZone) {
@TruffleBoundary
private DateTime localtime(long milliseconds, RubyString timeZone) {
return new DateTime(milliseconds, org.jruby.RubyTime.getTimeZoneFromTZString(getContext().getRuntime(), timeZone.toString()));
}

@@ -160,7 +140,7 @@ public TimeDecomposePrimitiveNode(RubyContext context, SourceSection sourceSecti
super(context, sourceSection);
}

@CompilerDirectives.TruffleBoundary
@TruffleBoundary
@Specialization
public RubyArray timeDecompose(RubyTime time) {
final DateTime dateTime = time.getDateTime();
@@ -203,7 +183,7 @@ public TimeStrftimePrimitiveNode(RubyContext context, SourceSection sourceSectio
super(context, sourceSection);
}

@CompilerDirectives.TruffleBoundary
@TruffleBoundary
@Specialization
public RubyString timeStrftime(RubyTime time, RubyString format) {
final RubyDateFormatter rdf = getContext().getRuntime().getCurrentContext().getRubyDateFormatter();

4 comments on commit 6c85c32

@bjfish
Copy link
Contributor

@bjfish bjfish commented on 6c85c32 May 26, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a small regression in jt test mri ruby/test_time.rb

  1) Error:
TestTime#test_big_minus:
TypeError: Truffle doesn't have a case for the org.jruby.truffle.nodes.rubinius.TimePrimitiveNodesFactory$TimeSSpecificPrimitiveNodeFactory$TimeSSpecificPrimitiveNodeGen node with values of type  java.lang.Long=1152921504606846976 java.lang.Integer=0 java.lang.Boolean=false NilClass(org.jruby.truffle.runtime.core.RubyBasicObject)
    core:/core/rubinius/bootstrap/time.rb:38:in `specific': Truffle doesn't have a case for the org.jruby.truffle.nodes.rubinius.TimePrimitiveNodesFactory$TimeSSpecificPrimitiveNodeFactory$TimeSSpecificPrimitiveNodeGen node with values of type  java.lang.Long=1152921504606846976 java.lang.Integer=0 java.lang.Boolean=false NilClass(org.jruby.truffle.runtime.core.RubyBasicObject) (TypeError)
        from core:/core/rubinius/common/time.rb:40:in `at'
        from /Users/brandonfish/Documents/jruby/test/mri/ruby/test_time.rb:139:in `test_big_minus'
        from /Users/brandonfish/Documents/jruby/test/mri/lib/test/unit.rb:888:in `run_test'

@eregon
Copy link
Member Author

@eregon eregon commented on 6c85c32 May 27, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems we should never have passed that test since the date is outside Joda-Time range.
I will fix and tag.

@eregon
Copy link
Member Author

@eregon eregon commented on 6c85c32 May 27, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6c0982f, seems we pass the test as we "correctly" raise a RangeError now.

@eregon
Copy link
Member Author

@eregon eregon commented on 6c85c32 May 27, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for watching as always 😄

Please sign in to comment.