Ejemplo n.º 1
0
 @JRubyMethod(
     name = {"create_invoker", "createInvoker"},
     required = 5)
 public IRubyObject createInvoker(ThreadContext context, IRubyObject[] args) {
   RubyArray paramTypes = (RubyArray) args[3];
   NativeParam[] nativeParamTypes = new NativeParam[paramTypes.size()];
   for (int i = 0; i < paramTypes.size(); ++i) {
     IRubyObject obj = (IRubyObject) paramTypes.entry(i);
     if (obj instanceof NativeParam) {
       nativeParamTypes[i] = (NativeParam) obj;
     } else if (obj instanceof RubyInteger) {
       nativeParamTypes[i] = NativeType.valueOf(Util.int32Value(obj));
     } else {
       context.getRuntime().newArgumentError("Invalid parameter type");
     }
   }
   try {
     return createInvoker(
         context.getRuntime(),
         args[0].isNil() ? null : args[0].toString(),
         args[1].toString(),
         NativeType.valueOf(Util.int32Value(args[2])),
         nativeParamTypes,
         args[4].toString());
   } catch (UnsatisfiedLinkError ex) {
     return context.getRuntime().getNil();
   }
 }
Ejemplo n.º 2
0
  @Override
  public Label interpret(InterpreterContext interp) {
    // ENEBO: Can I assume since IR figured this is an internal array it will be RubyArray like
    // this?
    RubyArray array = (RubyArray) getArg().retrieve(interp);

    getResult().store(interp, array.entry(index));
    return null;
  }
  @Override
  public long[] toNative(IRubyObject value, ToNativeContext context) {
    RubyArray rbArray = value.convertToArray();
    long[] arr = new long[rbArray.getLength()];

    if (ArrayFlags.isIn(arrayFlags)) {
      for (int i = 0; i < arr.length; i++) {
        arr[i] = Util.longValue(rbArray.entry(i));
      }
    }

    return arr;
  }
Ejemplo n.º 4
0
    public void put(
        ThreadContext context,
        StructLayout.Storage cache,
        Member m,
        IRubyObject ptr,
        IRubyObject value) {

      if (isCharArray() && value instanceof RubyString) {
        ByteList bl = value.convertToString().getByteList();
        m.getMemoryIO(ptr)
            .putZeroTerminatedByteArray(
                m.offset,
                bl.getUnsafeBytes(),
                bl.begin(),
                Math.min(bl.length(), arrayType.length() - 1));

      } else if (false) {
        RubyArray ary = value.convertToArray();
        int count = ary.size();
        if (count > arrayType.length()) {
          throw context.getRuntime().newIndexError("array too big");
        }
        AbstractMemory memory = (AbstractMemory) ptr;

        // Clear any elements that will not be filled by the array
        if (count < arrayType.length()) {
          memory
              .getMemoryIO()
              .setMemory(
                  m.offset + (count * arrayType.getComponentType().getNativeSize()),
                  (arrayType.length() - count) * arrayType.getComponentType().getNativeSize(),
                  (byte) 0);
        }

        for (int i = 0; i < count; ++i) {
          op.put(
              context.getRuntime(),
              memory,
              m.offset + (i * arrayType.getComponentType().getNativeSize()),
              ary.entry(i));
        }
      } else {
        throw context.getRuntime().newNotImplementedError("cannot set array field");
      }
    }
Ejemplo n.º 5
0
 @SuppressWarnings("deprecation")
 private static Object rubyToJacob(IRubyObject value) {
   // NOTE: JavaUtil.convertRubyToJava can return null
   // NOTE: JavaUtil.convertRubyToJava does not support arrays
   if (value instanceof WIN32OLE) return ((WIN32OLE) value).getDispatch();
   else if (value instanceof RubyArray) {
     RubyArray rbAry = (RubyArray) value;
     IRubyObject[] ary = new IRubyObject[rbAry.size()];
     for (int i = 0; i < rbAry.size(); i++) {
       ary[i] = (IRubyObject) rbAry.entry(i);
     }
     return rubyToJacob(ary);
   } else if (value instanceof RubyHash) {
     IRubyObject[] ary = new IRubyObject[((RubyHash) value).size()];
     RubyHash hash = (RubyHash) value;
     int i = 0;
     for (Object o : hash.directValues()) {
       ary[i++] = (IRubyObject) o;
     }
     return rubyToJacob(ary);
   }
   return JavaUtil.convertRubyToJava(value);
 }