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/hash.h"
19#include "internal/object.h"
20#include "internal/proc.h"
21#include "internal/symbol.h"
25#include "ractor_core.h"
48static int method_arity(
VALUE);
49static int method_min_max_arity(
VALUE,
int *max);
54#define IS_METHOD_PROC_IFUNC(ifunc) ((ifunc)->func == bmcall)
57block_mark_and_move(
struct rb_block *block)
59 switch (block->type) {
61 case block_type_ifunc:
64 rb_gc_mark_and_move(&captured->self);
65 rb_gc_mark_and_move(&captured->code.val);
67 rb_gc_mark_and_move((
VALUE *)&captured->ep[VM_ENV_DATA_INDEX_ENV]);
71 case block_type_symbol:
72 rb_gc_mark_and_move(&block->as.symbol);
75 rb_gc_mark_and_move(&block->as.proc);
81proc_mark_and_move(
void *ptr)
84 block_mark_and_move((
struct rb_block *)&proc->block);
89 VALUE env[VM_ENV_DATA_SIZE + 1];
93proc_memsize(
const void *ptr)
96 if (proc->block.as.captured.ep == ((
const cfunc_proc_t *)ptr)->env+1)
109 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED
113rb_proc_alloc(
VALUE klass)
127proc_clone(
VALUE self)
129 VALUE procval = rb_proc_dup(self);
130 return rb_obj_clone_setup(self, procval,
Qnil);
137 VALUE procval = rb_proc_dup(self);
138 return rb_obj_dup_setup(self, procval);
248 GetProcPtr(procval, proc);
250 return RBOOL(proc->is_lambda);
256binding_free(
void *ptr)
258 RUBY_FREE_ENTER(
"binding");
260 RUBY_FREE_LEAVE(
"binding");
264binding_mark_and_move(
void *ptr)
268 block_mark_and_move((
struct rb_block *)&bind->block);
269 rb_gc_mark_and_move((
VALUE *)&bind->pathobj);
273binding_memsize(
const void *ptr)
281 binding_mark_and_move,
284 binding_mark_and_move,
286 0, 0, RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_FREE_IMMEDIATELY
290rb_binding_alloc(
VALUE klass)
296 rb_yjit_collect_binding_alloc();
302binding_copy(
VALUE self)
306 GetBindingPtr(self, src);
307 GetBindingPtr(bindval, dst);
308 rb_vm_block_copy(bindval, &dst->block, &src->block);
310 dst->first_lineno = src->first_lineno;
316binding_dup(
VALUE self)
318 return rb_obj_dup_setup(self, binding_copy(self));
323binding_clone(
VALUE self)
325 return rb_obj_clone_setup(self, binding_copy(self),
Qnil);
332 return rb_vm_make_binding(ec, ec->cfp);
380rb_f_binding(
VALUE self)
402bind_eval(
int argc,
VALUE *argv,
VALUE bindval)
406 rb_scan_args(argc, argv,
"12", &args[0], &args[2], &args[3]);
408 return rb_f_eval(argc+1, args,
Qnil );
412get_local_variable_ptr(
const rb_env_t **envp,
ID lid)
416 if (!VM_ENV_FLAGS(env->ep, VM_FRAME_FLAG_CFRAME)) {
417 if (VM_ENV_FLAGS(env->ep, VM_ENV_FLAG_ISOLATED)) {
423 VM_ASSERT(rb_obj_is_iseq((
VALUE)iseq));
425 const unsigned int local_table_size = ISEQ_BODY(iseq)->local_table_size;
426 for (
unsigned int i=0; i<local_table_size; i++) {
427 if (ISEQ_BODY(iseq)->local_table[i] == lid) {
428 if (ISEQ_BODY(iseq)->local_iseq == iseq &&
429 ISEQ_BODY(iseq)->param.flags.has_block &&
430 (
unsigned int)ISEQ_BODY(iseq)->param.block_start == i) {
431 const VALUE *ep = env->ep;
432 if (!VM_ENV_FLAGS(ep, VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM)) {
433 RB_OBJ_WRITE(env, &env->env[i], rb_vm_bh_to_procval(GET_EC(), VM_ENV_BLOCK_HANDLER(ep)));
434 VM_ENV_FLAGS_SET(ep, VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM);
439 unsigned int last_lvar = env->env_size+VM_ENV_INDEX_LAST_LVAR
441 return &env->env[last_lvar - (local_table_size - i)];
449 }
while ((env = rb_vm_env_prev_env(env)) != NULL);
461check_local_id(
VALUE bindval,
volatile VALUE *pname)
468 rb_name_err_raise(
"wrong local variable name '%1$s' for %2$s",
473 if (!rb_is_local_name(name)) {
474 rb_name_err_raise(
"wrong local variable name '%1$s' for %2$s",
501bind_local_variables(
VALUE bindval)
506 GetBindingPtr(bindval, bind);
507 env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
508 return rb_vm_env_local_variables(env);
512rb_numparam_id_p(
ID id)
514 return (tNUMPARAM_1 << ID_SCOPE_SHIFT) <=
id &&
id < ((tNUMPARAM_1 + 9) << ID_SCOPE_SHIFT);
535bind_local_variable_get(
VALUE bindval,
VALUE sym)
537 ID lid = check_local_id(bindval, &sym);
542 if (!lid)
goto undefined;
543 if (rb_numparam_id_p(lid)) {
544 rb_name_err_raise(
"numbered parameter '%1$s' is not a local variable",
548 GetBindingPtr(bindval, bind);
550 env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
551 if ((ptr = get_local_variable_ptr(&env, lid)) != NULL) {
557 rb_name_err_raise(
"local variable '%1$s' is not defined for %2$s",
590 ID lid = check_local_id(bindval, &sym);
595 if (!lid) lid = rb_intern_str(sym);
596 if (rb_numparam_id_p(lid)) {
597 rb_name_err_raise(
"numbered parameter '%1$s' is not a local variable",
601 GetBindingPtr(bindval, bind);
602 env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
603 if ((ptr = get_local_variable_ptr(&env, lid)) == NULL) {
605 ptr = rb_binding_add_dynavars(bindval, bind, 1, &lid);
606 env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
610 rb_yjit_collect_binding_set();
636bind_local_variable_defined_p(
VALUE bindval,
VALUE sym)
638 ID lid = check_local_id(bindval, &sym);
644 GetBindingPtr(bindval, bind);
645 env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
646 return RBOOL(get_local_variable_ptr(&env, lid));
656bind_receiver(
VALUE bindval)
659 GetBindingPtr(bindval, bind);
660 return vm_block_self(&bind->block);
670bind_location(
VALUE bindval)
674 GetBindingPtr(bindval, bind);
675 loc[0] = pathobj_path(bind->pathobj);
676 loc[1] =
INT2FIX(bind->first_lineno);
690 proc = &sproc->basic;
691 vm_block_type_set(&proc->block, block_type_ifunc);
693 *(
VALUE **)&proc->block.as.captured.ep = ep = sproc->env + VM_ENV_DATA_SIZE-1;
694 ep[VM_ENV_DATA_INDEX_FLAGS] = VM_FRAME_MAGIC_IFUNC | VM_FRAME_FLAG_CFRAME | VM_ENV_FLAG_LOCAL | VM_ENV_FLAG_ESCAPED;
695 ep[VM_ENV_DATA_INDEX_ME_CREF] =
Qfalse;
696 ep[VM_ENV_DATA_INDEX_SPECVAL] = VM_BLOCK_HANDLER_NONE;
697 ep[VM_ENV_DATA_INDEX_ENV] =
Qundef;
700 RB_OBJ_WRITE(procval, &proc->block.as.captured.code.ifunc, ifunc);
702 proc->is_lambda = TRUE;
707rb_func_proc_dup(
VALUE src_obj)
709 RUBY_ASSERT(rb_typeddata_is_instance_of(src_obj, &proc_data_type));
712 GetProcPtr(src_obj, src_proc);
713 RUBY_ASSERT(vm_block_type(&src_proc->block) == block_type_ifunc);
718 memcpy(&proc->basic, src_proc,
sizeof(
rb_proc_t));
722 const VALUE *src_ep = src_proc->block.as.captured.ep;
723 VALUE *ep = *(
VALUE **)&proc->basic.block.as.captured.ep = proc->env + VM_ENV_DATA_SIZE - 1;
724 ep[VM_ENV_DATA_INDEX_FLAGS] = src_ep[VM_ENV_DATA_INDEX_FLAGS];
725 ep[VM_ENV_DATA_INDEX_ME_CREF] = src_ep[VM_ENV_DATA_INDEX_ME_CREF];
726 ep[VM_ENV_DATA_INDEX_SPECVAL] = src_ep[VM_ENV_DATA_INDEX_SPECVAL];
727 RB_OBJ_WRITE(proc_obj, &ep[VM_ENV_DATA_INDEX_ENV], src_ep[VM_ENV_DATA_INDEX_ENV]);
735 VALUE procval = rb_proc_alloc(klass);
737 GetProcPtr(procval, proc);
739 vm_block_type_set(&proc->block, block_type_symbol);
741 proc->is_lambda = TRUE;
751 min_argc >= (
int)(1U << (
SIZEOF_VALUE * CHAR_BIT) / 2) ||
754 rb_raise(
rb_eRangeError,
"minimum argument number out of range: %d",
759 max_argc >= (
int)(1U << (
SIZEOF_VALUE * CHAR_BIT) / 2) ||
762 rb_raise(
rb_eRangeError,
"maximum argument number out of range: %d",
767 struct vm_ifunc *ifunc = IMEMO_NEW(
struct vm_ifunc, imemo_ifunc, (
VALUE)rb_vm_svar_lep(ec, ec->cfp));
770 ifunc->argc.min = min_argc;
771 ifunc->argc.max = max_argc;
779 struct vm_ifunc *ifunc = rb_vm_ifunc_new(func, (
void *)val, min_argc, max_argc);
783static const char proc_without_block[] =
"tried to create Proc object without a block";
786proc_new(
VALUE klass, int8_t is_lambda)
793 if ((block_handler = rb_vm_frame_block_handler(cfp)) == VM_BLOCK_HANDLER_NONE) {
794 rb_raise(rb_eArgError, proc_without_block);
798 switch (vm_block_handler_type(block_handler)) {
799 case block_handler_type_proc:
800 procval = VM_BH_TO_PROC(block_handler);
806 VALUE newprocval = rb_proc_dup(procval);
807 RBASIC_SET_CLASS(newprocval, klass);
812 case block_handler_type_symbol:
814 sym_proc_new(klass, VM_BH_TO_SYMBOL(block_handler)) :
815 rb_sym_to_proc(VM_BH_TO_SYMBOL(block_handler));
818 case block_handler_type_ifunc:
819 case block_handler_type_iseq:
820 return rb_vm_make_proc_lambda(ec, VM_BH_TO_CAPT_BLOCK(block_handler), klass, is_lambda);
822 VM_UNREACHABLE(proc_new);
841rb_proc_s_new(
int argc,
VALUE *argv,
VALUE klass)
843 VALUE block = proc_new(klass, FALSE);
875f_lambda_filter_non_literal(
void)
878 VALUE block_handler = rb_vm_frame_block_handler(cfp);
880 if (block_handler == VM_BLOCK_HANDLER_NONE) {
885 switch (vm_block_handler_type(block_handler)) {
886 case block_handler_type_iseq:
887 if (RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)->ep == VM_BH_TO_ISEQ_BLOCK(block_handler)->ep) {
891 case block_handler_type_symbol:
893 case block_handler_type_proc:
898 case block_handler_type_ifunc:
902 rb_raise(rb_eArgError,
"the lambda method requires a literal block");
916 f_lambda_filter_non_literal();
972proc_call(
int argc,
VALUE *argv,
VALUE procval)
978#if SIZEOF_LONG > SIZEOF_INT
982 if (argc > INT_MAX || argc < 0) {
983 rb_raise(rb_eArgError,
"too many arguments (%lu)",
984 (
unsigned long)argc);
989#define check_argc(argc) (argc)
999 GetProcPtr(self, proc);
1000 vret = rb_vm_invoke_proc(GET_EC(), proc, argc, argv,
1001 kw_splat, VM_BLOCK_HANDLER_NONE);
1014proc_to_block_handler(
VALUE procval)
1016 return NIL_P(procval) ? VM_BLOCK_HANDLER_NONE : procval;
1025 GetProcPtr(self, proc);
1026 vret = rb_vm_invoke_proc(ec, proc, argc, argv, kw_splat, proc_to_block_handler(passed_procval));
1080proc_arity(
VALUE self)
1087rb_iseq_min_max_arity(
const rb_iseq_t *iseq,
int *max)
1089 *max = ISEQ_BODY(iseq)->param.flags.has_rest == FALSE ?
1090 ISEQ_BODY(iseq)->param.lead_num + ISEQ_BODY(iseq)->param.opt_num + ISEQ_BODY(iseq)->param.post_num +
1091 (ISEQ_BODY(iseq)->param.flags.has_kw == TRUE || ISEQ_BODY(iseq)->param.flags.has_kwrest == TRUE || ISEQ_BODY(iseq)->param.flags.forwardable == TRUE)
1093 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);
1097rb_vm_block_min_max_arity(
const struct rb_block *block,
int *max)
1100 switch (vm_block_type(block)) {
1101 case block_type_iseq:
1102 return rb_iseq_min_max_arity(rb_iseq_check(block->as.captured.code.iseq), max);
1103 case block_type_proc:
1104 block = vm_proc_block(block->as.proc);
1106 case block_type_ifunc:
1108 const struct vm_ifunc *ifunc = block->as.captured.code.ifunc;
1109 if (IS_METHOD_PROC_IFUNC(ifunc)) {
1111 return method_min_max_arity((
VALUE)ifunc->data, max);
1113 *max = ifunc->argc.max;
1114 return ifunc->argc.min;
1116 case block_type_symbol:
1131rb_proc_min_max_arity(
VALUE self,
int *max)
1134 GetProcPtr(self, proc);
1135 return rb_vm_block_min_max_arity(&proc->block, max);
1143 GetProcPtr(self, proc);
1144 min = rb_vm_block_min_max_arity(&proc->block, &max);
1151 switch (vm_block_handler_type(block_handler)) {
1152 case block_handler_type_iseq:
1153 block->type = block_type_iseq;
1154 block->as.captured = *VM_BH_TO_ISEQ_BLOCK(block_handler);
1156 case block_handler_type_ifunc:
1157 block->type = block_type_ifunc;
1158 block->as.captured = *VM_BH_TO_IFUNC_BLOCK(block_handler);
1160 case block_handler_type_symbol:
1161 block->type = block_type_symbol;
1162 block->as.symbol = VM_BH_TO_SYMBOL(block_handler);
1164 case block_handler_type_proc:
1165 block->type = block_type_proc;
1166 block->as.proc = VM_BH_TO_PROC(block_handler);
1171rb_block_pair_yield_optimizable(
void)
1176 VALUE block_handler = rb_vm_frame_block_handler(cfp);
1179 if (block_handler == VM_BLOCK_HANDLER_NONE) {
1180 rb_raise(rb_eArgError,
"no block given");
1183 block_setup(&block, block_handler);
1184 min = rb_vm_block_min_max_arity(&block, &max);
1186 switch (vm_block_type(&block)) {
1187 case block_type_symbol:
1190 case block_type_proc:
1192 VALUE procval = block_handler;
1194 GetProcPtr(procval, proc);
1195 if (proc->is_lambda)
return 0;
1196 if (min != max)
return 0;
1200 case block_type_ifunc:
1202 const struct vm_ifunc *ifunc = block.as.captured.code.ifunc;
1203 if (ifunc->flags & IFUNC_YIELD_OPTIMIZABLE)
return 1;
1217 VALUE block_handler = rb_vm_frame_block_handler(cfp);
1220 if (block_handler == VM_BLOCK_HANDLER_NONE) {
1221 rb_raise(rb_eArgError,
"no block given");
1224 block_setup(&block, block_handler);
1226 switch (vm_block_type(&block)) {
1227 case block_type_symbol:
1230 case block_type_proc:
1234 min = rb_vm_block_min_max_arity(&block, &max);
1240rb_block_min_max_arity(
int *max)
1244 VALUE block_handler = rb_vm_frame_block_handler(cfp);
1247 if (block_handler == VM_BLOCK_HANDLER_NONE) {
1248 rb_raise(rb_eArgError,
"no block given");
1251 block_setup(&block, block_handler);
1252 return rb_vm_block_min_max_arity(&block, max);
1256rb_proc_get_iseq(
VALUE self,
int *is_proc)
1261 GetProcPtr(self, proc);
1262 block = &proc->block;
1263 if (is_proc) *is_proc = !proc->is_lambda;
1265 switch (vm_block_type(block)) {
1266 case block_type_iseq:
1267 return rb_iseq_check(block->as.captured.code.iseq);
1268 case block_type_proc:
1269 return rb_proc_get_iseq(block->as.proc, is_proc);
1270 case block_type_ifunc:
1272 const struct vm_ifunc *ifunc = block->as.captured.code.ifunc;
1273 if (IS_METHOD_PROC_IFUNC(ifunc)) {
1275 if (is_proc) *is_proc = 0;
1276 return rb_method_iseq((
VALUE)ifunc->data);
1282 case block_type_symbol:
1286 VM_UNREACHABLE(rb_proc_get_iseq);
1319 const rb_proc_t *self_proc, *other_proc;
1320 const struct rb_block *self_block, *other_block;
1326 GetProcPtr(self, self_proc);
1327 GetProcPtr(other, other_proc);
1329 if (self_proc->is_from_method != other_proc->is_from_method ||
1330 self_proc->is_lambda != other_proc->is_lambda) {
1334 self_block = &self_proc->block;
1335 other_block = &other_proc->block;
1337 if (vm_block_type(self_block) != vm_block_type(other_block)) {
1341 switch (vm_block_type(self_block)) {
1342 case block_type_iseq:
1343 if (self_block->as.captured.ep != \
1344 other_block->as.captured.ep ||
1345 self_block->as.captured.code.iseq != \
1346 other_block->as.captured.code.iseq) {
1350 case block_type_ifunc:
1351 if (self_block->as.captured.code.ifunc != \
1352 other_block->as.captured.code.ifunc) {
1363 case block_type_proc:
1364 if (self_block->as.proc != other_block->as.proc) {
1368 case block_type_symbol:
1369 if (self_block->as.symbol != other_block->as.symbol) {
1384 if (!iseq)
return Qnil;
1385 rb_iseq_check(iseq);
1386 loc[i++] = rb_iseq_path(iseq);
1400 return iseq_location(iseq);
1419rb_proc_location(
VALUE self)
1421 return iseq_location(rb_proc_get_iseq(self, 0));
1425rb_unnamed_parameters(
int arity)
1428 int n = (arity < 0) ? ~arity : arity;
1462rb_proc_parameters(
int argc,
VALUE *argv,
VALUE self)
1464 static ID keyword_ids[1];
1470 iseq = rb_proc_get_iseq(self, &is_proc);
1472 if (!keyword_ids[0]) {
1473 CONST_ID(keyword_ids[0],
"lambda");
1480 if (!
NIL_P(lambda)) {
1481 is_proc = !
RTEST(lambda);
1488 return rb_iseq_parameters(iseq, is_proc);
1492rb_hash_proc(st_index_t hash,
VALUE prc)
1495 GetProcPtr(prc, proc);
1497 switch (vm_block_type(&proc->block)) {
1498 case block_type_iseq:
1499 hash = rb_st_hash_uint(hash, (st_index_t)proc->block.as.captured.code.iseq->body);
1501 case block_type_ifunc:
1502 hash = rb_st_hash_uint(hash, (st_index_t)proc->block.as.captured.code.ifunc->func);
1503 hash = rb_st_hash_uint(hash, (st_index_t)proc->block.as.captured.code.ifunc->data);
1505 case block_type_symbol:
1506 hash = rb_st_hash_uint(hash, rb_any_hash(proc->block.as.symbol));
1508 case block_type_proc:
1509 hash = rb_st_hash_uint(hash, rb_any_hash(proc->block.as.proc));
1512 rb_bug(
"rb_hash_proc: unknown block type %d", vm_block_type(&proc->block));
1518 if (vm_block_type(&proc->block) != block_type_ifunc) {
1519 hash =
rb_hash_uint(hash, (st_index_t)proc->block.as.captured.ep);
1542rb_sym_to_proc(
VALUE sym)
1544 enum {SYM_PROC_CACHE_SIZE = 67};
1546 if (rb_ractor_main_p()) {
1547 if (!sym_proc_cache) {
1553 long index = (
id % SYM_PROC_CACHE_SIZE);
1555 if (
RTEST(procval)) {
1557 GetProcPtr(procval, proc);
1559 if (proc->block.as.symbol == sym) {
1564 procval = sym_proc_new(
rb_cProc, sym);
1570 return sym_proc_new(
rb_cProc, sym);
1584proc_hash(
VALUE self)
1588 hash = rb_hash_proc(hash, self);
1594rb_block_to_s(
VALUE self,
const struct rb_block *block,
const char *additional_info)
1597 VALUE str = rb_sprintf(
"#<%"PRIsVALUE
":", cname);
1600 switch (vm_block_type(block)) {
1601 case block_type_proc:
1602 block = vm_proc_block(block->as.proc);
1604 case block_type_iseq:
1606 const rb_iseq_t *iseq = rb_iseq_check(block->as.captured.code.iseq);
1607 rb_str_catf(str,
"%p %"PRIsVALUE
":%d", (
void *)self,
1609 ISEQ_BODY(iseq)->location.first_lineno);
1612 case block_type_symbol:
1613 rb_str_catf(str,
"%p(&%+"PRIsVALUE
")", (
void *)self, block->as.symbol);
1615 case block_type_ifunc:
1616 rb_str_catf(str,
"%p", (
void *)block->as.captured.code.ifunc);
1634proc_to_s(
VALUE self)
1637 GetProcPtr(self, proc);
1638 return rb_block_to_s(self, &proc->block, proc->is_lambda ?
" (lambda)" : NULL);
1650proc_to_proc(
VALUE self)
1656bm_mark_and_move(
void *ptr)
1658 struct METHOD *data = ptr;
1659 rb_gc_mark_and_move((
VALUE *)&data->recv);
1660 rb_gc_mark_and_move((
VALUE *)&data->klass);
1661 rb_gc_mark_and_move((
VALUE *)&data->iclass);
1662 rb_gc_mark_and_move((
VALUE *)&data->owner);
1674 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_EMBEDDABLE
1687 ID rmiss = idRespond_to_missing;
1689 if (UNDEF_P(obj))
return 0;
1690 if (rb_method_basic_definition_p(klass, rmiss))
return 0;
1708 def->type = VM_METHOD_TYPE_MISSING;
1709 def->original_id = id;
1711 me = rb_method_entry_create(
id, klass, METHOD_VISI_UNDEF, def);
1723 if (!respond_to_missing_p(klass, obj, vid, scope))
return Qfalse;
1724 return mnew_missing(klass, obj,
SYM2ID(vid), mclass);
1734 rb_method_visibility_t visi = METHOD_VISI_UNDEF;
1737 if (UNDEFINED_METHOD_ENTRY_P(me)) {
1738 if (respond_to_missing_p(klass, obj,
ID2SYM(
id), scope)) {
1739 return mnew_missing(klass, obj,
id, mclass);
1741 if (!error)
return Qnil;
1742 rb_print_undef(klass,
id, METHOD_VISI_UNDEF);
1744 if (visi == METHOD_VISI_UNDEF) {
1745 visi = METHOD_ENTRY_VISI(me);
1747 if (scope && (visi != METHOD_VISI_PUBLIC)) {
1748 if (!error)
return Qnil;
1749 rb_print_inaccessible(klass,
id, visi);
1752 if (me->def->type == VM_METHOD_TYPE_ZSUPER) {
1753 if (me->defined_class) {
1755 id = me->def->original_id;
1756 me = (
rb_method_entry_t *)rb_callable_method_entry_with_refinements(klass,
id, &iclass);
1760 id = me->def->original_id;
1761 me = rb_method_entry_without_refinements(klass,
id, &iclass);
1777 RB_OBJ_WRITE(method, &data->owner, original_me->owner);
1787 return mnew_internal(me, klass, iclass, obj,
id, mclass, scope, TRUE);
1797 me = (
rb_method_entry_t *)rb_callable_method_entry_with_refinements(klass,
id, &iclass);
1798 return mnew_from_me(me, klass, iclass, obj,
id, mclass, scope);
1802mnew_unbound(
VALUE klass,
ID id,
VALUE mclass,
int scope)
1807 me = rb_method_entry_with_refinements(klass,
id, &iclass);
1808 return mnew_from_me(me, klass, iclass,
Qundef,
id, mclass, scope);
1814 VALUE defined_class = me->defined_class;
1815 return defined_class ? defined_class : me->owner;
1860 VALUE klass1, klass2;
1868 m1 = (
struct METHOD *)RTYPEDDATA_GET_DATA(method);
1869 m2 = (
struct METHOD *)RTYPEDDATA_GET_DATA(other);
1871 klass1 = method_entry_defined_class(m1->me);
1872 klass2 = method_entry_defined_class(m2->me);
1874 if (!rb_method_entry_eq(m1->me, m2->me) ||
1876 m1->klass != m2->klass ||
1877 m1->recv != m2->recv) {
1898#define unbound_method_eq method_eq
1910method_hash(
VALUE method)
1917 hash = rb_hash_method_entry(hash, m->me);
1933method_unbind(
VALUE obj)
1936 struct METHOD *orig, *data;
1940 &method_data_type, data);
1945 RB_OBJ_WRITE(method, &data->me, rb_method_entry_clone(orig->me));
1960method_receiver(
VALUE obj)
1976method_name(
VALUE obj)
1981 return ID2SYM(data->me->called_id);
1998method_original_name(
VALUE obj)
2003 return ID2SYM(data->me->def->original_id);
2025method_owner(
VALUE obj)
2039method_namespace(
VALUE obj)
2045 ns = data->me->def->ns;
2047 if (ns->ns_object)
return ns->ns_object;
2049 rb_bug(
"Unexpected namespace on the method definition: %p", (
void*) ns);
2056#define MSG(s) rb_fstring_lit("undefined method '%1$s' for"s" '%2$s'")
2060 if (RCLASS_SINGLETON_P(c)) {
2061 VALUE obj = RCLASS_ATTACHED_OBJECT(klass);
2078 rb_name_err_raise_str(s, c, str);
2090 VALUE m = mnew_missing_by_name(klass, obj, &vid, scope, mclass);
2092 rb_method_name_error(klass, vid);
2094 return mnew_callable(klass, obj,
id, mclass, scope);
2139 return obj_method(obj, vid, FALSE);
2152 return obj_method(obj, vid, TRUE);
2156rb_obj_singleton_method_lookup(
VALUE arg)
2163rb_obj_singleton_method_lookup_fail(
VALUE arg1,
VALUE arg2)
2200 NIL_P(klass = RCLASS_ORIGIN(sc)) ||
2201 !
NIL_P(rb_special_singleton_class(obj))) {
2210 VALUE args[2] = {obj, vid};
2211 VALUE ruby_method =
rb_rescue(rb_obj_singleton_method_lookup, (
VALUE)args, rb_obj_singleton_method_lookup_fail,
Qfalse);
2213 struct METHOD *method = (
struct METHOD *)RTYPEDDATA_GET_DATA(ruby_method);
2216 VALUE method_class = method->iclass;
2220 if (lookup_class == method_class) {
2224 }
while (lookup_class && lookup_class != stop_class);
2230 rb_name_err_raise(
"undefined singleton method '%1$s' for '%2$s'",
2271 rb_method_name_error(mod, vid);
2284rb_mod_public_instance_method(
VALUE mod,
VALUE vid)
2288 rb_method_name_error(mod, vid);
2299 int is_method = FALSE;
2318 "wrong argument type %s (expected Proc/Method/UnboundMethod)",
2325 struct METHOD *method = (
struct METHOD *)RTYPEDDATA_GET_DATA(body);
2328 if (RCLASS_SINGLETON_P(method->me->owner)) {
2330 "can't bind singleton method to a different class");
2334 "bind argument must be a subclass of % "PRIsVALUE,
2338 rb_method_entry_set(mod,
id, method->me, scope_visi->method_visi);
2339 if (scope_visi->module_func) {
2345 VALUE procval = rb_proc_dup(body);
2346 if (vm_proc_iseq(procval) != NULL) {
2348 GetProcPtr(procval, proc);
2349 proc->is_lambda = TRUE;
2350 proc->is_from_method = TRUE;
2352 rb_add_method(mod,
id, VM_METHOD_TYPE_BMETHOD, (
void *)procval, scope_visi->method_visi);
2353 if (scope_visi->module_func) {
2354 rb_add_method(
rb_singleton_class(mod),
id, VM_METHOD_TYPE_BMETHOD, (
void *)body, METHOD_VISI_PUBLIC);
2402rb_mod_define_method(
int argc,
VALUE *argv,
VALUE mod)
2404 const rb_cref_t *cref = rb_vm_cref_in_context(mod, mod);
2409 scope_visi = CREF_SCOPE_VISI(cref);
2412 return rb_mod_define_method_with_visibility(argc, argv, mod, scope_visi);
2447rb_obj_define_method(
int argc,
VALUE *argv,
VALUE obj)
2452 return rb_mod_define_method_with_visibility(argc, argv, klass, &scope_visi);
2463top_define_method(
int argc,
VALUE *argv,
VALUE obj)
2465 return rb_mod_define_method(argc, argv, rb_top_main_class(
"define_method"));
2486method_clone(
VALUE self)
2489 struct METHOD *orig, *data;
2493 rb_obj_clone_setup(self, clone,
Qnil);
2498 RB_OBJ_WRITE(clone, &data->me, rb_method_entry_clone(orig->me));
2504method_dup(
VALUE self)
2507 struct METHOD *orig, *data;
2511 rb_obj_dup_setup(self, clone);
2516 RB_OBJ_WRITE(clone, &data->me, rb_method_entry_clone(orig->me));
2564rb_method_call_pass_called_kw(
int argc,
const VALUE *argv,
VALUE method)
2584method_callable_method_entry(
const struct METHOD *data)
2586 if (data->me->defined_class == 0) rb_bug(
"method_callable_method_entry: not callable.");
2592 int argc,
const VALUE *argv,
VALUE passed_procval,
int kw_splat)
2594 vm_passed_block_handler_set(ec, proc_to_block_handler(passed_procval));
2595 return rb_vm_call_kw(ec, data->recv, data->me->called_id, argc, argv,
2596 method_callable_method_entry(data), kw_splat);
2602 const struct METHOD *data;
2606 if (UNDEF_P(data->recv)) {
2607 rb_raise(
rb_eTypeError,
"can't call unbound method; bind first");
2609 return call_method_data(ec, data, argc, argv, passed_procval, kw_splat);
2676 VALUE methclass = data->owner;
2677 VALUE iclass = data->me->defined_class;
2681 VALUE refined_class = rb_refinement_module_get_refined_class(methclass);
2682 if (!
NIL_P(refined_class)) methclass = refined_class;
2685 if (RCLASS_SINGLETON_P(methclass)) {
2687 "singleton method called for a different object");
2690 rb_raise(
rb_eTypeError,
"bind argument must be an instance of % "PRIsVALUE,
2697 me = rb_method_entry_clone(data->me);
2707 me = rb_method_entry_clone(me);
2709 VALUE ic = rb_class_search_ancestor(klass, me->owner);
2715 klass = rb_include_class_new(methclass, klass);
2717 me = (
const rb_method_entry_t *) rb_method_entry_complement_defined_class(me, me->called_id, klass);
2720 *methclass_out = methclass;
2722 *iclass_out = iclass;
2764 VALUE methclass, klass, iclass;
2766 const struct METHOD *data;
2768 convert_umethod_to_method_components(data, recv, &methclass, &klass, &iclass, &me,
true);
2790umethod_bind_call(
int argc,
VALUE *argv,
VALUE method)
2793 VALUE recv = argv[0];
2800 const struct METHOD *data;
2805 vm_passed_block_handler_set(ec, proc_to_block_handler(passed_procval));
2809 VALUE methclass, klass, iclass;
2811 convert_umethod_to_method_components(data, recv, &methclass, &klass, &iclass, &me,
false);
2812 struct METHOD bound = { recv, klass, 0, methclass, me };
2827 if (!def)
return *max = 0;
2828 switch (def->type) {
2829 case VM_METHOD_TYPE_CFUNC:
2830 if (def->body.cfunc.argc < 0) {
2834 return *max = check_argc(def->body.cfunc.argc);
2835 case VM_METHOD_TYPE_ZSUPER:
2838 case VM_METHOD_TYPE_ATTRSET:
2840 case VM_METHOD_TYPE_IVAR:
2842 case VM_METHOD_TYPE_ALIAS:
2843 def = def->body.alias.original_me->def;
2845 case VM_METHOD_TYPE_BMETHOD:
2846 return rb_proc_min_max_arity(def->body.bmethod.proc, max);
2847 case VM_METHOD_TYPE_ISEQ:
2848 return rb_iseq_min_max_arity(rb_iseq_check(def->body.iseq.
iseqptr), max);
2849 case VM_METHOD_TYPE_UNDEF:
2850 case VM_METHOD_TYPE_NOTIMPLEMENTED:
2852 case VM_METHOD_TYPE_MISSING:
2855 case VM_METHOD_TYPE_OPTIMIZED: {
2856 switch (def->body.optimized.type) {
2857 case OPTIMIZED_METHOD_TYPE_SEND:
2860 case OPTIMIZED_METHOD_TYPE_CALL:
2863 case OPTIMIZED_METHOD_TYPE_BLOCK_CALL:
2866 case OPTIMIZED_METHOD_TYPE_STRUCT_AREF:
2869 case OPTIMIZED_METHOD_TYPE_STRUCT_ASET:
2877 case VM_METHOD_TYPE_REFINED:
2881 rb_bug(
"method_def_min_max_arity: invalid method entry type (%d)", def->type);
2888 int max, min = method_def_min_max_arity(def, &max);
2889 return min == max ? min : -min-1;
2895 return method_def_arity(me->def);
2942method_arity_m(
VALUE method)
2944 int n = method_arity(method);
2949method_arity(
VALUE method)
2954 return rb_method_entry_arity(data->me);
2958original_method_entry(
VALUE mod,
ID id)
2962 while ((me = rb_method_entry(mod,
id)) != 0) {
2964 if (def->type != VM_METHOD_TYPE_ZSUPER)
break;
2966 id = def->original_id;
2972method_min_max_arity(
VALUE method,
int *max)
2974 const struct METHOD *data;
2977 return method_def_min_max_arity(data->me->def, max);
2985 return rb_method_entry_arity(me);
2995rb_callable_receiver(
VALUE callable)
2998 VALUE binding = proc_binding(callable);
2999 return rb_funcall(binding, rb_intern(
"receiver"), 0);
3002 return method_receiver(callable);
3010rb_method_def(
VALUE method)
3012 const struct METHOD *data;
3015 return data->me->def;
3021 switch (def->type) {
3022 case VM_METHOD_TYPE_ISEQ:
3023 return rb_iseq_check(def->body.iseq.
iseqptr);
3024 case VM_METHOD_TYPE_BMETHOD:
3025 return rb_proc_get_iseq(def->body.bmethod.proc, 0);
3026 case VM_METHOD_TYPE_ALIAS:
3027 return method_def_iseq(def->body.alias.original_me->def);
3028 case VM_METHOD_TYPE_CFUNC:
3029 case VM_METHOD_TYPE_ATTRSET:
3030 case VM_METHOD_TYPE_IVAR:
3031 case VM_METHOD_TYPE_ZSUPER:
3032 case VM_METHOD_TYPE_UNDEF:
3033 case VM_METHOD_TYPE_NOTIMPLEMENTED:
3034 case VM_METHOD_TYPE_OPTIMIZED:
3035 case VM_METHOD_TYPE_MISSING:
3036 case VM_METHOD_TYPE_REFINED:
3043rb_method_iseq(
VALUE method)
3045 return method_def_iseq(rb_method_def(method));
3049method_cref(
VALUE method)
3054 switch (def->type) {
3055 case VM_METHOD_TYPE_ISEQ:
3056 return def->body.iseq.
cref;
3057 case VM_METHOD_TYPE_ALIAS:
3058 def = def->body.alias.original_me->def;
3068 if (def->type == VM_METHOD_TYPE_ATTRSET || def->type == VM_METHOD_TYPE_IVAR) {
3069 if (!def->body.attr.location)
3073 return iseq_location(method_def_iseq(def));
3079 if (!me)
return Qnil;
3080 return method_def_location(me->def);
3099rb_method_location(
VALUE method)
3101 return method_def_location(rb_method_def(method));
3105vm_proc_method_def(
VALUE procval)
3111 GetProcPtr(procval, proc);
3112 block = &proc->block;
3114 if (vm_block_type(block) == block_type_ifunc &&
3115 IS_METHOD_PROC_IFUNC(ifunc = block->as.captured.code.ifunc)) {
3116 return rb_method_def((
VALUE)ifunc->data);
3129 switch (def->type) {
3130 case VM_METHOD_TYPE_ISEQ:
3131 iseq = method_def_iseq(def);
3132 return rb_iseq_parameters(iseq, 0);
3133 case VM_METHOD_TYPE_BMETHOD:
3134 if ((iseq = method_def_iseq(def)) != NULL) {
3135 return rb_iseq_parameters(iseq, 0);
3137 else if ((bmethod_def = vm_proc_method_def(def->body.bmethod.proc)) != NULL) {
3138 return method_def_parameters(bmethod_def);
3142 case VM_METHOD_TYPE_ALIAS:
3143 return method_def_parameters(def->body.alias.original_me->def);
3145 case VM_METHOD_TYPE_OPTIMIZED:
3146 if (def->body.optimized.type == OPTIMIZED_METHOD_TYPE_STRUCT_ASET) {
3147 VALUE param = rb_ary_new_from_args(2,
ID2SYM(rb_intern(
"req")),
ID2SYM(rb_intern(
"_")));
3148 return rb_ary_new_from_args(1, param);
3152 case VM_METHOD_TYPE_CFUNC:
3153 case VM_METHOD_TYPE_ATTRSET:
3154 case VM_METHOD_TYPE_IVAR:
3155 case VM_METHOD_TYPE_ZSUPER:
3156 case VM_METHOD_TYPE_UNDEF:
3157 case VM_METHOD_TYPE_NOTIMPLEMENTED:
3158 case VM_METHOD_TYPE_MISSING:
3159 case VM_METHOD_TYPE_REFINED:
3163 return rb_unnamed_parameters(method_def_arity(def));
3187rb_method_parameters(
VALUE method)
3189 return method_def_parameters(rb_method_def(method));
3226method_inspect(
VALUE method)
3230 const char *sharp =
"#";
3232 VALUE defined_class;
3235 str = rb_sprintf(
"#<% "PRIsVALUE
": ",
rb_obj_class(method));
3237 mklass = data->iclass;
3238 if (!mklass) mklass = data->klass;
3248 if (data->me->def->type == VM_METHOD_TYPE_ALIAS) {
3249 defined_class = data->me->def->body.alias.original_me->owner;
3252 defined_class = method_entry_defined_class(data->me);
3259 if (UNDEF_P(data->recv)) {
3263 else if (RCLASS_SINGLETON_P(mklass)) {
3264 VALUE v = RCLASS_ATTACHED_OBJECT(mklass);
3266 if (UNDEF_P(data->recv)) {
3269 else if (data->recv == v) {
3282 mklass = data->klass;
3283 if (RCLASS_SINGLETON_P(mklass)) {
3284 VALUE v = RCLASS_ATTACHED_OBJECT(mklass);
3292 if (defined_class != mklass) {
3293 rb_str_catf(str,
"(% "PRIsVALUE
")", defined_class);
3298 if (data->me->called_id != data->me->def->original_id) {
3299 rb_str_catf(str,
"(%"PRIsVALUE
")",
3300 rb_id2str(data->me->def->original_id));
3302 if (data->me->def->type == VM_METHOD_TYPE_NOTIMPLEMENTED) {
3308 VALUE params = rb_method_parameters(method);
3309 VALUE pair, name, kind;
3315 const VALUE keyrest =
ID2SYM(rb_intern(
"keyrest"));
3332 for (
int i = 0; i <
RARRAY_LEN(params); i++) {
3339 if (kind == req || kind == opt) {
3342 else if (kind == rest || kind == keyrest) {
3345 else if (kind == block) {
3348 else if (kind == nokey) {
3354 rb_str_catf(str,
"%"PRIsVALUE, name);
3356 else if (kind == opt) {
3357 rb_str_catf(str,
"%"PRIsVALUE
"=...", name);
3359 else if (kind == keyreq) {
3360 rb_str_catf(str,
"%"PRIsVALUE
":", name);
3362 else if (kind == key) {
3363 rb_str_catf(str,
"%"PRIsVALUE
": ...", name);
3365 else if (kind == rest) {
3366 if (name ==
ID2SYM(
'*')) {
3370 rb_str_catf(str,
"*%"PRIsVALUE, name);
3373 else if (kind == keyrest) {
3374 if (name !=
ID2SYM(idPow)) {
3375 rb_str_catf(str,
"**%"PRIsVALUE, name);
3384 else if (kind == block) {
3385 if (name ==
ID2SYM(
'&')) {
3394 rb_str_catf(str,
"&%"PRIsVALUE, name);
3397 else if (kind == nokey) {
3409 VALUE loc = rb_method_location(method);
3411 rb_str_catf(str,
" %"PRIsVALUE
":%"PRIsVALUE,
3444method_to_proc(
VALUE method)
3458 procval =
rb_block_call(rb_mRubyVMFrozenCore, idLambda, 0, 0, bmcall, method);
3459 GetProcPtr(procval, proc);
3460 proc->is_from_method = 1;
3464extern VALUE rb_find_defined_class_by_owner(
VALUE current_class,
VALUE target_owner);
3475method_super_method(
VALUE method)
3477 const struct METHOD *data;
3478 VALUE super_class, iclass;
3483 iclass = data->iclass;
3484 if (!iclass)
return Qnil;
3485 if (data->me->def->type == VM_METHOD_TYPE_ALIAS && data->me->defined_class) {
3486 super_class =
RCLASS_SUPER(rb_find_defined_class_by_owner(data->me->defined_class,
3487 data->me->def->body.alias.original_me->owner));
3488 mid = data->me->def->body.alias.original_me->def->original_id;
3492 mid = data->me->def->original_id;
3494 if (!super_class)
return Qnil;
3495 me = (
rb_method_entry_t *)rb_callable_method_entry_with_refinements(super_class, mid, &iclass);
3496 if (!me)
return Qnil;
3497 return mnew_internal(me, me->owner, iclass, data->recv, mid,
rb_obj_class(method), FALSE, FALSE);
3507localjump_xvalue(
VALUE exc)
3521localjump_reason(
VALUE exc)
3526rb_cref_t *rb_vm_cref_new_toplevel(
void);
3535 VM_ASSERT(env->ep > env->env);
3536 VM_ASSERT(VM_ENV_ESCAPED_P(env->ep));
3539 cref = rb_vm_cref_new_toplevel();
3543 new_ep = &new_body[env->ep - env->env];
3544 new_env = vm_env_new(new_ep, new_body, env->env_size, env->iseq);
3551 new_ep[VM_ENV_DATA_INDEX_ENV] = (
VALUE)new_env;
3553 VM_ASSERT(VM_ENV_ESCAPED_P(new_ep));
3571proc_binding(
VALUE self)
3580 GetProcPtr(self, proc);
3581 block = &proc->block;
3583 if (proc->is_isolated) rb_raise(rb_eArgError,
"Can't create Binding from isolated Proc");
3586 switch (vm_block_type(block)) {
3587 case block_type_iseq:
3588 iseq = block->as.captured.code.iseq;
3589 binding_self = block->as.captured.self;
3590 env = VM_ENV_ENVVAL_PTR(block->as.captured.ep);
3592 case block_type_proc:
3593 GetProcPtr(block->as.proc, proc);
3594 block = &proc->block;
3596 case block_type_ifunc:
3598 const struct vm_ifunc *ifunc = block->as.captured.code.ifunc;
3599 if (IS_METHOD_PROC_IFUNC(ifunc)) {
3601 VALUE name = rb_fstring_lit(
"<empty_iseq>");
3603 binding_self = method_receiver(method);
3604 iseq = rb_method_iseq(method);
3605 env = VM_ENV_ENVVAL_PTR(block->as.captured.ep);
3606 env = env_clone(env, method_cref(method));
3608 empty = rb_iseq_new(
Qnil, name, name,
Qnil, 0, ISEQ_TYPE_TOP);
3614 case block_type_symbol:
3615 rb_raise(rb_eArgError,
"Can't create Binding from C level Proc");
3620 GetBindingPtr(bindval, bind);
3621 RB_OBJ_WRITE(bindval, &bind->block.as.captured.self, binding_self);
3622 RB_OBJ_WRITE(bindval, &bind->block.as.captured.code.iseq, env->iseq);
3623 rb_vm_block_ep_update(bindval, &bind->block, env->ep);
3627 rb_iseq_check(iseq);
3628 RB_OBJ_WRITE(bindval, &bind->pathobj, ISEQ_BODY(iseq)->location.pathobj);
3629 bind->first_lineno = ISEQ_BODY(iseq)->location.first_lineno;
3633 rb_iseq_pathobj_new(rb_fstring_lit(
"(binding)"),
Qnil));
3634 bind->first_lineno = 1;
3649 GetProcPtr(proc, procp);
3650 is_lambda = procp->is_lambda;
3654 GetProcPtr(proc, procp);
3655 procp->is_lambda = is_lambda;
3662 VALUE proc, passed, arity;
3671 if (!
NIL_P(blockarg)) {
3672 rb_warn(
"given block not used");
3674 arity = make_curry_proc(proc, passed, arity);
3729proc_curry(
int argc,
const VALUE *argv,
VALUE self)
3731 int sarity, max_arity, min_arity = rb_proc_min_max_arity(self, &max_arity);
3744 return make_curry_proc(self,
rb_ary_new(), arity);
3780rb_method_curry(
int argc,
const VALUE *argv,
VALUE self)
3782 VALUE proc = method_to_proc(self);
3783 return proc_curry(argc, argv, proc);
3801 return rb_funcallv(f, idCall, 1, &fargs);
3812 mesg = rb_fstring_lit(
"callable object is expected");
3836 return rb_proc_compose_to_left(self, to_callable(g));
3842 VALUE proc, args, procs[2];
3848 args = rb_ary_tmp_new_from_values(0, 2, procs);
3851 GetProcPtr(g, procp);
3852 is_lambda = procp->is_lambda;
3860 GetProcPtr(proc, procp);
3861 procp->is_lambda = is_lambda;
3895 return rb_proc_compose_to_right(self, to_callable(g));
3901 VALUE proc, args, procs[2];
3907 args = rb_ary_tmp_new_from_values(0, 2, procs);
3909 GetProcPtr(self, procp);
3910 is_lambda = procp->is_lambda;
3913 GetProcPtr(proc, procp);
3914 procp->is_lambda = is_lambda;
3936rb_method_compose_to_left(
VALUE self,
VALUE g)
3939 self = method_to_proc(self);
3940 return proc_compose_to_left(self, g);
3960rb_method_compose_to_right(
VALUE self,
VALUE g)
3963 self = method_to_proc(self);
3964 return proc_compose_to_right(self, g);
4000proc_ruby2_keywords(
VALUE procval)
4003 GetProcPtr(procval, proc);
4005 rb_check_frozen(procval);
4007 if (proc->is_from_method) {
4008 rb_warn(
"Skipping set of ruby2_keywords flag for proc (proc created from method)");
4012 switch (proc->block.type) {
4013 case block_type_iseq:
4014 if (ISEQ_BODY(proc->block.as.captured.code.iseq)->param.flags.has_rest &&
4015 !ISEQ_BODY(proc->block.as.captured.code.iseq)->param.flags.has_post &&
4016 !ISEQ_BODY(proc->block.as.captured.code.iseq)->param.flags.has_kw &&
4017 !ISEQ_BODY(proc->block.as.captured.code.iseq)->param.flags.has_kwrest) {
4018 ISEQ_BODY(proc->block.as.captured.code.iseq)->param.flags.ruby2_keywords = 1;
4021 rb_warn(
"Skipping set of ruby2_keywords flag for proc (proc accepts keywords or post arguments or proc does not accept argument splat)");
4025 rb_warn(
"Skipping set of ruby2_keywords flag for proc (proc not defined in Ruby)");
4447 rb_add_method_optimized(
rb_cProc, idCall, OPTIMIZED_METHOD_TYPE_CALL, 0, METHOD_VISI_PUBLIC);
4448 rb_add_method_optimized(
rb_cProc, rb_intern(
"[]"), OPTIMIZED_METHOD_TYPE_CALL, 0, METHOD_VISI_PUBLIC);
4449 rb_add_method_optimized(
rb_cProc, rb_intern(
"==="), OPTIMIZED_METHOD_TYPE_CALL, 0, METHOD_VISI_PUBLIC);
4450 rb_add_method_optimized(
rb_cProc, rb_intern(
"yield"), OPTIMIZED_METHOD_TYPE_CALL, 0, METHOD_VISI_PUBLIC);
4484 rb_vm_register_special_exception(ruby_error_sysstack,
rb_eSysStackError,
"stack level too deep");
4553 "define_method", top_define_method, -1);
4594 rb_gc_register_address(&sym_proc_cache);
#define RUBY_ASSERT_ALWAYS(expr,...)
A variant of RUBY_ASSERT that does not interface with RUBY_DEBUG.
#define RUBY_ASSERT(...)
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.
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
VALUE rb_singleton_class(VALUE obj)
Finds or creates the singleton class of the passed 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 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 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 CONST_ID
Old name of RUBY_CONST_ID.
#define rb_ary_new2
Old name of rb_ary_new_capa.
VALUE rb_eLocalJumpError
LocalJumpError exception.
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
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.
VALUE rb_class_superclass(VALUE klass)
Queries the parent of the given class.
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.
#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...
VALUE rb_ary_new_from_values(long n, const VALUE *elts)
Identical to rb_ary_new_from_args(), except how objects are passed.
VALUE rb_ary_dup(VALUE ary)
Duplicates an array.
VALUE rb_ary_plus(VALUE lhs, VALUE rhs)
Creates a new array, concatenating the former to the latter.
VALUE rb_ary_new(void)
Allocates a new, empty array.
VALUE rb_ary_hidden_new(long capa)
Allocates a hidden (no class) empty array.
VALUE rb_ary_push(VALUE ary, VALUE elem)
Special case of rb_ary_cat() that it adds only one element.
VALUE rb_ary_freeze(VALUE obj)
Freeze an array, preventing further modifications.
void rb_ary_store(VALUE ary, long key, VALUE val)
Destructively stores the passed value to the passed array's passed index.
#define UNLIMITED_ARGUMENTS
This macro is used in conjunction with rb_check_arity().
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.
VALUE rb_str_buf_append(VALUE dst, VALUE src)
Identical to rb_str_cat_cstr(), except it takes Ruby's string instead of C's.
void rb_str_set_len(VALUE str, long len)
Overwrites the length of the string.
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.
VALUE rb_str_intern(VALUE str)
Identical to rb_to_symbol(), except it assumes the receiver being an instance of RString.
void rb_undef_alloc_func(VALUE klass)
Deletes the allocator function of a class.
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.
VALUE rb_rescue(type *q, VALUE w, type *e, VALUE r)
An equivalent of rescue clause.
#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.
#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
Internal header for Namespace.
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.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.