|
13 | 13 | import com.oracle.truffle.api.dsl.Specialization; |
14 | 14 | import com.oracle.truffle.api.frame.VirtualFrame; |
15 | 15 | import com.oracle.truffle.api.source.SourceSection; |
| 16 | + |
16 | 17 | import org.joda.time.DateTime; |
17 | 18 | import org.joda.time.DateTimeZone; |
18 | 19 | import org.jruby.truffle.nodes.time.ReadTimeZoneNode; |
@@ -212,42 +213,29 @@ public RubyString timeStrftime(RubyTime time, RubyString format) { |
212 | 213 |
|
213 | 214 | } |
214 | 215 |
|
215 | | - @RubiniusPrimitive(name = "time_s_from_array", needsSelf = true) |
| 216 | + @RubiniusPrimitive(name = "time_s_from_array", needsSelf = true, lowerFixnumParameters = { 0 /*sec*/, 6 /*nsec*/, 7 /*isdst*/}) |
216 | 217 | public static abstract class TimeSFromArrayPrimitiveNode extends RubiniusPrimitiveNode { |
217 | 218 |
|
218 | 219 | public TimeSFromArrayPrimitiveNode(RubyContext context, SourceSection sourceSection) { |
219 | 220 | super(context, sourceSection); |
220 | 221 | } |
221 | 222 |
|
222 | | - @Specialization(guards = {"isNil(sec)", "isNil(nsec)"}) |
223 | | - public RubyTime timeSFromArray(VirtualFrame frame, RubyClass timeClass, Object sec, int min, int hour, int mday, int month, int year, |
224 | | - Object nsec, int isdst, boolean fromutc, Object utcoffset) { |
225 | | - return timeSFromArray(frame, timeClass, 0, min, hour, mday, month, year, nsec, isdst, fromutc, utcoffset); |
| 223 | + @Specialization |
| 224 | + public RubyTime timeSFromArray(VirtualFrame frame, RubyClass timeClass, int sec, int min, int hour, int mday, int month, int year, |
| 225 | + int nsec, int isdst, boolean fromutc, Object utcoffset) { |
| 226 | + return buildTime(frame, timeClass, sec, min, hour, mday, month, year, nsec, isdst, fromutc, utcoffset); |
226 | 227 | } |
227 | 228 |
|
228 | | - @Specialization(guards = "isNil(nsec)") |
229 | | - public RubyTime timeSFromArray(VirtualFrame frame, RubyClass timeClass, int sec, int min, int hour, int mday, int month, int year, |
| 229 | + @Specialization(guards = "!isInteger(sec) || !isInteger(nsec)") |
| 230 | + public RubyTime timeSFromArrayFallback(VirtualFrame frame, RubyClass timeClass, Object sec, int min, int hour, int mday, int month, int year, |
230 | 231 | Object nsec, int isdst, boolean fromutc, Object utcoffset) { |
231 | | - return buildTime(frame, timeClass, sec, min, hour, mday, month, year, 0, isdst, fromutc, utcoffset); |
| 232 | + return null; // Primitive failure |
232 | 233 | } |
233 | 234 |
|
234 | | - @Specialization |
235 | | - public RubyTime timeSFromArray(VirtualFrame frame, RubyClass timeClass, long sec, int min, int hour, int mday, int month, int year, |
| 235 | + private RubyTime buildTime(VirtualFrame frame, RubyClass timeClass, int sec, int min, int hour, int mday, int month, int year, |
236 | 236 | int nsec, int isdst, boolean fromutc, Object utcoffset) { |
237 | | - // TODO CS 15-Feb-15 that cast |
238 | | - return buildTime(frame, timeClass, (int) sec, min, hour, mday, month, year, nsec, isdst, fromutc, utcoffset); |
239 | | - } |
| 237 | + CompilerDirectives.transferToInterpreter(); |
240 | 238 |
|
241 | | - @Specialization |
242 | | - public RubyTime timeSFromArray(VirtualFrame frame, RubyClass timeClass, int sec, int min, int hour, int mday, int month, int year, |
243 | | - long nsec, int isdst, boolean fromutc, Object utcoffset) { |
244 | | - // TODO CS 15-Feb-15 that cast |
245 | | - return buildTime(frame, timeClass, sec, min, hour, mday, month, year, (int) nsec, isdst, fromutc, utcoffset); |
246 | | - } |
247 | | - |
248 | | - @Specialization |
249 | | - public RubyTime buildTime(VirtualFrame frame, RubyClass timeClass, int sec, int min, int hour, int mday, int month, int year, |
250 | | - int nsec, int isdst, boolean fromutc, Object utcoffset) { |
251 | 239 | if (sec < 0 || sec > 59 || |
252 | 240 | min < 0 || min > 59 || |
253 | 241 | hour < 0 || hour > 23 || |
@@ -281,40 +269,7 @@ public RubyTime buildTime(VirtualFrame frame, RubyClass timeClass, int sec, int |
281 | 269 | } |
282 | 270 | } |
283 | 271 |
|
284 | | - @Specialization(guards = "isNil(nsec)") |
285 | | - public RubyTime timeSFromArray(RubyClass timeClass, RubyBasicObject sec, int min, int hour, int mday, int month, int year, |
286 | | - Object nsec, int isdst, boolean fromutc, Object utcoffset) { |
287 | | - return null; |
288 | | - } |
289 | | - |
290 | | - @Specialization |
291 | | - public RubyTime timeSFromArray(VirtualFrame frame, RubyClass timeClass, double sec, int min, int hour, int mday, int month, int year, |
292 | | - long nsec, int isdst, boolean fromutc, Object utcoffset) { |
293 | | - return timeSFromArray(frame, timeClass, sec, min, hour, mday, month, year, (int) nsec, isdst, fromutc, utcoffset); |
294 | | - } |
295 | | - |
296 | | - @Specialization |
297 | | - public RubyTime timeSFromArray(VirtualFrame frame, RubyClass timeClass, double sec, int min, int hour, int mday, int month, int year, |
298 | | - int nsec, long isdst, boolean fromutc, Object utcoffset) { |
299 | | - return timeSFromArray(frame, timeClass, sec, min, hour, mday, month, year, nsec, (int) isdst, fromutc, utcoffset); |
300 | | - } |
301 | | - |
302 | | - @Specialization(guards = "isNil(nsec)") |
303 | | - public RubyTime timeSFromArray(VirtualFrame frame, RubyClass timeClass, double sec, int min, int hour, int mday, int month, int year, |
304 | | - Object nsec, int isdst, boolean fromutc, Object utcoffset) { |
305 | | - final int secondsWhole = (int) sec; |
306 | | - final int nanosecondsFractional = (int) ((sec * 1_000_000_000) - (secondsWhole * 1_000_000_000)); |
307 | | - return buildTime(frame, timeClass, secondsWhole, min, hour, mday, month, year, nanosecondsFractional, isdst, fromutc, utcoffset); |
308 | | - } |
309 | | - |
310 | | - @Specialization |
311 | | - public RubyTime timeSFromArray(VirtualFrame frame, RubyClass timeClass, double sec, int min, int hour, int mday, int month, int year, |
312 | | - int nsec, int isdst, boolean fromutc, Object utcoffset) { |
313 | | - final int secondsWhole = (int) sec; |
314 | | - return buildTime(frame, timeClass, secondsWhole, min, hour, mday, month, year, nsec, isdst, fromutc, utcoffset); |
315 | | - } |
316 | | - |
317 | | - private int cast(Object value) { |
| 272 | + private static int cast(Object value) { |
318 | 273 | if (value instanceof Integer) { |
319 | 274 | return (int) value; |
320 | 275 | } else if (value instanceof Long) { |
|
0 commit comments