looksee 4.2.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +15 -0
  3. data/Rakefile +27 -0
  4. data/ext/extconf.rb +6 -7
  5. data/ext/mri/3.0.0/id_table.h +36 -0
  6. data/ext/mri/3.0.0/internal/array.h +119 -0
  7. data/ext/mri/3.0.0/internal/class.h +174 -0
  8. data/ext/mri/3.0.0/internal/compilers.h +108 -0
  9. data/ext/mri/3.0.0/internal/gc.h +161 -0
  10. data/ext/mri/3.0.0/internal/imemo.h +243 -0
  11. data/ext/mri/3.0.0/internal/serial.h +24 -0
  12. data/ext/mri/3.0.0/internal/static_assert.h +17 -0
  13. data/ext/mri/3.0.0/internal/warnings.h +17 -0
  14. data/ext/mri/3.0.0/internal.h +107 -0
  15. data/ext/mri/3.0.0/method.h +246 -0
  16. data/ext/mri/3.2.0/id_table.h +36 -0
  17. data/ext/mri/3.2.0/internal/array.h +162 -0
  18. data/ext/mri/3.2.0/internal/class.h +212 -0
  19. data/ext/mri/3.2.0/internal/compilers.h +107 -0
  20. data/ext/mri/3.2.0/internal/gc.h +188 -0
  21. data/ext/mri/3.2.0/internal/imemo.h +242 -0
  22. data/ext/mri/3.2.0/internal/serial.h +23 -0
  23. data/ext/mri/3.2.0/internal/static_assert.h +16 -0
  24. data/ext/mri/3.2.0/internal/warnings.h +16 -0
  25. data/ext/mri/3.2.0/internal.h +113 -0
  26. data/ext/mri/{2.3.0 → 3.2.0}/method.h +95 -55
  27. data/ext/mri/mri.c +7 -37
  28. data/lib/looksee/adapter/base.rb +17 -3
  29. data/lib/looksee/adapter.rb +0 -1
  30. data/lib/looksee/clean.rb +1 -3
  31. data/lib/looksee/core_ext.rb +21 -9
  32. data/lib/looksee/help.rb +2 -2
  33. data/lib/looksee/inspector.rb +11 -0
  34. data/lib/looksee/lookup_path.rb +1 -1
  35. data/lib/looksee/version.rb +1 -1
  36. data/spec/looksee/adapter_spec.rb +53 -47
  37. data/spec/looksee/core_ext_spec.rb +2 -2
  38. data/spec/looksee/inspector_spec.rb +42 -0
  39. data/spec/looksee/lookup_path_spec.rb +1 -1
  40. metadata +34 -20
  41. data/ext/mri/2.1.0/internal.h +0 -889
  42. data/ext/mri/2.1.0/method.h +0 -142
  43. data/ext/mri/2.2.0/internal.h +0 -1182
  44. data/ext/mri/2.2.0/method.h +0 -141
  45. data/ext/mri/2.3.0/internal.h +0 -1404
  46. data/ext/rbx/rbx.c +0 -4
  47. data/lib/looksee/adapter/rubinius.rb +0 -25
