12#include "eval_intern.h"
15#include "internal/class.h"
16#include "internal/error.h"
17#include "internal/eval.h"
18#include "internal/object.h"
19#include "internal/proc.h"
20#include "internal/symbol.h"
26#if !defined(__GNUC__) || __GNUC__ < 5 || defined(__MINGW32__)
27# define NO_CLOBBERED(v) (*(volatile VALUE *)&(v))
29# define NO_CLOBBERED(v) (v)
32#define UPDATE_TYPED_REFERENCE(_type, _ref) *(_type*)&_ref = (_type)rb_gc_location((VALUE)_ref)
33#define UPDATE_REFERENCE(_ref) UPDATE_TYPED_REFERENCE(VALUE, _ref)
55static int method_arity(
VALUE);
56static int method_min_max_arity(
VALUE,
int *max);
59#define attached id__attached__
63#define IS_METHOD_PROC_IFUNC(ifunc) ((ifunc)->func == bmcall)
77 RB_FL_TEST_RAW(obj, ~flags));
83block_mark(
const struct rb_block *block)
85 switch (vm_block_type(block)) {
87 case block_type_ifunc:
90 RUBY_MARK_MOVABLE_UNLESS_NULL(captured->self);
91 RUBY_MARK_MOVABLE_UNLESS_NULL((
VALUE)captured->code.val);
92 if (captured->ep && !UNDEF_P(captured->ep[VM_ENV_DATA_INDEX_ENV]) ) {
93 rb_gc_mark(VM_ENV_ENVVAL(captured->ep));
97 case block_type_symbol:
98 RUBY_MARK_MOVABLE_UNLESS_NULL(block->as.symbol);
100 case block_type_proc:
101 RUBY_MARK_MOVABLE_UNLESS_NULL(block->as.proc);
107block_compact(
struct rb_block *block)
109 switch (block->type) {
110 case block_type_iseq:
111 case block_type_ifunc:
114 captured->self = rb_gc_location(captured->self);
115 captured->code.val = rb_gc_location(captured->code.val);
118 case block_type_symbol:
119 block->as.symbol = rb_gc_location(block->as.symbol);
121 case block_type_proc:
122 block->as.proc = rb_gc_location(block->as.proc);
128proc_compact(
void *ptr)
131 block_compact((
struct rb_block *)&proc->block);
138 block_mark(&proc->block);
139 RUBY_MARK_LEAVE(
"proc");
144 VALUE env[VM_ENV_DATA_SIZE + 1];
148proc_memsize(
const void *ptr)
151 if (proc->block.as.captured.ep == ((
const cfunc_proc_t *)ptr)->env+1)
164 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED
168rb_proc_alloc(
VALUE klass)
182proc_clone(
VALUE self)
184 VALUE procval = rb_proc_dup(self);
296 GetProcPtr(procval, proc);
298 return RBOOL(proc->is_lambda);
304binding_free(
void *ptr)
306 RUBY_FREE_ENTER(
"binding");
308 RUBY_FREE_LEAVE(
"binding");
312binding_mark(
void *ptr)
316 RUBY_MARK_ENTER(
"binding");
317 block_mark(&bind->block);
318 rb_gc_mark_movable(bind->pathobj);
319 RUBY_MARK_LEAVE(
"binding");
323binding_compact(
void *ptr)
327 block_compact((
struct rb_block *)&bind->block);
328 UPDATE_REFERENCE(bind->pathobj);
332binding_memsize(
const void *ptr)
345 0, 0, RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_FREE_IMMEDIATELY
349rb_binding_alloc(
VALUE klass)
355 rb_yjit_collect_binding_alloc();
363binding_dup(
VALUE self)
367 GetBindingPtr(self, src);
368 GetBindingPtr(bindval, dst);
369 rb_vm_block_copy(bindval, &dst->block, &src->block);
371 dst->first_lineno = src->first_lineno;
377binding_clone(
VALUE self)
379 VALUE bindval = binding_dup(self);
388 return rb_vm_make_binding(ec, ec->cfp);
408rb_f_binding(
VALUE self)
430bind_eval(
int argc,
VALUE *argv,
VALUE bindval)
434 rb_scan_args(argc, argv,
"12", &args[0], &args[2], &args[3]);
436 return rb_f_eval(argc+1, args,
Qnil );
440get_local_variable_ptr(
const rb_env_t **envp,
ID lid)
444 if (!VM_ENV_FLAGS(env->ep, VM_FRAME_FLAG_CFRAME)) {
445 if (VM_ENV_FLAGS(env->ep, VM_ENV_FLAG_ISOLATED)) {
452 VM_ASSERT(rb_obj_is_iseq((
VALUE)iseq));
454 for (i=0; i<ISEQ_BODY(iseq)->local_table_size; i++) {
455 if (ISEQ_BODY(iseq)->local_table[i] == lid) {
456 if (ISEQ_BODY(iseq)->local_iseq == iseq &&
457 ISEQ_BODY(iseq)->param.flags.has_block &&
458 (
unsigned int)ISEQ_BODY(iseq)->param.block_start == i) {
459 const VALUE *ep = env->ep;
460 if (!VM_ENV_FLAGS(ep, VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM)) {
461 RB_OBJ_WRITE(env, &env->env[i], rb_vm_bh_to_procval(GET_EC(), VM_ENV_BLOCK_HANDLER(ep)));
462 VM_ENV_FLAGS_SET(ep, VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM);
475 }
while ((env = rb_vm_env_prev_env(env)) != NULL);
487check_local_id(
VALUE bindval,
volatile VALUE *pname)
494 rb_name_err_raise(
"wrong local variable name `%1$s' for %2$s",
499 if (!rb_is_local_name(name)) {
500 rb_name_err_raise(
"wrong local variable name `%1$s' for %2$s",
527bind_local_variables(
VALUE bindval)
532 GetBindingPtr(bindval, bind);
533 env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
534 return rb_vm_env_local_variables(env);
555bind_local_variable_get(
VALUE bindval,
VALUE sym)
557 ID lid = check_local_id(bindval, &sym);
562 if (!lid)
goto undefined;
564 GetBindingPtr(bindval, bind);
566 env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
567 if ((ptr = get_local_variable_ptr(&env, lid)) != NULL) {
573 rb_name_err_raise(
"local variable `%1$s' is not defined for %2$s",
606 ID lid = check_local_id(bindval, &sym);
613 GetBindingPtr(bindval, bind);
614 env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
615 if ((ptr = get_local_variable_ptr(&env, lid)) == NULL) {
617 ptr = rb_binding_add_dynavars(bindval, bind, 1, &lid);
618 env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
622 rb_yjit_collect_binding_set();
648bind_local_variable_defined_p(
VALUE bindval,
VALUE sym)
650 ID lid = check_local_id(bindval, &sym);
656 GetBindingPtr(bindval, bind);
657 env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
658 return RBOOL(get_local_variable_ptr(&env, lid));
668bind_receiver(
VALUE bindval)
671 GetBindingPtr(bindval, bind);
672 return vm_block_self(&bind->block);
682bind_location(
VALUE bindval)
686 GetBindingPtr(bindval, bind);
687 loc[0] = pathobj_path(bind->pathobj);
688 loc[1] =
INT2FIX(bind->first_lineno);
701 proc = &sproc->basic;
702 vm_block_type_set(&proc->block, block_type_ifunc);
704 *(
VALUE **)&proc->block.as.captured.ep = ep = sproc->env + VM_ENV_DATA_SIZE-1;
705 ep[VM_ENV_DATA_INDEX_FLAGS] = VM_FRAME_MAGIC_IFUNC | VM_FRAME_FLAG_CFRAME | VM_ENV_FLAG_LOCAL | VM_ENV_FLAG_ESCAPED;
706 ep[VM_ENV_DATA_INDEX_ME_CREF] =
Qfalse;
707 ep[VM_ENV_DATA_INDEX_SPECVAL] = VM_BLOCK_HANDLER_NONE;
708 ep[VM_ENV_DATA_INDEX_ENV] =
Qundef;
711 RB_OBJ_WRITE(procval, &proc->block.as.captured.code.ifunc, ifunc);
712 proc->is_lambda = TRUE;
719 VALUE procval = rb_proc_alloc(klass);
721 GetProcPtr(procval, proc);
723 vm_block_type_set(&proc->block, block_type_symbol);
724 proc->is_lambda = TRUE;
739 min_argc >= (
int)(1U << (
SIZEOF_VALUE * CHAR_BIT) / 2) ||
747 max_argc >= (
int)(1U << (
SIZEOF_VALUE * CHAR_BIT) / 2) ||
753 arity.argc.min = min_argc;
754 arity.argc.max = max_argc;
755 VALUE ret = rb_imemo_new(imemo_ifunc, (
VALUE)func, (
VALUE)data, arity.packed, 0);
759MJIT_FUNC_EXPORTED
VALUE
762 struct vm_ifunc *ifunc = rb_vm_ifunc_proc_new(func, (
void *)val);
766MJIT_FUNC_EXPORTED
VALUE
769 struct vm_ifunc *ifunc = rb_vm_ifunc_new(func, (
void *)val, min_argc, max_argc);
773static const char proc_without_block[] =
"tried to create Proc object without a block";
776proc_new(
VALUE klass, int8_t is_lambda, int8_t kernel)
783 if ((block_handler = rb_vm_frame_block_handler(cfp)) == VM_BLOCK_HANDLER_NONE) {
788 switch (vm_block_handler_type(block_handler)) {
789 case block_handler_type_proc:
790 procval = VM_BH_TO_PROC(block_handler);
792 if (RBASIC_CLASS(procval) == klass) {
796 VALUE newprocval = rb_proc_dup(procval);
797 RBASIC_SET_CLASS(newprocval, klass);
802 case block_handler_type_symbol:
804 sym_proc_new(klass, VM_BH_TO_SYMBOL(block_handler)) :
805 rb_sym_to_proc(VM_BH_TO_SYMBOL(block_handler));
808 case block_handler_type_ifunc:
809 return rb_vm_make_proc_lambda(ec, VM_BH_TO_CAPT_BLOCK(block_handler), klass, is_lambda);
810 case block_handler_type_iseq:
814 if (is_lambda && last_ruby_cfp && vm_cfp_forwarded_bh_p(last_ruby_cfp, block_handler)) {
817 return rb_vm_make_proc_lambda(ec, captured, klass, is_lambda);
820 VM_UNREACHABLE(proc_new);
839rb_proc_s_new(
int argc,
VALUE *argv,
VALUE klass)
841 VALUE block = proc_new(klass, FALSE, FALSE);
850 return proc_new(
rb_cProc, FALSE, FALSE);
863 return proc_new(
rb_cProc, FALSE, TRUE);
869 return proc_new(
rb_cProc, TRUE, FALSE);
876 VALUE block_handler = rb_vm_frame_block_handler(cfp);
878 if (block_handler != VM_BLOCK_HANDLER_NONE) {
879 switch (vm_block_handler_type(block_handler)) {
880 case block_handler_type_iseq:
881 if (RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)->ep == VM_BH_TO_ISEQ_BLOCK(block_handler)->ep) {
885 case block_handler_type_symbol:
887 case block_handler_type_proc:
892 case block_handler_type_ifunc:
897 rb_warn_deprecated(
"lambda without a literal block",
"the proc without lambda");
967proc_call(
int argc,
VALUE *argv,
VALUE procval)
973#if SIZEOF_LONG > SIZEOF_INT
977 if (argc > INT_MAX || argc < 0) {
979 (
unsigned long)argc);
984#define check_argc(argc) (argc)
994 GetProcPtr(self, proc);
995 vret = rb_vm_invoke_proc(GET_EC(), proc, argc, argv,
996 kw_splat, VM_BLOCK_HANDLER_NONE);
1009proc_to_block_handler(
VALUE procval)
1011 return NIL_P(procval) ? VM_BLOCK_HANDLER_NONE : procval;
1020 GetProcPtr(self, proc);
1021 vret = rb_vm_invoke_proc(ec, proc, argc, argv, kw_splat, proc_to_block_handler(passed_procval));
1075proc_arity(
VALUE self)
1082rb_iseq_min_max_arity(
const rb_iseq_t *iseq,
int *max)
1084 *max = ISEQ_BODY(iseq)->param.flags.has_rest == FALSE ?
1085 ISEQ_BODY(iseq)->param.lead_num + ISEQ_BODY(iseq)->param.opt_num + ISEQ_BODY(iseq)->param.post_num +
1086 (ISEQ_BODY(iseq)->param.flags.has_kw == TRUE || ISEQ_BODY(iseq)->param.flags.has_kwrest == TRUE)
1088 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);
1092rb_vm_block_min_max_arity(
const struct rb_block *block,
int *max)
1095 switch (vm_block_type(block)) {
1096 case block_type_iseq:
1097 return rb_iseq_min_max_arity(rb_iseq_check(block->as.captured.code.iseq), max);
1098 case block_type_proc:
1099 block = vm_proc_block(block->as.proc);
1101 case block_type_ifunc:
1103 const struct vm_ifunc *ifunc = block->as.captured.code.ifunc;
1104 if (IS_METHOD_PROC_IFUNC(ifunc)) {
1106 return method_min_max_arity((
VALUE)ifunc->data, max);
1108 *max = ifunc->argc.max;
1109 return ifunc->argc.min;
1111 case block_type_symbol:
1126rb_proc_min_max_arity(
VALUE self,
int *max)
1129 GetProcPtr(self, proc);
1130 return rb_vm_block_min_max_arity(&proc->block, max);
1138 GetProcPtr(self, proc);
1139 min = rb_vm_block_min_max_arity(&proc->block, &max);
1146 switch (vm_block_handler_type(block_handler)) {
1147 case block_handler_type_iseq:
1148 block->type = block_type_iseq;
1149 block->as.captured = *VM_BH_TO_ISEQ_BLOCK(block_handler);
1151 case block_handler_type_ifunc:
1152 block->type = block_type_ifunc;
1153 block->as.captured = *VM_BH_TO_IFUNC_BLOCK(block_handler);
1155 case block_handler_type_symbol:
1156 block->type = block_type_symbol;
1157 block->as.symbol = VM_BH_TO_SYMBOL(block_handler);
1159 case block_handler_type_proc:
1160 block->type = block_type_proc;
1161 block->as.proc = VM_BH_TO_PROC(block_handler);
1166rb_block_pair_yield_optimizable(
void)
1171 VALUE block_handler = rb_vm_frame_block_handler(cfp);
1174 if (block_handler == VM_BLOCK_HANDLER_NONE) {
1178 block_setup(&block, block_handler);
1179 min = rb_vm_block_min_max_arity(&block, &max);
1181 switch (vm_block_type(&block)) {
1182 case block_handler_type_symbol:
1185 case block_handler_type_proc:
1187 VALUE procval = block_handler;
1189 GetProcPtr(procval, proc);
1190 if (proc->is_lambda)
return 0;
1191 if (min != max)
return 0;
1206 VALUE block_handler = rb_vm_frame_block_handler(cfp);
1209 if (block_handler == VM_BLOCK_HANDLER_NONE) {
1213 block_setup(&block, block_handler);
1215 switch (vm_block_type(&block)) {
1216 case block_handler_type_symbol:
1219 case block_handler_type_proc:
1223 min = rb_vm_block_min_max_arity(&block, &max);
1229rb_block_min_max_arity(
int *max)
1233 VALUE block_handler = rb_vm_frame_block_handler(cfp);
1236 if (block_handler == VM_BLOCK_HANDLER_NONE) {
1240 block_setup(&block, block_handler);
1241 return rb_vm_block_min_max_arity(&block, max);
1245rb_proc_get_iseq(
VALUE self,
int *is_proc)
1250 GetProcPtr(self, proc);
1251 block = &proc->block;
1252 if (is_proc) *is_proc = !proc->is_lambda;
1254 switch (vm_block_type(block)) {
1255 case block_type_iseq:
1256 return rb_iseq_check(block->as.captured.code.iseq);
1257 case block_type_proc:
1258 return rb_proc_get_iseq(block->as.proc, is_proc);
1259 case block_type_ifunc:
1261 const struct vm_ifunc *ifunc = block->as.captured.code.ifunc;
1262 if (IS_METHOD_PROC_IFUNC(ifunc)) {
1264 if (is_proc) *is_proc = 0;
1265 return rb_method_iseq((
VALUE)ifunc->data);
1271 case block_type_symbol:
1275 VM_UNREACHABLE(rb_proc_get_iseq);
1308 const rb_proc_t *self_proc, *other_proc;
1309 const struct rb_block *self_block, *other_block;
1315 GetProcPtr(self, self_proc);
1316 GetProcPtr(other, other_proc);
1318 if (self_proc->is_from_method != other_proc->is_from_method ||
1319 self_proc->is_lambda != other_proc->is_lambda) {
1323 self_block = &self_proc->block;
1324 other_block = &other_proc->block;
1326 if (vm_block_type(self_block) != vm_block_type(other_block)) {
1330 switch (vm_block_type(self_block)) {
1331 case block_type_iseq:
1332 if (self_block->as.captured.ep != \
1333 other_block->as.captured.ep ||
1334 self_block->as.captured.code.iseq != \
1335 other_block->as.captured.code.iseq) {
1339 case block_type_ifunc:
1340 if (self_block->as.captured.ep != \
1341 other_block->as.captured.ep ||
1342 self_block->as.captured.code.ifunc != \
1343 other_block->as.captured.code.ifunc) {
1347 case block_type_proc:
1348 if (self_block->as.proc != other_block->as.proc) {
1352 case block_type_symbol:
1353 if (self_block->as.symbol != other_block->as.symbol) {
1367 if (!iseq)
return Qnil;
1368 rb_iseq_check(iseq);
1369 loc[0] = rb_iseq_path(iseq);
1370 loc[1] =
RB_INT2NUM(ISEQ_BODY(iseq)->location.first_lineno);
1375MJIT_FUNC_EXPORTED
VALUE
1378 return iseq_location(iseq);
1390rb_proc_location(
VALUE self)
1392 return iseq_location(rb_proc_get_iseq(self, 0));
1396rb_unnamed_parameters(
int arity)
1399 int n = (arity < 0) ? ~arity : arity;
1405 rb_ary_push(param, a);
1433rb_proc_parameters(
int argc,
VALUE *argv,
VALUE self)
1435 static ID keyword_ids[1];
1441 iseq = rb_proc_get_iseq(self, &is_proc);
1443 if (!keyword_ids[0]) {
1444 CONST_ID(keyword_ids[0],
"lambda");
1447 rb_scan_args(argc, argv,
"0:", &opt);
1451 if (!
NIL_P(lambda)) {
1452 is_proc = !
RTEST(lambda);
1459 return rb_iseq_parameters(iseq, is_proc);
1463rb_hash_proc(st_index_t hash,
VALUE prc)
1466 GetProcPtr(prc, proc);
1467 hash =
rb_hash_uint(hash, (st_index_t)proc->block.as.captured.code.val);
1468 hash =
rb_hash_uint(hash, (st_index_t)proc->block.as.captured.self);
1469 return rb_hash_uint(hash, (st_index_t)proc->block.as.captured.ep);
1487MJIT_FUNC_EXPORTED
VALUE
1488rb_sym_to_proc(
VALUE sym)
1491 enum {SYM_PROC_CACHE_SIZE = 67};
1496 if (!sym_proc_cache) {
1497 sym_proc_cache = rb_ary_hidden_new(SYM_PROC_CACHE_SIZE * 2);
1498 rb_gc_register_mark_object(sym_proc_cache);
1499 rb_ary_store(sym_proc_cache, SYM_PROC_CACHE_SIZE*2 - 1,
Qnil);
1503 index = (
id % SYM_PROC_CACHE_SIZE) << 1;
1510 RARRAY_ASET(sym_proc_cache, index, sym);
1511 RARRAY_ASET(sym_proc_cache, index + 1, proc);
1526proc_hash(
VALUE self)
1530 hash = rb_hash_proc(hash, self);
1536rb_block_to_s(
VALUE self,
const struct rb_block *block,
const char *additional_info)
1542 switch (vm_block_type(block)) {
1543 case block_type_proc:
1544 block = vm_proc_block(block->as.proc);
1546 case block_type_iseq:
1548 const rb_iseq_t *iseq = rb_iseq_check(block->as.captured.code.iseq);
1549 rb_str_catf(str,
"%p %"PRIsVALUE
":%d", (
void *)self,
1551 ISEQ_BODY(iseq)->location.first_lineno);
1554 case block_type_symbol:
1555 rb_str_catf(str,
"%p(&%+"PRIsVALUE
")", (
void *)self, block->as.symbol);
1557 case block_type_ifunc:
1558 rb_str_catf(str,
"%p", (
void *)block->as.captured.code.ifunc);
1576proc_to_s(
VALUE self)
1579 GetProcPtr(self, proc);
1580 return rb_block_to_s(self, &proc->block, proc->is_lambda ?
" (lambda)" : NULL);
1592proc_to_proc(
VALUE self)
1600 struct METHOD *data = ptr;
1601 rb_gc_mark_movable(data->recv);
1602 rb_gc_mark_movable(data->klass);
1603 rb_gc_mark_movable(data->iclass);
1604 rb_gc_mark_movable(data->owner);
1605 rb_gc_mark_movable((
VALUE)data->me);
1609bm_compact(
void *ptr)
1611 struct METHOD *data = ptr;
1612 UPDATE_REFERENCE(data->recv);
1613 UPDATE_REFERENCE(data->klass);
1614 UPDATE_REFERENCE(data->iclass);
1615 UPDATE_REFERENCE(data->owner);
1620bm_memsize(
const void *ptr)
1622 return sizeof(
struct METHOD);
1633 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
1646 ID rmiss = idRespond_to_missing;
1648 if (UNDEF_P(obj))
return 0;
1649 if (rb_method_basic_definition_p(klass, rmiss))
return 0;
1650 return RTEST(rb_funcall(obj, rmiss, 2, sym, RBOOL(!scope)));
1667 def->type = VM_METHOD_TYPE_MISSING;
1668 def->original_id = id;
1670 me = rb_method_entry_create(
id, klass, METHOD_VISI_UNDEF, def);
1682 if (!respond_to_missing_p(klass, obj, vid, scope))
return Qfalse;
1683 return mnew_missing(klass, obj,
SYM2ID(vid), mclass);
1693 rb_method_visibility_t visi = METHOD_VISI_UNDEF;
1696 if (UNDEFINED_METHOD_ENTRY_P(me)) {
1697 if (respond_to_missing_p(klass, obj,
ID2SYM(
id), scope)) {
1698 return mnew_missing(klass, obj,
id, mclass);
1700 if (!error)
return Qnil;
1701 rb_print_undef(klass,
id, METHOD_VISI_UNDEF);
1703 if (visi == METHOD_VISI_UNDEF) {
1704 visi = METHOD_ENTRY_VISI(me);
1706 if (scope && (visi != METHOD_VISI_PUBLIC)) {
1707 if (!error)
return Qnil;
1708 rb_print_inaccessible(klass,
id, visi);
1711 if (me->def->type == VM_METHOD_TYPE_ZSUPER) {
1712 if (me->defined_class) {
1714 id = me->def->original_id;
1715 me = (
rb_method_entry_t *)rb_callable_method_entry_with_refinements(klass,
id, &iclass);
1719 id = me->def->original_id;
1720 me = rb_method_entry_without_refinements(klass,
id, &iclass);
1736 RB_OBJ_WRITE(method, &data->owner, original_me->owner);
1746 return mnew_internal(me, klass, iclass, obj,
id, mclass, scope, TRUE);
1756 me = (
rb_method_entry_t *)rb_callable_method_entry_with_refinements(klass,
id, &iclass);
1757 return mnew_from_me(me, klass, iclass, obj,
id, mclass, scope);
1761mnew_unbound(
VALUE klass,
ID id,
VALUE mclass,
int scope)
1766 me = rb_method_entry_with_refinements(klass,
id, &iclass);
1767 return mnew_from_me(me, klass, iclass,
Qundef,
id, mclass, scope);
1773 VALUE defined_class = me->defined_class;
1774 return defined_class ? defined_class : me->owner;
1819 VALUE klass1, klass2;
1830 klass1 = method_entry_defined_class(m1->me);
1831 klass2 = method_entry_defined_class(m2->me);
1833 if (!rb_method_entry_eq(m1->me, m2->me) ||
1835 m1->klass != m2->klass ||
1836 m1->recv != m2->recv) {
1857#define unbound_method_eq method_eq
1869method_hash(
VALUE method)
1876 hash = rb_hash_method_entry(hash, m->me);
1892method_unbind(
VALUE obj)
1895 struct METHOD *orig, *data;
1899 &method_data_type, data);
1904 RB_OBJ_WRITE(method, &data->me, rb_method_entry_clone(orig->me));
1919method_receiver(
VALUE obj)
1935method_name(
VALUE obj)
1940 return ID2SYM(data->me->called_id);
1957method_original_name(
VALUE obj)
1962 return ID2SYM(data->me->def->original_id);
1984method_owner(
VALUE obj)
1994#define MSG(s) rb_fstring_lit("undefined method `%1$s' for"s" `%2$s'")
2016 rb_name_err_raise_str(s, c, str);
2028 VALUE m = mnew_missing_by_name(klass, obj, &vid, scope, mclass);
2030 rb_method_name_error(klass, vid);
2032 return mnew_callable(klass, obj,
id, mclass, scope);
2077 return obj_method(obj, vid, FALSE);
2090 return obj_method(obj, vid, TRUE);
2126 else if (
NIL_P(klass = RCLASS_ORIGIN(klass))) {
2138 if (UNDEFINED_METHOD_ENTRY_P(me)) {
2141 else if (UNDEFINED_REFINED_METHOD_P(me->def)) {
2145 return mnew_from_me(me, klass, klass, obj,
id,
rb_cMethod, FALSE);
2150 rb_name_err_raise(
"undefined singleton method `%1$s' for `%2$s'",
2191 rb_method_name_error(mod, vid);
2204rb_mod_public_instance_method(
VALUE mod,
VALUE vid)
2208 rb_method_name_error(mod, vid);
2219 int is_method = FALSE;
2221 rb_check_arity(argc, 1, 2);
2238 "wrong argument type %s (expected Proc/Method/UnboundMethod)",
2246 if (method->me->owner != mod && !RB_TYPE_P(method->me->owner,
T_MODULE) &&
2250 "can't bind singleton method to a different class");
2254 "bind argument must be a subclass of % "PRIsVALUE,
2258 rb_method_entry_set(mod,
id, method->me, scope_visi->method_visi);
2259 if (scope_visi->module_func) {
2265 VALUE procval = rb_proc_dup(body);
2266 if (vm_proc_iseq(procval) != NULL) {
2268 GetProcPtr(procval, proc);
2269 proc->is_lambda = TRUE;
2270 proc->is_from_method = TRUE;
2272 rb_add_method(mod,
id, VM_METHOD_TYPE_BMETHOD, (
void *)procval, scope_visi->method_visi);
2273 if (scope_visi->module_func) {
2274 rb_add_method(
rb_singleton_class(mod),
id, VM_METHOD_TYPE_BMETHOD, (
void *)body, METHOD_VISI_PUBLIC);
2322rb_mod_define_method(
int argc,
VALUE *argv,
VALUE mod)
2324 const rb_cref_t *cref = rb_vm_cref_in_context(mod, mod);
2329 scope_visi = CREF_SCOPE_VISI(cref);
2332 return rb_mod_define_method_with_visibility(argc, argv, mod, scope_visi);
2367rb_obj_define_method(
int argc,
VALUE *argv,
VALUE obj)
2372 return rb_mod_define_method_with_visibility(argc, argv, klass, &scope_visi);
2383top_define_method(
int argc,
VALUE *argv,
VALUE obj)
2388 klass = th->top_wrapper;
2390 rb_warning(
"main.define_method in the wrapped load is effective only in wrapper module");
2395 return rb_mod_define_method(argc, argv, klass);
2416method_clone(
VALUE self)
2419 struct METHOD *orig, *data;
2428 RB_OBJ_WRITE(clone, &data->me, rb_method_entry_clone(orig->me));
2476rb_method_call_pass_called_kw(
int argc,
const VALUE *argv,
VALUE method)
2496method_callable_method_entry(
const struct METHOD *data)
2498 if (data->me->defined_class == 0)
rb_bug(
"method_callable_method_entry: not callable.");
2504 int argc,
const VALUE *argv,
VALUE passed_procval,
int kw_splat)
2506 vm_passed_block_handler_set(ec, proc_to_block_handler(passed_procval));
2507 return rb_vm_call_kw(ec, data->recv, data->me->called_id, argc, argv,
2508 method_callable_method_entry(data), kw_splat);
2514 const struct METHOD *data;
2518 if (UNDEF_P(data->recv)) {
2521 return call_method_data(ec, data, argc, argv, passed_procval, kw_splat);
2588 VALUE methclass = data->owner;
2589 VALUE iclass = data->me->defined_class;
2592 if (RB_TYPE_P(methclass,
T_MODULE)) {
2593 VALUE refined_class = rb_refinement_module_get_refined_class(methclass);
2594 if (!
NIL_P(refined_class)) methclass = refined_class;
2599 "singleton method called for a different object");
2609 me = rb_method_entry_clone(data->me);
2615 if (RB_TYPE_P(me->owner,
T_MODULE)) {
2619 me = rb_method_entry_clone(me);
2627 klass = rb_include_class_new(methclass, klass);
2629 me = (
const rb_method_entry_t *) rb_method_entry_complement_defined_class(me, me->called_id, klass);
2632 *methclass_out = methclass;
2634 *iclass_out = iclass;
2676 VALUE methclass, klass, iclass;
2678 const struct METHOD *data;
2680 convert_umethod_to_method_components(data, recv, &methclass, &klass, &iclass, &me,
true);
2702umethod_bind_call(
int argc,
VALUE *argv,
VALUE method)
2705 VALUE recv = argv[0];
2712 const struct METHOD *data;
2717 vm_passed_block_handler_set(ec, proc_to_block_handler(passed_procval));
2721 VALUE methclass, klass, iclass;
2723 convert_umethod_to_method_components(data, recv, &methclass, &klass, &iclass, &me,
false);
2724 struct METHOD bound = { recv, klass, 0, methclass, me };
2739 if (!def)
return *max = 0;
2740 switch (def->type) {
2741 case VM_METHOD_TYPE_CFUNC:
2742 if (def->body.cfunc.argc < 0) {
2746 return *max = check_argc(def->body.cfunc.argc);
2747 case VM_METHOD_TYPE_ZSUPER:
2750 case VM_METHOD_TYPE_ATTRSET:
2752 case VM_METHOD_TYPE_IVAR:
2754 case VM_METHOD_TYPE_ALIAS:
2755 def = def->body.alias.original_me->def;
2757 case VM_METHOD_TYPE_BMETHOD:
2758 return rb_proc_min_max_arity(def->body.bmethod.proc, max);
2759 case VM_METHOD_TYPE_ISEQ:
2760 return rb_iseq_min_max_arity(rb_iseq_check(def->body.iseq.
iseqptr), max);
2761 case VM_METHOD_TYPE_UNDEF:
2762 case VM_METHOD_TYPE_NOTIMPLEMENTED:
2764 case VM_METHOD_TYPE_MISSING:
2767 case VM_METHOD_TYPE_OPTIMIZED: {
2768 switch (def->body.optimized.type) {
2769 case OPTIMIZED_METHOD_TYPE_SEND:
2772 case OPTIMIZED_METHOD_TYPE_CALL:
2775 case OPTIMIZED_METHOD_TYPE_BLOCK_CALL:
2778 case OPTIMIZED_METHOD_TYPE_STRUCT_AREF:
2781 case OPTIMIZED_METHOD_TYPE_STRUCT_ASET:
2789 case VM_METHOD_TYPE_REFINED:
2793 rb_bug(
"method_def_min_max_arity: invalid method entry type (%d)", def->type);
2800 int max, min = method_def_min_max_arity(def, &max);
2801 return min == max ? min : -min-1;
2807 return method_def_arity(me->def);
2854method_arity_m(
VALUE method)
2856 int n = method_arity(method);
2861method_arity(
VALUE method)
2866 return rb_method_entry_arity(data->me);
2870original_method_entry(
VALUE mod,
ID id)
2874 while ((me = rb_method_entry(mod,
id)) != 0) {
2876 if (def->type != VM_METHOD_TYPE_ZSUPER)
break;
2878 id = def->original_id;
2884method_min_max_arity(
VALUE method,
int *max)
2886 const struct METHOD *data;
2889 return method_def_min_max_arity(data->me->def, max);
2897 return rb_method_entry_arity(me);
2907rb_callable_receiver(
VALUE callable)
2910 VALUE binding = proc_binding(callable);
2911 return rb_funcall(binding, rb_intern(
"receiver"), 0);
2914 return method_receiver(callable);
2922rb_method_def(
VALUE method)
2924 const struct METHOD *data;
2927 return data->me->def;
2933 switch (def->type) {
2934 case VM_METHOD_TYPE_ISEQ:
2935 return rb_iseq_check(def->body.iseq.
iseqptr);
2936 case VM_METHOD_TYPE_BMETHOD:
2937 return rb_proc_get_iseq(def->body.bmethod.proc, 0);
2938 case VM_METHOD_TYPE_ALIAS:
2939 return method_def_iseq(def->body.alias.original_me->def);
2940 case VM_METHOD_TYPE_CFUNC:
2941 case VM_METHOD_TYPE_ATTRSET:
2942 case VM_METHOD_TYPE_IVAR:
2943 case VM_METHOD_TYPE_ZSUPER:
2944 case VM_METHOD_TYPE_UNDEF:
2945 case VM_METHOD_TYPE_NOTIMPLEMENTED:
2946 case VM_METHOD_TYPE_OPTIMIZED:
2947 case VM_METHOD_TYPE_MISSING:
2948 case VM_METHOD_TYPE_REFINED:
2955rb_method_iseq(
VALUE method)
2957 return method_def_iseq(rb_method_def(method));
2961method_cref(
VALUE method)
2966 switch (def->type) {
2967 case VM_METHOD_TYPE_ISEQ:
2968 return def->body.iseq.
cref;
2969 case VM_METHOD_TYPE_ALIAS:
2970 def = def->body.alias.original_me->def;
2980 if (def->type == VM_METHOD_TYPE_ATTRSET || def->type == VM_METHOD_TYPE_IVAR) {
2981 if (!def->body.attr.location)
2983 return rb_ary_dup(def->body.attr.location);
2985 return iseq_location(method_def_iseq(def));
2991 if (!me)
return Qnil;
2992 return method_def_location(me->def);
3004rb_method_location(
VALUE method)
3006 return method_def_location(rb_method_def(method));
3010vm_proc_method_def(
VALUE procval)
3016 GetProcPtr(procval, proc);
3017 block = &proc->block;
3019 if (vm_block_type(block) == block_type_ifunc &&
3020 IS_METHOD_PROC_IFUNC(ifunc = block->as.captured.code.ifunc)) {
3021 return rb_method_def((
VALUE)ifunc->data);
3034 switch (def->type) {
3035 case VM_METHOD_TYPE_ISEQ:
3036 iseq = method_def_iseq(def);
3037 return rb_iseq_parameters(iseq, 0);
3038 case VM_METHOD_TYPE_BMETHOD:
3039 if ((iseq = method_def_iseq(def)) != NULL) {
3040 return rb_iseq_parameters(iseq, 0);
3042 else if ((bmethod_def = vm_proc_method_def(def->body.bmethod.proc)) != NULL) {
3043 return method_def_parameters(bmethod_def);
3047 case VM_METHOD_TYPE_ALIAS:
3048 return method_def_parameters(def->body.alias.original_me->def);
3050 case VM_METHOD_TYPE_OPTIMIZED:
3051 if (def->body.optimized.type == OPTIMIZED_METHOD_TYPE_STRUCT_ASET) {
3052 VALUE param = rb_ary_new_from_args(2,
ID2SYM(rb_intern(
"req")),
ID2SYM(rb_intern(
"_")));
3053 return rb_ary_new_from_args(1, param);
3057 case VM_METHOD_TYPE_CFUNC:
3058 case VM_METHOD_TYPE_ATTRSET:
3059 case VM_METHOD_TYPE_IVAR:
3060 case VM_METHOD_TYPE_ZSUPER:
3061 case VM_METHOD_TYPE_UNDEF:
3062 case VM_METHOD_TYPE_NOTIMPLEMENTED:
3063 case VM_METHOD_TYPE_MISSING:
3064 case VM_METHOD_TYPE_REFINED:
3068 return rb_unnamed_parameters(method_def_arity(def));
3092rb_method_parameters(
VALUE method)
3094 return method_def_parameters(rb_method_def(method));
3131method_inspect(
VALUE method)
3135 const char *sharp =
"#";
3137 VALUE defined_class;
3142 mklass = data->iclass;
3143 if (!mklass) mklass = data->klass;
3150 mklass = RBASIC_CLASS(mklass);
3153 if (data->me->def->type == VM_METHOD_TYPE_ALIAS) {
3154 defined_class = data->me->def->body.alias.original_me->owner;
3157 defined_class = method_entry_defined_class(data->me);
3160 if (RB_TYPE_P(defined_class,
T_ICLASS)) {
3161 defined_class = RBASIC_CLASS(defined_class);
3164 if (data->recv ==
Qundef) {
3171 if (UNDEF_P(data->recv)) {
3174 else if (data->recv == v) {
3187 mklass = data->klass;
3193 }
while (RB_TYPE_P(mklass,
T_ICLASS));
3197 if (defined_class != mklass) {
3198 rb_str_catf(str,
"(% "PRIsVALUE
")", defined_class);
3203 if (data->me->called_id != data->me->def->original_id) {
3205 rb_id2str(data->me->def->original_id));
3207 if (data->me->def->type == VM_METHOD_TYPE_NOTIMPLEMENTED) {
3213 VALUE params = rb_method_parameters(method);
3214 VALUE pair, name, kind;
3220 const VALUE keyrest =
ID2SYM(rb_intern(
"keyrest"));
3237 for (
int i = 0; i <
RARRAY_LEN(params); i++) {
3244 if (kind == req || kind == opt) {
3247 else if (kind == rest || kind == keyrest) {
3250 else if (kind == block) {
3253 else if (kind == nokey) {
3261 else if (kind == opt) {
3264 else if (kind == keyreq) {
3267 else if (kind == key) {
3270 else if (kind == rest) {
3271 if (name ==
ID2SYM(
'*')) {
3278 else if (kind == keyrest) {
3279 if (name !=
ID2SYM(idPow)) {
3289 else if (kind == block) {
3290 if (name ==
ID2SYM(
'&')) {
3302 else if (kind == nokey) {
3314 VALUE loc = rb_method_location(method);
3349method_to_proc(
VALUE method)
3363 procval =
rb_block_call(rb_mRubyVMFrozenCore, idLambda, 0, 0, bmcall, method);
3364 GetProcPtr(procval, proc);
3365 proc->is_from_method = 1;
3369extern VALUE rb_find_defined_class_by_owner(
VALUE current_class,
VALUE target_owner);
3380method_super_method(
VALUE method)
3382 const struct METHOD *data;
3383 VALUE super_class, iclass;
3388 iclass = data->iclass;
3389 if (!iclass)
return Qnil;
3390 if (data->me->def->type == VM_METHOD_TYPE_ALIAS && data->me->defined_class) {
3391 super_class =
RCLASS_SUPER(rb_find_defined_class_by_owner(data->me->defined_class,
3392 data->me->def->body.alias.original_me->owner));
3393 mid = data->me->def->body.alias.original_me->def->original_id;
3397 mid = data->me->def->original_id;
3399 if (!super_class)
return Qnil;
3400 me = (
rb_method_entry_t *)rb_callable_method_entry_with_refinements(super_class, mid, &iclass);
3401 if (!me)
return Qnil;
3402 return mnew_internal(me, me->owner, iclass, data->recv, mid,
rb_obj_class(method), FALSE, FALSE);
3412localjump_xvalue(
VALUE exc)
3426localjump_reason(
VALUE exc)
3431rb_cref_t *rb_vm_cref_new_toplevel(
void);
3440 VM_ASSERT(env->ep > env->env);
3441 VM_ASSERT(VM_ENV_ESCAPED_P(env->ep));
3444 cref = rb_vm_cref_new_toplevel();
3449 new_ep = &new_body[env->ep - env->env];
3450 new_env = vm_env_new(new_ep, new_body, env->env_size, env->iseq);
3452 VM_ASSERT(VM_ENV_ESCAPED_P(new_ep));
3470proc_binding(
VALUE self)
3479 GetProcPtr(self, proc);
3480 block = &proc->block;
3485 switch (vm_block_type(block)) {
3486 case block_type_iseq:
3487 iseq = block->as.captured.code.iseq;
3488 binding_self = block->as.captured.self;
3489 env = VM_ENV_ENVVAL_PTR(block->as.captured.ep);
3491 case block_type_proc:
3492 GetProcPtr(block->as.proc, proc);
3493 block = &proc->block;
3495 case block_type_ifunc:
3497 const struct vm_ifunc *ifunc = block->as.captured.code.ifunc;
3498 if (IS_METHOD_PROC_IFUNC(ifunc)) {
3500 VALUE name = rb_fstring_lit(
"<empty_iseq>");
3502 binding_self = method_receiver(method);
3503 iseq = rb_method_iseq(method);
3504 env = VM_ENV_ENVVAL_PTR(block->as.captured.ep);
3505 env = env_clone(env, method_cref(method));
3507 empty = rb_iseq_new(NULL, name, name,
Qnil, 0, ISEQ_TYPE_TOP);
3513 case block_type_symbol:
3519 GetBindingPtr(bindval, bind);
3520 RB_OBJ_WRITE(bindval, &bind->block.as.captured.self, binding_self);
3521 RB_OBJ_WRITE(bindval, &bind->block.as.captured.code.iseq, env->iseq);
3522 rb_vm_block_ep_update(bindval, &bind->block, env->ep);
3526 rb_iseq_check(iseq);
3527 RB_OBJ_WRITE(bindval, &bind->pathobj, ISEQ_BODY(iseq)->location.pathobj);
3528 bind->first_lineno = ISEQ_BODY(iseq)->location.first_lineno;
3532 rb_iseq_pathobj_new(rb_fstring_lit(
"(binding)"),
Qnil));
3533 bind->first_lineno = 1;
3548 GetProcPtr(proc, procp);
3549 is_lambda = procp->is_lambda;
3550 rb_ary_freeze(passed);
3551 rb_ary_freeze(args);
3553 GetProcPtr(proc, procp);
3554 procp->is_lambda = is_lambda;
3561 VALUE proc, passed, arity;
3566 passed = rb_ary_plus(passed,
rb_ary_new4(argc, argv));
3567 rb_ary_freeze(passed);
3570 if (!
NIL_P(blockarg)) {
3571 rb_warn(
"given block not used");
3573 arity = make_curry_proc(proc, passed, arity);
3628proc_curry(
int argc,
const VALUE *argv,
VALUE self)
3630 int sarity, max_arity, min_arity = rb_proc_min_max_arity(self, &max_arity);
3633 if (rb_check_arity(argc, 0, 1) == 0 ||
NIL_P(arity = argv[0])) {
3639 rb_check_arity(sarity, min_arity, max_arity);
3643 return make_curry_proc(self, rb_ary_new(), arity);
3679rb_method_curry(
int argc,
const VALUE *argv,
VALUE self)
3681 VALUE proc = method_to_proc(self);
3682 return proc_curry(argc, argv, proc);
3700 return rb_funcallv(f, idCall, 1, &fargs);
3711 mesg = rb_fstring_lit(
"callable object is expected");
3735 return rb_proc_compose_to_left(self, to_callable(g));
3741 VALUE proc, args, procs[2];
3747 args = rb_ary_tmp_new_from_values(0, 2, procs);
3750 GetProcPtr(g, procp);
3751 is_lambda = procp->is_lambda;
3759 GetProcPtr(proc, procp);
3760 procp->is_lambda = is_lambda;
3794 return rb_proc_compose_to_right(self, to_callable(g));
3800 VALUE proc, args, procs[2];
3806 args = rb_ary_tmp_new_from_values(0, 2, procs);
3808 GetProcPtr(self, procp);
3809 is_lambda = procp->is_lambda;
3812 GetProcPtr(proc, procp);
3813 procp->is_lambda = is_lambda;
3835rb_method_compose_to_left(
VALUE self,
VALUE g)
3838 self = method_to_proc(self);
3839 return proc_compose_to_left(self, g);
3859rb_method_compose_to_right(
VALUE self,
VALUE g)
3862 self = method_to_proc(self);
3863 return proc_compose_to_right(self, g);
3899proc_ruby2_keywords(
VALUE procval)
3902 GetProcPtr(procval, proc);
3906 if (proc->is_from_method) {
3907 rb_warn(
"Skipping set of ruby2_keywords flag for proc (proc created from method)");
3911 switch (proc->block.type) {
3912 case block_type_iseq:
3913 if (ISEQ_BODY(proc->block.as.captured.code.iseq)->param.flags.has_rest &&
3914 !ISEQ_BODY(proc->block.as.captured.code.iseq)->param.flags.has_kw &&
3915 !ISEQ_BODY(proc->block.as.captured.code.iseq)->param.flags.has_kwrest) {
3916 ISEQ_BODY(proc->block.as.captured.code.iseq)->param.flags.ruby2_keywords = 1;
3919 rb_warn(
"Skipping set of ruby2_keywords flag for proc (proc accepts keywords or proc does not accept argument splat)");
3923 rb_warn(
"Skipping set of ruby2_keywords flag for proc (proc not defined in Ruby)");
4276 rb_add_method_optimized(
rb_cProc, idCall, OPTIMIZED_METHOD_TYPE_CALL, 0, METHOD_VISI_PUBLIC);
4277 rb_add_method_optimized(
rb_cProc, rb_intern(
"[]"), OPTIMIZED_METHOD_TYPE_CALL, 0, METHOD_VISI_PUBLIC);
4278 rb_add_method_optimized(
rb_cProc, rb_intern(
"==="), OPTIMIZED_METHOD_TYPE_CALL, 0, METHOD_VISI_PUBLIC);
4279 rb_add_method_optimized(
rb_cProc, rb_intern(
"yield"), OPTIMIZED_METHOD_TYPE_CALL, 0, METHOD_VISI_PUBLIC);
4313 rb_vm_register_special_exception(ruby_error_sysstack,
rb_eSysStackError,
"stack level too deep");
4378 "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.
@ RUBY_FL_PROMOTED1
This flag has something to do with our garbage collector.
@ RUBY_FL_PROMOTED0
This flag has something to do with our garbage collector.
@ RUBY_FL_EXIVAR
This flag has something to do with instance variables.
@ 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_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.
void rb_raise(VALUE exc, const char *fmt,...)
Exception entry point.
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.
void rb_bug(const char *fmt,...)
Interpreter panic switch.
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 always regardless of runtime -W flag.
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_eArgError
ArgumentError exception.
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_cObject
Documented in include/ruby/internal/globals.h.
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_class_search_ancestor(VALUE klass, VALUE super)
Internal header for Object.
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_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.
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.
VALUE rb_ivar_get(VALUE obj, ID name)
Identical to rb_iv_get(), except it accepts the name as an ID instead of a C string.
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.
ID rb_to_id(VALUE str)
Identical to rb_intern(), except it takes an instance of rb_cString.
ID rb_intern_str(VALUE str)
Identical to rb_intern(), except it takes an instance of rb_cString.
VALUE rb_iv_get(VALUE obj, const char *name)
Obtains an instance variable.
#define RB_INT2NUM
Just another name of rb_int2num_inline.
VALUE rb_sprintf(const char *fmt,...)
Ruby's extended sprintf(3).
VALUE rb_str_catf(VALUE dst, const char *fmt,...)
Identical to rb_sprintf(), except it renders the output to the specified object rather than creating ...
#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.
#define RARRAY_AREF(a, i)
#define RARRAY_CONST_PTR
Just another name of rb_array_const_ptr.
#define RCLASS_SUPER
Just another name of rb_class_get_superclass.
#define DATA_PTR(obj)
Convenient getter macro.
#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.
const rb_iseq_t * iseqptr
iseq pointer, should be separated from iseqval
rb_cref_t * cref
class reference, should be marked
IFUNC (Internal FUNCtion)
uintptr_t VALUE
Type that represents a Ruby object.
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...