12#include "eval_intern.h"
14#include "internal/class.h"
15#include "internal/error.h"
16#include "internal/eval.h"
17#include "internal/gc.h"
18#include "internal/object.h"
19#include "internal/proc.h"
20#include "internal/symbol.h"
46static int method_arity(
VALUE);
47static int method_min_max_arity(
VALUE,
int *max);
52#define IS_METHOD_PROC_IFUNC(ifunc) ((ifunc)->func == bmcall)
72block_mark_and_move(
struct rb_block *block)
74 switch (block->type) {
76 case block_type_ifunc:
79 rb_gc_mark_and_move(&captured->self);
80 rb_gc_mark_and_move(&captured->code.val);
82 rb_gc_mark_and_move((
VALUE *)&captured->ep[VM_ENV_DATA_INDEX_ENV]);
86 case block_type_symbol:
87 rb_gc_mark_and_move(&block->as.symbol);
90 rb_gc_mark_and_move(&block->as.proc);
96proc_mark_and_move(
void *ptr)
99 block_mark_and_move((
struct rb_block *)&proc->block);
104 VALUE env[VM_ENV_DATA_SIZE + 1];
108proc_memsize(
const void *ptr)
111 if (proc->block.as.captured.ep == ((
const cfunc_proc_t *)ptr)->env+1)
124 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED
128rb_proc_alloc(
VALUE klass)
142proc_clone(
VALUE self)
144 VALUE procval = rb_proc_dup(self);
154 VALUE procval = rb_proc_dup(self);
266 GetProcPtr(procval, proc);
268 return RBOOL(proc->is_lambda);
274binding_free(
void *ptr)
276 RUBY_FREE_ENTER(
"binding");
278 RUBY_FREE_LEAVE(
"binding");
282binding_mark_and_move(
void *ptr)
286 block_mark_and_move((
struct rb_block *)&bind->block);
287 rb_gc_mark_and_move((
VALUE *)&bind->pathobj);
291binding_memsize(
const void *ptr)
299 binding_mark_and_move,
302 binding_mark_and_move,
304 0, 0, RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_FREE_IMMEDIATELY
308rb_binding_alloc(
VALUE klass)
314 rb_yjit_collect_binding_alloc();
322binding_dup(
VALUE self)
326 GetBindingPtr(self, src);
327 GetBindingPtr(bindval, dst);
328 rb_vm_block_copy(bindval, &dst->block, &src->block);
330 dst->first_lineno = src->first_lineno;
336binding_clone(
VALUE self)
338 VALUE bindval = binding_dup(self);
347 return rb_vm_make_binding(ec, ec->cfp);
395rb_f_binding(
VALUE self)
417bind_eval(
int argc,
VALUE *argv,
VALUE bindval)
421 rb_scan_args(argc, argv,
"12", &args[0], &args[2], &args[3]);
423 return rb_f_eval(argc+1, args,
Qnil );
427get_local_variable_ptr(
const rb_env_t **envp,
ID lid)
431 if (!VM_ENV_FLAGS(env->ep, VM_FRAME_FLAG_CFRAME)) {
432 if (VM_ENV_FLAGS(env->ep, VM_ENV_FLAG_ISOLATED)) {
439 VM_ASSERT(rb_obj_is_iseq((
VALUE)iseq));
441 for (i=0; i<ISEQ_BODY(iseq)->local_table_size; i++) {
442 if (ISEQ_BODY(iseq)->local_table[i] == lid) {
443 if (ISEQ_BODY(iseq)->local_iseq == iseq &&
444 ISEQ_BODY(iseq)->param.flags.has_block &&
445 (
unsigned int)ISEQ_BODY(iseq)->param.block_start == i) {
446 const VALUE *ep = env->ep;
447 if (!VM_ENV_FLAGS(ep, VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM)) {
448 RB_OBJ_WRITE(env, &env->env[i], rb_vm_bh_to_procval(GET_EC(), VM_ENV_BLOCK_HANDLER(ep)));
449 VM_ENV_FLAGS_SET(ep, VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM);
462 }
while ((env = rb_vm_env_prev_env(env)) != NULL);
474check_local_id(
VALUE bindval,
volatile VALUE *pname)
481 rb_name_err_raise(
"wrong local variable name `%1$s' for %2$s",
486 if (!rb_is_local_name(name)) {
487 rb_name_err_raise(
"wrong local variable name `%1$s' for %2$s",
514bind_local_variables(
VALUE bindval)
519 GetBindingPtr(bindval, bind);
520 env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
521 return rb_vm_env_local_variables(env);
542bind_local_variable_get(
VALUE bindval,
VALUE sym)
544 ID lid = check_local_id(bindval, &sym);
549 if (!lid)
goto undefined;
551 GetBindingPtr(bindval, bind);
553 env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
554 if ((ptr = get_local_variable_ptr(&env, lid)) != NULL) {
560 rb_name_err_raise(
"local variable `%1$s' is not defined for %2$s",
593 ID lid = check_local_id(bindval, &sym);
598 if (!lid) lid = rb_intern_str(sym);
600 GetBindingPtr(bindval, bind);
601 env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
602 if ((ptr = get_local_variable_ptr(&env, lid)) == NULL) {
604 ptr = rb_binding_add_dynavars(bindval, bind, 1, &lid);
605 env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
609 rb_yjit_collect_binding_set();
635bind_local_variable_defined_p(
VALUE bindval,
VALUE sym)
637 ID lid = check_local_id(bindval, &sym);
643 GetBindingPtr(bindval, bind);
644 env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
645 return RBOOL(get_local_variable_ptr(&env, lid));
655bind_receiver(
VALUE bindval)
658 GetBindingPtr(bindval, bind);
659 return vm_block_self(&bind->block);
669bind_location(
VALUE bindval)
673 GetBindingPtr(bindval, bind);
674 loc[0] = pathobj_path(bind->pathobj);
675 loc[1] =
INT2FIX(bind->first_lineno);
688 proc = &sproc->basic;
689 vm_block_type_set(&proc->block, block_type_ifunc);
691 *(
VALUE **)&proc->block.as.captured.ep = ep = sproc->env + VM_ENV_DATA_SIZE-1;
692 ep[VM_ENV_DATA_INDEX_FLAGS] = VM_FRAME_MAGIC_IFUNC | VM_FRAME_FLAG_CFRAME | VM_ENV_FLAG_LOCAL | VM_ENV_FLAG_ESCAPED;
693 ep[VM_ENV_DATA_INDEX_ME_CREF] =
Qfalse;
694 ep[VM_ENV_DATA_INDEX_SPECVAL] = VM_BLOCK_HANDLER_NONE;
695 ep[VM_ENV_DATA_INDEX_ENV] =
Qundef;
698 RB_OBJ_WRITE(procval, &proc->block.as.captured.code.ifunc, ifunc);
699 proc->is_lambda = TRUE;
706 VALUE procval = rb_proc_alloc(klass);
708 GetProcPtr(procval, proc);
710 vm_block_type_set(&proc->block, block_type_symbol);
711 proc->is_lambda = TRUE;
726 min_argc >= (
int)(1U << (
SIZEOF_VALUE * CHAR_BIT) / 2) ||
729 rb_raise(
rb_eRangeError,
"minimum argument number out of range: %d",
734 max_argc >= (
int)(1U << (
SIZEOF_VALUE * CHAR_BIT) / 2) ||
737 rb_raise(
rb_eRangeError,
"maximum argument number out of range: %d",
740 arity.argc.min = min_argc;
741 arity.argc.max = max_argc;
743 VALUE ret = rb_imemo_new(imemo_ifunc, (
VALUE)func, (
VALUE)data, arity.packed, (
VALUE)rb_vm_svar_lep(ec, ec->cfp));
750 struct vm_ifunc *ifunc = rb_vm_ifunc_proc_new(func, (
void *)val);
757 struct vm_ifunc *ifunc = rb_vm_ifunc_new(func, (
void *)val, min_argc, max_argc);
761static const char proc_without_block[] =
"tried to create Proc object without a block";
764proc_new(
VALUE klass, int8_t is_lambda)
771 if ((block_handler = rb_vm_frame_block_handler(cfp)) == VM_BLOCK_HANDLER_NONE) {
772 rb_raise(rb_eArgError, proc_without_block);
776 switch (vm_block_handler_type(block_handler)) {
777 case block_handler_type_proc:
778 procval = VM_BH_TO_PROC(block_handler);
784 VALUE newprocval = rb_proc_dup(procval);
785 RBASIC_SET_CLASS(newprocval, klass);
790 case block_handler_type_symbol:
792 sym_proc_new(klass, VM_BH_TO_SYMBOL(block_handler)) :
793 rb_sym_to_proc(VM_BH_TO_SYMBOL(block_handler));
796 case block_handler_type_ifunc:
797 case block_handler_type_iseq:
798 return rb_vm_make_proc_lambda(ec, VM_BH_TO_CAPT_BLOCK(block_handler), klass, is_lambda);
800 VM_UNREACHABLE(proc_new);
819rb_proc_s_new(
int argc,
VALUE *argv,
VALUE klass)
821 VALUE block = proc_new(klass, FALSE);
853f_lambda_filter_non_literal(
void)
856 VALUE block_handler = rb_vm_frame_block_handler(cfp);
858 if (block_handler == VM_BLOCK_HANDLER_NONE) {
863 switch (vm_block_handler_type(block_handler)) {
864 case block_handler_type_iseq:
865 if (RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)->ep == VM_BH_TO_ISEQ_BLOCK(block_handler)->ep) {
869 case block_handler_type_symbol:
871 case block_handler_type_proc:
876 case block_handler_type_ifunc:
880 rb_raise(rb_eArgError,
"the lambda method requires a literal block");
894 f_lambda_filter_non_literal();
950proc_call(
int argc,
VALUE *argv,
VALUE procval)
956#if SIZEOF_LONG > SIZEOF_INT
960 if (argc > INT_MAX || argc < 0) {
961 rb_raise(rb_eArgError,
"too many arguments (%lu)",
962 (
unsigned long)argc);
967#define check_argc(argc) (argc)
977 GetProcPtr(self, proc);
978 vret = rb_vm_invoke_proc(GET_EC(), proc, argc, argv,
979 kw_splat, VM_BLOCK_HANDLER_NONE);
992proc_to_block_handler(
VALUE procval)
994 return NIL_P(procval) ? VM_BLOCK_HANDLER_NONE : procval;
1003 GetProcPtr(self, proc);
1004 vret = rb_vm_invoke_proc(ec, proc, argc, argv, kw_splat, proc_to_block_handler(passed_procval));
1058proc_arity(
VALUE self)
1065rb_iseq_min_max_arity(
const rb_iseq_t *iseq,
int *max)
1067 *max = ISEQ_BODY(iseq)->param.flags.has_rest == FALSE ?
1068 ISEQ_BODY(iseq)->param.lead_num + ISEQ_BODY(iseq)->param.opt_num + ISEQ_BODY(iseq)->param.post_num +
1069 (ISEQ_BODY(iseq)->param.flags.has_kw == TRUE || ISEQ_BODY(iseq)->param.flags.has_kwrest == TRUE)
1071 return ISEQ_BODY(iseq)->param.lead_num + ISEQ_BODY(iseq)->param.post_num + (ISEQ_BODY(iseq)->param.flags.has_kw && ISEQ_BODY(iseq)->param.keyword->required_num > 0);
1075rb_vm_block_min_max_arity(
const struct rb_block *block,
int *max)
1078 switch (vm_block_type(block)) {
1079 case block_type_iseq:
1080 return rb_iseq_min_max_arity(rb_iseq_check(block->as.captured.code.iseq), max);
1081 case block_type_proc:
1082 block = vm_proc_block(block->as.proc);
1084 case block_type_ifunc:
1086 const struct vm_ifunc *ifunc = block->as.captured.code.ifunc;
1087 if (IS_METHOD_PROC_IFUNC(ifunc)) {
1089 return method_min_max_arity((
VALUE)ifunc->data, max);
1091 *max = ifunc->argc.max;
1092 return ifunc->argc.min;
1094 case block_type_symbol:
1109rb_proc_min_max_arity(
VALUE self,
int *max)
1112 GetProcPtr(self, proc);
1113 return rb_vm_block_min_max_arity(&proc->block, max);
1121 GetProcPtr(self, proc);
1122 min = rb_vm_block_min_max_arity(&proc->block, &max);
1129 switch (vm_block_handler_type(block_handler)) {
1130 case block_handler_type_iseq:
1131 block->type = block_type_iseq;
1132 block->as.captured = *VM_BH_TO_ISEQ_BLOCK(block_handler);
1134 case block_handler_type_ifunc:
1135 block->type = block_type_ifunc;
1136 block->as.captured = *VM_BH_TO_IFUNC_BLOCK(block_handler);
1138 case block_handler_type_symbol:
1139 block->type = block_type_symbol;
1140 block->as.symbol = VM_BH_TO_SYMBOL(block_handler);
1142 case block_handler_type_proc:
1143 block->type = block_type_proc;
1144 block->as.proc = VM_BH_TO_PROC(block_handler);
1149rb_block_pair_yield_optimizable(
void)
1154 VALUE block_handler = rb_vm_frame_block_handler(cfp);
1157 if (block_handler == VM_BLOCK_HANDLER_NONE) {
1158 rb_raise(rb_eArgError,
"no block given");
1161 block_setup(&block, block_handler);
1162 min = rb_vm_block_min_max_arity(&block, &max);
1164 switch (vm_block_type(&block)) {
1165 case block_handler_type_symbol:
1168 case block_handler_type_proc:
1170 VALUE procval = block_handler;
1172 GetProcPtr(procval, proc);
1173 if (proc->is_lambda)
return 0;
1174 if (min != max)
return 0;
1189 VALUE block_handler = rb_vm_frame_block_handler(cfp);
1192 if (block_handler == VM_BLOCK_HANDLER_NONE) {
1193 rb_raise(rb_eArgError,
"no block given");
1196 block_setup(&block, block_handler);
1198 switch (vm_block_type(&block)) {
1199 case block_handler_type_symbol:
1202 case block_handler_type_proc:
1206 min = rb_vm_block_min_max_arity(&block, &max);
1212rb_block_min_max_arity(
int *max)
1216 VALUE block_handler = rb_vm_frame_block_handler(cfp);
1219 if (block_handler == VM_BLOCK_HANDLER_NONE) {
1220 rb_raise(rb_eArgError,
"no block given");
1223 block_setup(&block, block_handler);
1224 return rb_vm_block_min_max_arity(&block, max);
1228rb_proc_get_iseq(
VALUE self,
int *is_proc)
1233 GetProcPtr(self, proc);
1234 block = &proc->block;
1235 if (is_proc) *is_proc = !proc->is_lambda;
1237 switch (vm_block_type(block)) {
1238 case block_type_iseq:
1239 return rb_iseq_check(block->as.captured.code.iseq);
1240 case block_type_proc:
1241 return rb_proc_get_iseq(block->as.proc, is_proc);
1242 case block_type_ifunc:
1244 const struct vm_ifunc *ifunc = block->as.captured.code.ifunc;
1245 if (IS_METHOD_PROC_IFUNC(ifunc)) {
1247 if (is_proc) *is_proc = 0;
1248 return rb_method_iseq((
VALUE)ifunc->data);
1254 case block_type_symbol:
1258 VM_UNREACHABLE(rb_proc_get_iseq);
1291 const rb_proc_t *self_proc, *other_proc;
1292 const struct rb_block *self_block, *other_block;
1298 GetProcPtr(self, self_proc);
1299 GetProcPtr(other, other_proc);
1301 if (self_proc->is_from_method != other_proc->is_from_method ||
1302 self_proc->is_lambda != other_proc->is_lambda) {
1306 self_block = &self_proc->block;
1307 other_block = &other_proc->block;
1309 if (vm_block_type(self_block) != vm_block_type(other_block)) {
1313 switch (vm_block_type(self_block)) {
1314 case block_type_iseq:
1315 if (self_block->as.captured.ep != \
1316 other_block->as.captured.ep ||
1317 self_block->as.captured.code.iseq != \
1318 other_block->as.captured.code.iseq) {
1322 case block_type_ifunc:
1323 if (self_block->as.captured.ep != \
1324 other_block->as.captured.ep ||
1325 self_block->as.captured.code.ifunc != \
1326 other_block->as.captured.code.ifunc) {
1330 case block_type_proc:
1331 if (self_block->as.proc != other_block->as.proc) {
1335 case block_type_symbol:
1336 if (self_block->as.symbol != other_block->as.symbol) {
1350 if (!iseq)
return Qnil;
1351 rb_iseq_check(iseq);
1352 loc[0] = rb_iseq_path(iseq);
1353 loc[1] =
RB_INT2NUM(ISEQ_BODY(iseq)->location.first_lineno);
1361 return iseq_location(iseq);
1373rb_proc_location(
VALUE self)
1375 return iseq_location(rb_proc_get_iseq(self, 0));
1379rb_unnamed_parameters(
int arity)
1382 int n = (arity < 0) ? ~arity : arity;
1388 rb_ary_push(param, a);
1416rb_proc_parameters(
int argc,
VALUE *argv,
VALUE self)
1418 static ID keyword_ids[1];
1424 iseq = rb_proc_get_iseq(self, &is_proc);
1426 if (!keyword_ids[0]) {
1427 CONST_ID(keyword_ids[0],
"lambda");
1434 if (!
NIL_P(lambda)) {
1435 is_proc = !
RTEST(lambda);
1442 return rb_iseq_parameters(iseq, is_proc);
1446rb_hash_proc(st_index_t hash,
VALUE prc)
1449 GetProcPtr(prc, proc);
1450 hash =
rb_hash_uint(hash, (st_index_t)proc->block.as.captured.code.val);
1451 hash =
rb_hash_uint(hash, (st_index_t)proc->block.as.captured.self);
1452 return rb_hash_uint(hash, (st_index_t)proc->block.as.captured.ep);
1471rb_sym_to_proc(
VALUE sym)
1474 enum {SYM_PROC_CACHE_SIZE = 67};
1479 if (!sym_proc_cache) {
1480 sym_proc_cache = rb_ary_hidden_new(SYM_PROC_CACHE_SIZE * 2);
1481 rb_gc_register_mark_object(sym_proc_cache);
1482 rb_ary_store(sym_proc_cache, SYM_PROC_CACHE_SIZE*2 - 1,
Qnil);
1486 index = (
id % SYM_PROC_CACHE_SIZE) << 1;
1509proc_hash(
VALUE self)
1513 hash = rb_hash_proc(hash, self);
1519rb_block_to_s(
VALUE self,
const struct rb_block *block,
const char *additional_info)
1522 VALUE str = rb_sprintf(
"#<%"PRIsVALUE
":", cname);
1525 switch (vm_block_type(block)) {
1526 case block_type_proc:
1527 block = vm_proc_block(block->as.proc);
1529 case block_type_iseq:
1531 const rb_iseq_t *iseq = rb_iseq_check(block->as.captured.code.iseq);
1532 rb_str_catf(str,
"%p %"PRIsVALUE
":%d", (
void *)self,
1534 ISEQ_BODY(iseq)->location.first_lineno);
1537 case block_type_symbol:
1538 rb_str_catf(str,
"%p(&%+"PRIsVALUE
")", (
void *)self, block->as.symbol);
1540 case block_type_ifunc:
1541 rb_str_catf(str,
"%p", (
void *)block->as.captured.code.ifunc);
1559proc_to_s(
VALUE self)
1562 GetProcPtr(self, proc);
1563 return rb_block_to_s(self, &proc->block, proc->is_lambda ?
" (lambda)" : NULL);
1575proc_to_proc(
VALUE self)
1581bm_mark_and_move(
void *ptr)
1583 struct METHOD *data = ptr;
1584 rb_gc_mark_and_move((
VALUE *)&data->recv);
1585 rb_gc_mark_and_move((
VALUE *)&data->klass);
1586 rb_gc_mark_and_move((
VALUE *)&data->iclass);
1587 rb_gc_mark_and_move((
VALUE *)&data->owner);
1599 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_EMBEDDABLE
1612 ID rmiss = idRespond_to_missing;
1614 if (UNDEF_P(obj))
return 0;
1615 if (rb_method_basic_definition_p(klass, rmiss))
return 0;
1633 def->type = VM_METHOD_TYPE_MISSING;
1634 def->original_id = id;
1636 me = rb_method_entry_create(
id, klass, METHOD_VISI_UNDEF, def);
1646 VALUE vid = rb_str_intern(*name);
1648 if (!respond_to_missing_p(klass, obj, vid, scope))
return Qfalse;
1649 return mnew_missing(klass, obj,
SYM2ID(vid), mclass);
1659 rb_method_visibility_t visi = METHOD_VISI_UNDEF;
1662 if (UNDEFINED_METHOD_ENTRY_P(me)) {
1663 if (respond_to_missing_p(klass, obj,
ID2SYM(
id), scope)) {
1664 return mnew_missing(klass, obj,
id, mclass);
1666 if (!error)
return Qnil;
1667 rb_print_undef(klass,
id, METHOD_VISI_UNDEF);
1669 if (visi == METHOD_VISI_UNDEF) {
1670 visi = METHOD_ENTRY_VISI(me);
1672 if (scope && (visi != METHOD_VISI_PUBLIC)) {
1673 if (!error)
return Qnil;
1674 rb_print_inaccessible(klass,
id, visi);
1677 if (me->def->type == VM_METHOD_TYPE_ZSUPER) {
1678 if (me->defined_class) {
1680 id = me->def->original_id;
1681 me = (
rb_method_entry_t *)rb_callable_method_entry_with_refinements(klass,
id, &iclass);
1685 id = me->def->original_id;
1686 me = rb_method_entry_without_refinements(klass,
id, &iclass);
1702 RB_OBJ_WRITE(method, &data->owner, original_me->owner);
1712 return mnew_internal(me, klass, iclass, obj,
id, mclass, scope, TRUE);
1722 me = (
rb_method_entry_t *)rb_callable_method_entry_with_refinements(klass,
id, &iclass);
1723 return mnew_from_me(me, klass, iclass, obj,
id, mclass, scope);
1727mnew_unbound(
VALUE klass,
ID id,
VALUE mclass,
int scope)
1732 me = rb_method_entry_with_refinements(klass,
id, &iclass);
1733 return mnew_from_me(me, klass, iclass,
Qundef,
id, mclass, scope);
1739 VALUE defined_class = me->defined_class;
1740 return defined_class ? defined_class : me->owner;
1785 VALUE klass1, klass2;
1793 m1 = (
struct METHOD *)RTYPEDDATA_GET_DATA(method);
1794 m2 = (
struct METHOD *)RTYPEDDATA_GET_DATA(other);
1796 klass1 = method_entry_defined_class(m1->me);
1797 klass2 = method_entry_defined_class(m2->me);
1799 if (!rb_method_entry_eq(m1->me, m2->me) ||
1801 m1->klass != m2->klass ||
1802 m1->recv != m2->recv) {
1823#define unbound_method_eq method_eq
1835method_hash(
VALUE method)
1842 hash = rb_hash_method_entry(hash, m->me);
1858method_unbind(
VALUE obj)
1861 struct METHOD *orig, *data;
1865 &method_data_type, data);
1870 RB_OBJ_WRITE(method, &data->me, rb_method_entry_clone(orig->me));
1885method_receiver(
VALUE obj)
1901method_name(
VALUE obj)
1906 return ID2SYM(data->me->called_id);
1923method_original_name(
VALUE obj)
1928 return ID2SYM(data->me->def->original_id);
1950method_owner(
VALUE obj)
1960#define MSG(s) rb_fstring_lit("undefined method `%1$s' for"s" `%2$s'")
1965 VALUE obj = RCLASS_ATTACHED_OBJECT(klass);
1982 rb_name_err_raise_str(s, c, str);
1994 VALUE m = mnew_missing_by_name(klass, obj, &vid, scope, mclass);
1996 rb_method_name_error(klass, vid);
1998 return mnew_callable(klass, obj,
id, mclass, scope);
2043 return obj_method(obj, vid, FALSE);
2056 return obj_method(obj, vid, TRUE);
2090 NIL_P(klass = RCLASS_ORIGIN(klass)) ||
2091 !
NIL_P(rb_special_singleton_class(obj))) {
2103 if (UNDEFINED_METHOD_ENTRY_P(me)) {
2106 else if (UNDEFINED_REFINED_METHOD_P(me->def)) {
2110 return mnew_from_me(me, klass, klass, obj,
id,
rb_cMethod, FALSE);
2115 rb_name_err_raise(
"undefined singleton method `%1$s' for `%2$s'",
2156 rb_method_name_error(mod, vid);
2169rb_mod_public_instance_method(
VALUE mod,
VALUE vid)
2173 rb_method_name_error(mod, vid);
2184 int is_method = FALSE;
2203 "wrong argument type %s (expected Proc/Method/UnboundMethod)",
2210 struct METHOD *method = (
struct METHOD *)RTYPEDDATA_GET_DATA(body);
2211 if (method->me->owner != mod && !RB_TYPE_P(method->me->owner,
T_MODULE) &&
2215 "can't bind singleton method to a different class");
2219 "bind argument must be a subclass of % "PRIsVALUE,
2223 rb_method_entry_set(mod,
id, method->me, scope_visi->method_visi);
2224 if (scope_visi->module_func) {
2230 VALUE procval = rb_proc_dup(body);
2231 if (vm_proc_iseq(procval) != NULL) {
2233 GetProcPtr(procval, proc);
2234 proc->is_lambda = TRUE;
2235 proc->is_from_method = TRUE;
2237 rb_add_method(mod,
id, VM_METHOD_TYPE_BMETHOD, (
void *)procval, scope_visi->method_visi);
2238 if (scope_visi->module_func) {
2239 rb_add_method(
rb_singleton_class(mod),
id, VM_METHOD_TYPE_BMETHOD, (
void *)body, METHOD_VISI_PUBLIC);
2287rb_mod_define_method(
int argc,
VALUE *argv,
VALUE mod)
2289 const rb_cref_t *cref = rb_vm_cref_in_context(mod, mod);
2294 scope_visi = CREF_SCOPE_VISI(cref);
2297 return rb_mod_define_method_with_visibility(argc, argv, mod, scope_visi);
2332rb_obj_define_method(
int argc,
VALUE *argv,
VALUE obj)
2337 return rb_mod_define_method_with_visibility(argc, argv, klass, &scope_visi);
2348top_define_method(
int argc,
VALUE *argv,
VALUE obj)
2353 klass = th->top_wrapper;
2355 rb_warning(
"main.define_method in the wrapped load is effective only in wrapper module");
2360 return rb_mod_define_method(argc, argv, klass);
2381method_clone(
VALUE self)
2384 struct METHOD *orig, *data;
2393 RB_OBJ_WRITE(clone, &data->me, rb_method_entry_clone(orig->me));
2441rb_method_call_pass_called_kw(
int argc,
const VALUE *argv,
VALUE method)
2461method_callable_method_entry(
const struct METHOD *data)
2463 if (data->me->defined_class == 0) rb_bug(
"method_callable_method_entry: not callable.");
2469 int argc,
const VALUE *argv,
VALUE passed_procval,
int kw_splat)
2471 vm_passed_block_handler_set(ec, proc_to_block_handler(passed_procval));
2472 return rb_vm_call_kw(ec, data->recv, data->me->called_id, argc, argv,
2473 method_callable_method_entry(data), kw_splat);
2479 const struct METHOD *data;
2483 if (UNDEF_P(data->recv)) {
2484 rb_raise(
rb_eTypeError,
"can't call unbound method; bind first");
2486 return call_method_data(ec, data, argc, argv, passed_procval, kw_splat);
2553 VALUE methclass = data->owner;
2554 VALUE iclass = data->me->defined_class;
2557 if (RB_TYPE_P(methclass,
T_MODULE)) {
2558 VALUE refined_class = rb_refinement_module_get_refined_class(methclass);
2559 if (!
NIL_P(refined_class)) methclass = refined_class;
2564 "singleton method called for a different object");
2567 rb_raise(
rb_eTypeError,
"bind argument must be an instance of % "PRIsVALUE,
2574 me = rb_method_entry_clone(data->me);
2580 if (RB_TYPE_P(me->owner,
T_MODULE)) {
2584 me = rb_method_entry_clone(me);
2586 VALUE ic = rb_class_search_ancestor(klass, me->owner);
2592 klass = rb_include_class_new(methclass, klass);
2594 me = (
const rb_method_entry_t *) rb_method_entry_complement_defined_class(me, me->called_id, klass);
2597 *methclass_out = methclass;
2599 *iclass_out = iclass;
2641 VALUE methclass, klass, iclass;
2643 const struct METHOD *data;
2645 convert_umethod_to_method_components(data, recv, &methclass, &klass, &iclass, &me,
true);
2667umethod_bind_call(
int argc,
VALUE *argv,
VALUE method)
2670 VALUE recv = argv[0];
2677 const struct METHOD *data;
2682 vm_passed_block_handler_set(ec, proc_to_block_handler(passed_procval));
2686 VALUE methclass, klass, iclass;
2688 convert_umethod_to_method_components(data, recv, &methclass, &klass, &iclass, &me,
false);
2689 struct METHOD bound = { recv, klass, 0, methclass, me };
2704 if (!def)
return *max = 0;
2705 switch (def->type) {
2706 case VM_METHOD_TYPE_CFUNC:
2707 if (def->body.cfunc.argc < 0) {
2711 return *max = check_argc(def->body.cfunc.argc);
2712 case VM_METHOD_TYPE_ZSUPER:
2715 case VM_METHOD_TYPE_ATTRSET:
2717 case VM_METHOD_TYPE_IVAR:
2719 case VM_METHOD_TYPE_ALIAS:
2720 def = def->body.alias.original_me->def;
2722 case VM_METHOD_TYPE_BMETHOD:
2723 return rb_proc_min_max_arity(def->body.bmethod.proc, max);
2724 case VM_METHOD_TYPE_ISEQ:
2725 return rb_iseq_min_max_arity(rb_iseq_check(def->body.iseq.
iseqptr), max);
2726 case VM_METHOD_TYPE_UNDEF:
2727 case VM_METHOD_TYPE_NOTIMPLEMENTED:
2729 case VM_METHOD_TYPE_MISSING:
2732 case VM_METHOD_TYPE_OPTIMIZED: {
2733 switch (def->body.optimized.type) {
2734 case OPTIMIZED_METHOD_TYPE_SEND:
2737 case OPTIMIZED_METHOD_TYPE_CALL:
2740 case OPTIMIZED_METHOD_TYPE_BLOCK_CALL:
2743 case OPTIMIZED_METHOD_TYPE_STRUCT_AREF:
2746 case OPTIMIZED_METHOD_TYPE_STRUCT_ASET:
2754 case VM_METHOD_TYPE_REFINED:
2758 rb_bug(
"method_def_min_max_arity: invalid method entry type (%d)", def->type);
2765 int max, min = method_def_min_max_arity(def, &max);
2766 return min == max ? min : -min-1;
2772 return method_def_arity(me->def);
2819method_arity_m(
VALUE method)
2821 int n = method_arity(method);
2826method_arity(
VALUE method)
2831 return rb_method_entry_arity(data->me);
2835original_method_entry(
VALUE mod,
ID id)
2839 while ((me = rb_method_entry(mod,
id)) != 0) {
2841 if (def->type != VM_METHOD_TYPE_ZSUPER)
break;
2843 id = def->original_id;
2849method_min_max_arity(
VALUE method,
int *max)
2851 const struct METHOD *data;
2854 return method_def_min_max_arity(data->me->def, max);
2862 return rb_method_entry_arity(me);
2872rb_callable_receiver(
VALUE callable)
2875 VALUE binding = proc_binding(callable);
2876 return rb_funcall(binding, rb_intern(
"receiver"), 0);
2879 return method_receiver(callable);
2887rb_method_def(
VALUE method)
2889 const struct METHOD *data;
2892 return data->me->def;
2898 switch (def->type) {
2899 case VM_METHOD_TYPE_ISEQ:
2900 return rb_iseq_check(def->body.iseq.
iseqptr);
2901 case VM_METHOD_TYPE_BMETHOD:
2902 return rb_proc_get_iseq(def->body.bmethod.proc, 0);
2903 case VM_METHOD_TYPE_ALIAS:
2904 return method_def_iseq(def->body.alias.original_me->def);
2905 case VM_METHOD_TYPE_CFUNC:
2906 case VM_METHOD_TYPE_ATTRSET:
2907 case VM_METHOD_TYPE_IVAR:
2908 case VM_METHOD_TYPE_ZSUPER:
2909 case VM_METHOD_TYPE_UNDEF:
2910 case VM_METHOD_TYPE_NOTIMPLEMENTED:
2911 case VM_METHOD_TYPE_OPTIMIZED:
2912 case VM_METHOD_TYPE_MISSING:
2913 case VM_METHOD_TYPE_REFINED:
2920rb_method_iseq(
VALUE method)
2922 return method_def_iseq(rb_method_def(method));
2926method_cref(
VALUE method)
2931 switch (def->type) {
2932 case VM_METHOD_TYPE_ISEQ:
2933 return def->body.iseq.
cref;
2934 case VM_METHOD_TYPE_ALIAS:
2935 def = def->body.alias.original_me->def;
2945 if (def->type == VM_METHOD_TYPE_ATTRSET || def->type == VM_METHOD_TYPE_IVAR) {
2946 if (!def->body.attr.location)
2948 return rb_ary_dup(def->body.attr.location);
2950 return iseq_location(method_def_iseq(def));
2956 if (!me)
return Qnil;
2957 return method_def_location(me->def);
2969rb_method_location(
VALUE method)
2971 return method_def_location(rb_method_def(method));
2975vm_proc_method_def(
VALUE procval)
2981 GetProcPtr(procval, proc);
2982 block = &proc->block;
2984 if (vm_block_type(block) == block_type_ifunc &&
2985 IS_METHOD_PROC_IFUNC(ifunc = block->as.captured.code.ifunc)) {
2986 return rb_method_def((
VALUE)ifunc->data);
2999 switch (def->type) {
3000 case VM_METHOD_TYPE_ISEQ:
3001 iseq = method_def_iseq(def);
3002 return rb_iseq_parameters(iseq, 0);
3003 case VM_METHOD_TYPE_BMETHOD:
3004 if ((iseq = method_def_iseq(def)) != NULL) {
3005 return rb_iseq_parameters(iseq, 0);
3007 else if ((bmethod_def = vm_proc_method_def(def->body.bmethod.proc)) != NULL) {
3008 return method_def_parameters(bmethod_def);
3012 case VM_METHOD_TYPE_ALIAS:
3013 return method_def_parameters(def->body.alias.original_me->def);
3015 case VM_METHOD_TYPE_OPTIMIZED:
3016 if (def->body.optimized.type == OPTIMIZED_METHOD_TYPE_STRUCT_ASET) {
3017 VALUE param = rb_ary_new_from_args(2,
ID2SYM(rb_intern(
"req")),
ID2SYM(rb_intern(
"_")));
3018 return rb_ary_new_from_args(1, param);
3022 case VM_METHOD_TYPE_CFUNC:
3023 case VM_METHOD_TYPE_ATTRSET:
3024 case VM_METHOD_TYPE_IVAR:
3025 case VM_METHOD_TYPE_ZSUPER:
3026 case VM_METHOD_TYPE_UNDEF:
3027 case VM_METHOD_TYPE_NOTIMPLEMENTED:
3028 case VM_METHOD_TYPE_MISSING:
3029 case VM_METHOD_TYPE_REFINED:
3033 return rb_unnamed_parameters(method_def_arity(def));
3057rb_method_parameters(
VALUE method)
3059 return method_def_parameters(rb_method_def(method));
3096method_inspect(
VALUE method)
3100 const char *sharp =
"#";
3102 VALUE defined_class;
3105 str = rb_sprintf(
"#<% "PRIsVALUE
": ",
rb_obj_class(method));
3107 mklass = data->iclass;
3108 if (!mklass) mklass = data->klass;
3118 if (data->me->def->type == VM_METHOD_TYPE_ALIAS) {
3119 defined_class = data->me->def->body.alias.original_me->owner;
3122 defined_class = method_entry_defined_class(data->me);
3125 if (RB_TYPE_P(defined_class,
T_ICLASS)) {
3129 if (data->recv ==
Qundef) {
3131 rb_str_buf_append(str,
rb_inspect(defined_class));
3134 VALUE v = RCLASS_ATTACHED_OBJECT(mklass);
3136 if (UNDEF_P(data->recv)) {
3139 else if (data->recv == v) {
3144 rb_str_buf_append(str,
rb_inspect(data->recv));
3152 mklass = data->klass;
3154 VALUE v = RCLASS_ATTACHED_OBJECT(mklass);
3158 }
while (RB_TYPE_P(mklass,
T_ICLASS));
3162 if (defined_class != mklass) {
3163 rb_str_catf(str,
"(% "PRIsVALUE
")", defined_class);
3168 if (data->me->called_id != data->me->def->original_id) {
3169 rb_str_catf(str,
"(%"PRIsVALUE
")",
3170 rb_id2str(data->me->def->original_id));
3172 if (data->me->def->type == VM_METHOD_TYPE_NOTIMPLEMENTED) {
3178 VALUE params = rb_method_parameters(method);
3179 VALUE pair, name, kind;
3185 const VALUE keyrest =
ID2SYM(rb_intern(
"keyrest"));
3202 for (
int i = 0; i <
RARRAY_LEN(params); i++) {
3209 if (kind == req || kind == opt) {
3212 else if (kind == rest || kind == keyrest) {
3215 else if (kind == block) {
3218 else if (kind == nokey) {
3224 rb_str_catf(str,
"%"PRIsVALUE, name);
3226 else if (kind == opt) {
3227 rb_str_catf(str,
"%"PRIsVALUE
"=...", name);
3229 else if (kind == keyreq) {
3230 rb_str_catf(str,
"%"PRIsVALUE
":", name);
3232 else if (kind == key) {
3233 rb_str_catf(str,
"%"PRIsVALUE
": ...", name);
3235 else if (kind == rest) {
3236 if (name ==
ID2SYM(
'*')) {
3240 rb_str_catf(str,
"*%"PRIsVALUE, name);
3243 else if (kind == keyrest) {
3244 if (name !=
ID2SYM(idPow)) {
3245 rb_str_catf(str,
"**%"PRIsVALUE, name);
3248 rb_str_set_len(str, RSTRING_LEN(str) - 2);
3254 else if (kind == block) {
3255 if (name ==
ID2SYM(
'&')) {
3257 rb_str_set_len(str, RSTRING_LEN(str) - 2);
3264 rb_str_catf(str,
"&%"PRIsVALUE, name);
3267 else if (kind == nokey) {
3279 VALUE loc = rb_method_location(method);
3281 rb_str_catf(str,
" %"PRIsVALUE
":%"PRIsVALUE,
3314method_to_proc(
VALUE method)
3328 procval =
rb_block_call(rb_mRubyVMFrozenCore, idLambda, 0, 0, bmcall, method);
3329 GetProcPtr(procval, proc);
3330 proc->is_from_method = 1;
3334extern VALUE rb_find_defined_class_by_owner(
VALUE current_class,
VALUE target_owner);
3345method_super_method(
VALUE method)
3347 const struct METHOD *data;
3348 VALUE super_class, iclass;
3353 iclass = data->iclass;
3354 if (!iclass)
return Qnil;
3355 if (data->me->def->type == VM_METHOD_TYPE_ALIAS && data->me->defined_class) {
3356 super_class =
RCLASS_SUPER(rb_find_defined_class_by_owner(data->me->defined_class,
3357 data->me->def->body.alias.original_me->owner));
3358 mid = data->me->def->body.alias.original_me->def->original_id;
3362 mid = data->me->def->original_id;
3364 if (!super_class)
return Qnil;
3365 me = (
rb_method_entry_t *)rb_callable_method_entry_with_refinements(super_class, mid, &iclass);
3366 if (!me)
return Qnil;
3367 return mnew_internal(me, me->owner, iclass, data->recv, mid,
rb_obj_class(method), FALSE, FALSE);
3377localjump_xvalue(
VALUE exc)
3391localjump_reason(
VALUE exc)
3396rb_cref_t *rb_vm_cref_new_toplevel(
void);
3405 VM_ASSERT(env->ep > env->env);
3406 VM_ASSERT(VM_ENV_ESCAPED_P(env->ep));
3409 cref = rb_vm_cref_new_toplevel();
3413 new_ep = &new_body[env->ep - env->env];
3414 new_env = vm_env_new(new_ep, new_body, env->env_size, env->iseq);
3421 new_ep[VM_ENV_DATA_INDEX_ENV] = (
VALUE)new_env;
3423 VM_ASSERT(VM_ENV_ESCAPED_P(new_ep));
3441proc_binding(
VALUE self)
3450 GetProcPtr(self, proc);
3451 block = &proc->block;
3453 if (proc->is_isolated) rb_raise(rb_eArgError,
"Can't create Binding from isolated Proc");
3456 switch (vm_block_type(block)) {
3457 case block_type_iseq:
3458 iseq = block->as.captured.code.iseq;
3459 binding_self = block->as.captured.self;
3460 env = VM_ENV_ENVVAL_PTR(block->as.captured.ep);
3462 case block_type_proc:
3463 GetProcPtr(block->as.proc, proc);
3464 block = &proc->block;
3466 case block_type_ifunc:
3468 const struct vm_ifunc *ifunc = block->as.captured.code.ifunc;
3469 if (IS_METHOD_PROC_IFUNC(ifunc)) {
3471 VALUE name = rb_fstring_lit(
"<empty_iseq>");
3473 binding_self = method_receiver(method);
3474 iseq = rb_method_iseq(method);
3475 env = VM_ENV_ENVVAL_PTR(block->as.captured.ep);
3476 env = env_clone(env, method_cref(method));
3478 empty = rb_iseq_new(NULL, name, name,
Qnil, 0, ISEQ_TYPE_TOP);
3484 case block_type_symbol:
3485 rb_raise(rb_eArgError,
"Can't create Binding from C level Proc");
3490 GetBindingPtr(bindval, bind);
3491 RB_OBJ_WRITE(bindval, &bind->block.as.captured.self, binding_self);
3492 RB_OBJ_WRITE(bindval, &bind->block.as.captured.code.iseq, env->iseq);
3493 rb_vm_block_ep_update(bindval, &bind->block, env->ep);
3497 rb_iseq_check(iseq);
3498 RB_OBJ_WRITE(bindval, &bind->pathobj, ISEQ_BODY(iseq)->location.pathobj);
3499 bind->first_lineno = ISEQ_BODY(iseq)->location.first_lineno;
3503 rb_iseq_pathobj_new(rb_fstring_lit(
"(binding)"),
Qnil));
3504 bind->first_lineno = 1;
3519 GetProcPtr(proc, procp);
3520 is_lambda = procp->is_lambda;
3521 rb_ary_freeze(passed);
3522 rb_ary_freeze(args);
3524 GetProcPtr(proc, procp);
3525 procp->is_lambda = is_lambda;
3532 VALUE proc, passed, arity;
3537 passed = rb_ary_plus(passed,
rb_ary_new4(argc, argv));
3538 rb_ary_freeze(passed);
3541 if (!
NIL_P(blockarg)) {
3542 rb_warn(
"given block not used");
3544 arity = make_curry_proc(proc, passed, arity);
3599proc_curry(
int argc,
const VALUE *argv,
VALUE self)
3601 int sarity, max_arity, min_arity = rb_proc_min_max_arity(self, &max_arity);
3614 return make_curry_proc(self, rb_ary_new(), arity);
3650rb_method_curry(
int argc,
const VALUE *argv,
VALUE self)
3652 VALUE proc = method_to_proc(self);
3653 return proc_curry(argc, argv, proc);
3671 return rb_funcallv(f, idCall, 1, &fargs);
3682 mesg = rb_fstring_lit(
"callable object is expected");
3706 return rb_proc_compose_to_left(self, to_callable(g));
3712 VALUE proc, args, procs[2];
3718 args = rb_ary_tmp_new_from_values(0, 2, procs);
3721 GetProcPtr(g, procp);
3722 is_lambda = procp->is_lambda;
3730 GetProcPtr(proc, procp);
3731 procp->is_lambda = is_lambda;
3765 return rb_proc_compose_to_right(self, to_callable(g));
3771 VALUE proc, args, procs[2];
3777 args = rb_ary_tmp_new_from_values(0, 2, procs);
3779 GetProcPtr(self, procp);
3780 is_lambda = procp->is_lambda;
3783 GetProcPtr(proc, procp);
3784 procp->is_lambda = is_lambda;
3806rb_method_compose_to_left(
VALUE self,
VALUE g)
3809 self = method_to_proc(self);
3810 return proc_compose_to_left(self, g);
3830rb_method_compose_to_right(
VALUE self,
VALUE g)
3833 self = method_to_proc(self);
3834 return proc_compose_to_right(self, g);
3870proc_ruby2_keywords(
VALUE procval)
3873 GetProcPtr(procval, proc);
3877 if (proc->is_from_method) {
3878 rb_warn(
"Skipping set of ruby2_keywords flag for proc (proc created from method)");
3882 switch (proc->block.type) {
3883 case block_type_iseq:
3884 if (ISEQ_BODY(proc->block.as.captured.code.iseq)->param.flags.has_rest &&
3885 !ISEQ_BODY(proc->block.as.captured.code.iseq)->param.flags.has_kw &&
3886 !ISEQ_BODY(proc->block.as.captured.code.iseq)->param.flags.has_kwrest) {
3887 ISEQ_BODY(proc->block.as.captured.code.iseq)->param.flags.ruby2_keywords = 1;
3890 rb_warn(
"Skipping set of ruby2_keywords flag for proc (proc accepts keywords or proc does not accept argument splat)");
3894 rb_warn(
"Skipping set of ruby2_keywords flag for proc (proc not defined in Ruby)");
4247 rb_add_method_optimized(
rb_cProc, idCall, OPTIMIZED_METHOD_TYPE_CALL, 0, METHOD_VISI_PUBLIC);
4248 rb_add_method_optimized(
rb_cProc, rb_intern(
"[]"), OPTIMIZED_METHOD_TYPE_CALL, 0, METHOD_VISI_PUBLIC);
4249 rb_add_method_optimized(
rb_cProc, rb_intern(
"==="), OPTIMIZED_METHOD_TYPE_CALL, 0, METHOD_VISI_PUBLIC);
4250 rb_add_method_optimized(
rb_cProc, rb_intern(
"yield"), OPTIMIZED_METHOD_TYPE_CALL, 0, METHOD_VISI_PUBLIC);
4284 rb_vm_register_special_exception(ruby_error_sysstack,
rb_eSysStackError,
"stack level too deep");
4349 "define_method", top_define_method, -1);
#define RBIMPL_ASSERT_OR_ASSUME(expr)
This is either RUBY_ASSERT or RBIMPL_ASSUME, depending on RUBY_DEBUG.
#define RUBY_ASSERT(expr)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
#define rb_define_method(klass, mid, func, arity)
Defines klass#mid.
#define rb_define_singleton_method(klass, mid, func, arity)
Defines klass.mid.
#define rb_define_private_method(klass, mid, func, arity)
Defines klass#mid and makes it private.
#define rb_define_global_function(mid, func, arity)
Defines rb_mKernel #mid.
static VALUE RB_FL_TEST(VALUE obj, VALUE flags)
Tests if the given flag(s) are set or not.
static VALUE RB_FL_TEST_RAW(VALUE obj, VALUE flags)
This is an implementation detail of RB_FL_TEST().
@ RUBY_FL_EXIVAR
This flag has something to do with instance variables.
@ RUBY_FL_PROMOTED
Ruby objects are "generational".
@ RUBY_FL_FINALIZE
This flag has something to do with finalisers.
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
VALUE rb_singleton_class_clone(VALUE obj)
Clones a singleton class.
VALUE rb_singleton_class(VALUE obj)
Finds or creates the singleton class of the passed object.
void rb_singleton_class_attached(VALUE klass, VALUE obj)
Attaches a singleton class to its corresponding object.
VALUE rb_singleton_class_get(VALUE obj)
Returns the singleton class of obj, or nil if obj is not a singleton object.
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
void rb_undef_method(VALUE klass, const char *name)
Defines an undef of a method.
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Retrieves argument from argc and argv to given VALUE references according to the format string.
int rb_block_given_p(void)
Determines if the current method is given a block.
int rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *values)
Keyword argument deconstructor.
#define rb_str_new2
Old name of rb_str_new_cstr.
#define FL_SINGLETON
Old name of RUBY_FL_SINGLETON.
#define rb_str_buf_cat2
Old name of rb_usascii_str_new_cstr.
#define Qundef
Old name of RUBY_Qundef.
#define INT2FIX
Old name of RB_INT2FIX.
#define ID2SYM
Old name of RB_ID2SYM.
#define OBJ_FREEZE
Old name of RB_OBJ_FREEZE.
#define UNREACHABLE_RETURN
Old name of RBIMPL_UNREACHABLE_RETURN.
#define SYM2ID
Old name of RB_SYM2ID.
#define ZALLOC
Old name of RB_ZALLOC.
#define CLASS_OF
Old name of rb_class_of.
#define rb_ary_new4
Old name of rb_ary_new_from_values.
#define FIX2INT
Old name of RB_FIX2INT.
#define T_MODULE
Old name of RUBY_T_MODULE.
#define ASSUME
Old name of RBIMPL_ASSUME.
#define T_ICLASS
Old name of RUBY_T_ICLASS.
#define ALLOC_N
Old name of RB_ALLOC_N.
#define rb_ary_new3
Old name of rb_ary_new_from_args.
#define CLONESETUP
Old name of rb_clone_setup.
#define Qtrue
Old name of RUBY_Qtrue.
#define ST2FIX
Old name of RB_ST2FIX.
#define Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
#define NIL_P
Old name of RB_NIL_P.
#define T_CLASS
Old name of RUBY_T_CLASS.
#define BUILTIN_TYPE
Old name of RB_BUILTIN_TYPE.
#define Check_TypedStruct(v, t)
Old name of rb_check_typeddata.
#define FL_TEST
Old name of RB_FL_TEST.
#define CONST_ID
Old name of RUBY_CONST_ID.
#define rb_ary_new2
Old name of rb_ary_new_capa.
VALUE rb_eLocalJumpError
LocalJumpError exception.
int rb_typeddata_is_kind_of(VALUE obj, const rb_data_type_t *data_type)
Checks if the given object is of given kind.
VALUE rb_eStandardError
StandardError exception.
VALUE rb_eRangeError
RangeError exception.
VALUE rb_eTypeError
TypeError exception.
void rb_warn(const char *fmt,...)
Identical to rb_warning(), except it reports unless $VERBOSE is nil.
VALUE rb_exc_new_str(VALUE etype, VALUE str)
Identical to rb_exc_new_cstr(), except it takes a Ruby's string instead of C's.
VALUE rb_eException
Mother of all exceptions.
VALUE rb_eSysStackError
SystemStackError exception.
void rb_warning(const char *fmt,...)
Issues a warning.
VALUE rb_cUnboundMethod
UnboundMethod class.
VALUE rb_mKernel
Kernel module.
VALUE rb_cBinding
Binding class.
VALUE rb_obj_class(VALUE obj)
Queries the class of an object.
VALUE rb_inspect(VALUE obj)
Generates a human-readable textual representation of the given object.
VALUE rb_cModule
Module class.
VALUE rb_class_inherited_p(VALUE scion, VALUE ascendant)
Determines if the given two modules are relatives.
VALUE rb_obj_is_kind_of(VALUE obj, VALUE klass)
Queries if the given object is an instance (of possibly descendants) of the given class.
VALUE rb_cProc
Proc class.
VALUE rb_cMethod
Method class.
VALUE rb_obj_setup(VALUE obj, VALUE klass, VALUE type)
Fills common fields in the object.
#define RB_OBJ_WRITTEN(old, oldv, young)
Identical to RB_OBJ_WRITE(), except it doesn't write any values, but only a WB declaration.
#define RB_OBJ_WRITE(old, slot, young)
Declaration of a "back" pointer.
VALUE rb_funcall(VALUE recv, ID mid, int n,...)
Calls a method.
VALUE rb_funcall_with_block_kw(VALUE recv, ID mid, int argc, const VALUE *argv, VALUE procval, int kw_splat)
Identical to rb_funcallv_with_block(), except you can specify how to handle the last element of the g...
#define UNLIMITED_ARGUMENTS
This macro is used in conjunction with rb_check_arity().
#define rb_check_frozen
Just another name of rb_check_frozen.
static int rb_check_arity(int argc, int min, int max)
Ensures that the passed integer is in the passed range.
int rb_is_local_id(ID id)
Classifies the given ID, then sees if it is a local variable.
VALUE rb_method_call_with_block(int argc, const VALUE *argv, VALUE recv, VALUE proc)
Identical to rb_proc_call(), except you can additionally pass a proc as a block.
int rb_obj_method_arity(VALUE obj, ID mid)
Identical to rb_mod_method_arity(), except it searches for singleton methods rather than instance met...
VALUE rb_proc_call(VALUE recv, VALUE args)
Evaluates the passed proc with the passed arguments.
VALUE rb_proc_call_with_block_kw(VALUE recv, int argc, const VALUE *argv, VALUE proc, int kw_splat)
Identical to rb_proc_call_with_block(), except you can specify how to handle the last element of the ...
VALUE rb_method_call_kw(int argc, const VALUE *argv, VALUE recv, int kw_splat)
Identical to rb_method_call(), except you can specify how to handle the last element of the given arr...
VALUE rb_obj_method(VALUE recv, VALUE mid)
Creates a method object.
VALUE rb_proc_lambda_p(VALUE recv)
Queries if the given object is a lambda.
VALUE rb_block_proc(void)
Constructs a Proc object from implicitly passed components.
VALUE rb_proc_call_with_block(VALUE recv, int argc, const VALUE *argv, VALUE proc)
Identical to rb_proc_call(), except you can additionally pass another proc object,...
int rb_mod_method_arity(VALUE mod, ID mid)
Queries the number of mandatory arguments of the method defined in the given module.
VALUE rb_method_call_with_block_kw(int argc, const VALUE *argv, VALUE recv, VALUE proc, int kw_splat)
Identical to rb_method_call_with_block(), except you can specify how to handle the last element of th...
VALUE rb_obj_is_method(VALUE recv)
Queries if the given object is a method.
VALUE rb_block_lambda(void)
Identical to rb_proc_new(), except it returns a lambda.
VALUE rb_proc_call_kw(VALUE recv, VALUE args, int kw_splat)
Identical to rb_proc_call(), except you can specify how to handle the last element of the given array...
VALUE rb_binding_new(void)
Snapshots the current execution context and turn it into an instance of rb_cBinding.
int rb_proc_arity(VALUE recv)
Queries the number of mandatory arguments of the given Proc.
VALUE rb_method_call(int argc, const VALUE *argv, VALUE recv)
Evaluates the passed method with the passed arguments.
VALUE rb_obj_is_proc(VALUE recv)
Queries if the given object is a proc.
#define rb_hash_uint(h, i)
Just another name of st_hash_uint.
#define rb_hash_end(h)
Just another name of st_hash_end.
VALUE rb_str_append(VALUE dst, VALUE src)
Identical to rb_str_buf_append(), except it converts the right hand side before concatenating.
st_index_t rb_hash_start(st_index_t i)
Starts a series of hashing.
#define rb_str_cat_cstr(buf, str)
Identical to rb_str_cat(), except it assumes the passed pointer is a pointer to a C string.
void rb_undef_alloc_func(VALUE klass)
Deletes the allocator function of a class.
VALUE rb_check_funcall(VALUE recv, ID mid, int argc, const VALUE *argv)
Identical to rb_funcallv(), except it returns RUBY_Qundef instead of raising rb_eNoMethodError.
int rb_obj_respond_to(VALUE obj, ID mid, int private_p)
Identical to rb_respond_to(), except it additionally takes the visibility parameter.
ID rb_check_id(volatile VALUE *namep)
Detects if the given name is already interned or not.
VALUE rb_iv_get(VALUE obj, const char *name)
Obtains an instance variable.
#define RB_INT2NUM
Just another name of rb_int2num_inline.
#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)
Shim for block function parameters.
rb_block_call_func * rb_block_call_func_t
Shorthand type that represents an iterator-written-in-C function pointer.
VALUE rb_block_call_func(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg))
This is the type of a function that the interpreter expect for C-backended blocks.
#define MEMCPY(p1, p2, type, n)
Handy macro to call memcpy.
#define RB_GC_GUARD(v)
Prevents premature destruction of local objects.
VALUE rb_block_call(VALUE q, ID w, int e, const VALUE *r, type *t, VALUE y)
Call a method with a block.
VALUE rb_proc_new(type *q, VALUE w)
Creates a rb_cProc instance.
void rb_copy_generic_ivar(VALUE clone, VALUE obj)
Copies the list of instance variables.
#define RARRAY_LEN
Just another name of rb_array_len.
static void RARRAY_ASET(VALUE ary, long i, VALUE v)
Assigns an object in an array.
#define RARRAY_AREF(a, i)
#define RARRAY_CONST_PTR
Just another name of rb_array_const_ptr.
static VALUE RBASIC_CLASS(VALUE obj)
Queries the class of an object.
#define RCLASS_SUPER
Just another name of rb_class_get_superclass.
#define RUBY_TYPED_DEFAULT_FREE
This is a value you can set to rb_data_type_struct::dfree.
#define TypedData_Get_Struct(obj, type, data_type, sval)
Obtains a C struct from inside of a wrapper Ruby object.
#define TypedData_Make_Struct(klass, type, data_type, sval)
Identical to TypedData_Wrap_Struct, except it allocates a new data region internally instead of takin...
const char * rb_obj_classname(VALUE obj)
Queries the name of the class of the passed object.
#define RB_PASS_CALLED_KEYWORDS
Pass keywords if current method is called with keywords, useful for argument delegation.
#define RB_NO_KEYWORDS
Do not pass keywords.
static bool RB_SPECIAL_CONST_P(VALUE obj)
Checks if the given object is of enum ruby_special_consts.
#define RTEST
This is an old name of RB_TEST.
#define _(args)
This was a transition path from K&R to ANSI.
This is the struct that holds necessary info for a struct.
rb_cref_t * cref
class reference, should be marked
const rb_iseq_t * iseqptr
iseq pointer, should be separated from iseqval
IFUNC (Internal FUNCtion)
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
#define SIZEOF_VALUE
Identical to sizeof(VALUE), except it is a macro that can also be used inside of preprocessor directi...
uintptr_t VALUE
Type that represents a Ruby object.