Example #1
0
 public IRubyObject get(
     ThreadContext context, StructLayout.Storage cache, Member m, IRubyObject ptr) {
   // Read an int from the native memory, then upcall to the ruby value
   // lookup code to convert it to the appropriate symbol
   return m.type.callMethod(
       context, "find", op.get(context.getRuntime(), m.getMemoryIO(ptr), m.offset));
 }
Example #2
0
 public void put(
     ThreadContext context,
     StructLayout.Storage cache,
     Member m,
     IRubyObject ptr,
     IRubyObject value) {
   op.put(context.getRuntime(), m.getMemoryIO(ptr), m.offset, value);
 }
Example #3
0
    public ArrayFieldIO(Type.Array arrayType) {
      this.arrayType = arrayType;
      this.op = MemoryOp.getMemoryOp(arrayType.getComponentType());

      if (op == null) {
        throw arrayType
            .getRuntime()
            .newNotImplementedError("unsupported array field type: " + arrayType);
      }
    }
Example #4
0
 public void put(
     ThreadContext context,
     StructLayout.Storage cache,
     Member m,
     IRubyObject ptr,
     IRubyObject value) {
   // Upcall to ruby to convert :foo to an int, then write it out
   op.put(
       context.getRuntime(),
       m.getMemoryIO(ptr),
       m.offset,
       m.type.callMethod(context, "find", value));
 }
Example #5
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");
      }
    }
Example #6
0
 private IRubyObject get(Ruby runtime, int index) {
   return aio.get(runtime, ptr, getOffset(index));
 }
Example #7
0
 public EnumFieldIO(ByteOrder order) {
   this.op = MemoryOp.getMemoryOp(NativeType.INT, order);
 }
Example #8
0
 public IRubyObject get(
     ThreadContext context, StructLayout.Storage cache, Member m, IRubyObject ptr) {
   return op.get(context.getRuntime(), m.getMemoryIO(ptr), m.offset);
 }
Example #9
0
 NumberFieldIO(Type type, ByteOrder order) {
   this.op = MemoryOp.getMemoryOp(type, order);
 }
Example #10
0
 @JRubyMethod(name = "[]=")
 public IRubyObject put(ThreadContext context, IRubyObject index, IRubyObject value) {
   aio.put(context.getRuntime(), ptr, getOffset(index), value);
   return value;
 }
Example #11
0
 @JRubyMethod(name = "[]")
 public IRubyObject get(ThreadContext context, IRubyObject index) {
   return aio.get(context.getRuntime(), ptr, getOffset(index));
 }