case UINT64: if (!isRubyNum(value)) { throw runtime.newTypeError("Expected number type for integral field."); case FLOAT: if (!isRubyNum(value)) throw runtime.newTypeError("Expected number type for float field."); break; case DOUBLE: if (!isRubyNum(value)) throw runtime.newTypeError("Expected number type for double field."); break; case BOOL: break; case MESSAGE: if (value.getMetaClass() != typeClass) { throw runtime.newTypeError(value, typeClass);
private static void checkArrayType(Ruby runtime, IRubyObject obj) { if (!(obj instanceof RubyArray)) { throw runtime.newTypeError("wrong argument type " + obj.getMetaClass().getName() + " (expected Array)"); } }
protected final IRubyObject callMethodMissing(ThreadContext context, IRubyObject self, RubyClass selfType, DynamicMethod method, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) { return Helpers.selectMethodMissing(context, selfType, method.getVisibility(), methodName, callType).call(context, self, self.getMetaClass(), methodName, arg0, arg1, arg2, block); }
@JRubyMethod(name = "new", meta = true) public static final IRubyObject newStructByReference(ThreadContext context, IRubyObject klass, IRubyObject structClass) { if (!(structClass instanceof RubyClass)) { throw context.runtime.newTypeError("wrong argument type " + structClass.getMetaClass().getName() + " (expected Class)"); } if (!((RubyClass) structClass).isKindOfModule(context.runtime.getFFI().structClass)) { throw context.runtime.newTypeError("wrong argument type " + structClass.getMetaClass().getName() + " (expected subclass of FFI::Struct)"); } return new StructByReference(context.runtime, (RubyClass) klass, (RubyClass) structClass, null); }
@JRubyMethod(meta = true, name = "set_meta_class") public static IRubyObject set_meta_class(ThreadContext context, IRubyObject recv, IRubyObject obj, IRubyObject klass) { if (!(klass instanceof RubyClass)) { klass = klass.getMetaClass(); } ((RubyObject) obj).setMetaClass((RubyClass) klass); return context.nil; }
public static IRubyObject invokeSuper(ThreadContext context, IRubyObject self, RubyModule klass, String name, IRubyObject[] args, Block block) { checkSuperDisabledOrOutOfMethod(context, klass, name); RubyClass superClass = findImplementerIfNecessary(self.getMetaClass(), klass).getSuperClass(); DynamicMethod method = superClass != null ? superClass.searchMethod(name) : UndefinedMethod.INSTANCE; if (method.isUndefined()) { return callMethodMissing(context, self, method.getVisibility(), name, CallType.SUPER, args, block); } return method.call(context, self, superClass, name, args, block); }
public static MemoryIO convertToPointerMemoryIO(ThreadContext context, IRubyObject parameter, CachingCallSite callSite) { DynamicMethod method = getConversionMethod(parameter, callSite); IRubyObject ptr = method.call(context, parameter, parameter.getMetaClass(), callSite.getMethodName(), Block.NULL_BLOCK); if (ptr instanceof AbstractMemory) { return ((AbstractMemory) ptr).getMemoryIO(); } throw parameter.getRuntime().newTypeError(parameter.getMetaClass() + "#" + callSite.getMethodName() + " should return " + context.runtime.getFFI().pointerClass); }
/** nucomp_coerce * */ @JRubyMethod(name = "coerce") public IRubyObject coerce(ThreadContext context, IRubyObject other) { if (other instanceof RubyNumeric && f_real_p(context, other)) { return context.runtime.newArray(newComplexBang(context, getMetaClass(), (RubyNumeric) other), this); } if (other instanceof RubyComplex) return context.runtime.newArray(other, this); Ruby runtime = context.runtime; throw runtime.newTypeError(str(runtime, types(runtime, other.getMetaClass()), " can't be coerced into ", types(runtime, getMetaClass()))); }
@JRubyMethod(name = "to_s") @Override public IRubyObject to_s() { if (message.isNil()) return getRuntime().newString(message.getMetaClass().getName()); RubyString str = message.convertToString(); if (str != message) message = str; if (isTaint()) message.setTaint(true); return message; }
public static IRubyObject invokedynamic(ThreadContext context, IRubyObject self, MethodNames method, IRubyObject arg0) { RubyClass metaclass = self.getMetaClass(); String name = method.realName(); return getMethodCached(context, metaclass, method.ordinal(), name).call(context, self, metaclass, name, arg0); }
private static String formatReceiver(final IRubyObject object) { if ( object instanceof RubyModule ) { return ((RubyModule) object).getName(); } return object.getMetaClass().getRealClass().getName(); }
private LexerSource source(ThreadContext context, IRubyObject src, String filename, int lineno) { // FIXME: respond_to? returns private methods DynamicMethod method = src.getMetaClass().searchMethod("gets"); if (method.isUndefined() || method.getVisibility() == Visibility.PRIVATE) { return new ByteListLexerSource(filename, lineno, src.convertToString().getByteList(), null); } return new GetsLexerSource(filename, lineno, src, null); }
@JRubyMethod(name = "new", meta = true) public static final IRubyObject newStructByReference(ThreadContext context, IRubyObject klass, IRubyObject structClass) { if (!(structClass instanceof RubyClass)) { throw context.runtime.newTypeError("wrong argument type " + structClass.getMetaClass().getName() + " (expected Class)"); } if (!((RubyClass) structClass).isKindOfModule(context.runtime.getFFI().structClass)) { throw context.runtime.newTypeError("wrong argument type " + structClass.getMetaClass().getName() + " (expected subclass of FFI::Struct)"); } return new StructByReference(context.runtime, (RubyClass) klass, (RubyClass) structClass, null); }
public static IRubyObject callMethodMissing(CacheEntry entry, CallType callType, ThreadContext context, IRubyObject self, String name, IRubyObject[] args, Block block) { return Helpers.selectMethodMissing(context, self, entry.method.getVisibility(), name, callType).call(context, self, self.getMetaClass(), name, args, block); }
private static void checkArrayType(Ruby runtime, IRubyObject obj) { if (!(obj instanceof RubyArray)) { throw runtime.newTypeError("wrong argument type " + obj.getMetaClass().getName() + " (expected Array)"); } }
@JRubyMethod(name = "eql?", required = 1) public IRubyObject eql_p(ThreadContext context, IRubyObject other) { if (this == other) return context.tru; if (!(other instanceof RubyStruct)) return context.fals; if (getMetaClass() != other.getMetaClass()) { return context.fals; } if (other == this) return context.tru; // recursion guard return context.safeRecurse(EqlRecursive.INSTANCE, other, this, "eql?", true); }
public static IRubyObject invokeSuper(ThreadContext context, IRubyObject self, RubyModule klass, String name, IRubyObject[] args, Block block) { checkSuperDisabledOrOutOfMethod(context, klass, name); RubyClass superClass = findImplementerIfNecessary(self.getMetaClass(), klass).getSuperClass(); DynamicMethod method = superClass != null ? superClass.searchMethod(name) : UndefinedMethod.INSTANCE; if (method.isUndefined()) { return callMethodMissing(context, self, method.getVisibility(), name, CallType.SUPER, args, block); } return method.call(context, self, superClass, name, args, block); }
public static MemoryIO convertToPointerMemoryIO(ThreadContext context, IRubyObject parameter, CachingCallSite callSite) { DynamicMethod method = getConversionMethod(parameter, callSite); IRubyObject ptr = method.call(context, parameter, parameter.getMetaClass(), callSite.getMethodName(), Block.NULL_BLOCK); if (ptr instanceof AbstractMemory) { return ((AbstractMemory) ptr).getMemoryIO(); } throw parameter.getRuntime().newTypeError(parameter.getMetaClass() + "#" + callSite.getMethodName() + " should return " + context.runtime.getFFI().pointerClass); }
/** nucomp_coerce * */ @JRubyMethod(name = "coerce") public IRubyObject coerce(ThreadContext context, IRubyObject other) { if (other instanceof RubyNumeric && f_real_p(context, other)) { return context.runtime.newArray(newComplexBang(context, getMetaClass(), (RubyNumeric) other), this); } if (other instanceof RubyComplex) return context.runtime.newArray(other, this); Ruby runtime = context.runtime; throw runtime.newTypeError(str(runtime, types(runtime, other.getMetaClass()), " can't be coerced into ", types(runtime, getMetaClass()))); }
case UINT64: if (!Utils.isRubyNum(value)) { throw runtime.newTypeError("Expected number type for integral field."); case FLOAT: if (!Utils.isRubyNum(value)) throw runtime.newTypeError("Expected number type for float field."); val = (float) RubyNumeric.num2dbl(value); break; case DOUBLE: if (!Utils.isRubyNum(value)) throw runtime.newTypeError("Expected number type for double field."); val = RubyNumeric.num2dbl(value); break; case MESSAGE: RubyClass typeClass = (RubyClass) ((RubyDescriptor) getDescriptorForField(context, fieldDescriptor)).msgclass(context); if (!value.getMetaClass().equals(typeClass)) throw runtime.newTypeError(value, "Invalid type to assign to submessage field."); val = ((RubyMessage) value).build(context, depth + 1);