@@ -0,0 +1,243 @@
1
+ #ifndef INTERNAL_IMEMO_H /*-*-C-*-vi:se ft=c:*/
2
+ #define INTERNAL_IMEMO_H
3
+ /**
4
+ * @file
5
+ * @author Ruby developers <ruby-core@ruby-lang.org>
6
+ * @copyright This file is a part of the programming language Ruby.
7
+ * Permission is hereby granted, to either redistribute and/or
8
+ * modify this file, provided that the conditions mentioned in the
9
+ * file COPYING are met. Consult the file for details.
10
+ * @brief IMEMO: Internal memo object.
11
+ */
12
+ #include "ruby/internal/config.h"
13
+ #include <stddef.h> /* for size_t */
14
+ #include "internal/array.h" /* for rb_ary_tmp_new_fill */
15
+ #include "internal/gc.h" /* for RB_OBJ_WRITE */
16
+ #include "ruby/internal/stdbool.h" /* for bool */
17
+ #include "ruby/ruby.h" /* for rb_block_call_func_t */
18
+
19
+ #ifndef IMEMO_DEBUG
20
+ # define IMEMO_DEBUG 0
21
+ #endif
22
+
23
+ #define IMEMO_MASK 0x0f
24
+
25
+ /* FL_USER0 to FL_USER3 is for type */
26
+ #define IMEMO_FL_USHIFT (FL_USHIFT + 4)
27
+ #define IMEMO_FL_USER0 FL_USER4
28
+ #define IMEMO_FL_USER1 FL_USER5
29
+ #define IMEMO_FL_USER2 FL_USER6
30
+ #define IMEMO_FL_USER3 FL_USER7
31
+ #define IMEMO_FL_USER4 FL_USER8
32
+ #define IMEMO_FL_USER5 FL_USER9
33
+
34
+ enum imemo_type {
35
+ imemo_env = 0,
36
+ imemo_cref = 1, /*!< class reference */
37
+ imemo_svar = 2, /*!< special variable */
38
+ imemo_throw_data = 3,
39
+ imemo_ifunc = 4, /*!< iterator function */
40
+ imemo_memo = 5,
41
+ imemo_ment = 6,
42
+ imemo_iseq = 7,
43
+ imemo_tmpbuf = 8,
44
+ imemo_ast = 9,
45
+ imemo_parser_strterm = 10,
46
+ imemo_callinfo = 11,
47
+ imemo_callcache = 12,
48
+ };
49
+
50
+ /* CREF (Class REFerence) is defined in method.h */
51
+
52
+ /*! SVAR (Special VARiable) */
53
+ struct vm_svar {
54
+ VALUE flags;
55
+ const VALUE cref_or_me; /*!< class reference or rb_method_entry_t */
56
+ const VALUE lastline;
57
+ const VALUE backref;
58
+ const VALUE others;
59
+ };
60
+
61
+ /*! THROW_DATA */
62
+ struct vm_throw_data {
63
+ VALUE flags;
64
+ VALUE reserved;
65
+ const VALUE throw_obj;
66
+ const struct rb_control_frame_struct *catch_frame;
67
+ int throw_state;
68
+ };
69
+
70
+ #define THROW_DATA_CONSUMED IMEMO_FL_USER0
71
+
72
+ /* IFUNC (Internal FUNCtion) */
73
+
74
+ struct vm_ifunc_argc {
75
+ #if SIZEOF_INT * 2 > SIZEOF_VALUE
76
+ signed int min: (SIZEOF_VALUE * CHAR_BIT) / 2;
77
+ signed int max: (SIZEOF_VALUE * CHAR_BIT) / 2;
78
+ #else
79
+ int min, max;
80
+ #endif
81
+ };
82
+
83
+ /*! IFUNC (Internal FUNCtion) */
84
+ struct vm_ifunc {
85
+ VALUE flags;
86
+ VALUE reserved;
87
+ rb_block_call_func_t func;
88
+ const void *data;
89
+ struct vm_ifunc_argc argc;
90
+ };
91
+
92
+ struct rb_imemo_tmpbuf_struct {
93
+ VALUE flags;
94
+ VALUE reserved;
95
+ VALUE *ptr; /* malloc'ed buffer */
96
+ struct rb_imemo_tmpbuf_struct *next; /* next imemo */
97
+ size_t cnt; /* buffer size in VALUE */
98
+ };
99
+
100
+ /*! MEMO
101
+ *
102
+ * @see imemo_type
103
+ * */
104
+ struct MEMO {
105
+ VALUE flags;
106
+ VALUE reserved;
107
+ const VALUE v1;
108
+ const VALUE v2;
109
+ union {
110
+ long cnt;
111
+ long state;
112
+ const VALUE value;
113
+ void (*func)(void);
114
+ } u3;
115
+ };
116
+
117
+ /* ment is in method.h */
118
+
119
+ #define THROW_DATA_P(err) imemo_throw_data_p((VALUE)err)
120
+ #define MEMO_CAST(m) ((struct MEMO *)(m))
121
+ #define MEMO_NEW(a, b, c) ((struct MEMO *)rb_imemo_new(imemo_memo, (VALUE)(a), (VALUE)(b), (VALUE)(c), 0))
122
+ #define MEMO_FOR(type, value) ((type *)RARRAY_PTR(value))
123
+ #define NEW_MEMO_FOR(type, value) \
124
+ ((value) = rb_ary_tmp_new_fill(type_roomof(type, VALUE)), MEMO_FOR(type, value))
125
+ #define NEW_PARTIAL_MEMO_FOR(type, value, member) \
126
+ ((value) = rb_ary_tmp_new_fill(type_roomof(type, VALUE)), \
127
+ rb_ary_set_len((value), offsetof(type, member) / sizeof(VALUE)), \
128
+ MEMO_FOR(type, value))
129
+
130
+ typedef struct rb_imemo_tmpbuf_struct rb_imemo_tmpbuf_t;
131
+ VALUE rb_imemo_new(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0);
132
+ rb_imemo_tmpbuf_t *rb_imemo_tmpbuf_parser_heap(void *buf, rb_imemo_tmpbuf_t *old_heap, size_t cnt);
133
+ struct vm_ifunc *rb_vm_ifunc_new(rb_block_call_func_t func, const void *data, int min_argc, int max_argc);
134
+ void rb_strterm_mark(VALUE obj);
135
+ static inline enum imemo_type imemo_type(VALUE imemo);
136
+ static inline int imemo_type_p(VALUE imemo, enum imemo_type imemo_type);
137
+ static inline bool imemo_throw_data_p(VALUE imemo);
138
+ static inline struct vm_ifunc *rb_vm_ifunc_proc_new(rb_block_call_func_t func, const void *data);
139
+ static inline VALUE rb_imemo_tmpbuf_auto_free_pointer(void);
140
+ static inline void *RB_IMEMO_TMPBUF_PTR(VALUE v);
141
+ static inline void *rb_imemo_tmpbuf_set_ptr(VALUE v, void *ptr);
142
+ static inline VALUE rb_imemo_tmpbuf_auto_free_pointer_new_from_an_RString(VALUE str);
143
+ static inline void MEMO_V1_SET(struct MEMO *m, VALUE v);
144
+ static inline void MEMO_V2_SET(struct MEMO *m, VALUE v);
145
+
146
+ RUBY_SYMBOL_EXPORT_BEGIN
147
+ #if IMEMO_DEBUG
148
+ VALUE rb_imemo_new_debug(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0, const char *file, int line);
149
+ #define rb_imemo_new(type, v1, v2, v3, v0) rb_imemo_new_debug(type, v1, v2, v3, v0, __FILE__, __LINE__)
150
+ #else
151
+ VALUE rb_imemo_new(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0);
152
+ #endif
153
+ const char *rb_imemo_name(enum imemo_type type);
154
+ RUBY_SYMBOL_EXPORT_END
155
+
156
+ static inline enum imemo_type
157
+ imemo_type(VALUE imemo)
158
+ {
159
+ return (RBASIC(imemo)->flags >> FL_USHIFT) & IMEMO_MASK;
160
+ }
161
+
162
+ static inline int
163
+ imemo_type_p(VALUE imemo, enum imemo_type imemo_type)
164
+ {
165
+ if (LIKELY(!RB_SPECIAL_CONST_P(imemo))) {
166
+ /* fixed at compile time if imemo_type is given. */
167
+ const VALUE mask = (IMEMO_MASK << FL_USHIFT) | RUBY_T_MASK;
168
+ const VALUE expected_type = (imemo_type << FL_USHIFT) | T_IMEMO;
169
+ /* fixed at runtime. */
170
+ return expected_type == (RBASIC(imemo)->flags & mask);
171
+ }
172
+ else {
173
+ return 0;
174
+ }
175
+ }
176
+
177
+ #define IMEMO_TYPE_P(v, t) imemo_type_p((VALUE)v, t)
178
+
179
+ static inline bool
180
+ imemo_throw_data_p(VALUE imemo)
181
+ {
182
+ return RB_TYPE_P(imemo, T_IMEMO);
183
+ }
184
+
185
+ static inline struct vm_ifunc *
186
+ rb_vm_ifunc_proc_new(rb_block_call_func_t func, const void *data)
187
+ {
188
+ return rb_vm_ifunc_new(func, data, 0, UNLIMITED_ARGUMENTS);
189
+ }
190
+
191
+ static inline VALUE
192
+ rb_imemo_tmpbuf_auto_free_pointer(void)
193
+ {
194
+ return rb_imemo_new(imemo_tmpbuf, 0, 0, 0, 0);
195
+ }
196
+
197
+ static inline void *
198
+ RB_IMEMO_TMPBUF_PTR(VALUE v)
199
+ {
200
+ const struct rb_imemo_tmpbuf_struct *p = (const void *)v;
201
+ return p->ptr;
202
+ }
203
+
204
+ static inline void *
205
+ rb_imemo_tmpbuf_set_ptr(VALUE v, void *ptr)
206
+ {
207
+ return ((rb_imemo_tmpbuf_t *)v)->ptr = ptr;
208
+ }
209
+
210
+ static inline VALUE
211
+ rb_imemo_tmpbuf_auto_free_pointer_new_from_an_RString(VALUE str)
212
+ {
213
+ const void *src;
214
+ VALUE imemo;
215
+ rb_imemo_tmpbuf_t *tmpbuf;
216
+ void *dst;
217
+ size_t len;
218
+
219
+ SafeStringValue(str);
220
+ /* create tmpbuf to keep the pointer before xmalloc */
221
+ imemo = rb_imemo_tmpbuf_auto_free_pointer();
222
+ tmpbuf = (rb_imemo_tmpbuf_t *)imemo;
223
+ len = RSTRING_LEN(str);
224
+ src = RSTRING_PTR(str);
225
+ dst = ruby_xmalloc(len);
226
+ memcpy(dst, src, len);
227
+ tmpbuf->ptr = dst;
228
+ return imemo;
229
+ }
230
+
231
+ static inline void
232
+ MEMO_V1_SET(struct MEMO *m, VALUE v)
233
+ {
234
+ RB_OBJ_WRITE(m, &m->v1, v);
235
+ }
236
+
237
+ static inline void
238
+ MEMO_V2_SET(struct MEMO *m, VALUE v)
239
+ {
240
+ RB_OBJ_WRITE(m, &m->v2, v);
241
+ }
242
+
243
+ #endif /* INTERNAL_IMEMO_H */
@@ -0,0 +1,24 @@
1
+ #ifndef INTERNAL_SERIAL_H /*-*-C-*-vi:se ft=c:*/
2
+ #define INTERNAL_SERIAL_H
3
+ /**
4
+ * @file
5
+ * @author Ruby developers <ruby-core@ruby-lang.org>
6
+ * @copyright This file is a part of the programming language Ruby.
7
+ * Permission is hereby granted, to either redistribute and/or
8
+ * modify this file, provided that the conditions mentioned in the
9
+ * file COPYING are met. Consult the file for details.
10
+ * @brief Internal header for rb_serial_t.
11
+ */
12
+ #include "ruby/internal/config.h" /* for HAVE_LONG_LONG */
13
+ #include "ruby/defines.h" /* for LONG_LONG */
14
+
15
+ #ifndef HAVE_LONG_LONG
16
+ # error need C99+
17
+ #endif
18
+
19
+ typedef unsigned LONG_LONG rb_serial_t;
20
+ #define SERIALT2NUM ULL2NUM
21
+ #define PRI_SERIALT_PREFIX PRI_LL_PREFIX
22
+ #define SIZEOF_SERIAL_T SIZEOF_LONG_LONG
23
+
24
+ #endif /* INTERNAL_SERIAL_H */
@@ -0,0 +1,17 @@
1
+ #ifndef INTERNAL_STATIC_ASSERT_H /*-*-C-*-vi:se ft=c:*/
2
+ #define INTERNAL_STATIC_ASSERT_H
3
+ /**
4
+ * @file
5
+ * @author Ruby developers <ruby-core@ruby-lang.org>
6
+ * @copyright This file is a part of the programming language Ruby.
7
+ * Permission is hereby granted, to either redistribute and/or
8
+ * modify this file, provided that the conditions mentioned in the
9
+ * file COPYING are met. Consult the file for details.
10
+ * @brief C11 shim for _Static_assert.
11
+ */
12
+ #include "ruby/internal/static_assert.h"
13
+ #ifndef STATIC_ASSERT
14
+ # define STATIC_ASSERT RBIMPL_STATIC_ASSERT
15
+ #endif
16
+
17
+ #endif /* INTERNAL_STATIC_ASSERT_H */
@@ -0,0 +1,17 @@
1
+ #ifndef INTERNAL_WARNINGS_H /*-*-C-*-vi:se ft=c:*/
2
+ #define INTERNAL_WARNINGS_H
3
+ /**
4
+ * @file
5
+ * @author Ruby developers <ruby-core@ruby-lang.org>
6
+ * @copyright This file is a part of the programming language Ruby.
7
+ * Permission is hereby granted, to either redistribute and/or
8
+ * modify this file, provided that the conditions mentioned in the
9
+ * file COPYING are met. Consult the file for details.
10
+ * @brief Internal header to suppres / mandate warnings.
11
+ */
12
+ #include "ruby/internal/warning_push.h"
13
+ #define COMPILER_WARNING_PUSH RBIMPL_WARNING_PUSH()
14
+ #define COMPILER_WARNING_POP RBIMPL_WARNING_POP()
15
+ #define COMPILER_WARNING_ERROR(flag) RBIMPL_WARNING_ERROR(flag)
16
+ #define COMPILER_WARNING_IGNORED(flag) RBIMPL_WARNING_IGNORED(flag)
17
+ #endif /* INTERNAL_WARNINGS_H */
@@ -0,0 +1,107 @@
1
+ #ifndef RUBY_INTERNAL_H /*-*-C-*-vi:se ft=c:*/
2
+ #define RUBY_INTERNAL_H 1
3
+ /**
4
+ * @file
5
+ * @author $Author$
6
+ * @date Tue May 17 11:42:20 JST 2011
7
+ * @copyright Copyright (C) 2011 Yukihiro Matsumoto
8
+ * @copyright This file is a part of the programming language Ruby.
9
+ * Permission is hereby granted, to either redistribute and/or
10
+ * modify this file, provided that the conditions mentioned in the
11
+ * file COPYING are met. Consult the file for details.
12
+ */
13
+ #include "ruby/internal/config.h"
14
+
15
+ #ifdef __cplusplus
16
+ # error not for C++
17
+ #endif
18
+
19
+ #define LIKELY(x) RB_LIKELY(x)
20
+ #define UNLIKELY(x) RB_UNLIKELY(x)
21
+
22
+ #define numberof(array) ((int)(sizeof(array) / sizeof((array)[0])))
23
+ #define roomof(x, y) (((x) + (y) - 1) / (y))
24
+ #define type_roomof(x, y) roomof(sizeof(x), sizeof(y))
25
+
26
+ /* Prevent compiler from reordering access */
27
+ #define ACCESS_ONCE(type,x) (*((volatile type *)&(x)))
28
+
29
+ #include "ruby/ruby.h"
30
+
31
+ /* Following macros were formerly defined in this header but moved to somewhere
32
+ * else. In order to detect them we undef here. */
33
+
34
+ /* internal/array.h */
35
+ #undef RARRAY_AREF
36
+
37
+ /* internal/class.h */
38
+ #undef RClass
39
+ #undef RCLASS_SUPER
40
+
41
+ /* internal/gc.h */
42
+ #undef NEWOBJ_OF
43
+ #undef RB_NEWOBJ_OF
44
+ #undef RB_OBJ_WRITE
45
+
46
+ /* internal/hash.h */
47
+ #undef RHASH_IFNONE
48
+ #undef RHASH_SIZE
49
+ #undef RHASH_TBL
50
+ #undef RHASH_EMPTY_P
51
+
52
+ /* internal/object.h */
53
+ #undef ROBJECT_IV_INDEX_TBL
54
+
55
+ /* internal/struct.h */
56
+ #undef RSTRUCT_LEN
57
+ #undef RSTRUCT_PTR
58
+ #undef RSTRUCT_SET
59
+ #undef RSTRUCT_GET
60
+
61
+ /* Also, we keep the following macros here. They are expected to be
62
+ * overridden in each headers. */
63
+
64
+ /* internal/array.h */
65
+ #define rb_ary_new_from_args(...) rb_nonexistent_symbol(__VA_ARGS__)
66
+
67
+ /* internal/io.h */
68
+ #define rb_io_fptr_finalize(...) rb_nonexistent_symbol(__VA_ARGS__)
69
+
70
+ /* internal/string.h */
71
+ #define rb_fstring_cstr(...) rb_nonexistent_symbol(__VA_ARGS__)
72
+
73
+ /* internal/symbol.h */
74
+ #define rb_sym_intern_ascii_cstr(...) rb_nonexistent_symbol(__VA_ARGS__)
75
+
76
+ /* internal/vm.h */
77
+ #define rb_funcallv(...) rb_nonexistent_symbol(__VA_ARGS__)
78
+ #define rb_method_basic_definition_p(...) rb_nonexistent_symbol(__VA_ARGS__)
79
+
80
+
81
+ /* MRI debug support */
82
+
83
+ /* gc.c */
84
+ void rb_obj_info_dump(VALUE obj);
85
+ void rb_obj_info_dump_loc(VALUE obj, const char *file, int line, const char *func);
86
+
87
+ /* debug.c */
88
+
89
+ RUBY_SYMBOL_EXPORT_BEGIN
90
+ void ruby_debug_breakpoint(void);
91
+ PRINTF_ARGS(void ruby_debug_printf(const char*, ...), 1, 2);
92
+ RUBY_SYMBOL_EXPORT_END
93
+
94
+ // show obj data structure without any side-effect
95
+ #define rp(obj) rb_obj_info_dump_loc((VALUE)(obj), __FILE__, __LINE__, RUBY_FUNCTION_NAME_STRING)
96
+
97
+ // same as rp, but add message header
98
+ #define rp_m(msg, obj) do { \
99
+ fprintf(stderr, "%s", (msg)); \
100
+ rb_obj_info_dump((VALUE)obj); \
101
+ } while (0)
102
+
103
+ // `ruby_debug_breakpoint()` does nothing,
104
+ // but breakpoint is set in run.gdb, so `make gdb` can stop here.
105
+ #define bp() ruby_debug_breakpoint()
106
+
107
+ #endif /* RUBY_INTERNAL_H */
@@ -0,0 +1,246 @@
1
+ #ifndef RUBY_METHOD_H
2
+ #define RUBY_METHOD_H 1
3
+ /**********************************************************************
4
+ *
5
+ * method.h -
6
+ *
7
+ * $Author$
8
+ * created at: Wed Jul 15 20:02:33 2009
9
+ *
10
+ * Copyright (C) 2009 Koichi Sasada
11
+ *
12
+ **********************************************************************/
13
+
14
+ #include "internal.h"
15
+ #include "internal/imemo.h"
16
+ #include "internal/compilers.h"
17
+ #include "internal/static_assert.h"
18
+ #include "internal/class.h"
19
+
20
+ #ifndef END_OF_ENUMERATION
21
+ # if defined(__GNUC__) &&! defined(__STRICT_ANSI__)
22
+ # define END_OF_ENUMERATION(key)
23
+ # else
24
+ # define END_OF_ENUMERATION(key) END_OF_##key##_PLACEHOLDER = 0
25
+ # endif
26
+ #endif
27
+
28
+ /* cref */
29
+
30
+ typedef enum {
31
+ METHOD_VISI_UNDEF = 0x00,
32
+ METHOD_VISI_PUBLIC = 0x01,
33
+ METHOD_VISI_PRIVATE = 0x02,
34
+ METHOD_VISI_PROTECTED = 0x03,
35
+
36
+ METHOD_VISI_MASK = 0x03
37
+ } rb_method_visibility_t;
38
+
39
+ typedef struct rb_scope_visi_struct {
40
+ BITFIELD(rb_method_visibility_t, method_visi, 3);
41
+ unsigned int module_func : 1;
42
+ } rb_scope_visibility_t;
43
+
44
+ /*! CREF (Class REFerence) */
45
+ typedef struct rb_cref_struct {
46
+ VALUE flags;
47
+ VALUE refinements;
48
+ VALUE klass;
49
+ struct rb_cref_struct * next;
50
+ const rb_scope_visibility_t scope_visi;
51
+ } rb_cref_t;
52
+
53
+ /* method data type */
54
+
55
+ typedef struct rb_method_entry_struct {
56
+ VALUE flags;
57
+ VALUE defined_class;
58
+ struct rb_method_definition_struct * const def;
59
+ ID called_id;
60
+ VALUE owner;
61
+ } rb_method_entry_t;
62
+
63
+ typedef struct rb_callable_method_entry_struct { /* same fields with rb_method_entry_t */
64
+ VALUE flags;
65
+ const VALUE defined_class;
66
+ struct rb_method_definition_struct * const def;
67
+ ID called_id;
68
+ const VALUE owner;
69
+ } rb_callable_method_entry_t;
70
+
71
+ #define METHOD_ENTRY_VISI(me) (rb_method_visibility_t)(((me)->flags & (IMEMO_FL_USER0 | IMEMO_FL_USER1)) >> (IMEMO_FL_USHIFT+0))
72
+ #define METHOD_ENTRY_BASIC(me) (int) (((me)->flags & (IMEMO_FL_USER2 )) >> (IMEMO_FL_USHIFT+2))
73
+ #define METHOD_ENTRY_COMPLEMENTED(me) ((me)->flags & IMEMO_FL_USER3)
74
+ #define METHOD_ENTRY_COMPLEMENTED_SET(me) ((me)->flags |= IMEMO_FL_USER3)
75
+ #define METHOD_ENTRY_CACHED(me) ((me)->flags & IMEMO_FL_USER4)
76
+ #define METHOD_ENTRY_CACHED_SET(me) ((me)->flags |= IMEMO_FL_USER4)
77
+ #define METHOD_ENTRY_INVALIDATED(me) ((me)->flags & IMEMO_FL_USER5)
78
+ #define METHOD_ENTRY_INVALIDATED_SET(me) ((me)->flags |= IMEMO_FL_USER5)
79
+ #define METHOD_ENTRY_CACHEABLE(me) !(METHOD_ENTRY_VISI(me) == METHOD_VISI_PROTECTED)
80
+
81
+ static inline void
82
+ METHOD_ENTRY_VISI_SET(rb_method_entry_t *me, rb_method_visibility_t visi)
83
+ {
84
+ VM_ASSERT((int)visi >= 0 && visi <= 3);
85
+ me->flags = (me->flags & ~(IMEMO_FL_USER0 | IMEMO_FL_USER1)) | (visi << (IMEMO_FL_USHIFT+0));
86
+ }
87
+ static inline void
88
+ METHOD_ENTRY_BASIC_SET(rb_method_entry_t *me, unsigned int basic)
89
+ {
90
+ VM_ASSERT(basic <= 1);
91
+ me->flags = (me->flags & ~(IMEMO_FL_USER2 )) | (basic << (IMEMO_FL_USHIFT+2));
92
+ }
93
+ static inline void
94
+ METHOD_ENTRY_FLAGS_SET(rb_method_entry_t *me, rb_method_visibility_t visi, unsigned int basic)
95
+ {
96
+ VM_ASSERT((int)visi >= 0 && visi <= 3);
97
+ VM_ASSERT(basic <= 1);
98
+ me->flags =
99
+ (me->flags & ~(IMEMO_FL_USER0|IMEMO_FL_USER1|IMEMO_FL_USER2)) |
100
+ ((visi << (IMEMO_FL_USHIFT+0)) | (basic << (IMEMO_FL_USHIFT+2)));
101
+ }
102
+ static inline void
103
+ METHOD_ENTRY_FLAGS_COPY(rb_method_entry_t *dst, const rb_method_entry_t *src)
104
+ {
105
+ dst->flags =
106
+ (dst->flags & ~(IMEMO_FL_USER0|IMEMO_FL_USER1|IMEMO_FL_USER2)) |
107
+ (src->flags & (IMEMO_FL_USER0|IMEMO_FL_USER1|IMEMO_FL_USER2));
108
+ }
109
+
110
+ typedef enum {
111
+ VM_METHOD_TYPE_ISEQ, /*!< Ruby method */
112
+ VM_METHOD_TYPE_CFUNC, /*!< C method */
113
+ VM_METHOD_TYPE_ATTRSET, /*!< attr_writer or attr_accessor */
114
+ VM_METHOD_TYPE_IVAR, /*!< attr_reader or attr_accessor */
115
+ VM_METHOD_TYPE_BMETHOD,
116
+ VM_METHOD_TYPE_ZSUPER,
117
+ VM_METHOD_TYPE_ALIAS,
118
+ VM_METHOD_TYPE_UNDEF,
119
+ VM_METHOD_TYPE_NOTIMPLEMENTED,
120
+ VM_METHOD_TYPE_OPTIMIZED, /*!< Kernel#send, Proc#call, etc */
121
+ VM_METHOD_TYPE_MISSING, /*!< wrapper for method_missing(id) */
122
+ VM_METHOD_TYPE_REFINED, /*!< refinement */
123
+
124
+ END_OF_ENUMERATION(VM_METHOD_TYPE)
125
+ } rb_method_type_t;
126
+ #define VM_METHOD_TYPE_MINIMUM_BITS 4
127
+ STATIC_ASSERT(VM_METHOD_TYPE_MINIMUM_BITS,
128
+ VM_METHOD_TYPE_REFINED <= (1<<VM_METHOD_TYPE_MINIMUM_BITS));
129
+
130
+ #ifndef rb_iseq_t
131
+ typedef struct rb_iseq_struct rb_iseq_t;
132
+ #define rb_iseq_t rb_iseq_t
133
+ #endif
134
+
135
+ typedef struct rb_method_iseq_struct {
136
+ rb_iseq_t * iseqptr; /*!< iseq pointer, should be separated from iseqval */
137
+ rb_cref_t * cref; /*!< class reference, should be marked */
138
+ } rb_method_iseq_t; /* check rb_add_method_iseq() when modify the fields */
139
+
140
+ typedef struct rb_method_cfunc_struct {
141
+ VALUE (*func)(ANYARGS);
142
+ VALUE (*invoker)(VALUE recv, int argc, const VALUE *argv, VALUE (*func)(ANYARGS));
143
+ int argc;
144
+ } rb_method_cfunc_t;
145
+
146
+ typedef struct rb_method_attr_struct {
147
+ ID id;
148
+ VALUE location; /* should be marked */
149
+ } rb_method_attr_t;
150
+
151
+ typedef struct rb_method_alias_struct {
152
+ struct rb_method_entry_struct * original_me; /* original_me->klass is original owner */
153
+ } rb_method_alias_t;
154
+
155
+ typedef struct rb_method_refined_struct {
156
+ struct rb_method_entry_struct * orig_me;
157
+ VALUE owner;
158
+ } rb_method_refined_t;
159
+
160
+ typedef struct rb_method_bmethod_struct {
161
+ VALUE proc; /* should be marked */
162
+ struct rb_hook_list_struct *hooks;
163
+ VALUE defined_ractor;
164
+ } rb_method_bmethod_t;
165
+
166
+ enum method_optimized_type {
167
+ OPTIMIZED_METHOD_TYPE_SEND,
168
+ OPTIMIZED_METHOD_TYPE_CALL,
169
+ OPTIMIZED_METHOD_TYPE_BLOCK_CALL,
170
+ OPTIMIZED_METHOD_TYPE__MAX
171
+ };
172
+
173
+ struct rb_method_definition_struct {
174
+ BITFIELD(rb_method_type_t, type, VM_METHOD_TYPE_MINIMUM_BITS);
175
+ int alias_count : 28;
176
+ int complemented_count : 28;
177
+
178
+ union {
179
+ rb_method_iseq_t iseq;
180
+ rb_method_cfunc_t cfunc;
181
+ rb_method_attr_t attr;
182
+ rb_method_alias_t alias;
183
+ rb_method_refined_t refined;
184
+ rb_method_bmethod_t bmethod;
185
+
186
+ enum method_optimized_type optimize_type;
187
+ } body;
188
+
189
+ ID original_id;
190
+ uintptr_t method_serial;
191
+ };
192
+
193
+ struct rb_id_table;
194
+
195
+ typedef struct rb_method_definition_struct rb_method_definition_t;
196
+ STATIC_ASSERT(sizeof_method_def, offsetof(rb_method_definition_t, body)==8);
197
+
198
+ #define UNDEFINED_METHOD_ENTRY_P(me) (!(me) || !(me)->def || (me)->def->type == VM_METHOD_TYPE_UNDEF)
199
+ #define UNDEFINED_REFINED_METHOD_P(def) \
200
+ ((def)->type == VM_METHOD_TYPE_REFINED && \
201
+ UNDEFINED_METHOD_ENTRY_P((def)->body.refined.orig_me))
202
+
203
+ void rb_add_method_cfunc(VALUE klass, ID mid, VALUE (*func)(ANYARGS), int argc, rb_method_visibility_t visi);
204
+ void rb_add_method_iseq(VALUE klass, ID mid, const rb_iseq_t *iseq, rb_cref_t *cref, rb_method_visibility_t visi);
205
+ void rb_add_refined_method_entry(VALUE refined_class, ID mid);
206
+ void rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_visibility_t visi);
207
+
208
+ rb_method_entry_t *rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *, rb_method_visibility_t noex);
209
+ rb_method_entry_t *rb_method_entry_create(ID called_id, VALUE klass, rb_method_visibility_t visi, const rb_method_definition_t *def);
210
+
211
+ const rb_method_entry_t *rb_method_entry_at(VALUE obj, ID id);
212
+
213
+ const rb_method_entry_t *rb_method_entry(VALUE klass, ID id);
214
+ const rb_method_entry_t *rb_method_entry_with_refinements(VALUE klass, ID id, VALUE *defined_class);
215
+ const rb_method_entry_t *rb_method_entry_without_refinements(VALUE klass, ID id, VALUE *defined_class);
216
+ const rb_method_entry_t *rb_resolve_refined_method(VALUE refinements, const rb_method_entry_t *me);
217
+ RUBY_SYMBOL_EXPORT_BEGIN
218
+ const rb_method_entry_t *rb_resolve_me_location(const rb_method_entry_t *, VALUE[5]);
219
+ RUBY_SYMBOL_EXPORT_END
220
+
221
+ const rb_callable_method_entry_t *rb_callable_method_entry(VALUE klass, ID id);
222
+ const rb_callable_method_entry_t *rb_callable_method_entry_with_refinements(VALUE klass, ID id, VALUE *defined_class);
223
+ const rb_callable_method_entry_t *rb_callable_method_entry_without_refinements(VALUE klass, ID id, VALUE *defined_class);
224
+
225
+ int rb_method_entry_arity(const rb_method_entry_t *me);
226
+ int rb_method_entry_eq(const rb_method_entry_t *m1, const rb_method_entry_t *m2);
227
+ st_index_t rb_hash_method_entry(st_index_t hash, const rb_method_entry_t *me);
228
+
229
+ VALUE rb_method_entry_location(const rb_method_entry_t *me);
230
+
231
+ void rb_free_method_entry(const rb_method_entry_t *me);
232
+
233
+ const rb_method_entry_t *rb_method_entry_clone(const rb_method_entry_t *me);
234
+ 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);
235
+ void rb_method_entry_copy(rb_method_entry_t *dst, const rb_method_entry_t *src);
236
+
237
+ void rb_method_table_insert(VALUE klass, struct rb_id_table *table, ID method_id, const rb_method_entry_t *me);
238
+
239
+ void rb_scope_visibility_set(rb_method_visibility_t);
240
+
241
+ VALUE rb_unnamed_parameters(int arity);
242
+
243
+ void rb_clear_method_cache(VALUE klass_or_module, ID mid);
244
+ void rb_clear_method_cache_all(void);
245
+
246
+ #endif /* RUBY_METHOD_H */
@@ -0,0 +1,36 @@
1
+ #ifndef RUBY_ID_TABLE_H
2
+ #define RUBY_ID_TABLE_H 1
3
+ #include "ruby/internal/config.h"
4
+ #include <stddef.h>
5
+ #include "ruby/ruby.h"
6
+
7
+ struct rb_id_table;
8
+
9
+ /* compatible with ST_* */
10
+ enum rb_id_table_iterator_result {
11
+ ID_TABLE_CONTINUE = ST_CONTINUE,
12
+ ID_TABLE_STOP = ST_STOP,
13
+ ID_TABLE_DELETE = ST_DELETE,
14
+ ID_TABLE_REPLACE = ST_REPLACE,
15
+ ID_TABLE_ITERATOR_RESULT_END
16
+ };
17
+
18
+ struct rb_id_table *rb_id_table_create(size_t size);
19
+ void rb_id_table_free(struct rb_id_table *tbl);
20
+ void rb_id_table_clear(struct rb_id_table *tbl);
21
+
22
+ size_t rb_id_table_size(const struct rb_id_table *tbl);
23
+ size_t rb_id_table_memsize(const struct rb_id_table *tbl);
24
+
25
+ int rb_id_table_insert(struct rb_id_table *tbl, ID id, VALUE val);
26
+ int rb_id_table_lookup(struct rb_id_table *tbl, ID id, VALUE *valp);
27
+ int rb_id_table_delete(struct rb_id_table *tbl, ID id);
28
+
29
+ typedef enum rb_id_table_iterator_result rb_id_table_update_value_callback_func_t(VALUE *val, void *data, int existing);
30
+ typedef enum rb_id_table_iterator_result rb_id_table_foreach_func_t(ID id, VALUE val, void *data);
31
+ typedef enum rb_id_table_iterator_result rb_id_table_foreach_values_func_t(VALUE val, void *data);
32
+ void rb_id_table_foreach(struct rb_id_table *tbl, rb_id_table_foreach_func_t *func, void *data);
33
+ void rb_id_table_foreach_values(struct rb_id_table *tbl, rb_id_table_foreach_values_func_t *func, void *data);
34
+ void rb_id_table_foreach_values_with_replace(struct rb_id_table *tbl, rb_id_table_foreach_values_func_t *func, rb_id_table_update_value_callback_func_t *replace, void *data);
35
+
36
+ #endif /* RUBY_ID_TABLE_H */