20#define PROC_NEW_REQUIRES_BLOCK 0
22#if !defined(__GNUC__) || __GNUC__ < 5 || defined(__MINGW32__)
23# define NO_CLOBBERED(v) (*(volatile VALUE *)&(v))
25# define NO_CLOBBERED(v) (v)
28#define UPDATE_TYPED_REFERENCE(_type, _ref) *(_type*)&_ref = (_type)rb_gc_location((VALUE)_ref)
29#define UPDATE_REFERENCE(_ref) UPDATE_TYPED_REFERENCE(VALUE, _ref)
47static int method_arity(
VALUE);
48static int method_min_max_arity(
VALUE,
int *max);
50#define attached id__attached__
54#define IS_METHOD_PROC_IFUNC(ifunc) ((ifunc)->func == bmcall)
57block_mark(
const struct rb_block *block)
59 switch (vm_block_type(block)) {
83 switch (block->
type) {
105proc_compact(
void *
ptr)
115 block_mark(&proc->
block);
125proc_memsize(
const void *
ptr)
164proc_clone(
VALUE self)
286binding_free(
void *
ptr)
294binding_mark(
void *
ptr)
299 block_mark(&bind->
block);
305binding_compact(
void *
ptr)
314binding_memsize(
const void *
ptr)
342binding_dup(
VALUE self)
356binding_clone(
VALUE self)
358 VALUE bindval = binding_dup(
self);
387rb_f_binding(
VALUE self)
419get_local_variable_ptr(
const rb_env_t **envp,
ID lid)
462check_local_id(
VALUE bindval,
volatile VALUE *pname)
502bind_local_variables(
VALUE bindval)
508 env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->
block));
532 ID lid = check_local_id(bindval, &
sym);
541 env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->
block));
542 if ((
ptr = get_local_variable_ptr(&
env, lid)) ==
NULL) {
580 ID lid = check_local_id(bindval, &
sym);
588 env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->
block));
589 if ((
ptr = get_local_variable_ptr(&
env, lid)) ==
NULL) {
592 env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->
block));
620 ID lid = check_local_id(bindval, &
sym);
627 env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->
block));
638bind_receiver(
VALUE bindval)
642 return vm_block_self(&bind->
block);
652bind_location(
VALUE bindval)
657 loc[0] = pathobj_path(bind->
pathobj);
671 proc = &sproc->
basic;
724 return IFUNC_NEW(func, data, arity.packed);
730 struct vm_ifunc *ifunc = rb_vm_ifunc_proc_new(
func, (
void *)val);
741static const char proc_without_block[] =
"tried to create Proc object without a block";
752#if !PROC_NEW_REQUIRES_BLOCK
760 const char *
name = kernel ?
"Kernel#proc" :
"Proc.new";
800 if (is_lambda && last_ruby_cfp && vm_cfp_forwarded_bh_p(last_ruby_cfp,
block_handler)) {
933#if SIZEOF_LONG > SIZEOF_INT
939 (
unsigned long)
argc);
944#define check_argc(argc) (argc)
980proc_to_block_handler(
VALUE procval)
1054proc_arity(
VALUE self)
1071rb_vm_block_min_max_arity(
const struct rb_block *block,
int *max)
1074 switch (vm_block_type(block)) {
1078 block = vm_proc_block(block->
as.
proc);
1085 return method_min_max_arity((
VALUE)ifunc->
data, max);
1104rb_proc_min_max_arity(
VALUE self,
int *max)
1108 return rb_vm_block_min_max_arity(&proc->
block, max);
1117 min = rb_vm_block_min_max_arity(&proc->
block, &max);
1157 min = rb_vm_block_min_max_arity(&block, &max);
1159 switch (vm_block_type(&block)) {
1190 return rb_vm_block_min_max_arity(&block, max);
1200 block = &
proc->block;
1201 if (is_proc) *is_proc = !
proc->is_lambda;
1203 switch (vm_block_type(block)) {
1213 if (is_proc) *is_proc = 0;
1234 rb_iseq_check(
iseq);
1244 return iseq_location(
iseq);
1265 int n = (arity < 0) ? ~arity : arity;
1291rb_proc_parameters(
VALUE self)
1315 enum {SYM_PROC_CACHE_SIZE = 67};
1320 if (!sym_proc_cache) {
1327 index = (
id % SYM_PROC_CACHE_SIZE) << 1;
1350proc_hash(
VALUE self)
1366 switch (vm_block_type(block)) {
1368 block = vm_proc_block(block->
as.
proc);
1400proc_to_s(
VALUE self)
1416proc_to_proc(
VALUE self)
1432bm_compact(
void *
ptr)
1442bm_memsize(
const void *
ptr)
1444 return sizeof(
struct METHOD);
1508 if (!respond_to_missing_p(
klass,
obj, vid, scope))
return Qfalse;
1523 return mnew_missing(
klass,
obj,
id, mclass);
1585 return defined_class ? defined_class :
me->
owner;
1630 VALUE klass1, klass2;
1641 klass1 = method_entry_defined_class(m1->
me);
1642 klass2 = method_entry_defined_class(m2->
me);
1664method_hash(
VALUE method)
1690 struct METHOD *orig, *data;
1694 &method_data_type, data);
1780#define MSG(s) rb_fstring_lit("undefined method `%1$s' for"s" `%2$s'")
1814 VALUE m = mnew_missing_by_name(
klass,
obj, &vid, scope, mclass);
1818 return mnew(
klass,
obj,
id, mclass, scope);
1863 return obj_method(
obj, vid,
FALSE);
1876 return obj_method(
obj, vid,
TRUE);
2036 int is_method =
FALSE;
2039 scope_visi = CREF_SCOPE_VISI(cref);
2046#if PROC_NEW_REQUIRES_BLOCK
2077 "wrong argument type %s (expected Proc/Method/UnboundMethod)",
2089 "can't bind singleton method to a different class");
2093 "bind argument must be a subclass of % "PRIsVALUE,
2105 if (vm_proc_iseq(procval) !=
NULL) {
2174 rb_warning(
"main.define_method in the wrapped load is effective only in wrapper module");
2200method_clone(
VALUE self)
2203 struct METHOD *orig, *data;
2280method_callable_method_entry(
const struct METHOD *data)
2290 vm_passed_block_handler_set(ec, proc_to_block_handler(passed_procval));
2292 method_callable_method_entry(data), kw_splat);
2298 const struct METHOD *data;
2305 return call_method_data(ec, data,
argc,
argv, passed_procval, kw_splat);
2384 "singleton method called for a different object");
2406 *methclass_out = methclass;
2452 convert_umethod_to_method_components(method,
recv, &methclass, &
klass, &
iclass, &
me);
2482 convert_umethod_to_method_components(method,
recv, &methclass, &
klass, &
iclass, &
me);
2502 if (!def)
return *max = 0;
2503 switch (def->
type) {
2523 return rb_iseq_min_max_arity(rb_iseq_check(def->
body.
iseq.
iseqptr), max);
2550 rb_bug(
"rb_method_entry_min_max_arity: invalid method entry type (%d)", def->
type);
2557 int max, min = rb_method_entry_min_max_arity(
me, &max);
2558 return min == max ? min : -min-1;
2605method_arity_m(
VALUE method)
2607 int n = method_arity(method);
2612method_arity(
VALUE method)
2635method_min_max_arity(
VALUE method,
int *max)
2637 const struct METHOD *data;
2640 return rb_method_entry_min_max_arity(data->
me, max);
2660 const struct METHOD *data;
2663 return data->
me->
def;
2669 switch (def->
type) {
2697method_cref(
VALUE method)
2702 switch (def->
type) {
2721 return iseq_location(method_def_iseq(def));
2728 return method_def_location(
me->
def);
2765rb_method_parameters(
VALUE method)
2808method_inspect(
VALUE method)
2812 const char *sharp =
"#";
2814 VALUE defined_class;
2819 mklass = data->
klass;
2833 defined_class = method_entry_defined_class(data->
me);
2846 else if (data->
recv ==
v) {
2860 if (defined_class != mklass) {
2876 VALUE params = rb_method_parameters(method);
2897 if (kind == req || kind == opt) {
2900 else if (kind == rest || kind == keyrest) {
2903 else if (kind == block) {
2906 else if (kind == nokey) {
2914 else if (kind == opt) {
2917 else if (kind == keyreq) {
2920 else if (kind ==
key) {
2923 else if (kind == rest) {
2932 else if (kind == keyrest) {
2935 else if (kind == block) {
2948 else if (kind == nokey) {
2979mlambda(
VALUE method)
3007method_to_proc(
VALUE method)
3021 procval =
rb_iterate(mlambda, 0, bmcall, method);
3038method_super_method(
VALUE method)
3040 const struct METHOD *data;
3057 if (!super_class)
return Qnil;
3107 new_ep = &new_body[
env->ep -
env->env];
3108 new_env = vm_env_new(new_ep, new_body,
env->env_size,
env->iseq);
3128proc_binding(
VALUE self)
3138 block = &
proc->block;
3141 switch (vm_block_type(block)) {
3149 block = &
proc->block;
3160 binding_self = method_receiver(method);
3163 env = env_clone(
env, method_cref(method));
3185 rb_iseq_check(
iseq);
3220 VALUE proc, passed, arity;
3229 if (!
NIL_P(blockarg)) {
3230 rb_warn(
"given block not used");
3232 arity = make_curry_proc(proc, passed, arity);
3285 int sarity, max_arity, min_arity = rb_proc_min_max_arity(
self, &max_arity);
3298 return make_curry_proc(
self,
rb_ary_new(), arity);
3336 VALUE proc = method_to_proc(
self);
3337 return proc_curry(
argc,
argv, proc);
3390 return rb_proc_compose_to_left(
self, to_callable(g));
3396 VALUE proc, args, procs[2];
3443 return rb_proc_compose_to_right(
self, to_callable(g));
3449 VALUE proc, args, procs[2];
3484rb_method_compose_to_left(
VALUE self,
VALUE g)
3487 self = method_to_proc(
self);
3488 return proc_compose_to_left(
self, g);
3508rb_method_compose_to_right(
VALUE self,
VALUE g)
3511 self = method_to_proc(
self);
3512 return proc_compose_to_right(
self, g);
3548proc_ruby2_keywords(
VALUE procval)
3556 rb_warn(
"Skipping set of ruby2_keywords flag for proc (proc created from method)");
3568 rb_warn(
"Skipping set of ruby2_keywords flag for proc (proc accepts keywords or proc does not accept argument splat)");
3572 rb_warn(
"Skipping set of ruby2_keywords flag for proc (proc not defined in Ruby)");
4027 "define_method", top_define_method, -1);
char str[HTML_ESCAPE_MAX_LEN+1]
void rb_print_undef(VALUE klass, ID id, rb_method_visibility_t visi)
void rb_print_inaccessible(VALUE klass, ID id, rb_method_visibility_t visi)
#define rb_intern_str(string)
VALUE rb_define_class(const char *, VALUE)
Defines a top-level class.
VALUE rb_singleton_class(VALUE)
Returns the singleton class of obj.
VALUE rb_include_class_new(VALUE, VALUE)
VALUE rb_singleton_class_get(VALUE obj)
Returns the singleton class of obj, or nil if obj is not a singleton object.
void rb_undef_method(VALUE, const char *)
void rb_define_alias(VALUE, const char *, const char *)
Defines an alias of a method.
int rb_block_given_p(void)
Determines if the current method is given a block.
VALUE rb_mKernel
Kernel module.
VALUE rb_cObject
Object class.
VALUE rb_block_call_func(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg))
VALUE rb_cModule
Module class.
void rb_raise(VALUE exc, const char *fmt,...)
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)
void rb_bug(const char *fmt,...)
void rb_warn(const char *fmt,...)
VALUE rb_exc_new_str(VALUE, VALUE)
VALUE rb_obj_class(VALUE)
Equivalent to Object#class in Ruby.
VALUE rb_inspect(VALUE)
Convenient wrapper of Object::inspect.
VALUE rb_class_inherited_p(VALUE mod, VALUE arg)
Determines if mod inherits arg.
VALUE rb_obj_is_kind_of(VALUE, VALUE)
Determines if obj is a kind of c.
VALUE rb_class_search_ancestor(VALUE klass, VALUE super)
VALUE rb_proc_call(VALUE self, VALUE args)
rb_cref_t * rb_vm_cref_new_toplevel(void)
int rb_method_entry_arity(const rb_method_entry_t *me)
const rb_method_definition_t * rb_method_def(VALUE method)
const rb_data_type_t ruby_binding_data_type
VALUE rb_obj_singleton_method(VALUE obj, VALUE vid)
const rb_cref_t * rb_vm_cref_in_context(VALUE self, VALUE cbase)
VALUE rb_binding_alloc(VALUE klass)
st_index_t rb_hash_proc(st_index_t hash, VALUE prc)
VALUE rb_proc_call_with_block_kw(VALUE self, int argc, const VALUE *argv, VALUE passed_procval, int kw_splat)
VALUE rb_func_lambda_new(rb_block_call_func_t func, VALUE val, int min_argc, int max_argc)
VALUE rb_obj_is_method(VALUE m)
const rb_iseq_t * rb_proc_get_iseq(VALUE self, int *is_proc)
VALUE rb_block_to_s(VALUE self, const struct rb_block *block, const char *additional_info)
int rb_proc_arity(VALUE self)
VALUE rb_block_proc(void)
VALUE rb_proc_call_kw(VALUE self, VALUE args, int kw_splat)
VALUE rb_proc_lambda_p(VALUE procval)
int rb_mod_method_arity(VALUE mod, ID id)
VALUE rb_unnamed_parameters(int arity)
MJIT_FUNC_EXPORTED VALUE rb_func_proc_new(rb_block_call_func_t func, VALUE val)
const rb_iseq_t * rb_method_iseq(VALUE method)
VALUE rb_find_defined_class_by_owner(VALUE current_class, VALUE target_owner)
MJIT_FUNC_EXPORTED VALUE rb_sym_to_proc(VALUE sym)
#define IS_METHOD_PROC_IFUNC(ifunc)
VALUE rb_obj_method(VALUE obj, VALUE vid)
MJIT_FUNC_EXPORTED VALUE rb_iseq_location(const rb_iseq_t *iseq)
VALUE rb_method_call_kw(int argc, const VALUE *argv, VALUE method, int kw_splat)
struct vm_ifunc * rb_vm_ifunc_new(rb_block_call_func_t func, const void *data, int min_argc, int max_argc)
int rb_obj_method_arity(VALUE obj, ID id)
VALUE rb_proc_location(VALUE self)
#define UPDATE_REFERENCE(_ref)
VALUE rb_method_entry_location(const rb_method_entry_t *me)
VALUE rb_method_location(VALUE method)
VALUE rb_block_lambda(void)
VALUE rb_method_call(int argc, const VALUE *argv, VALUE method)
void rb_method_name_error(VALUE klass, VALUE str)
VALUE rb_proc_new(rb_block_call_func_t func, VALUE val)
VALUE rb_binding_new(void)
VALUE rb_method_call_with_block(int argc, const VALUE *argv, VALUE method, VALUE passed_procval)
VALUE rb_proc_call_with_block(VALUE self, int argc, const VALUE *argv, VALUE passed_procval)
VALUE rb_obj_public_method(VALUE obj, VALUE vid)
VALUE rb_method_call_with_block_kw(int argc, const VALUE *argv, VALUE method, VALUE passed_procval, int kw_splat)
int rb_block_min_max_arity(int *max)
#define UPDATE_TYPED_REFERENCE(_type, _ref)
VALUE rb_obj_is_proc(VALUE proc)
VALUE rb_proc_alloc(VALUE klass)
const rb_method_entry_t *const me
VALUE env[VM_ENV_DATA_SIZE+1]
unsigned short first_lineno
const struct rb_block block
struct rb_captured_block captured
struct rb_method_definition_struct *const def
const VALUE defined_class
const struct vm_ifunc * ifunc
union rb_captured_block::@53 code
unsigned int ruby2_keywords
struct rb_iseq_constant_body::@45 param
unsigned int local_table_size
const struct rb_iseq_constant_body::@45::rb_iseq_param_keyword * keyword
rb_iseq_location_t location
struct rb_iseq_constant_body::@45::@47 flags
struct rb_iseq_struct * local_iseq
struct rb_iseq_constant_body * body
struct rb_method_entry_struct * original_me
rb_method_bmethod_t bmethod
enum method_optimized_type optimize_type
union rb_method_definition_struct::@41 body
struct rb_method_definition_struct *const def
rb_iseq_t * iseqptr
iseq pointer, should be separated from iseqval
rb_cref_t * cref
class reference, should be marked
const struct rb_block block
unsigned int is_from_method
rb_method_visibility_t method_visi
IFUNC (Internal FUNCtion)
struct vm_ifunc_argc argc
rb_block_call_func_t func
int rb_is_local_id(ID id)
VALUE rb_vm_frame_block_handler(const rb_control_frame_t *cfp)
VALUE rb_vm_top_self(void)
void rb_vm_block_ep_update(VALUE obj, const struct rb_block *dst, const VALUE *ep)
MJIT_STATIC VALUE rb_vm_bh_to_procval(const rb_execution_context_t *ec, VALUE block_handler)