Пример #1
0
    @ExplodeLoop
    @Override
    public RubyArray executeArray(VirtualFrame frame) {
      CompilerDirectives.transferToInterpreter();

      final Object[] executedValues = new Object[values.length];

      for (int n = 0; n < values.length; n++) {
        executedValues[n] = values[n].execute(frame);
      }

      final RubyArray array =
          RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(), executedValues);
      final Object store = array.getStore();

      if (store == null) {
        replace(new EmptyArrayLiteralNode(getContext(), getSourceSection(), values));
      }
      if (store instanceof int[]) {
        replace(new IntegerFixnumArrayLiteralNode(getContext(), getSourceSection(), values));
      } else if (store instanceof long[]) {
        replace(new LongFixnumArrayLiteralNode(getContext(), getSourceSection(), values));
      } else if (store instanceof double[]) {
        replace(new FloatArrayLiteralNode(getContext(), getSourceSection(), values));
      } else {
        replace(new ObjectArrayLiteralNode(getContext(), getSourceSection(), values));
      }

      return array;
    }
Пример #2
0
  protected RubyArray makeGeneric(VirtualFrame frame, Object[] alreadyExecuted) {
    CompilerAsserts.neverPartOfCompilation();

    replace(new ObjectArrayLiteralNode(getContext(), getSourceSection(), values));

    final Object[] executedValues = new Object[values.length];

    for (int n = 0; n < values.length; n++) {
      if (n < alreadyExecuted.length) {
        executedValues[n] = alreadyExecuted[n];
      } else {
        executedValues[n] = values[n].execute(frame);
      }
    }

    return RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(), executedValues);
  }