예제 #1
0
    @Specialization(guards = "isRubyBignum(b)")
    public DynamicObject coerce(DynamicObject a, DynamicObject b) {
      CompilerDirectives.transferToInterpreter();

      Object[] store = new Object[] {b, a};
      return Layouts.ARRAY.createArray(
          getContext().getCoreLibrary().getArrayFactory(), store, store.length);
    }
예제 #2
0
    @Specialization
    public DynamicObject coerce(DynamicObject a, long b) {
      CompilerDirectives.transferToInterpreter();

      // TODO (eregon, 16 Feb. 2015): This is NOT spec, but let's try to see if we can make it work.
      // b is converted to a Bignum here in other implementations.
      Object[] store = new Object[] {b, a};
      return Layouts.ARRAY.createArray(
          getContext().getCoreLibrary().getArrayFactory(), store, store.length);
    }
예제 #3
0
 public static boolean isArrayShape(Shape shape) {
   return Layouts.ARRAY.isArray(shape.getObjectType());
 }
예제 #4
0
  private DynamicObject translate(UnsupportedSpecializationException exception) {
    if (getContext().getOptions().EXCEPTIONS_PRINT_JAVA) {
      exception.printStackTrace();
    }

    final StringBuilder builder = new StringBuilder();
    builder.append("Truffle doesn't have a case for the ");
    builder.append(exception.getNode().getClass().getName());
    builder.append(" node with values of type ");

    for (Object value : exception.getSuppliedValues()) {
      builder.append(" ");

      if (value == null) {
        builder.append("null");
      } else if (value instanceof DynamicObject) {
        builder.append(
            Layouts.MODULE
                .getFields(Layouts.BASIC_OBJECT.getLogicalClass(((DynamicObject) value)))
                .getName());
        builder.append("(");
        builder.append(value.getClass().getName());
        builder.append(")");

        if (RubyGuards.isRubyArray(value)) {
          final DynamicObject array = (DynamicObject) value;
          builder.append("[");

          if (Layouts.ARRAY.getStore(array) == null) {
            builder.append("null");
          } else {
            builder.append(Layouts.ARRAY.getStore(array).getClass().getName());
          }

          builder.append(",");
          builder.append(Layouts.ARRAY.getSize(array));
          builder.append("]");
        } else if (RubyGuards.isRubyHash(value)) {
          final Object store = Layouts.HASH.getStore((DynamicObject) value);

          if (store == null) {
            builder.append("[null]");
          } else {
            builder.append("[");
            builder.append(store.getClass().getName());
            builder.append("]");
          }
        }
      } else {
        builder.append(value.getClass().getName());
      }

      if (value instanceof Number || value instanceof Boolean) {
        builder.append("=");
        builder.append(value.toString());
      }
    }

    switch (unsupportedOperationBehavior) {
      case TYPE_ERROR:
        return getContext().getCoreLibrary().typeError(builder.toString(), this);
      case ARGUMENT_ERROR:
        return getContext().getCoreLibrary().argumentError(builder.toString(), this);
      default:
        throw new UnsupportedOperationException();
    }
  }