Ruby 2.0.0p353(2013-11-22revision43784)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

method.h
Go to the documentation of this file.
1 /**********************************************************************
2
3 method.h -
4
5 $Author: nagachika $
6 created at: Wed Jul 15 20:02:33 2009
7
8 Copyright (C) 2009 Koichi Sasada
9
10 **********************************************************************/
11 #ifndef METHOD_H
12 #define METHOD_H
13
14 #ifndef END_OF_ENUMERATION
15 # ifdef __GNUC__
16 # define END_OF_ENUMERATION(key)
17 # else
18 # define END_OF_ENUMERATION(key) END_OF_##key##_PLACEHOLDER = 0
19 # endif
20 #endif
21
22 typedef enum {
23 NOEX_PUBLIC = 0x00,
24 NOEX_NOSUPER = 0x01,
25 NOEX_PRIVATE = 0x02,
26 NOEX_PROTECTED = 0x04,
27 NOEX_MASK = 0x06,
28 NOEX_BASIC = 0x08,
29 NOEX_UNDEF = NOEX_NOSUPER,
30 NOEX_MODFUNC = 0x12,
31 NOEX_SUPER = 0x20,
32 NOEX_VCALL = 0x40,
33 NOEX_RESPONDS = 0x80,
34
35 NOEX_BIT_WIDTH = 8,
36 NOEX_SAFE_SHIFT_OFFSET = ((NOEX_BIT_WIDTH+3)/4)*4 /* round up to nibble */
37 } rb_method_flag_t;
38
39 #define NOEX_SAFE(n) ((int)((n) >> NOEX_SAFE_SHIFT_OFFSET) & 0x0F)
40 #define NOEX_WITH(n, s) (((s) << NOEX_SAFE_SHIFT_OFFSET) | (n) | (ruby_running ? 0 : NOEX_BASIC))
41 #define NOEX_WITH_SAFE(n) NOEX_WITH((n), rb_safe_level())
42
43 /* method data type */
44
45 typedef enum {
46 VM_METHOD_TYPE_ISEQ,
47 VM_METHOD_TYPE_CFUNC,
48 VM_METHOD_TYPE_ATTRSET,
49 VM_METHOD_TYPE_IVAR,
50 VM_METHOD_TYPE_BMETHOD,
51 VM_METHOD_TYPE_ZSUPER,
52 VM_METHOD_TYPE_UNDEF,
53 VM_METHOD_TYPE_NOTIMPLEMENTED,
54 VM_METHOD_TYPE_OPTIMIZED, /* Kernel#send, Proc#call, etc */
55 VM_METHOD_TYPE_MISSING, /* wrapper for method_missing(id) */
56 VM_METHOD_TYPE_REFINED,
57
58 END_OF_ENUMERATION(VM_METHOD_TYPE)
59 } rb_method_type_t;
60
61 struct rb_call_info_struct;
62
63 typedef struct rb_method_cfunc_struct {
64 VALUE (*func)(ANYARGS);
65 VALUE (*invoker)(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv);
66 int argc;
67 } rb_method_cfunc_t;
68
69 typedef struct rb_method_attr_struct {
70 ID id;
71 VALUE location;
72 } rb_method_attr_t;
73
74 typedef struct rb_iseq_struct rb_iseq_t;
75
76 typedef struct rb_method_definition_struct {
77 rb_method_type_t type; /* method type */
78 ID original_id;
79 union {
80 rb_iseq_t *iseq; /* should be mark */
81 rb_method_cfunc_t cfunc;
82 rb_method_attr_t attr;
83 VALUE proc; /* should be mark */
84 enum method_optimized_type {
85 OPTIMIZED_METHOD_TYPE_SEND,
86 OPTIMIZED_METHOD_TYPE_CALL,
87
88 OPTIMIZED_METHOD_TYPE__MAX
89 } optimize_type;
90 struct rb_method_entry_struct *orig_me;
91 } body;
92 int alias_count;
93 } rb_method_definition_t;
94
95 typedef struct rb_method_entry_struct {
96 rb_method_flag_t flag;
97 char mark;
98 rb_method_definition_t *def;
99 ID called_id;
100 VALUE klass; /* should be mark */
101 } rb_method_entry_t;
102
103 struct unlinked_method_entry_list_entry {
104 struct unlinked_method_entry_list_entry *next;
105 rb_method_entry_t *me;
106 };
107
108 #define UNDEFINED_METHOD_ENTRY_P(me) (!(me) || !(me)->def || (me)->def->type == VM_METHOD_TYPE_UNDEF)
109
110 void rb_add_method_cfunc(VALUE klass, ID mid, VALUE (*func)(ANYARGS), int argc, rb_method_flag_t noex);
111 rb_method_entry_t *rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_flag_t noex);
112 rb_method_entry_t *rb_method_entry(VALUE klass, ID id, VALUE *define_class_ptr);
113 void rb_add_refined_method_entry(VALUE refined_class, ID mid);
114 rb_method_entry_t *rb_resolve_refined_method(VALUE refinements,
115 const rb_method_entry_t *me,
116 VALUE *defined_class_ptr);
117 rb_method_entry_t *rb_method_entry_with_refinements(VALUE klass, ID id,
118 VALUE *defined_class_ptr);
119 rb_method_entry_t *rb_method_entry_without_refinements(VALUE klass, ID id,
120 VALUE *defined_class_ptr);
121
122 rb_method_entry_t *rb_method_entry_get_without_cache(VALUE klass, ID id, VALUE *define_class_ptr);
123 rb_method_entry_t *rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *, rb_method_flag_t noex);
124
125 int rb_method_entry_arity(const rb_method_entry_t *me);
126 int rb_method_entry_eq(const rb_method_entry_t *m1, const rb_method_entry_t *m2);
127 st_index_t rb_hash_method_entry(st_index_t hash, const rb_method_entry_t *me);
128
129 VALUE rb_method_entry_location(rb_method_entry_t *me);
130 VALUE rb_mod_method_location(VALUE mod, ID id);
131 VALUE rb_obj_method_location(VALUE obj, ID id);
132
133 void rb_mark_method_entry(const rb_method_entry_t *me);
134 void rb_free_method_entry(rb_method_entry_t *me);
135 void rb_sweep_method_entry(void *vm);
136 void rb_free_m_table(st_table *tbl);
137
138 #endif /* METHOD_H */
unlinked_method_entry_list_entry::next
struct unlinked_method_entry_list_entry * next
Definition: method.h:104
rb_method_entry_struct::mark
char mark
Definition: method.h:97
VM_METHOD_TYPE_MISSING
Definition: method.h:55
rb_method_definition_struct
Definition: method.h:76
rb_method_attr_struct
Definition: method.h:69
NOEX_RESPONDS
Definition: method.h:33
rb_method_definition_struct::type
rb_method_type_t type
Definition: method.h:77
rb_method_definition_struct::attr
rb_method_attr_t attr
Definition: method.h:82
st_table
Definition: ripper.y:77
rb_method_definition_struct::OPTIMIZED_METHOD_TYPE_CALL
Definition: method.h:86
rb_method_entry_struct::flag
rb_method_flag_t flag
Definition: method.h:96
func
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:108
NOEX_SUPER
Definition: method.h:31
rb_mod_method_location
VALUE rb_mod_method_location(VALUE mod, ID id)
Definition: proc.c:1883
rb_method_entry_without_refinements
rb_method_entry_t * rb_method_entry_without_refinements(VALUE klass, ID id, VALUE *defined_class_ptr)
Definition: vm_method.c:632
rb_method_definition_struct::orig_me
struct rb_method_entry_struct * orig_me
Definition: method.h:90
rb_method_attr_t
struct rb_method_attr_struct rb_method_attr_t
VM_METHOD_TYPE_ISEQ
Definition: method.h:46
rb_method_flag_t
rb_method_flag_t
Definition: method.h:22
NOEX_MODFUNC
Definition: method.h:30
rb_method_entry_struct::called_id
ID called_id
Definition: method.h:99
rb_sweep_method_entry
void rb_sweep_method_entry(void *vm)
Definition: vm_method.c:122
rb_method_definition_struct::body
union rb_method_definition_struct::@112 body
rb_method_entry_t
struct rb_method_entry_struct rb_method_entry_t
NOEX_BASIC
Definition: method.h:28
VM_METHOD_TYPE_BMETHOD
Definition: method.h:50
rb_method_attr_struct::id
ID id
Definition: method.h:70
tbl
VALUE tbl
Definition: tkutil.c:1280
rb_method_cfunc_struct::argc
int argc
Definition: method.h:66
rb_method_definition_t
struct rb_method_definition_struct rb_method_definition_t
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:1094
rb_mark_method_entry
void rb_mark_method_entry(const rb_method_entry_t *me)
Definition: gc.c:2447
VM_METHOD_TYPE_REFINED
Definition: method.h:56
rb_method_definition_struct::original_id
ID original_id
Definition: method.h:78
hash
VALUE hash
Definition: tkutil.c:267
NOEX_MASK
Definition: method.h:27
rb_method_definition_struct::cfunc
rb_method_cfunc_t cfunc
Definition: method.h:81
rb_method_entry_get_without_cache
rb_method_entry_t * rb_method_entry_get_without_cache(VALUE klass, ID id, VALUE *define_class_ptr)
Definition: vm_method.c:521
rb_method_definition_struct::proc
VALUE proc
Definition: method.h:83
rb_method_definition_struct::OPTIMIZED_METHOD_TYPE__MAX
Definition: method.h:88
VM_METHOD_TYPE_UNDEF
Definition: method.h:52
ID
unsigned long ID
Definition: ripper.y:105
rb_free_method_entry
void rb_free_method_entry(rb_method_entry_t *me)
Definition: vm_method.c:169
obj
static VALUE VALUE obj
Definition: tcltklib.c:3158
ANYARGS
#define ANYARGS
rb_method_entry_arity
int rb_method_entry_arity(const rb_method_entry_t *me)
Definition: proc.c:1743
rb_method_entry_struct
Definition: method.h:95
rb_method_definition_struct::iseq
rb_iseq_t * iseq
Definition: method.h:80
rb_method_definition_struct::optimize_type
enum rb_method_definition_struct::@112::method_optimized_type optimize_type
rb_resolve_refined_method
rb_method_entry_t * rb_resolve_refined_method(VALUE refinements, const rb_method_entry_t *me, VALUE *defined_class_ptr)
Definition: vm_method.c:586
rb_method_entry
rb_method_entry_t * rb_method_entry(VALUE klass, ID id, VALUE *define_class_ptr)
Definition: vm_method.c:551
rb_method_cfunc_struct::func
VALUE(* func)(ANYARGS)
Definition: method.h:64
rb_method_entry_struct::klass
VALUE klass
Definition: method.h:100
VM_METHOD_TYPE_NOTIMPLEMENTED
Definition: method.h:53
rb_method_type_t
rb_method_type_t
Definition: method.h:45
rb_method_cfunc_struct
Definition: method.h:63
argv
VALUE * argv
Definition: tcltklib.c:1971
VM_METHOD_TYPE_ATTRSET
Definition: method.h:48
rb_method_entry_with_refinements
rb_method_entry_t * rb_method_entry_with_refinements(VALUE klass, ID id, VALUE *defined_class_ptr)
Definition: vm_method.c:614
rb_method_attr_struct::location
VALUE location
Definition: method.h:71
rb_add_method
rb_method_entry_t * rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_flag_t noex)
Definition: vm_method.c:402
NOEX_SAFE_SHIFT_OFFSET
Definition: method.h:36
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:1176
type
int type
Definition: tcltklib.c:111
argc
int argc
Definition: tcltklib.c:1970
NOEX_PROTECTED
Definition: method.h:26
rb_method_cfunc_struct::invoker
VALUE(* invoker)(VALUE(*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv)
Definition: method.h:65
VM_METHOD_TYPE_OPTIMIZED
Definition: method.h:54
rb_method_cfunc_t
struct rb_method_cfunc_struct rb_method_cfunc_t
rb_method_entry_location
VALUE rb_method_entry_location(rb_method_entry_t *me)
Definition: proc.c:1876
END_OF_ENUMERATION
#define END_OF_ENUMERATION(key)
Definition: method.h:18
rb_method_entry_struct::def
rb_method_definition_t * def
Definition: method.h:98
rb_call_info_struct
Definition: vm_core.h:146
st_index_t
st_data_t st_index_t
Definition: ripper.y:63
klass
klass
Definition: tcltklib.c:3504
rb_method_definition_struct::OPTIMIZED_METHOD_TYPE_SEND
Definition: method.h:85
rb_add_refined_method_entry
void rb_add_refined_method_entry(VALUE refined_class, ID mid)
Definition: vm_method.c:210
rb_iseq_struct
Definition: vm_core.h:196
NOEX_BIT_WIDTH
Definition: method.h:35
unlinked_method_entry_list_entry::me
rb_method_entry_t * me
Definition: method.h:105
rb_method_definition_struct::alias_count
int alias_count
Definition: method.h:92
VALUE
unsigned long VALUE
Definition: ripper.y:104
VM_METHOD_TYPE_CFUNC
Definition: method.h:47
rb_method_entry_set
rb_method_entry_t * rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *, rb_method_flag_t noex)
Definition: vm_method.c:464
NOEX_PUBLIC
Definition: method.h:23
mod
#define mod(x, y)
Definition: date_strftime.c:28
rb_add_method_cfunc
void rb_add_method_cfunc(VALUE klass, ID mid, VALUE(*func)(ANYARGS), int argc, rb_method_flag_t noex)
Definition: vm_method.c:84
VM_METHOD_TYPE_IVAR
Definition: method.h:49
NOEX_UNDEF
Definition: method.h:29
NOEX_VCALL
Definition: method.h:32
rb_free_m_table
void rb_free_m_table(st_table *tbl)
Definition: gc.c:800
NOEX_PRIVATE
Definition: method.h:25
rb_obj_method_location
VALUE rb_obj_method_location(VALUE obj, ID id)
Definition: proc.c:1890
unlinked_method_entry_list_entry
Definition: method.h:103
VM_METHOD_TYPE_ZSUPER
Definition: method.h:51
NOEX_NOSUPER
Definition: method.h:24