Class: Module
- Inherits:
-
Object
- Object
- Module
- Defined in:
- (unknown)
Instance Method Summary collapse
-
#define_jit_method(name, function) ⇒ Object
Use a Function to define an instance method on a module.
Instance Method Details
#define_jit_method(name, function) ⇒ Object
Use a Function to define an instance method on a module. The function should have one of two signatures:
-
The first parameter to the function should be an OBJECT that represents the self parameter and the rest of the parameters, or
-
The function’s signature should be Type::RUBY_VARARG_SIGNATURE.
1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 |
# File 'ext/jit_ext.c', line 1413
static VALUE module_define_jit_method(VALUE klass, VALUE name_v, VALUE function_v)
{
char const * name;
jit_function_t function;
jit_type_t signature;
int signature_tag;
int arity;
VALUE closure_v;
struct Closure * closure;
if(SYMBOL_P(name_v))
{
name = rb_id2name(SYM2ID(name_v));
}
else
{
name = STR2CSTR(name_v);
}
Data_Get_Struct(function_v, struct _jit_function, function);
signature = jit_function_get_signature(function);
signature_tag = (int)jit_function_get_meta(function, RJT_TAG_FOR_SIGNATURE);
if(signature_tag == JIT_TYPE_FIRST_TAGGED + RJT_RUBY_VARARG_SIGNATURE)
{
arity = -1;
}
else
{
/* TODO: check the types to make sure they are OBJECT */
arity = jit_type_num_params(signature) - 1;
}
closure_v = function_to_closure(function_v);
Data_Get_Struct(closure_v, struct Closure, closure);
define_method_with_data(
klass, rb_intern(name), RUBY_METHOD_FUNC(closure->function_ptr),
arity, closure_v);
return Qnil;
}
|