Ruby  2.7.1p83(2020-03-31revisiona0c7c23c9cec0d0ffcba012279cd652d28ad5bf3)
method.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  method.h -
4 
5  $Author$
6  created at: Wed Jul 15 20:02:33 2009
7 
8  Copyright (C) 2009 Koichi Sasada
9 
10 **********************************************************************/
11 #ifndef RUBY_METHOD_H
12 #define RUBY_METHOD_H 1
13 
14 #include "internal.h"
15 
16 #ifndef END_OF_ENUMERATION
17 # if defined(__GNUC__) &&! defined(__STRICT_ANSI__)
18 # define END_OF_ENUMERATION(key)
19 # else
20 # define END_OF_ENUMERATION(key) END_OF_##key##_PLACEHOLDER = 0
21 # endif
22 #endif
23 
24 /* cref */
25 
26 typedef enum {
31 
34 
35 typedef struct rb_scope_visi_struct {
37  unsigned int module_func : 1;
39 
41 typedef struct rb_cref_struct {
45  struct rb_cref_struct * next;
47 } rb_cref_t;
48 
49 /* method data type */
50 
51 typedef struct rb_method_entry_struct {
58 
59 typedef struct rb_callable_method_entry_struct { /* same fields with rb_method_entry_t */
64  const VALUE owner;
66 
67 #define METHOD_ENTRY_VISI(me) (rb_method_visibility_t)(((me)->flags & (IMEMO_FL_USER0 | IMEMO_FL_USER1)) >> (IMEMO_FL_USHIFT+0))
68 #define METHOD_ENTRY_BASIC(me) (int) (((me)->flags & (IMEMO_FL_USER2 )) >> (IMEMO_FL_USHIFT+2))
69 #define METHOD_ENTRY_COMPLEMENTED(me) ((me)->flags & IMEMO_FL_USER3)
70 #define METHOD_ENTRY_COMPLEMENTED_SET(me) ((me)->flags = (me)->flags | IMEMO_FL_USER3)
71 
72 static inline void
73 METHOD_ENTRY_VISI_SET(rb_method_entry_t *me, rb_method_visibility_t visi)
74 {
75  VM_ASSERT((int)visi >= 0 && visi <= 3);
76  me->flags = (me->flags & ~(IMEMO_FL_USER0 | IMEMO_FL_USER1)) | (visi << (IMEMO_FL_USHIFT+0));
77 }
78 static inline void
79 METHOD_ENTRY_BASIC_SET(rb_method_entry_t *me, unsigned int basic)
80 {
81  VM_ASSERT(basic <= 1);
82  me->flags = (me->flags & ~(IMEMO_FL_USER2 )) | (basic << (IMEMO_FL_USHIFT+2));
83 }
84 static inline void
85 METHOD_ENTRY_FLAGS_SET(rb_method_entry_t *me, rb_method_visibility_t visi, unsigned int basic)
86 {
87  VM_ASSERT((int)visi >= 0 && visi <= 3);
88  VM_ASSERT(basic <= 1);
89  me->flags =
91  ((visi << (IMEMO_FL_USHIFT+0)) | (basic << (IMEMO_FL_USHIFT+2)));
92 }
93 static inline void
94 METHOD_ENTRY_FLAGS_COPY(rb_method_entry_t *dst, const rb_method_entry_t *src)
95 {
96  dst->flags =
99 }
100 
101 typedef enum {
115  END_OF_ENUMERATION(VM_METHOD_TYPE)
117 #define VM_METHOD_TYPE_MINIMUM_BITS 4
120 
121 #ifndef rb_iseq_t
122 typedef struct rb_iseq_struct rb_iseq_t;
123 #define rb_iseq_t rb_iseq_t
124 #endif
125 
126 typedef struct rb_method_iseq_struct {
129 } rb_method_iseq_t; /* check rb_add_method_iseq() when modify the fields */
130 
131 typedef struct rb_method_cfunc_struct {
133  VALUE (*invoker)(VALUE recv, int argc, const VALUE *argv, VALUE (*func)(ANYARGS));
134  int argc;
136 
137 typedef struct rb_method_attr_struct {
139  VALUE location; /* should be marked */
141 
142 typedef struct rb_method_alias_struct {
143  struct rb_method_entry_struct * original_me; /* original_me->klass is original owner */
145 
146 typedef struct rb_method_refined_struct {
150 
151 typedef struct rb_method_bmethod_struct {
152  VALUE proc; /* should be marked */
155 
161 };
162 
165  int alias_count : 28;
167 
168  union {
175 
177  } body;
178 
181 };
182 
184 STATIC_ASSERT(sizeof_method_def, offsetof(rb_method_definition_t, body)==8);
185 
186 #define UNDEFINED_METHOD_ENTRY_P(me) (!(me) || !(me)->def || (me)->def->type == VM_METHOD_TYPE_UNDEF)
187 #define UNDEFINED_REFINED_METHOD_P(def) \
188  ((def)->type == VM_METHOD_TYPE_REFINED && \
189  UNDEFINED_METHOD_ENTRY_P((def)->body.refined.orig_me))
190 
191 void rb_add_method_cfunc(VALUE klass, ID mid, VALUE (*func)(ANYARGS), int argc, rb_method_visibility_t visi);
193 void rb_add_refined_method_entry(VALUE refined_class, ID mid);
194 void rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_visibility_t visi);
195 
198 
200 
208 
212 
214 int rb_method_entry_eq(const rb_method_entry_t *m1, const rb_method_entry_t *m2);
216 
218 
220 
224 
226 
227 VALUE rb_unnamed_parameters(int arity);
228 
229 #endif /* RUBY_METHOD_H */
METHOD_VISI_PRIVATE
@ METHOD_VISI_PRIVATE
Definition: method.h:29
ID
unsigned long ID
Definition: ruby.h:103
RUBY_SYMBOL_EXPORT_END
#define RUBY_SYMBOL_EXPORT_END
Definition: missing.h:49
rb_method_entry_arity
int rb_method_entry_arity(const rb_method_entry_t *me)
Definition: proc.c:2543
obj
const VALUE VALUE obj
Definition: rb_mjit_min_header-2.7.1.h:5742
rb_method_bmethod_struct
Definition: method.h:151
rb_method_bmethod_struct::proc
VALUE proc
Definition: method.h:152
rb_hook_list_struct
Definition: vm_core.h:565
rb_callable_method_entry_with_refinements
const rb_callable_method_entry_t * rb_callable_method_entry_with_refinements(VALUE klass, ID id, VALUE *defined_class)
Definition: vm_method.c:917
rb_method_entry_t
struct rb_method_entry_struct rb_method_entry_t
rb_method_entry_create
rb_method_entry_t * rb_method_entry_create(ID called_id, VALUE klass, rb_method_visibility_t visi, const rb_method_definition_t *def)
Definition: vm_method.c:397
klass
VALUE klass
Definition: rb_mjit_min_header-2.7.1.h:13259
rb_method_alias_t
struct rb_method_alias_struct rb_method_alias_t
VM_METHOD_TYPE_REFINED
@ VM_METHOD_TYPE_REFINED
refinement
Definition: method.h:113
rb_iseq_struct
Definition: vm_core.h:456
rb_method_definition_struct::method_serial
uintptr_t method_serial
Definition: method.h:180
rb_method_entry_complement_defined_class
const rb_callable_method_entry_t * rb_method_entry_complement_defined_class(const rb_method_entry_t *src_me, ID called_id, VALUE defined_class)
Definition: vm_method.c:415
rb_method_cfunc_struct::invoker
VALUE(* invoker)(VALUE recv, int argc, const VALUE *argv, VALUE(*func)(ANYARGS))
Definition: method.h:133
VM_METHOD_TYPE_OPTIMIZED
@ VM_METHOD_TYPE_OPTIMIZED
Kernel::send, Proc::call, etc.
Definition: method.h:111
rb_add_method_iseq
void rb_add_method_iseq(VALUE klass, ID mid, const rb_iseq_t *iseq, rb_cref_t *cref, rb_method_visibility_t visi)
Definition: vm_method.c:684
rb_method_definition_struct::attr
rb_method_attr_t attr
Definition: method.h:171
rb_method_iseq_struct::cref
rb_cref_t * cref
class reference, should be marked
Definition: method.h:128
rb_callable_method_entry_struct::owner
const VALUE owner
Definition: method.h:64
METHOD_VISI_MASK
@ METHOD_VISI_MASK
Definition: method.h:32
rb_method_attr_struct::id
ID id
Definition: method.h:138
VALUE
unsigned long VALUE
Definition: ruby.h:102
rb_scope_visibility_set
void rb_scope_visibility_set(rb_method_visibility_t)
Definition: vm_method.c:1138
rb_method_iseq_t
struct rb_method_iseq_struct rb_method_iseq_t
offsetof
#define offsetof(p_type, field)
Definition: addrinfo.h:186
rb_scope_visi_struct::method_visi
rb_method_visibility_t method_visi
Definition: rb_mjit_min_header-2.7.1.h:8776
OPTIMIZED_METHOD_TYPE_BLOCK_CALL
@ OPTIMIZED_METHOD_TYPE_BLOCK_CALL
Definition: method.h:159
rb_callable_method_entry_struct
Definition: method.h:59
rb_method_definition_struct::type
rb_method_type_t type
Definition: rb_mjit_min_header-2.7.1.h:8882
rb_method_attr_struct
Definition: method.h:137
rb_method_entry_struct::def
struct rb_method_definition_struct *const def
Definition: method.h:54
IMEMO_FL_USER1
#define IMEMO_FL_USER1
Definition: internal.h:1173
rb_method_entry_at
const rb_method_entry_t * rb_method_entry_at(VALUE obj, ID id)
Definition: vm_method.c:756
rb_method_definition_struct::BITFIELD
BITFIELD(rb_method_type_t, type, VM_METHOD_TYPE_MINIMUM_BITS)
rb_method_definition_struct::optimize_type
enum method_optimized_type optimize_type
Definition: method.h:176
rb_method_definition_struct::refined
rb_method_refined_t refined
Definition: method.h:173
rb_method_iseq_struct
Definition: method.h:126
rb_method_visibility_t
rb_method_visibility_t
Definition: method.h:26
iseq
const rb_iseq_t * iseq
Definition: rb_mjit_min_header-2.7.1.h:13509
rb_method_refined_struct::orig_me
struct rb_method_entry_struct * orig_me
Definition: method.h:147
me
const rb_callable_method_entry_t * me
Definition: rb_mjit_min_header-2.7.1.h:13231
rb_method_iseq_struct::iseqptr
rb_iseq_t * iseqptr
iseq pointer, should be separated from iseqval
Definition: method.h:127
rb_method_entry_copy
void rb_method_entry_copy(rb_method_entry_t *dst, const rb_method_entry_t *src)
Definition: vm_method.c:451
uintptr_t
unsigned int uintptr_t
Definition: win32.h:106
rb_method_entry_struct::owner
VALUE owner
Definition: method.h:56
rb_add_method_cfunc
void rb_add_method_cfunc(VALUE klass, ID mid, VALUE(*func)(ANYARGS), int argc, rb_method_visibility_t visi)
Definition: vm_method.c:134
rb_method_definition_struct::alias_count
int alias_count
Definition: method.h:165
rb_method_entry_set
rb_method_entry_t * rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *, rb_method_visibility_t noex)
Definition: vm_method.c:707
rb_callable_method_entry
const RUBY_SYMBOL_EXPORT_END rb_callable_method_entry_t * rb_callable_method_entry(VALUE klass, ID id)
Definition: vm_method.c:878
rb_resolve_refined_method
const rb_method_entry_t * rb_resolve_refined_method(VALUE refinements, const rb_method_entry_t *me)
Definition: vm_method.c:972
OPTIMIZED_METHOD_TYPE_SEND
@ OPTIMIZED_METHOD_TYPE_SEND
Definition: method.h:157
rb_method_alias_struct
Definition: method.h:142
rb_method_definition_struct::bmethod
rb_method_bmethod_t bmethod
Definition: method.h:174
VM_METHOD_TYPE_IVAR
@ VM_METHOD_TYPE_IVAR
attr_reader or attr_accessor
Definition: method.h:105
VM_ASSERT
#define VM_ASSERT(expr)
Definition: vm_core.h:56
rb_method_entry_eq
int rb_method_entry_eq(const rb_method_entry_t *m1, const rb_method_entry_t *m2)
Definition: vm_method.c:1476
IMEMO_FL_USER0
#define IMEMO_FL_USER0
Definition: internal.h:1172
rb_free_method_entry
void rb_free_method_entry(const rb_method_entry_t *me)
Definition: vm_method.c:174
VM_METHOD_TYPE_UNDEF
@ VM_METHOD_TYPE_UNDEF
Definition: method.h:109
rb_resolve_me_location
const RUBY_SYMBOL_EXPORT_BEGIN rb_method_entry_t * rb_resolve_me_location(const rb_method_entry_t *, VALUE[5])
Definition: thread.c:5400
rb_method_definition_struct::complemented_count
int complemented_count
Definition: method.h:166
IMEMO_FL_USER2
#define IMEMO_FL_USER2
Definition: internal.h:1174
rb_method_definition_struct::cfunc
rb_method_cfunc_t cfunc
Definition: method.h:170
OPTIMIZED_METHOD_TYPE__MAX
@ OPTIMIZED_METHOD_TYPE__MAX
Definition: method.h:160
rb_callable_method_entry_struct::called_id
ID called_id
Definition: method.h:63
rb_method_definition_struct::body
union rb_method_definition_struct::@118 body
rb_method_entry_location
VALUE rb_method_entry_location(const rb_method_entry_t *me)
Definition: proc.c:2713
OPTIMIZED_METHOD_TYPE_CALL
@ OPTIMIZED_METHOD_TYPE_CALL
Definition: method.h:158
rb_scope_visi_struct::module_func
unsigned int module_func
Definition: method.h:37
rb_method_attr_struct::location
VALUE location
Definition: method.h:139
rb_cref_struct::scope_visi
const rb_scope_visibility_t scope_visi
Definition: method.h:46
rb_callable_method_entry_without_refinements
const rb_callable_method_entry_t * rb_callable_method_entry_without_refinements(VALUE klass, ID id, VALUE *defined_class)
Definition: vm_method.c:931
rb_callable_method_entry_struct::defined_class
const VALUE defined_class
Definition: method.h:61
rb_method_definition_struct::alias
rb_method_alias_t alias
Definition: method.h:172
IMEMO_FL_USHIFT
#define IMEMO_FL_USHIFT
Definition: internal.h:1171
VM_METHOD_TYPE_CFUNC
@ VM_METHOD_TYPE_CFUNC
C method.
Definition: method.h:103
rb_method_cfunc_struct::func
VALUE(* func)(ANYARGS)
Definition: method.h:132
VM_METHOD_TYPE_NOTIMPLEMENTED
@ VM_METHOD_TYPE_NOTIMPLEMENTED
Definition: method.h:110
rb_cref_struct
CREF (Class REFerence)
Definition: method.h:41
rb_scope_visi_struct::BITFIELD
BITFIELD(rb_method_visibility_t, method_visi, 3)
st_index_t
st_data_t st_index_t
Definition: st.h:50
METHOD_VISI_UNDEF
@ METHOD_VISI_UNDEF
Definition: method.h:27
VM_METHOD_TYPE_BMETHOD
@ VM_METHOD_TYPE_BMETHOD
Definition: method.h:106
rb_unnamed_parameters
VALUE rb_unnamed_parameters(int arity)
Definition: proc.c:1262
rb_method_definition_struct::iseq
rb_method_iseq_t iseq
Definition: method.h:169
rb_method_entry_struct::flags
VALUE flags
Definition: method.h:52
rb_method_alias_struct::original_me
struct rb_method_entry_struct * original_me
Definition: method.h:143
METHOD_VISI_PROTECTED
@ METHOD_VISI_PROTECTED
Definition: method.h:30
rb_add_refined_method_entry
void rb_add_refined_method_entry(VALUE refined_class, ID mid)
Definition: vm_method.c:491
VM_METHOD_TYPE_ZSUPER
@ VM_METHOD_TYPE_ZSUPER
Definition: method.h:107
METHOD_VISI_PUBLIC
@ METHOD_VISI_PUBLIC
Definition: method.h:28
rb_method_refined_struct
Definition: method.h:146
rb_method_entry_clone
const rb_method_entry_t * rb_method_entry_clone(const rb_method_entry_t *me)
Definition: vm_method.c:406
rb_cref_struct::klass
VALUE klass
Definition: method.h:44
rb_method_bmethod_struct::hooks
struct rb_hook_list_struct * hooks
Definition: method.h:153
rb_method_type_t
rb_method_type_t
Definition: method.h:101
rb_method_refined_struct::owner
VALUE owner
Definition: method.h:148
END_OF_ENUMERATION
#define END_OF_ENUMERATION(key)
Definition: method.h:20
rb_cref_t
struct rb_cref_struct rb_cref_t
CREF (Class REFerence)
rb_add_method
void rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_visibility_t visi)
Definition: vm_method.c:674
VM_METHOD_TYPE_MISSING
@ VM_METHOD_TYPE_MISSING
wrapper for method_missing(id)
Definition: method.h:112
rb_method_cfunc_struct::argc
int argc
Definition: method.h:134
internal.h
argv
char ** argv
Definition: ruby.c:223
RUBY_SYMBOL_EXPORT_BEGIN
#define RUBY_SYMBOL_EXPORT_BEGIN
Definition: missing.h:48
rb_method_entry
const rb_method_entry_t * rb_method_entry(VALUE klass, ID id)
Definition: vm_method.c:837
VM_METHOD_TYPE_ATTRSET
@ VM_METHOD_TYPE_ATTRSET
attr_writer or attr_accessor
Definition: method.h:104
ANYARGS
#define ANYARGS
Definition: defines.h:201
rb_method_entry_struct::defined_class
VALUE defined_class
Definition: method.h:53
rb_method_refined_t
struct rb_method_refined_struct rb_method_refined_t
rb_callable_method_entry_struct::flags
VALUE flags
Definition: method.h:60
rb_cref_struct::refinements
VALUE refinements
Definition: method.h:43
rb_method_entry_struct::called_id
ID called_id
Definition: method.h:55
argc
int argc
Definition: ruby.c:222
VM_METHOD_TYPE_ISEQ
@ VM_METHOD_TYPE_ISEQ
Ruby method.
Definition: method.h:102
rb_cref_struct::flags
VALUE flags
Definition: method.h:42
rb_method_cfunc_t
struct rb_method_cfunc_struct rb_method_cfunc_t
rb_method_entry_without_refinements
const rb_method_entry_t * rb_method_entry_without_refinements(VALUE klass, ID id, VALUE *defined_class)
Definition: vm_method.c:925
rb_method_definition_struct::original_id
ID original_id
Definition: method.h:179
rb_method_definition_struct
Definition: method.h:163
rb_callable_method_entry_struct::def
struct rb_method_definition_struct *const def
Definition: method.h:62
rb_scope_visibility_t
struct rb_scope_visi_struct rb_scope_visibility_t
rb_scope_visi_struct
Definition: method.h:35
rb_hash_method_entry
st_index_t rb_hash_method_entry(st_index_t hash, const rb_method_entry_t *me)
Definition: vm_method.c:1575
method_optimized_type
method_optimized_type
Definition: method.h:156
rb_method_entry_struct
Definition: method.h:51
rb_callable_method_entry_t
struct rb_callable_method_entry_struct rb_callable_method_entry_t
rb_method_cfunc_struct
Definition: method.h:131
rb_method_entry_with_refinements
const rb_method_entry_t * rb_method_entry_with_refinements(VALUE klass, ID id, VALUE *defined_class)
Definition: vm_method.c:911
rb_method_attr_t
struct rb_method_attr_struct rb_method_attr_t
STATIC_ASSERT
STATIC_ASSERT(VM_METHOD_TYPE_MINIMUM_BITS, VM_METHOD_TYPE_REFINED<=(1<< VM_METHOD_TYPE_MINIMUM_BITS))
rb_method_bmethod_t
struct rb_method_bmethod_struct rb_method_bmethod_t
ruby::backward::cxxanyargs::type
VALUE type(ANYARGS)
ANYARGS-ed function type.
Definition: cxxanyargs.hpp:39
VM_METHOD_TYPE_ALIAS
@ VM_METHOD_TYPE_ALIAS
Definition: method.h:108
VM_METHOD_TYPE_MINIMUM_BITS
#define VM_METHOD_TYPE_MINIMUM_BITS
Definition: method.h:117
src
__inline__ const void *__restrict src
Definition: rb_mjit_min_header-2.7.1.h:2836
rb_cref_struct::next
struct rb_cref_struct * next
Definition: method.h:45