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"
22#include "internal/vm.h"
26#include "ractor_core.h"
47static VALUE rb_cSourceRange;
50static int method_arity(
VALUE);
51static int method_min_max_arity(
VALUE,
int *max);
64source_range_memsize(
const void *ptr)
69RUBY_REFERENCES(source_range_refs) = {
78 RUBY_REFS_LIST_PTR(source_range_refs),
93 data->start_line = location->beg_pos.lineno;
94 data->start_column = location->beg_pos.column;
95 data->end_line = location->end_pos.lineno;
96 data->end_column = location->end_pos.column;
109 VALUE path = rb_iseq_path(iseq);
110 VALUE absolute_path = rb_iseq_realpath(iseq);
115 return rb_source_range_new(path, absolute_path, &ISEQ_BODY(iseq)->location.code_location);
119source_range_data_get(
VALUE self)
134source_range_path(
VALUE self)
136 return source_range_data_get(self)->path;
147source_range_absolute_path(
VALUE self)
149 return source_range_data_get(self)->absolute_path;
159source_range_start_line(
VALUE self)
161 return INT2NUM(source_range_data_get(self)->start_line);
176source_range_start_column(
VALUE self)
178 return INT2NUM(source_range_data_get(self)->start_column);
197source_range_end_line(
VALUE self)
199 return INT2NUM(source_range_data_get(self)->end_line);
218source_range_end_column(
VALUE self)
220 return INT2NUM(source_range_data_get(self)->end_column);
231source_range_inspect(
VALUE self)
235 VALUE path =
NIL_P(data->absolute_path) ? data->path : data->absolute_path;
237 VM_ASSERT(!
NIL_P(path));
240 rb_str_catf(str,
":(%d,%d)-(%d,%d)>",
241 data->start_line, data->start_column,
242 data->end_line, data->end_column);
249#define IS_METHOD_PROC_IFUNC(ifunc) ((ifunc)->func == bmcall)
252block_mark_and_move(
struct rb_block *block)
254 switch (block->type) {
255 case block_type_iseq:
256 case block_type_ifunc:
259 rb_gc_mark_and_move(&captured->self);
260 rb_gc_mark_and_move(&captured->code.val);
262 rb_gc_mark_and_move((
VALUE *)&captured->ep[VM_ENV_DATA_INDEX_ENV]);
266 case block_type_symbol:
267 rb_gc_mark_and_move(&block->as.symbol);
269 case block_type_proc:
270 rb_gc_mark_and_move(&block->as.proc);
275static ID id_refinements_recipe;
278proc_mark_and_move(
void *ptr)
281 block_mark_and_move((
struct rb_block *)&proc->block);
284enum refinement_recipe_index {
285 REFINEMENT_RECIPE_BASE_CREF,
286 REFINEMENT_RECIPE_CREF,
287 REFINEMENT_RECIPE_SRC_ISEQ,
288 REFINEMENT_RECIPE_MODS
294 if (r1 == r2)
return true;
297 if (
RARRAY_AREF(r1, REFINEMENT_RECIPE_BASE_CREF) !=
298 RARRAY_AREF(r2, REFINEMENT_RECIPE_BASE_CREF))
return false;
300 RARRAY_AREF(r2, REFINEMENT_RECIPE_SRC_ISEQ))
return false;
301 for (
long i = REFINEMENT_RECIPE_MODS; i <
len; i++) {
308rb_proc_refinements_recipe(
VALUE procval)
311 GetProcPtr(procval, proc);
312 if (!proc->is_refined)
return Qnil;
313 return rb_ivar_get(procval, id_refinements_recipe);
317rb_proc_set_refinements_recipe(
VALUE procval,
VALUE recipe)
320 GetProcPtr(procval, proc);
321 rb_ivar_set(procval, id_refinements_recipe, recipe);
322 proc->is_refined = 1;
327 VALUE env[VM_ENV_DATA_SIZE + 1];
331proc_memsize(
const void *ptr)
334 if (proc->block.as.captured.ep == ((
const cfunc_proc_t *)ptr)->env+1)
347 0, 0, RUBY_TYPED_THREAD_SAFE_FREE | RUBY_TYPED_WB_PROTECTED
350#define proc_data_type ruby_proc_data_type
353rb_proc_alloc(
VALUE klass)
362 return RBOOL(rb_typeddata_is_kind_of(proc, &proc_data_type));
367proc_clone(
VALUE self)
369 VALUE procval = rb_proc_dup_0(self);
370 return rb_obj_clone_setup(self, procval,
Qnil);
377 VALUE procval = rb_proc_dup_0(self);
378 return rb_obj_dup_setup(self, procval);
399enum refinement_memo_index {
400 REFINEMENT_MEMO_RECIPE,
401 REFINEMENT_MEMO_COPIED_ISEQ
404static VALUE refinement_memo_map;
407refinement_memo_get(
const rb_iseq_t *src_iseq)
411 if (refinement_memo_map) {
412 memo = rb_hash_lookup(refinement_memo_map, (
VALUE)src_iseq);
421 VM_ASSERT(ISEQ_BODY(src_iseq)->
type == ISEQ_TYPE_BLOCK);
429 RB_OBJ_SET_SHAREABLE(memo);
433 if (!refinement_memo_map) {
438 if (!refinement_memo_map) {
439 rb_vm_register_global_object(new_map);
440 refinement_memo_map = new_map;
442 rb_hash_aset(refinement_memo_map, (
VALUE)src_iseq, memo);
447refinement_recipe_modc(
VALUE recipe)
449 return NIL_P(recipe) ? 0 :
RARRAY_LEN(recipe) - REFINEMENT_RECIPE_MODS;
454 long argc,
const VALUE *mods)
456 long inherited = refinement_recipe_modc(src_recipe);
457 if (
RARRAY_AREF(recipe, REFINEMENT_RECIPE_BASE_CREF) != (
VALUE)base_cref)
return false;
458 if (refinement_recipe_modc(recipe) != inherited + argc)
return false;
459 for (
long i = 0; i < inherited; i++) {
460 if (
RARRAY_AREF(recipe, REFINEMENT_RECIPE_MODS + i) !=
461 RARRAY_AREF(src_recipe, REFINEMENT_RECIPE_MODS + i))
return false;
463 for (
long i = 0; i < argc; i++) {
464 if (
RARRAY_AREF(recipe, REFINEMENT_RECIPE_MODS + inherited + i) != mods[i])
return false;
472 long argc,
const VALUE *mods)
474 long inherited = refinement_recipe_modc(src_recipe);
479 for (
long i = 0; i < inherited; i++) {
482 for (
long i = 0; i < argc; i++) {
486 RB_OBJ_SET_SHAREABLE(recipe);
492 long argc,
const VALUE *mods)
494 VM_ASSERT(ISEQ_BODY(src_iseq)->
type == ISEQ_TYPE_BLOCK);
495 VALUE memo = refinement_memo_get(src_iseq);
498 if (!refinement_recipe_match(recipe, base_cref, src_recipe, argc, mods))
return Qnil;
503refinement_iseq_copy(
VALUE recipe)
507 VALUE memo = refinement_memo_get(src_iseq);
509 if (refinement_recipe_eq(
RARRAY_AREF(memo, REFINEMENT_MEMO_RECIPE), recipe)) {
512 if (ISEQ_BODY(copied_iseq)->param.flags.ruby2_keywords ==
513 ISEQ_BODY(src_iseq)->param.flags.ruby2_keywords) {
518 "Proc#refined re-copies the block because the ruby2_keywords flag changed after the copy was memoized"
524 "Proc#refined called with different modules for the same block disables memoization"
530 const rb_iseq_t *copied_iseq = rb_iseq_dup_with_independent_caches(src_iseq);
531 refinement_memo_set(src_iseq, recipe, copied_iseq);
535NOINLINE(
static void refinement_iseq_install(
VALUE procval,
rb_proc_t *proc));
540 const rb_iseq_t *copied_iseq = refinement_iseq_copy(recipe);
543 if (!
FL_TEST_RAW((
VALUE)proc->block.as.captured.code.iseq, ISEQ_REFINED_COPY)) {
552 if (UNLIKELY(!
FL_TEST_RAW((
VALUE)proc->block.as.captured.code.iseq, ISEQ_REFINED_COPY))) {
553 refinement_iseq_install(procval, proc);
558rb_proc_refinements_cref_for_call(
VALUE procval)
561 GetProcPtr(procval, proc);
562 if (!proc->is_refined)
return NULL;
564 refinement_iseq_ensure(procval, proc);
623proc_refined(
int argc,
VALUE *argv,
VALUE self)
626 GetProcPtr(self, src);
632 if (vm_block_type(&src->block) != block_type_iseq || src->is_from_method) {
633 rb_raise(rb_eArgError,
"can't apply refinements to a Proc without a Ruby block");
636 for (
int i = 0; i < argc; i++) {
640 const rb_iseq_t *src_iseq = src->block.as.captured.code.iseq;
641 VALUE src_recipe = rb_proc_refinements_recipe(self);
643 if (
NIL_P(src_recipe)) {
644 src_cref = base_cref = rb_vm_get_cref(src->block.as.captured.ep);
660 "Proc#refined on a Proc whose block was already copied by Proc#refined is not memoized"
665 refinement_memo_lookup(src_iseq, base_cref, src_recipe, argc, argv);
667 rb_cref_t *cref = rb_vm_cref_dup(src_cref);
670 for (
int i = 0; i < argc; i++) {
671 rb_using_module_recursive(cref, argv[i]);
676 VALUE refs = CREF_REFINEMENTS(cref);
679 RB_OBJ_SET_SHAREABLE(refs);
681 CREF_OMOD_SHARED_SET(cref);
682 CREF_REFINED_PROC_SET(cref);
683 recipe = refinement_recipe_new(base_cref, cref, src_iseq, src_recipe, argc, argv);
687 rb_iseq_dup_with_independent_caches(src_iseq) : src_iseq;
689 return rb_proc_dup_with_iseq_and_recipe(self, new_iseq, recipe);
799 GetProcPtr(procval, proc);
801 return RBOOL(proc->is_lambda);
807binding_free(
void *ptr)
809 RUBY_FREE_ENTER(
"binding");
811 RUBY_FREE_LEAVE(
"binding");
815binding_mark_and_move(
void *ptr)
819 block_mark_and_move((
struct rb_block *)&bind->block);
820 rb_gc_mark_and_move((
VALUE *)&bind->pathobj);
824binding_memsize(
const void *ptr)
832 binding_mark_and_move,
835 binding_mark_and_move,
837 0, 0, RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_THREAD_SAFE_FREE
841rb_binding_alloc(
VALUE klass)
847 rb_yjit_collect_binding_alloc();
853binding_copy(
VALUE self)
857 GetBindingPtr(self, src);
858 GetBindingPtr(bindval, dst);
859 rb_vm_block_copy(bindval, &dst->block, &src->block);
861 dst->first_lineno = src->first_lineno;
867binding_dup(
VALUE self)
869 return rb_obj_dup_setup(self, binding_copy(self));
874binding_clone(
VALUE self)
876 return rb_obj_clone_setup(self, binding_copy(self),
Qnil);
883 return rb_vm_make_binding(ec, ec->cfp);
931rb_f_binding(
VALUE self)
965bind_eval(
int argc,
VALUE *argv,
VALUE bindval)
969 rb_scan_args(argc, argv,
"12", &args[0], &args[2], &args[3]);
971 return rb_f_eval(argc+1, args,
Qnil );
975get_local_variable_ptr(
const rb_env_t **envp,
ID lid,
bool search_outer)
979 if (!VM_ENV_FLAGS(env->ep, VM_FRAME_FLAG_CFRAME)) {
980 if (VM_ENV_FLAGS(env->ep, VM_ENV_FLAG_ISOLATED)) {
986 VM_ASSERT(rb_obj_is_iseq((
VALUE)iseq));
988 const unsigned int local_table_size = ISEQ_BODY(iseq)->local_table_size;
989 for (
unsigned int i=0; i<local_table_size; i++) {
990 if (ISEQ_BODY(iseq)->local_table[i] == lid) {
991 if (ISEQ_BODY(iseq)->local_iseq == iseq &&
992 ISEQ_BODY(iseq)->param.flags.has_block &&
993 (
unsigned int)ISEQ_BODY(iseq)->param.block_start == i) {
994 const VALUE *ep = env->ep;
995 if (!VM_ENV_FLAGS(ep, VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM)) {
996 RB_OBJ_WRITE(env, &env->env[i], rb_vm_bh_to_procval(GET_EC(), VM_ENV_BLOCK_HANDLER(ep)));
997 VM_ENV_FLAGS_SET(ep, VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM);
1002 unsigned int last_lvar = env->env_size+VM_ENV_INDEX_LAST_LVAR
1004 return &env->env[last_lvar - (local_table_size - i)];
1012 }
while (search_outer && (env = rb_vm_env_prev_env(env)) != NULL);
1024check_local_id(
VALUE bindval,
volatile VALUE *pname)
1027 VALUE name = *pname;
1031 rb_name_err_raise(
"wrong local variable name '%1$s' for %2$s",
1036 if (!rb_is_local_name(name)) {
1037 rb_name_err_raise(
"wrong local variable name '%1$s' for %2$s",
1064bind_local_variables(
VALUE bindval)
1069 GetBindingPtr(bindval, bind);
1070 env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
1071 return rb_vm_env_local_variables(env);
1075rb_numparam_id_p(
ID id)
1077 return (tNUMPARAM_1 << ID_SCOPE_SHIFT) <=
id &&
id < ((tNUMPARAM_1 + 9) << ID_SCOPE_SHIFT);
1081rb_implicit_param_p(
ID id)
1083 return id == idItImplicit || rb_numparam_id_p(
id);
1104bind_local_variable_get(
VALUE bindval,
VALUE sym)
1106 ID lid = check_local_id(bindval, &sym);
1111 if (!lid)
goto undefined;
1112 if (rb_numparam_id_p(lid)) {
1113 rb_name_err_raise(
"numbered parameter '%1$s' is not a local variable",
1117 GetBindingPtr(bindval, bind);
1119 env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
1120 if ((ptr = get_local_variable_ptr(&env, lid, TRUE)) != NULL) {
1126 rb_name_err_raise(
"local variable '%1$s' is not defined for %2$s",
1159 ID lid = check_local_id(bindval, &sym);
1164 if (!lid) lid = rb_intern_str(sym);
1165 if (rb_numparam_id_p(lid)) {
1166 rb_name_err_raise(
"numbered parameter '%1$s' is not a local variable",
1170 GetBindingPtr(bindval, bind);
1171 env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
1172 if ((ptr = get_local_variable_ptr(&env, lid, TRUE)) == NULL) {
1174 ptr = rb_binding_add_dynavars(bindval, bind, 1, &lid);
1175 env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
1179 rb_yjit_collect_binding_set();
1205bind_local_variable_defined_p(
VALUE bindval,
VALUE sym)
1207 ID lid = check_local_id(bindval, &sym);
1212 if (rb_numparam_id_p(lid)) {
1213 rb_name_err_raise(
"numbered parameter '%1$s' is not a local variable",
1217 GetBindingPtr(bindval, bind);
1218 env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
1219 return RBOOL(get_local_variable_ptr(&env, lid, TRUE));
1243bind_implicit_parameters(
VALUE bindval)
1248 GetBindingPtr(bindval, bind);
1249 env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
1251 if (get_local_variable_ptr(&env, idItImplicit, FALSE)) {
1252 return rb_ary_new_from_args(1,
ID2SYM(idIt));
1255 env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
1256 return rb_vm_env_numbered_parameters(env);
1280bind_implicit_parameter_get(
VALUE bindval,
VALUE sym)
1282 ID lid = check_local_id(bindval, &sym);
1287 if (lid == idIt) lid = idItImplicit;
1289 if (!lid || !rb_implicit_param_p(lid)) {
1290 rb_name_err_raise(
"'%1$s' is not an implicit parameter",
1294 GetBindingPtr(bindval, bind);
1296 env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
1297 if ((ptr = get_local_variable_ptr(&env, lid, FALSE)) != NULL) {
1301 if (lid == idItImplicit) lid = idIt;
1302 rb_name_err_raise(
"implicit parameter '%1$s' is not defined for %2$s", bindval,
ID2SYM(lid));
1330bind_implicit_parameter_defined_p(
VALUE bindval,
VALUE sym)
1332 ID lid = check_local_id(bindval, &sym);
1336 if (lid == idIt) lid = idItImplicit;
1338 if (!lid || !rb_implicit_param_p(lid)) {
1339 rb_name_err_raise(
"'%1$s' is not an implicit parameter",
1343 GetBindingPtr(bindval, bind);
1344 env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
1345 return RBOOL(get_local_variable_ptr(&env, lid, FALSE));
1355bind_receiver(
VALUE bindval)
1358 GetBindingPtr(bindval, bind);
1359 return vm_block_self(&bind->block);
1369bind_location(
VALUE bindval)
1373 GetBindingPtr(bindval, bind);
1374 loc[0] = pathobj_path(bind->pathobj);
1375 loc[1] =
INT2FIX(bind->first_lineno);
1388 proc = &sproc->basic;
1389 vm_block_type_set(&proc->block, block_type_ifunc);
1391 *(
VALUE **)&proc->block.as.captured.ep = ep = sproc->env + VM_ENV_DATA_SIZE-1;
1392 ep[VM_ENV_DATA_INDEX_FLAGS] = VM_FRAME_MAGIC_IFUNC | VM_FRAME_FLAG_CFRAME | VM_ENV_FLAG_LOCAL | VM_ENV_FLAG_ESCAPED;
1393 ep[VM_ENV_DATA_INDEX_ME_CREF] =
Qfalse;
1394 ep[VM_ENV_DATA_INDEX_SPECVAL] = VM_BLOCK_HANDLER_NONE;
1395 ep[VM_ENV_DATA_INDEX_ENV] =
Qundef;
1398 RB_OBJ_WRITE(procval, &proc->block.as.captured.code.ifunc, ifunc);
1399 proc->is_lambda = TRUE;
1404rb_func_proc_dup(
VALUE src_obj)
1406 RUBY_ASSERT(rb_typeddata_is_instance_of(src_obj, &proc_data_type));
1409 GetProcPtr(src_obj, src_proc);
1410 RUBY_ASSERT(vm_block_type(&src_proc->block) == block_type_ifunc);
1415 memcpy(&proc->basic, src_proc,
sizeof(
rb_proc_t));
1419 const VALUE *src_ep = src_proc->block.as.captured.ep;
1420 VALUE *ep = *(
VALUE **)&proc->basic.block.as.captured.ep = proc->env + VM_ENV_DATA_SIZE - 1;
1421 ep[VM_ENV_DATA_INDEX_FLAGS] = src_ep[VM_ENV_DATA_INDEX_FLAGS];
1422 ep[VM_ENV_DATA_INDEX_ME_CREF] = src_ep[VM_ENV_DATA_INDEX_ME_CREF];
1423 ep[VM_ENV_DATA_INDEX_SPECVAL] = src_ep[VM_ENV_DATA_INDEX_SPECVAL];
1424 RB_OBJ_WRITE(proc_obj, &ep[VM_ENV_DATA_INDEX_ENV], src_ep[VM_ENV_DATA_INDEX_ENV]);
1432 VALUE procval = rb_proc_alloc(klass);
1434 GetProcPtr(procval, proc);
1436 vm_block_type_set(&proc->block, block_type_symbol);
1437 proc->is_lambda = TRUE;
1447 min_argc >= (
int)(1U << (
SIZEOF_VALUE * CHAR_BIT) / 2) ||
1450 rb_raise(
rb_eRangeError,
"minimum argument number out of range: %d",
1455 max_argc >= (
int)(1U << (
SIZEOF_VALUE * CHAR_BIT) / 2) ||
1458 rb_raise(
rb_eRangeError,
"maximum argument number out of range: %d",
1463 struct vm_ifunc *ifunc = IMEMO_NEW(
struct vm_ifunc, imemo_ifunc, (
VALUE)rb_vm_svar_lep(ec, ec->cfp));
1465 rb_gc_register_pinning_obj((
VALUE)ifunc);
1469 ifunc->argc.min = min_argc;
1470 ifunc->argc.max = max_argc;
1478 struct vm_ifunc *ifunc = rb_vm_ifunc_new(func, (
void *)val, min_argc, max_argc);
1482static const char proc_without_block[] =
"tried to create Proc object without a block";
1485proc_new(
VALUE klass, int8_t is_lambda)
1490 VALUE block_handler;
1492 if ((block_handler = rb_vm_frame_block_handler(cfp)) == VM_BLOCK_HANDLER_NONE) {
1493 rb_raise(rb_eArgError, proc_without_block);
1497 switch (vm_block_handler_type(block_handler)) {
1498 case block_handler_type_proc:
1499 procval = VM_BH_TO_PROC(block_handler);
1505 VALUE newprocval = rb_proc_dup(procval);
1506 RBASIC_SET_CLASS(newprocval, klass);
1511 case block_handler_type_symbol:
1513 sym_proc_new(klass, VM_BH_TO_SYMBOL(block_handler)) :
1514 rb_sym_to_proc(VM_BH_TO_SYMBOL(block_handler));
1517 case block_handler_type_ifunc:
1518 case block_handler_type_iseq:
1519 return rb_vm_make_proc_lambda(ec, VM_BH_TO_CAPT_BLOCK(block_handler), klass, is_lambda);
1521 VM_UNREACHABLE(proc_new);
1540rb_proc_s_new(
int argc,
VALUE *argv,
VALUE klass)
1542 VALUE block = proc_new(klass, FALSE);
1574f_lambda_filter_non_literal(
void)
1577 VALUE block_handler = rb_vm_frame_block_handler(cfp);
1579 if (block_handler == VM_BLOCK_HANDLER_NONE) {
1584 switch (vm_block_handler_type(block_handler)) {
1585 case block_handler_type_iseq:
1586 if (RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)->ep == VM_BH_TO_ISEQ_BLOCK(block_handler)->ep) {
1590 case block_handler_type_symbol:
1592 case block_handler_type_proc:
1597 case block_handler_type_ifunc:
1601 rb_raise(rb_eArgError,
"the lambda method requires a literal block");
1615 f_lambda_filter_non_literal();
1670proc_call(
int argc,
VALUE *argv,
VALUE procval)
1676#if SIZEOF_LONG > SIZEOF_INT
1678check_argc(
long argc)
1680 if (argc > INT_MAX || argc < 0) {
1681 rb_raise(rb_eArgError,
"too many arguments (%lu)",
1682 (
unsigned long)argc);
1687#define check_argc(argc) (argc)
1702 GetProcPtr(self, proc);
1703 vret = rb_vm_invoke_proc(GET_EC(), proc, argc, argv,
1704 kw_splat, VM_BLOCK_HANDLER_NONE,
1705 rb_proc_refinements_cref_for_call(self));
1718proc_to_block_handler(
VALUE procval)
1720 return NIL_P(procval) ? VM_BLOCK_HANDLER_NONE : procval;
1729 GetProcPtr(self, proc);
1730 vret = rb_vm_invoke_proc(ec, proc, argc, argv, kw_splat, proc_to_block_handler(passed_procval),
1731 rb_proc_refinements_cref_for_call(self));
1785proc_arity(
VALUE self)
1792rb_iseq_min_max_arity(
const rb_iseq_t *iseq,
int *max)
1794 *max = ISEQ_BODY(iseq)->param.flags.has_rest == FALSE ?
1795 ISEQ_BODY(iseq)->param.lead_num + ISEQ_BODY(iseq)->param.opt_num + ISEQ_BODY(iseq)->param.post_num +
1796 (ISEQ_BODY(iseq)->param.flags.has_kw == TRUE || ISEQ_BODY(iseq)->param.flags.has_kwrest == TRUE || ISEQ_BODY(iseq)->param.flags.forwardable == TRUE)
1798 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);
1802rb_vm_block_min_max_arity(
const struct rb_block *block,
int *max)
1805 switch (vm_block_type(block)) {
1806 case block_type_iseq:
1807 return rb_iseq_min_max_arity(rb_iseq_check(block->as.captured.code.iseq), max);
1808 case block_type_proc:
1809 block = vm_proc_block(block->as.proc);
1811 case block_type_ifunc:
1813 const struct vm_ifunc *ifunc = block->as.captured.code.ifunc;
1814 if (IS_METHOD_PROC_IFUNC(ifunc)) {
1816 return method_min_max_arity((
VALUE)ifunc->data, max);
1818 *max = ifunc->argc.max;
1819 return ifunc->argc.min;
1821 case block_type_symbol:
1836rb_proc_min_max_arity(
VALUE self,
int *max)
1839 GetProcPtr(self, proc);
1840 return rb_vm_block_min_max_arity(&proc->block, max);
1848 GetProcPtr(self, proc);
1849 min = rb_vm_block_min_max_arity(&proc->block, &max);
1856 switch (vm_block_handler_type(block_handler)) {
1857 case block_handler_type_iseq:
1858 block->type = block_type_iseq;
1859 block->as.captured = *VM_BH_TO_ISEQ_BLOCK(block_handler);
1861 case block_handler_type_ifunc:
1862 block->type = block_type_ifunc;
1863 block->as.captured = *VM_BH_TO_IFUNC_BLOCK(block_handler);
1865 case block_handler_type_symbol:
1866 block->type = block_type_symbol;
1867 block->as.symbol = VM_BH_TO_SYMBOL(block_handler);
1869 case block_handler_type_proc:
1870 block->type = block_type_proc;
1871 block->as.proc = VM_BH_TO_PROC(block_handler);
1876rb_block_pair_yield_optimizable(
void)
1881 VALUE block_handler = rb_vm_frame_block_handler(cfp);
1884 if (block_handler == VM_BLOCK_HANDLER_NONE) {
1885 rb_raise(rb_eArgError,
"no block given");
1888 block_setup(&block, block_handler);
1889 min = rb_vm_block_min_max_arity(&block, &max);
1891 switch (vm_block_type(&block)) {
1892 case block_type_symbol:
1895 case block_type_proc:
1897 VALUE procval = block_handler;
1899 GetProcPtr(procval, proc);
1900 if (proc->is_lambda)
return 0;
1901 if (min != max)
return 0;
1905 case block_type_ifunc:
1907 const struct vm_ifunc *ifunc = block.as.captured.code.ifunc;
1908 if (ifunc->flags & IFUNC_YIELD_OPTIMIZABLE)
return 1;
1922 VALUE block_handler = rb_vm_frame_block_handler(cfp);
1925 if (block_handler == VM_BLOCK_HANDLER_NONE) {
1926 rb_raise(rb_eArgError,
"no block given");
1929 block_setup(&block, block_handler);
1931 switch (vm_block_type(&block)) {
1932 case block_type_symbol:
1935 case block_type_proc:
1939 min = rb_vm_block_min_max_arity(&block, &max);
1945rb_block_min_max_arity(
int *max)
1949 VALUE block_handler = rb_vm_frame_block_handler(cfp);
1952 if (block_handler == VM_BLOCK_HANDLER_NONE) {
1953 rb_raise(rb_eArgError,
"no block given");
1956 block_setup(&block, block_handler);
1957 return rb_vm_block_min_max_arity(&block, max);
1961rb_proc_get_iseq(
VALUE self,
int *is_proc)
1966 GetProcPtr(self, proc);
1967 block = &proc->block;
1968 if (is_proc) *is_proc = !proc->is_lambda;
1970 switch (vm_block_type(block)) {
1971 case block_type_iseq:
1972 return rb_iseq_check(block->as.captured.code.iseq);
1973 case block_type_proc:
1974 return rb_proc_get_iseq(block->as.proc, is_proc);
1975 case block_type_ifunc:
1977 const struct vm_ifunc *ifunc = block->as.captured.code.ifunc;
1978 if (IS_METHOD_PROC_IFUNC(ifunc)) {
1980 if (is_proc) *is_proc = 0;
1981 return rb_method_iseq((
VALUE)ifunc->data);
1987 case block_type_symbol:
1991 VM_UNREACHABLE(rb_proc_get_iseq);
2024 const rb_proc_t *self_proc, *other_proc;
2025 const struct rb_block *self_block, *other_block;
2031 GetProcPtr(self, self_proc);
2032 GetProcPtr(other, other_proc);
2034 if (self_proc->is_from_method != other_proc->is_from_method ||
2035 self_proc->is_lambda != other_proc->is_lambda ||
2036 self_proc->is_refined != other_proc->is_refined) {
2040 self_block = &self_proc->block;
2041 other_block = &other_proc->block;
2043 if (vm_block_type(self_block) != vm_block_type(other_block)) {
2047 switch (vm_block_type(self_block)) {
2048 case block_type_iseq:
2049 if (self_block->as.captured.ep != \
2050 other_block->as.captured.ep) {
2055 if (self_proc->is_refined) {
2056 if (!refinement_recipe_eq(rb_proc_refinements_recipe(self),
2057 rb_proc_refinements_recipe(other))) {
2061 else if (self_block->as.captured.code.iseq != \
2062 other_block->as.captured.code.iseq) {
2066 case block_type_ifunc:
2067 if (self_block->as.captured.code.ifunc != \
2068 other_block->as.captured.code.ifunc) {
2079 case block_type_proc:
2080 if (self_block->as.proc != other_block->as.proc) {
2084 case block_type_symbol:
2085 if (self_block->as.symbol != other_block->as.symbol) {
2099 if (!iseq)
return Qnil;
2100 rb_iseq_check(iseq);
2101 loc[0] = rb_iseq_path(iseq);
2102 loc[1] =
RB_INT2NUM(ISEQ_BODY(iseq)->location.first_lineno);
2110 return iseq_location(iseq);
2122rb_proc_location(
VALUE self)
2124 return iseq_location(rb_proc_get_iseq(self, 0));
2141rb_proc_source_range(
VALUE self)
2143 return source_range_new(rb_proc_get_iseq(self, 0));
2147rb_unnamed_parameters(
int arity)
2150 int n = (arity < 0) ? ~arity : arity;
2184rb_proc_parameters(
int argc,
VALUE *argv,
VALUE self)
2186 static ID keyword_ids[1];
2192 iseq = rb_proc_get_iseq(self, &is_proc);
2194 if (!keyword_ids[0]) {
2195 CONST_ID(keyword_ids[0],
"lambda");
2202 if (!
NIL_P(lambda)) {
2203 is_proc = !
RTEST(lambda);
2210 return rb_iseq_parameters(iseq, is_proc);
2214rb_hash_proc(st_index_t hash,
VALUE prc)
2217 GetProcPtr(prc, proc);
2219 switch (vm_block_type(&proc->block)) {
2220 case block_type_iseq:
2221 if (proc->is_refined) {
2224 VALUE recipe = rb_proc_refinements_recipe(prc);
2226 hash = rb_st_hash_uint(hash, (st_index_t)
RARRAY_AREF(recipe, REFINEMENT_RECIPE_BASE_CREF));
2227 hash = rb_st_hash_uint(hash, (st_index_t)((
const rb_iseq_t *)
RARRAY_AREF(recipe, REFINEMENT_RECIPE_SRC_ISEQ))->body);
2228 for (
long i = REFINEMENT_RECIPE_MODS; i <
len; i++) {
2229 hash = rb_st_hash_uint(hash, (st_index_t)
RARRAY_AREF(recipe, i));
2233 hash = rb_st_hash_uint(hash, (st_index_t)proc->block.as.captured.code.iseq->body);
2236 case block_type_ifunc:
2237 hash = rb_st_hash_uint(hash, (st_index_t)proc->block.as.captured.code.ifunc->func);
2238 hash = rb_st_hash_uint(hash, (st_index_t)proc->block.as.captured.code.ifunc->data);
2240 case block_type_symbol:
2241 hash = rb_st_hash_uint(hash, rb_any_hash(proc->block.as.symbol));
2243 case block_type_proc:
2244 hash = rb_st_hash_uint(hash, rb_any_hash(proc->block.as.proc));
2247 rb_bug(
"rb_hash_proc: unknown block type %d", vm_block_type(&proc->block));
2253 if (vm_block_type(&proc->block) != block_type_ifunc) {
2254 hash =
rb_hash_uint(hash, (st_index_t)proc->block.as.captured.ep);
2277rb_sym_to_proc(
VALUE sym)
2279 enum {SYM_PROC_CACHE_SIZE = 67};
2281 if (rb_ractor_main_p()) {
2282 if (!sym_proc_cache) {
2288 long index = (
id % SYM_PROC_CACHE_SIZE);
2290 if (
RTEST(procval)) {
2292 GetProcPtr(procval, proc);
2294 if (proc->block.as.symbol == sym) {
2299 procval = sym_proc_new(
rb_cProc, sym);
2305 return sym_proc_new(
rb_cProc, sym);
2319proc_hash(
VALUE self)
2323 hash = rb_hash_proc(hash, self);
2329rb_block_to_s(
VALUE self,
const struct rb_block *block,
const char *additional_info)
2332 VALUE str = rb_sprintf(
"#<%"PRIsVALUE
":", cname);
2335 switch (vm_block_type(block)) {
2336 case block_type_proc:
2337 block = vm_proc_block(block->as.proc);
2339 case block_type_iseq:
2341 const rb_iseq_t *iseq = rb_iseq_check(block->as.captured.code.iseq);
2342 rb_str_catf(str,
"%p %"PRIsVALUE
":%d", (
void *)self,
2344 ISEQ_BODY(iseq)->location.first_lineno);
2347 case block_type_symbol:
2348 rb_str_catf(str,
"%p(&%+"PRIsVALUE
")", (
void *)self, block->as.symbol);
2350 case block_type_ifunc:
2351 rb_str_catf(str,
"%p", (
void *)block->as.captured.code.ifunc);
2369proc_to_s(
VALUE self)
2372 GetProcPtr(self, proc);
2373 return rb_block_to_s(self, &proc->block, proc->is_lambda ?
" (lambda)" : NULL);
2385proc_to_proc(
VALUE self)
2391bm_mark_and_move(
void *ptr)
2393 struct METHOD *data = ptr;
2394 rb_gc_mark_and_move((
VALUE *)&data->recv);
2395 rb_gc_mark_and_move((
VALUE *)&data->klass);
2396 rb_gc_mark_and_move((
VALUE *)&data->iclass);
2397 rb_gc_mark_and_move((
VALUE *)&data->owner);
2409 0, 0, RUBY_TYPED_THREAD_SAFE_FREE | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_EMBEDDABLE | RUBY_TYPED_FROZEN_SHAREABLE_NO_REC
2415 return RBOOL(rb_typeddata_is_kind_of(m, &method_data_type));
2422 ID rmiss = idRespond_to_missing;
2424 if (UNDEF_P(obj))
return 0;
2443 def->type = VM_METHOD_TYPE_MISSING;
2444 def->original_id = id;
2446 me = rb_method_entry_create(
id, klass, METHOD_VISI_UNDEF, def);
2458 if (!respond_to_missing_p(klass, obj, vid, scope))
return Qfalse;
2459 return mnew_missing(klass, obj,
SYM2ID(vid), mclass);
2471 rb_method_visibility_t visi = METHOD_VISI_UNDEF;
2474 if (UNDEFINED_METHOD_ENTRY_P(me)) {
2475 if (respond_to_missing_p(klass, obj,
ID2SYM(
id), scope)) {
2476 return mnew_missing(klass, obj,
id, mclass);
2478 if (!error)
return Qnil;
2479 rb_print_undef(klass,
id, METHOD_VISI_UNDEF);
2481 if (visi == METHOD_VISI_UNDEF) {
2482 visi = METHOD_ENTRY_VISI(me);
2484 if (scope && (visi != METHOD_VISI_PUBLIC)) {
2485 if (!error)
return Qnil;
2486 rb_print_inaccessible(klass,
id, visi);
2489 if (me->def->type == VM_METHOD_TYPE_ZSUPER ||
2490 (me->def->type == VM_METHOD_TYPE_CFUNC && me->def->body.cfunc.func == (rb_cfunc_t)rb_zsuper_to_super)) {
2491 if (me->def->type == VM_METHOD_TYPE_ZSUPER && me->defined_class) {
2493 id = me->def->original_id;
2494 me = (
rb_method_entry_t *)rb_callable_method_entry_with_refinements(klass,
id, &iclass);
2498 id = me->def->original_id;
2499 me = rb_method_entry_without_refinements(klass,
id, &iclass);
2515 RB_OBJ_WRITE(method, &data->owner, original_me->owner);
2525 return mnew_internal(me, klass, iclass, obj,
id, mclass, scope, TRUE);
2535 me = (
rb_method_entry_t *)rb_callable_method_entry_with_refinements(klass,
id, &iclass);
2536 return mnew_from_me(me, klass, iclass, obj,
id, mclass, scope);
2540mnew_unbound(
VALUE klass,
ID id,
VALUE mclass,
int scope)
2545 me = rb_method_entry_with_refinements(klass,
id, &iclass);
2546 return mnew_from_me(me, klass, iclass,
Qundef,
id, mclass, scope);
2552 VALUE defined_class = me->defined_class;
2553 return defined_class ? defined_class : me->owner;
2597 VALUE klass1, klass2;
2605 m1 = (
struct METHOD *)RTYPEDDATA_GET_DATA(method);
2606 m2 = (
struct METHOD *)RTYPEDDATA_GET_DATA(other);
2608 klass1 = method_entry_defined_class(m1->me);
2609 klass2 = method_entry_defined_class(m2->me);
2613 if (!rb_method_entry_eq(m1->me, m2->me) ||
2615 m1->klass != m2->klass ||
2616 m1->recv != m2->recv) {
2637#define unbound_method_eq method_eq
2649method_hash(
VALUE method)
2656 hash = rb_hash_method_entry(hash, m->me);
2672method_unbind(
VALUE obj)
2675 struct METHOD *orig, *data;
2679 &method_data_type, data);
2684 RB_OBJ_WRITE(method, &data->me, rb_method_entry_clone(orig->me));
2699method_receiver(
VALUE obj)
2715method_name(
VALUE obj)
2720 return ID2SYM(data->me->called_id);
2737method_original_name(
VALUE obj)
2742 return ID2SYM(data->me->def->original_id);
2764method_owner(
VALUE obj)
2778method_box(
VALUE obj)
2784 box = data->me->def->box;
2785 if (!box)
return Qnil;
2786 if (box->box_object)
return box->box_object;
2787 rb_bug(
"Unexpected box on the method definition: %p", (
void*) box);
2794#define MSG(s) rb_fstring_lit("undefined method '%1$s' for"s" '%2$s'")
2798 if (RCLASS_SINGLETON_P(c)) {
2799 VALUE obj = RCLASS_ATTACHED_OBJECT(klass);
2816 rb_name_err_raise_str(s, c, str);
2828 VALUE m = mnew_missing_by_name(klass, obj, &vid, scope, mclass);
2830 rb_method_name_error(klass, vid);
2832 return mnew_callable(klass, obj,
id, mclass, scope);
2877 return obj_method(obj, vid, FALSE);
2890 return obj_method(obj, vid, TRUE);
2894rb_obj_singleton_method_lookup(
VALUE arg)
2901rb_obj_singleton_method_lookup_fail(
VALUE arg1,
VALUE arg2)
2938 NIL_P(klass = RCLASS_ORIGIN(sc)) ||
2939 !
NIL_P(rb_special_singleton_class(obj))) {
2948 VALUE args[2] = {obj, vid};
2949 VALUE ruby_method =
rb_rescue(rb_obj_singleton_method_lookup, (
VALUE)args, rb_obj_singleton_method_lookup_fail,
Qfalse);
2951 struct METHOD *method = (
struct METHOD *)RTYPEDDATA_GET_DATA(ruby_method);
2954 VALUE method_class = method->iclass;
2958 if (lookup_class == method_class) {
2962 }
while (lookup_class && lookup_class != stop_class);
2968 rb_name_err_raise(
"undefined singleton method '%1$s' for '%2$s'",
3009 rb_method_name_error(mod, vid);
3022rb_mod_public_instance_method(
VALUE mod,
VALUE vid)
3026 rb_method_name_error(mod, vid);
3037 int is_method = FALSE;
3056 "wrong argument type %s (expected Proc/Method/UnboundMethod)",
3063 struct METHOD *method = (
struct METHOD *)RTYPEDDATA_GET_DATA(body);
3066 if (RCLASS_SINGLETON_P(method->me->owner)) {
3068 "can't bind singleton method to a different class");
3072 "bind argument must be a subclass of % "PRIsVALUE,
3076 rb_method_entry_set(mod,
id, method->me, scope_visi->method_visi);
3077 if (scope_visi->module_func) {
3084 GetProcPtr(body, body_proc);
3087 if (body_proc->is_refined) {
3088 rb_raise(rb_eArgError,
3089 "can't define a method from a Proc with refinements");
3091 VALUE procval = rb_proc_dup(body);
3092 if (vm_proc_iseq(procval) != NULL) {
3094 GetProcPtr(procval, proc);
3095 proc->is_lambda = TRUE;
3096 proc->is_from_method = TRUE;
3098 rb_add_method(mod,
id, VM_METHOD_TYPE_BMETHOD, (
void *)procval, scope_visi->method_visi);
3099 if (scope_visi->module_func) {
3100 rb_add_method(
rb_singleton_class(mod),
id, VM_METHOD_TYPE_BMETHOD, (
void *)body, METHOD_VISI_PUBLIC);
3148rb_mod_define_method(
int argc,
VALUE *argv,
VALUE mod)
3150 const rb_cref_t *cref = rb_vm_cref_in_context(mod, mod);
3155 scope_visi = CREF_SCOPE_VISI(cref);
3158 return rb_mod_define_method_with_visibility(argc, argv, mod, scope_visi);
3193rb_obj_define_method(
int argc,
VALUE *argv,
VALUE obj)
3198 return rb_mod_define_method_with_visibility(argc, argv, klass, &scope_visi);
3209top_define_method(
int argc,
VALUE *argv,
VALUE obj)
3211 return rb_mod_define_method(argc, argv, rb_top_main_class(
"define_method"));
3232method_clone(
VALUE self)
3235 struct METHOD *orig, *data;
3239 rb_obj_clone_setup(self, clone,
Qnil);
3244 RB_OBJ_WRITE(clone, &data->me, rb_method_entry_clone(orig->me));
3250method_dup(
VALUE self)
3253 struct METHOD *orig, *data;
3257 rb_obj_dup_setup(self, clone);
3262 RB_OBJ_WRITE(clone, &data->me, rb_method_entry_clone(orig->me));
3291rb_method_call_pass_called_kw(
int argc,
const VALUE *argv,
VALUE method)
3311method_callable_method_entry(
const struct METHOD *data)
3313 if (data->me->defined_class == 0) rb_bug(
"method_callable_method_entry: not callable.");
3319 int argc,
const VALUE *argv,
VALUE passed_procval,
int kw_splat)
3321 vm_passed_block_handler_set(ec, proc_to_block_handler(passed_procval));
3322 return rb_vm_call_kw(ec, data->recv, data->me->called_id, argc, argv,
3323 method_callable_method_entry(data), kw_splat);
3329 const struct METHOD *data;
3333 if (UNDEF_P(data->recv)) {
3334 rb_raise(
rb_eTypeError,
"can't call unbound method; bind first");
3336 return call_method_data(ec, data, argc, argv, passed_procval, kw_splat);
3403 VALUE methclass = data->owner;
3404 VALUE iclass = data->me->defined_class;
3408 VALUE refined_class = rb_refinement_module_get_refined_class(methclass);
3409 if (!
NIL_P(refined_class)) methclass = refined_class;
3412 if (RCLASS_SINGLETON_P(methclass)) {
3414 "singleton method called for a different object");
3417 rb_raise(
rb_eTypeError,
"bind argument must be an instance of % "PRIsVALUE,
3424 me = rb_method_entry_clone(data->me);
3434 me = rb_method_entry_clone(me);
3436 VALUE ic = rb_class_search_ancestor(klass, me->owner);
3442 klass = rb_include_class_new(methclass, klass);
3444 me = (
const rb_method_entry_t *) rb_method_entry_complement_defined_class(me, me->called_id, klass);
3447 *methclass_out = methclass;
3449 *iclass_out = iclass;
3491 VALUE methclass, klass, iclass;
3493 const struct METHOD *data;
3495 convert_umethod_to_method_components(data, recv, &methclass, &klass, &iclass, &me,
true);
3517umethod_bind_call(
int argc,
VALUE *argv,
VALUE method)
3520 VALUE recv = argv[0];
3527 const struct METHOD *data;
3532 vm_passed_block_handler_set(ec, proc_to_block_handler(passed_procval));
3536 VALUE methclass, klass, iclass;
3538 convert_umethod_to_method_components(data, recv, &methclass, &klass, &iclass, &me,
false);
3539 struct METHOD bound = { recv, klass, 0, methclass, me };
3554 if (!def)
return *max = 0;
3555 switch (def->type) {
3556 case VM_METHOD_TYPE_CFUNC:
3557 if (def->body.cfunc.argc < 0) {
3561 return *max = check_argc(def->body.cfunc.argc);
3562 case VM_METHOD_TYPE_ZSUPER:
3565 case VM_METHOD_TYPE_ATTRSET:
3567 case VM_METHOD_TYPE_IVAR:
3569 case VM_METHOD_TYPE_ALIAS:
3570 def = def->body.alias.original_me->def;
3572 case VM_METHOD_TYPE_BMETHOD:
3573 return rb_proc_min_max_arity(def->body.bmethod.proc, max);
3574 case VM_METHOD_TYPE_ISEQ:
3575 return rb_iseq_min_max_arity(rb_iseq_check(def->body.iseq.
iseqptr), max);
3576 case VM_METHOD_TYPE_UNDEF:
3577 case VM_METHOD_TYPE_NOTIMPLEMENTED:
3579 case VM_METHOD_TYPE_MISSING:
3582 case VM_METHOD_TYPE_OPTIMIZED: {
3583 switch (def->body.optimized.type) {
3584 case OPTIMIZED_METHOD_TYPE_SEND:
3587 case OPTIMIZED_METHOD_TYPE_CALL:
3590 case OPTIMIZED_METHOD_TYPE_BLOCK_CALL:
3593 case OPTIMIZED_METHOD_TYPE_STRUCT_AREF:
3596 case OPTIMIZED_METHOD_TYPE_STRUCT_ASET:
3604 case VM_METHOD_TYPE_REFINED:
3608 rb_bug(
"method_def_min_max_arity: invalid method entry type (%d)", def->type);
3615 int max, min = method_def_min_max_arity(def, &max);
3616 return min == max ? min : -min-1;
3622 return method_def_arity(me->def);
3669method_arity_m(
VALUE method)
3671 int n = method_arity(method);
3676method_arity(
VALUE method)
3681 return rb_method_entry_arity(data->me);
3685original_method_entry(
VALUE mod,
ID id)
3689 while ((me = rb_method_entry(mod,
id)) != 0) {
3692 if (def->type != VM_METHOD_TYPE_ZSUPER &&
3693 (def->type != VM_METHOD_TYPE_CFUNC ||
3694 def->body.cfunc.func != (rb_cfunc_t)rb_zsuper_to_super))
break;
3697 id = def->original_id;
3703method_min_max_arity(
VALUE method,
int *max)
3705 const struct METHOD *data;
3708 return method_def_min_max_arity(data->me->def, max);
3716 return rb_method_entry_arity(me);
3726rb_callable_receiver(
VALUE callable)
3729 VALUE binding = proc_binding(callable);
3730 return rb_funcall(binding, rb_intern(
"receiver"), 0);
3733 return method_receiver(callable);
3741rb_method_def(
VALUE method)
3743 const struct METHOD *data;
3746 return data->me->def;
3752 switch (def->type) {
3753 case VM_METHOD_TYPE_ISEQ:
3754 return rb_iseq_check(def->body.iseq.
iseqptr);
3755 case VM_METHOD_TYPE_BMETHOD:
3756 return rb_proc_get_iseq(def->body.bmethod.proc, 0);
3757 case VM_METHOD_TYPE_ALIAS:
3758 return method_def_iseq(def->body.alias.original_me->def);
3759 case VM_METHOD_TYPE_CFUNC:
3760 case VM_METHOD_TYPE_ATTRSET:
3761 case VM_METHOD_TYPE_IVAR:
3762 case VM_METHOD_TYPE_ZSUPER:
3763 case VM_METHOD_TYPE_UNDEF:
3764 case VM_METHOD_TYPE_NOTIMPLEMENTED:
3765 case VM_METHOD_TYPE_OPTIMIZED:
3766 case VM_METHOD_TYPE_MISSING:
3767 case VM_METHOD_TYPE_REFINED:
3774rb_method_iseq(
VALUE method)
3776 return method_def_iseq(rb_method_def(method));
3780method_cref(
VALUE method)
3785 switch (def->type) {
3786 case VM_METHOD_TYPE_ISEQ:
3787 return def->body.iseq.
cref;
3788 case VM_METHOD_TYPE_ALIAS:
3789 def = def->body.alias.original_me->def;
3799 if (def->type == VM_METHOD_TYPE_ATTRSET || def->type == VM_METHOD_TYPE_IVAR) {
3800 if (!def->body.attr.location)
3804 return iseq_location(method_def_iseq(def));
3810 if (!me)
return Qnil;
3811 return method_def_location(me->def);
3831rb_method_location(
VALUE method)
3833 return method_def_location(rb_method_def(method));
3839 return source_range_new(method_def_iseq(def));
3856rb_method_source_range(
VALUE method)
3858 return method_def_source_range(rb_method_def(method));
3862vm_proc_method_def(
VALUE procval)
3868 GetProcPtr(procval, proc);
3869 block = &proc->block;
3871 if (vm_block_type(block) == block_type_ifunc &&
3872 IS_METHOD_PROC_IFUNC(ifunc = block->as.captured.code.ifunc)) {
3873 return rb_method_def((
VALUE)ifunc->data);
3886 switch (def->type) {
3887 case VM_METHOD_TYPE_ISEQ:
3888 iseq = method_def_iseq(def);
3889 return rb_iseq_parameters(iseq, 0);
3890 case VM_METHOD_TYPE_BMETHOD:
3891 if ((iseq = method_def_iseq(def)) != NULL) {
3892 return rb_iseq_parameters(iseq, 0);
3894 else if ((bmethod_def = vm_proc_method_def(def->body.bmethod.proc)) != NULL) {
3895 return method_def_parameters(bmethod_def);
3899 case VM_METHOD_TYPE_ALIAS:
3900 return method_def_parameters(def->body.alias.original_me->def);
3902 case VM_METHOD_TYPE_OPTIMIZED:
3903 if (def->body.optimized.type == OPTIMIZED_METHOD_TYPE_STRUCT_ASET) {
3904 VALUE param = rb_ary_new_from_args(2,
ID2SYM(rb_intern(
"req")),
ID2SYM(rb_intern(
"_")));
3905 return rb_ary_new_from_args(1, param);
3909 case VM_METHOD_TYPE_CFUNC:
3910 case VM_METHOD_TYPE_ATTRSET:
3911 case VM_METHOD_TYPE_IVAR:
3912 case VM_METHOD_TYPE_ZSUPER:
3913 case VM_METHOD_TYPE_UNDEF:
3914 case VM_METHOD_TYPE_NOTIMPLEMENTED:
3915 case VM_METHOD_TYPE_MISSING:
3916 case VM_METHOD_TYPE_REFINED:
3920 return rb_unnamed_parameters(method_def_arity(def));
3944rb_method_parameters(
VALUE method)
3946 return method_def_parameters(rb_method_def(method));
3950append_param_name(
VALUE str,
VALUE name,
const char *unnamed)
3995method_inspect(
VALUE method)
3999 const char *sharp =
"#";
4001 VALUE defined_class;
4004 str = rb_sprintf(
"#<% "PRIsVALUE
": ",
rb_obj_class(method));
4006 mklass = data->iclass;
4007 if (!mklass) mklass = data->klass;
4017 if (data->me->def->type == VM_METHOD_TYPE_ALIAS) {
4018 defined_class = data->me->def->body.alias.original_me->owner;
4021 defined_class = method_entry_defined_class(data->me);
4028 if (UNDEF_P(data->recv)) {
4032 else if (RCLASS_SINGLETON_P(mklass)) {
4033 VALUE v = RCLASS_ATTACHED_OBJECT(mklass);
4035 if (UNDEF_P(data->recv)) {
4038 else if (data->recv == v) {
4051 mklass = data->klass;
4052 if (RCLASS_SINGLETON_P(mklass)) {
4053 VALUE v = RCLASS_ATTACHED_OBJECT(mklass);
4061 if (defined_class != mklass) {
4062 rb_str_catf(str,
"(% "PRIsVALUE
")", defined_class);
4067 if (data->me->called_id != data->me->def->original_id) {
4068 rb_str_catf(str,
"(%"PRIsVALUE
")",
4069 rb_id2str(data->me->def->original_id));
4071 if (data->me->def->type == VM_METHOD_TYPE_NOTIMPLEMENTED) {
4077 VALUE params = rb_method_parameters(method);
4078 VALUE pair, name, kind;
4084 const VALUE keyrest =
ID2SYM(rb_intern(
"keyrest"));
4087 const VALUE noblock =
ID2SYM(rb_intern(
"noblock"));
4102 for (
int i = 0; i <
RARRAY_LEN(params); i++) {
4113 append_param_name(str, name,
"_");
4115 else if (kind == opt) {
4118 else if (kind == keyreq) {
4121 else if (kind == key) {
4124 else if (kind == rest) {
4126 if (name !=
ID2SYM(
'*')) {
4127 append_param_name(str, name, NULL);
4130 else if (kind == keyrest) {
4131 if (name !=
ID2SYM(idPow)) {
4141 else if (kind == block) {
4142 if (name ==
ID2SYM(
'&')) {
4154 else if (kind == nokey) {
4157 else if (kind == noblock) {
4169 VALUE loc = rb_method_location(method);
4171 rb_str_catf(str,
" %"PRIsVALUE
":%"PRIsVALUE,
4204method_to_proc(
VALUE method)
4218 procval =
rb_block_call(rb_mRubyVMFrozenCore, idLambda, 0, 0, bmcall, method);
4219 GetProcPtr(procval, proc);
4220 proc->is_from_method = 1;
4224extern VALUE rb_find_defined_class_by_owner(
VALUE current_class,
VALUE target_owner);
4237method_super_method(
VALUE method)
4239 const struct METHOD *data;
4240 VALUE super_class, iclass;
4245 iclass = data->iclass;
4246 if (!iclass)
return Qnil;
4247 if (data->me->def->type == VM_METHOD_TYPE_ALIAS && data->me->defined_class) {
4248 super_class =
RCLASS_SUPER(rb_find_defined_class_by_owner(data->me->defined_class,
4249 data->me->def->body.alias.original_me->owner));
4250 mid = data->me->def->body.alias.original_me->def->original_id;
4253 VALUE klass = iclass;
4254 if (RICLASS_FOR_REFINEMENT_P(klass)) {
4256 klass =
RBASIC(klass)->klass;
4259 mid = data->me->def->original_id;
4261 if (!super_class)
return Qnil;
4271 switch (data->me->def->type) {
4272 case VM_METHOD_TYPE_ISEQ:
4273 cref = data->me->def->body.iseq.
cref;
4275 case VM_METHOD_TYPE_BMETHOD: {
4277 GetProcPtr(data->me->def->body.bmethod.proc, proc);
4278 const struct rb_block *block = &proc->block;
4279 if (vm_block_type(block) == block_type_iseq)
4280 cref = rb_vm_get_cref(block->as.captured.ep);
4286 VALUE klass = super_class;
4291 if (cme->def->type != VM_METHOD_TYPE_REFINED) {
4293 iclass = cme->defined_class;
4299 for (c = cref; c; c = CREF_NEXT(c)) {
4300 VALUE refs = CREF_REFINEMENTS(c);
4301 if (
NIL_P(refs))
continue;
4302 VALUE r = rb_hash_lookup(refs, cme->owner);
4303 if (
NIL_P(r))
continue;
4305 if (!ref_cme)
break;
4306 if (ref_cme->def->type == VM_METHOD_TYPE_REFINED)
continue;
4307 if (skip_def && rb_method_definition_eq(ref_cme->def, skip_def))
continue;
4309 iclass = ref_cme->defined_class;
4318 iclass = orig_me->defined_class ? orig_me->defined_class : cme->defined_class;
4323 if (!me)
return Qnil;
4324 return mnew_internal(me, me->owner, iclass, data->recv, mid,
rb_obj_class(method), FALSE, FALSE);
4334localjump_xvalue(
VALUE exc)
4348localjump_reason(
VALUE exc)
4353rb_cref_t *rb_vm_cref_new_toplevel(
void);
4362 VM_ASSERT(env->ep > env->env);
4363 VM_ASSERT(VM_ENV_ESCAPED_P(env->ep));
4366 cref = rb_vm_cref_new_toplevel();
4370 new_ep = &new_body[env->ep - env->env];
4371 new_env = vm_env_new(new_ep, new_body, env->env_size, env->iseq);
4378 new_ep[VM_ENV_DATA_INDEX_ENV] = (
VALUE)new_env;
4380 VM_ASSERT(VM_ENV_ESCAPED_P(new_ep));
4398proc_binding(
VALUE self)
4407 GetProcPtr(self, proc);
4408 block = &proc->block;
4410 if (proc->is_isolated) rb_raise(rb_eArgError,
"Can't create Binding from isolated Proc");
4413 switch (vm_block_type(block)) {
4414 case block_type_iseq:
4415 iseq = block->as.captured.code.iseq;
4416 binding_self = block->as.captured.self;
4417 env = VM_ENV_ENVVAL_PTR(block->as.captured.ep);
4419 case block_type_proc:
4420 GetProcPtr(block->as.proc, proc);
4421 block = &proc->block;
4423 case block_type_ifunc:
4425 const struct vm_ifunc *ifunc = block->as.captured.code.ifunc;
4426 if (IS_METHOD_PROC_IFUNC(ifunc)) {
4428 VALUE name = rb_fstring_lit(
"<empty_iseq>");
4430 binding_self = method_receiver(method);
4431 iseq = rb_method_iseq(method);
4432 env = VM_ENV_ENVVAL_PTR(block->as.captured.ep);
4433 env = env_clone(env, method_cref(method));
4435 empty = rb_iseq_new(
Qnil, name, name,
Qnil, 0, ISEQ_TYPE_TOP);
4441 case block_type_symbol:
4442 rb_raise(rb_eArgError,
"Can't create Binding from C level Proc");
4447 GetBindingPtr(bindval, bind);
4448 RB_OBJ_WRITE(bindval, &bind->block.as.captured.self, binding_self);
4449 RB_OBJ_WRITE(bindval, &bind->block.as.captured.code.iseq, env->iseq);
4450 rb_vm_block_ep_update(bindval, &bind->block, env->ep);
4454 rb_iseq_check(iseq);
4455 RB_OBJ_WRITE(bindval, &bind->pathobj, ISEQ_BODY(iseq)->location.pathobj);
4456 bind->first_lineno = ISEQ_BODY(iseq)->location.first_lineno;
4460 rb_iseq_pathobj_new(rb_fstring_lit(
"(binding)"),
Qnil));
4461 bind->first_lineno = 1;
4476 GetProcPtr(proc, procp);
4477 is_lambda = procp->is_lambda;
4481 GetProcPtr(proc, procp);
4482 procp->is_lambda = is_lambda;
4489 VALUE proc, passed, arity;
4498 if (!
NIL_P(blockarg)) {
4499 rb_warn(
"given block not used");
4501 arity = make_curry_proc(proc, passed, arity);
4564proc_curry(
int argc,
const VALUE *argv,
VALUE self)
4566 int sarity, max_arity, min_arity = rb_proc_min_max_arity(self, &max_arity);
4579 return make_curry_proc(self,
rb_ary_new(), arity);
4615rb_method_curry(
int argc,
const VALUE *argv,
VALUE self)
4617 VALUE proc = method_to_proc(self);
4618 return proc_curry(argc, argv, proc);
4647 mesg = rb_fstring_lit(
"callable object is expected");
4671 return rb_proc_compose_to_left(self, to_callable(g));
4677 VALUE proc, args, procs[2];
4683 args = rb_ary_tmp_new_from_values(0, 2, procs);
4686 GetProcPtr(g, procp);
4687 is_lambda = procp->is_lambda;
4695 GetProcPtr(proc, procp);
4696 procp->is_lambda = is_lambda;
4730 return rb_proc_compose_to_right(self, to_callable(g));
4736 VALUE proc, args, procs[2];
4742 args = rb_ary_tmp_new_from_values(0, 2, procs);
4744 GetProcPtr(self, procp);
4745 is_lambda = procp->is_lambda;
4748 GetProcPtr(proc, procp);
4749 procp->is_lambda = is_lambda;
4770rb_method_compose_to_left(
VALUE self,
VALUE g)
4773 self = method_to_proc(self);
4774 return proc_compose_to_left(self, g);
4793rb_method_compose_to_right(
VALUE self,
VALUE g)
4796 self = method_to_proc(self);
4797 return proc_compose_to_right(self, g);
4825proc_ruby2_keywords(
VALUE procval)
4828 GetProcPtr(procval, proc);
4830 rb_check_frozen(procval);
4832 if (proc->is_from_method) {
4833 rb_warn(
"Skipping set of ruby2_keywords flag for proc (proc created from method)");
4837 switch (proc->block.type) {
4838 case block_type_iseq:
4839 if (ISEQ_BODY(proc->block.as.captured.code.iseq)->param.flags.has_rest &&
4840 !ISEQ_BODY(proc->block.as.captured.code.iseq)->param.flags.has_post &&
4841 !ISEQ_BODY(proc->block.as.captured.code.iseq)->param.flags.has_kw &&
4842 !ISEQ_BODY(proc->block.as.captured.code.iseq)->param.flags.has_kwrest) {
4843 if (proc->is_refined) {
4848 rb_iseq_dup_with_independent_caches(proc->block.as.captured.code.iseq);
4849 ISEQ_BODY(copy)->param.flags.ruby2_keywords = 1;
4855 ISEQ_BODY(proc->block.as.captured.code.iseq)->param.flags.ruby2_keywords = 1;
4859 rb_warn(
"Skipping set of ruby2_keywords flag for proc (proc accepts keywords or post arguments or proc does not accept argument splat)");
4863 rb_warn(
"Skipping set of ruby2_keywords flag for proc (proc not defined in Ruby)");
5303 id_refinements_recipe = rb_make_internal_id();
5305 VALUE mRuby = rb_define_module(
"Ruby");
5308 rb_cSourceRange = rb_define_class_under(mRuby,
"SourceRange",
rb_cObject);
5312 rb_define_method(rb_cSourceRange,
"absolute_path", source_range_absolute_path, 0);
5313 rb_define_method(rb_cSourceRange,
"start_line", source_range_start_line, 0);
5314 rb_define_method(rb_cSourceRange,
"start_column", source_range_start_column, 0);
5316 rb_define_method(rb_cSourceRange,
"end_column", source_range_end_column, 0);
5324 rb_add_method_optimized(
rb_cProc, idCall, OPTIMIZED_METHOD_TYPE_CALL, 0, METHOD_VISI_PUBLIC);
5325 rb_add_method_optimized(
rb_cProc, rb_intern(
"[]"), OPTIMIZED_METHOD_TYPE_CALL, 0, METHOD_VISI_PUBLIC);
5326 rb_add_method_optimized(
rb_cProc, rb_intern(
"==="), OPTIMIZED_METHOD_TYPE_CALL, 0, METHOD_VISI_PUBLIC);
5327 rb_add_method_optimized(
rb_cProc, rb_intern(
"yield"), OPTIMIZED_METHOD_TYPE_CALL, 0, METHOD_VISI_PUBLIC);
5363 rb_vm_register_special_exception(ruby_error_sysstack,
rb_eSysStackError,
"stack level too deep");
5434 "define_method", top_define_method, -1);
5475 rb_gc_register_address(&sym_proc_cache);
#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_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_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 FL_TEST_RAW
Old name of RB_FL_TEST_RAW.
#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 INT2NUM
Old name of RB_INT2NUM.
#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_category_warn(rb_warning_category_t category, const char *fmt,...)
Identical to rb_category_warning(), except it reports unless $VERBOSE is nil.
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
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.
@ RB_WARN_CATEGORY_PERFORMANCE
Warning is for performance issues (not enabled by -w).
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_cObject
Object class.
VALUE rb_obj_hide(VALUE obj)
Make the object invisible from Ruby code.
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_funcallv(VALUE recv, ID mid, int argc, const VALUE *argv)
Identical to rb_funcall(), except it takes the method arguments as a C array.
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_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.
#define rb_str_new_cstr(str)
Identical to rb_str_new, 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_set(VALUE obj, ID name, VALUE val)
Identical to rb_iv_set(), except it accepts the name as an ID instead of a C string.
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_method_basic_definition_p(VALUE klass, ID mid)
Well... Let us hesitate from describing what a "basic definition" is.
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_sym2str(VALUE symbol)
Obtain a frozen string representation of a symbol (not including the leading colon).
ID rb_to_id(VALUE str)
Identical to rb_intern_str(), except it tries to convert the parameter object to an instance of rb_cS...
VALUE rb_iv_get(VALUE obj, const char *name)
Obtains an instance variable.
int len
Length of the buffer.
#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 type(ANYARGS)
ANYARGS-ed function type.
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.
static VALUE * RARRAY_PTR(VALUE ary)
Wild use of a C pointer.
#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 RBASIC(obj)
Convenient casting macro.
#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 RUBY_TYPED_FREE_IMMEDIATELY
Macros to see if each corresponding flag is defined.
#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.
Internal header for Ruby Box.
This is the struct that holds necessary info for a struct.
rb_cref_t * cref
class reference, should be marked
const rb_iseq_t * iseqptr
iseq pointer, should be separated from iseqval
IFUNC (Internal FUNCtion)
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
#define SIZEOF_VALUE
Identical to sizeof(VALUE), except it is a macro that can also be used inside of preprocessor directi...
uintptr_t VALUE
Type that represents a Ruby object.
static void Check_Type(VALUE v, enum ruby_value_type t)
Identical to RB_TYPE_P(), except it raises exceptions on predication failure.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.