示例#1
0
    @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;
    }
示例#2
0
    @Specialization
    public RubyString toS(RubyRange.IntegerFixnumRange range) {
      notDesignedForCompilation();

      return getContext()
          .makeString(range.getBegin() + (range.doesExcludeEnd() ? "..." : "..") + range.getEnd());
    }
示例#3
0
    @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);
    }
示例#4
0
    @Specialization
    public boolean equal(RubyRange.LongFixnumRange a, RubyRange.IntegerFixnumRange b) {
      notDesignedForCompilation();

      return a.doesExcludeEnd() == b.doesExcludeEnd()
          && a.getBegin() == b.getBegin()
          && a.getEnd() == b.getEnd();
    }
示例#5
0
    @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);
      }
    }
示例#6
0
 @Specialization
 public int last(RubyRange.IntegerFixnumRange range) {
   return range.getEnd();
 }
示例#7
0
 @Specialization
 public boolean include(RubyRange.IntegerFixnumRange range, int value) {
   return value >= range.getBegin() && value < range.getExclusiveEnd();
 }
示例#8
0
 @Specialization
 public int each(RubyRange.IntegerFixnumRange range) {
   return range.getBegin();
 }