2 #define RUBY_METHOD_H 1
15 #include "internal/imemo.h"
16 #include "internal/compilers.h"
17 #include "internal/static_assert.h"
19 #ifndef END_OF_ENUMERATION
20 # if defined(__GNUC__) &&! defined(__STRICT_ANSI__)
21 # define END_OF_ENUMERATION(key)
23 # define END_OF_ENUMERATION(key) END_OF_##key##_PLACEHOLDER = 0
30 METHOD_VISI_UNDEF = 0x00,
31 METHOD_VISI_PUBLIC = 0x01,
32 METHOD_VISI_PRIVATE = 0x02,
33 METHOD_VISI_PROTECTED = 0x03,
35 METHOD_VISI_MASK = 0x03
36 } rb_method_visibility_t;
39 BITFIELD(rb_method_visibility_t, method_visi, 3);
40 unsigned int module_func : 1;
64 const VALUE defined_class;
70 #define METHOD_ENTRY_VISI(me) (rb_method_visibility_t)(((me)->flags & (IMEMO_FL_USER0 | IMEMO_FL_USER1)) >> (IMEMO_FL_USHIFT+0))
71 #define METHOD_ENTRY_BASIC(me) (int) (((me)->flags & (IMEMO_FL_USER2 )) >> (IMEMO_FL_USHIFT+2))
72 #define METHOD_ENTRY_COMPLEMENTED(me) ((me)->flags & IMEMO_FL_USER3)
73 #define METHOD_ENTRY_COMPLEMENTED_SET(me) ((me)->flags |= IMEMO_FL_USER3)
74 #define METHOD_ENTRY_CACHED(me) ((me)->flags & IMEMO_FL_USER4)
75 #define METHOD_ENTRY_CACHED_SET(me) ((me)->flags |= IMEMO_FL_USER4)
76 #define METHOD_ENTRY_INVALIDATED(me) ((me)->flags & IMEMO_FL_USER5)
77 #define METHOD_ENTRY_INVALIDATED_SET(me) ((me)->flags |= IMEMO_FL_USER5)
82 VM_ASSERT((
int)visi >= 0 && visi <= 3);
83 me->flags = (me->flags & ~(IMEMO_FL_USER0 | IMEMO_FL_USER1)) | (visi << (IMEMO_FL_USHIFT+0));
88 VM_ASSERT(basic <= 1);
89 me->flags = (me->flags & ~(IMEMO_FL_USER2 )) | (basic << (IMEMO_FL_USHIFT+2));
92 METHOD_ENTRY_FLAGS_SET(
rb_method_entry_t *me, rb_method_visibility_t visi,
unsigned int basic)
94 VM_ASSERT((
int)visi >= 0 && visi <= 3);
95 VM_ASSERT(basic <= 1);
97 (me->flags & ~(IMEMO_FL_USER0|IMEMO_FL_USER1|IMEMO_FL_USER2)) |
98 ((visi << (IMEMO_FL_USHIFT+0)) | (basic << (IMEMO_FL_USHIFT+2)));
104 (dst->flags & ~(IMEMO_FL_USER0|IMEMO_FL_USER1|IMEMO_FL_USER2
106 (src->flags & (IMEMO_FL_USER0|IMEMO_FL_USER1|IMEMO_FL_USER2|IMEMO_FL_USER3));
111 VM_METHOD_TYPE_CFUNC,
112 VM_METHOD_TYPE_ATTRSET,
114 VM_METHOD_TYPE_BMETHOD,
115 VM_METHOD_TYPE_ZSUPER,
116 VM_METHOD_TYPE_ALIAS,
117 VM_METHOD_TYPE_UNDEF,
118 VM_METHOD_TYPE_NOTIMPLEMENTED,
119 VM_METHOD_TYPE_OPTIMIZED,
120 VM_METHOD_TYPE_MISSING,
121 VM_METHOD_TYPE_REFINED,
123 END_OF_ENUMERATION(VM_METHOD_TYPE)
125 #define VM_METHOD_TYPE_MINIMUM_BITS 4
126 STATIC_ASSERT(VM_METHOD_TYPE_MINIMUM_BITS,
127 VM_METHOD_TYPE_REFINED <= (1<<VM_METHOD_TYPE_MINIMUM_BITS));
131 #define rb_iseq_t rb_iseq_t
162 VALUE defined_ractor;
165 enum method_optimized_type {
166 OPTIMIZED_METHOD_TYPE_SEND,
167 OPTIMIZED_METHOD_TYPE_CALL,
168 OPTIMIZED_METHOD_TYPE_BLOCK_CALL,
169 OPTIMIZED_METHOD_TYPE_STRUCT_AREF,
170 OPTIMIZED_METHOD_TYPE_STRUCT_ASET,
171 OPTIMIZED_METHOD_TYPE__MAX
175 enum method_optimized_type type;
180 BITFIELD(rb_method_type_t,
type, VM_METHOD_TYPE_MINIMUM_BITS);
181 unsigned int iseq_overload: 1;
182 unsigned int no_redef_warning: 1;
183 unsigned int aliased : 1;
184 int reference_count : 28;
197 uintptr_t method_serial;
205 #define UNDEFINED_METHOD_ENTRY_P(me) (!(me) || !(me)->def || (me)->def->type == VM_METHOD_TYPE_UNDEF)
206 #define UNDEFINED_REFINED_METHOD_P(def) \
207 ((def)->type == VM_METHOD_TYPE_REFINED && \
208 UNDEFINED_METHOD_ENTRY_P((def)->body.refined.orig_me))
210 void rb_add_method(
VALUE klass,
ID mid, rb_method_type_t
type,
void *option, rb_method_visibility_t visi);
211 void rb_add_method_cfunc(
VALUE klass,
ID mid,
VALUE (*func)(
ANYARGS),
int argc, rb_method_visibility_t visi);
213 void rb_add_method_optimized(
VALUE klass,
ID mid,
enum method_optimized_type,
unsigned int index, rb_method_visibility_t visi);
214 void rb_add_refined_method_entry(
VALUE refined_class,
ID mid);
225 RUBY_SYMBOL_EXPORT_BEGIN
227 RUBY_SYMBOL_EXPORT_END
249 void rb_scope_visibility_set(rb_method_visibility_t);
251 VALUE rb_unnamed_parameters(
int arity);
253 void rb_clear_method_cache(
VALUE klass_or_module,
ID mid);
254 void rb_clear_all_refinement_method_cache(
void);
VALUE type(ANYARGS)
ANYARGS-ed function type.
#define ANYARGS
Functions declared using this macro take arbitrary arguments, including void.
rb_cref_t * cref
class reference, should be marked
const rb_iseq_t * iseqptr
iseq pointer, should be separated from iseqval
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
uintptr_t VALUE
Type that represents a Ruby object.