@Specialization public boolean equal(RubyRange.IntegerFixnumRange a, RubyRange.IntegerFixnumRange b) { notDesignedForCompilation(); return a.doesExcludeEnd() == b.doesExcludeEnd() && a.getBegin() == b.getBegin() && a.getEnd() == b.getEnd(); }
@Specialization public RubyString toS(RubyRange.IntegerFixnumRange range) { notDesignedForCompilation(); return getContext() .makeString(range.getBegin() + (range.doesExcludeEnd() ? "..." : "..") + range.getEnd()); }
@Specialization public Object step( VirtualFrame frame, RubyRange.IntegerFixnumRange range, int step, RubyProc block) { int count = 0; try { outer: for (int n = range.getBegin(); n < range.getExclusiveEnd(); n += step) { while (true) { if (CompilerDirectives.inInterpreter()) { count++; } try { yield(frame, block, n); continue outer; } catch (BreakException e) { breakProfile.enter(); return e.getResult(); } catch (NextException e) { nextProfile.enter(); continue outer; } catch (RedoException e) { redoProfile.enter(); } } } } finally { if (CompilerDirectives.inInterpreter()) { getRootNode().reportLoopCount(count); } } return range; }
@Specialization public RubyArray collect( VirtualFrame frame, RubyRange.IntegerFixnumRange range, RubyProc block) { final int begin = range.getBegin(); final int exclusiveEnd = range.getExclusiveEnd(); final int length = exclusiveEnd - begin; Object store = arrayBuilder.start(length); int count = 0; try { for (int n = 0; n < length; n++) { if (CompilerDirectives.inInterpreter()) { count++; } store = arrayBuilder.append(store, n, yield(frame, block, n)); } } finally { if (CompilerDirectives.inInterpreter()) { getRootNode().reportLoopCount(count); } } return new RubyArray( getContext().getCoreLibrary().getArrayClass(), arrayBuilder.finish(store, length), length); }
@Specialization public RubyArray toA(RubyRange.IntegerFixnumRange range) { final int begin = range.getBegin(); final int length = range.getExclusiveEnd() - begin; if (length < 0) { return new RubyArray(getContext().getCoreLibrary().getArrayClass()); } else { final int[] values = new int[length]; for (int n = 0; n < length; n++) { values[n] = begin + n; } return new RubyArray(getContext().getCoreLibrary().getArrayClass(), values, length); } }
@Specialization public boolean include(RubyRange.IntegerFixnumRange range, int value) { return value >= range.getBegin() && value < range.getExclusiveEnd(); }
@Specialization public int each(RubyRange.IntegerFixnumRange range) { return range.getBegin(); }