debase-ruby_core_source 0.7.9 → 0.7.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/README.md +2 -0
  4. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/addr2line.h +21 -0
  5. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/constant.h +36 -0
  6. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/dln.h +50 -0
  7. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/encdb.h +169 -0
  8. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/eval_intern.h +241 -0
  9. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/gc.h +104 -0
  10. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/id.h +135 -0
  11. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/insns.inc +187 -0
  12. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/insns_info.inc +724 -0
  13. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/internal.h +395 -0
  14. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/iseq.h +140 -0
  15. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/known_errors.inc +731 -0
  16. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/method.h +141 -0
  17. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/node.h +541 -0
  18. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/node_name.inc +212 -0
  19. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/opt_sc.inc +702 -0
  20. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/optinsn.inc +83 -0
  21. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/optunifs.inc +120 -0
  22. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/parse.h +181 -0
  23. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/probes_helper.h +67 -0
  24. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/regenc.h +227 -0
  25. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/regint.h +915 -0
  26. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/regparse.h +367 -0
  27. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/revision.h +1 -0
  28. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/ruby_atomic.h +170 -0
  29. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/siphash.h +48 -0
  30. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/thread_pthread.h +56 -0
  31. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/thread_win32.h +45 -0
  32. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/timev.h +21 -0
  33. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/transcode_data.h +127 -0
  34. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/transdb.h +193 -0
  35. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/version.h +52 -0
  36. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/vm.inc +3196 -0
  37. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/vm_core.h +1020 -0
  38. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/vm_debug.h +41 -0
  39. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/vm_exec.h +173 -0
  40. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/vm_insnhelper.h +274 -0
  41. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/vm_opts.h +56 -0
  42. data/lib/debase/ruby_core_source/ruby-2.0.0-p647/vmtc.inc +101 -0
  43. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/addr2line.h +21 -0
  44. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/constant.h +36 -0
  45. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/dln.h +51 -0
  46. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/encdb.h +170 -0
  47. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/eval_intern.h +270 -0
  48. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/gc.h +101 -0
  49. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/id.h +171 -0
  50. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/insns.inc +189 -0
  51. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/insns_info.inc +731 -0
  52. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/internal.h +894 -0
  53. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/iseq.h +136 -0
  54. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/known_errors.inc +731 -0
  55. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/method.h +145 -0
  56. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/node.h +543 -0
  57. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/node_name.inc +212 -0
  58. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/opt_sc.inc +710 -0
  59. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/optinsn.inc +83 -0
  60. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/optunifs.inc +121 -0
  61. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/parse.h +183 -0
  62. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/probes_helper.h +67 -0
  63. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/regenc.h +223 -0
  64. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/regint.h +911 -0
  65. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/regparse.h +363 -0
  66. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/revision.h +1 -0
  67. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/ruby_atomic.h +170 -0
  68. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/siphash.h +48 -0
  69. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/thread_native.h +23 -0
  70. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/thread_pthread.h +56 -0
  71. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/thread_win32.h +45 -0
  72. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/timev.h +42 -0
  73. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/transcode_data.h +123 -0
  74. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/transdb.h +190 -0
  75. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/version.h +52 -0
  76. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/vm.inc +3243 -0
  77. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/vm_core.h +1057 -0
  78. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/vm_debug.h +37 -0
  79. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/vm_exec.h +182 -0
  80. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/vm_insnhelper.h +273 -0
  81. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/vm_opts.h +56 -0
  82. data/lib/debase/ruby_core_source/ruby-2.1.7-p400/vmtc.inc +102 -0
  83. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/addr2line.h +21 -0
  84. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/ccan/build_assert/build_assert.h +40 -0
  85. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/ccan/check_type/check_type.h +63 -0
  86. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/ccan/container_of/container_of.h +142 -0
  87. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/ccan/list/list.h +635 -0
  88. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/ccan/str/str.h +16 -0
  89. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/constant.h +43 -0
  90. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/dln.h +51 -0
  91. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/eval_intern.h +275 -0
  92. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/gc.h +107 -0
  93. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/id.h +210 -0
  94. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/insns.inc +107 -0
  95. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/insns_info.inc +752 -0
  96. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/internal.h +1187 -0
  97. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/iseq.h +158 -0
  98. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/known_errors.inc +746 -0
  99. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/method.h +144 -0
  100. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/node.h +544 -0
  101. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/node_name.inc +212 -0
  102. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/opt_sc.inc +734 -0
  103. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/optinsn.inc +83 -0
  104. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/optunifs.inc +124 -0
  105. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/parse.h +184 -0
  106. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/probes_helper.h +67 -0
  107. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/regenc.h +234 -0
  108. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/regint.h +972 -0
  109. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/regparse.h +363 -0
  110. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/revision.h +1 -0
  111. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/ruby_atomic.h +170 -0
  112. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/siphash.h +48 -0
  113. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/symbol.h +88 -0
  114. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/thread_pthread.h +54 -0
  115. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/thread_win32.h +36 -0
  116. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/timev.h +42 -0
  117. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/transcode_data.h +123 -0
  118. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/version.h +52 -0
  119. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/vm.inc +3353 -0
  120. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/vm_core.h +1160 -0
  121. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/vm_debug.h +37 -0
  122. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/vm_exec.h +182 -0
  123. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/vm_insnhelper.h +233 -0
  124. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/vm_opts.h +56 -0
  125. data/lib/debase/ruby_core_source/ruby-2.2.3-p173/vmtc.inc +105 -0
  126. data/lib/debase/ruby_core_source/version.rb +1 -1
  127. metadata +124 -2
@@ -0,0 +1,1160 @@
1
+ /**********************************************************************
2
+
3
+ vm_core.h -
4
+
5
+ $Author: nagachika $
6
+ created at: 04/01/01 19:41:38 JST
7
+
8
+ Copyright (C) 2004-2007 Koichi Sasada
9
+
10
+ **********************************************************************/
11
+
12
+ #ifndef RUBY_VM_CORE_H
13
+ #define RUBY_VM_CORE_H
14
+
15
+ #define RUBY_VM_THREAD_MODEL 2
16
+
17
+ #include "ruby/ruby.h"
18
+ #include "ruby/st.h"
19
+
20
+ #include "node.h"
21
+ #include "vm_debug.h"
22
+ #include "vm_opts.h"
23
+ #include "id.h"
24
+ #include "method.h"
25
+ #include "ruby_atomic.h"
26
+ #include "ccan/list/list.h"
27
+
28
+ #include "ruby/thread_native.h"
29
+ #if defined(_WIN32)
30
+ #include "thread_win32.h"
31
+ #elif defined(HAVE_PTHREAD_H)
32
+ #include "thread_pthread.h"
33
+ #endif
34
+
35
+ #ifndef ENABLE_VM_OBJSPACE
36
+ #ifdef _WIN32
37
+ /*
38
+ * TODO: object space independent st_table.
39
+ * socklist needs st_table in rb_w32_sysinit(), before object space
40
+ * initialization.
41
+ * It is too early now to change st_hash_type, since it breaks binary
42
+ * compatibility.
43
+ */
44
+ #define ENABLE_VM_OBJSPACE 0
45
+ #else
46
+ #define ENABLE_VM_OBJSPACE 1
47
+ #endif
48
+ #endif
49
+
50
+ #include <setjmp.h>
51
+ #include <signal.h>
52
+
53
+ #ifndef NSIG
54
+ # define NSIG (_SIGMAX + 1) /* For QNX */
55
+ #endif
56
+
57
+ #define RUBY_NSIG NSIG
58
+
59
+ #ifdef HAVE_STDARG_PROTOTYPES
60
+ #include <stdarg.h>
61
+ #define va_init_list(a,b) va_start((a),(b))
62
+ #else
63
+ #include <varargs.h>
64
+ #define va_init_list(a,b) va_start((a))
65
+ #endif
66
+
67
+ #if defined(SIGSEGV) && defined(HAVE_SIGALTSTACK) && defined(SA_SIGINFO) && !defined(__NetBSD__)
68
+ #define USE_SIGALTSTACK
69
+ #endif
70
+
71
+ /*****************/
72
+ /* configuration */
73
+ /*****************/
74
+
75
+ /* gcc ver. check */
76
+ #if defined(__GNUC__) && __GNUC__ >= 2
77
+
78
+ #if OPT_TOKEN_THREADED_CODE
79
+ #if OPT_DIRECT_THREADED_CODE
80
+ #undef OPT_DIRECT_THREADED_CODE
81
+ #endif
82
+ #endif
83
+
84
+ #else /* defined(__GNUC__) && __GNUC__ >= 2 */
85
+
86
+ /* disable threaded code options */
87
+ #if OPT_DIRECT_THREADED_CODE
88
+ #undef OPT_DIRECT_THREADED_CODE
89
+ #endif
90
+ #if OPT_TOKEN_THREADED_CODE
91
+ #undef OPT_TOKEN_THREADED_CODE
92
+ #endif
93
+ #endif
94
+
95
+ #ifdef __native_client__
96
+ #undef OPT_DIRECT_THREADED_CODE
97
+ #endif
98
+
99
+ /* call threaded code */
100
+ #if OPT_CALL_THREADED_CODE
101
+ #if OPT_DIRECT_THREADED_CODE
102
+ #undef OPT_DIRECT_THREADED_CODE
103
+ #endif /* OPT_DIRECT_THREADED_CODE */
104
+ #if OPT_STACK_CACHING
105
+ #undef OPT_STACK_CACHING
106
+ #endif /* OPT_STACK_CACHING */
107
+ #endif /* OPT_CALL_THREADED_CODE */
108
+
109
+ typedef unsigned long rb_num_t;
110
+
111
+ /* iseq data type */
112
+
113
+ struct iseq_compile_data_ensure_node_stack;
114
+
115
+ typedef struct rb_compile_option_struct rb_compile_option_t;
116
+
117
+
118
+ struct iseq_inline_cache_entry {
119
+ rb_serial_t ic_serial;
120
+ union {
121
+ size_t index;
122
+ VALUE value;
123
+ } ic_value;
124
+ };
125
+
126
+ union iseq_inline_storage_entry {
127
+ struct {
128
+ struct rb_thread_struct *running_thread;
129
+ VALUE value;
130
+ } once;
131
+ struct iseq_inline_cache_entry cache;
132
+ };
133
+
134
+ /* to avoid warning */
135
+ struct rb_thread_struct;
136
+ struct rb_control_frame_struct;
137
+
138
+ typedef struct rb_call_info_kw_arg_struct {
139
+ int keyword_len;
140
+ VALUE keywords[1];
141
+ } rb_call_info_kw_arg_t;
142
+
143
+ /* rb_call_info_t contains calling information including inline cache */
144
+ typedef struct rb_call_info_struct {
145
+ /* fixed at compile time */
146
+ ID mid;
147
+
148
+ unsigned int flag;
149
+ int orig_argc;
150
+ rb_iseq_t *blockiseq;
151
+ rb_call_info_kw_arg_t *kw_arg;
152
+
153
+ /* inline cache: keys */
154
+ rb_serial_t method_state;
155
+ rb_serial_t class_serial;
156
+ VALUE klass;
157
+
158
+ /* inline cache: values */
159
+ const rb_method_entry_t *me;
160
+ VALUE defined_class;
161
+
162
+ /* temporary values for method calling */
163
+ struct rb_block_struct *blockptr;
164
+ VALUE recv;
165
+ int argc;
166
+ union {
167
+ int opt_pc; /* used by iseq */
168
+ int index; /* used by ivar */
169
+ int missing_reason; /* used by method_missing */
170
+ int inc_sp; /* used by cfunc */
171
+ } aux;
172
+
173
+ VALUE (*call)(struct rb_thread_struct *th, struct rb_control_frame_struct *cfp, struct rb_call_info_struct *ci);
174
+ } rb_call_info_t;
175
+
176
+ #if 1
177
+ #define GetCoreDataFromValue(obj, type, ptr) do { \
178
+ (ptr) = (type*)DATA_PTR(obj); \
179
+ } while (0)
180
+ #else
181
+ #define GetCoreDataFromValue(obj, type, ptr) Data_Get_Struct((obj), type, (ptr))
182
+ #endif
183
+
184
+ #define GetISeqPtr(obj, ptr) \
185
+ GetCoreDataFromValue((obj), rb_iseq_t, (ptr))
186
+
187
+ typedef struct rb_iseq_location_struct {
188
+ const VALUE path;
189
+ const VALUE absolute_path;
190
+ const VALUE base_label;
191
+ const VALUE label;
192
+ VALUE first_lineno; /* TODO: may be unsigned short */
193
+ } rb_iseq_location_t;
194
+
195
+ struct rb_iseq_struct;
196
+
197
+ struct rb_iseq_struct {
198
+ /***************/
199
+ /* static data */
200
+ /***************/
201
+
202
+ enum iseq_type {
203
+ ISEQ_TYPE_TOP,
204
+ ISEQ_TYPE_METHOD,
205
+ ISEQ_TYPE_BLOCK,
206
+ ISEQ_TYPE_CLASS,
207
+ ISEQ_TYPE_RESCUE,
208
+ ISEQ_TYPE_ENSURE,
209
+ ISEQ_TYPE_EVAL,
210
+ ISEQ_TYPE_MAIN,
211
+ ISEQ_TYPE_DEFINED_GUARD
212
+ } type; /* instruction sequence type */
213
+ #if defined(WORDS_BIGENDIAN) && (SIZEOF_VALUE > SIZEOF_INT)
214
+ char dummy[SIZEOF_VALUE - SIZEOF_INT]; /* [Bug #10037][ruby-core:63721] */
215
+ #endif
216
+ int stack_max; /* for stack overflow check */
217
+
218
+ rb_iseq_location_t location;
219
+
220
+ VALUE *iseq_encoded; /* encoded iseq (insn addr and operands) */
221
+ unsigned int iseq_size;
222
+ unsigned int line_info_size;
223
+
224
+ const VALUE mark_ary; /* Array: includes operands which should be GC marked */
225
+ const VALUE coverage; /* coverage array */
226
+
227
+ /* insn info, must be freed */
228
+ struct iseq_line_info_entry *line_info_table;
229
+
230
+ ID *local_table; /* must free */
231
+ int local_table_size;
232
+
233
+ /* sizeof(vars) + 1 */
234
+ int local_size;
235
+
236
+ union iseq_inline_storage_entry *is_entries;
237
+ int is_size;
238
+
239
+ int callinfo_size;
240
+ rb_call_info_t *callinfo_entries;
241
+
242
+ /**
243
+ * parameter information
244
+ *
245
+ * def m(a1, a2, ..., aM, # mandatory
246
+ * b1=(...), b2=(...), ..., bN=(...), # optional
247
+ * *c, # rest
248
+ * d1, d2, ..., dO, # post
249
+ * e1:(...), e2:(...), ..., eK:(...), # keyword
250
+ * **f, # keyword_rest
251
+ * &g) # block
252
+ * =>
253
+ *
254
+ * lead_num = M
255
+ * opt_num = N
256
+ * rest_start = M+N
257
+ * post_start = M+N+(*1)
258
+ * post_num = O
259
+ * keyword_num = K
260
+ * block_start = M+N+(*1)+O+K
261
+ * keyword_bits = M+N+(*1)+O+K+(&1)
262
+ * size = M+N+O+(*1)+K+(&1)+(**1) // parameter size.
263
+ */
264
+
265
+ struct {
266
+ struct {
267
+ unsigned int has_lead : 1;
268
+ unsigned int has_opt : 1;
269
+ unsigned int has_rest : 1;
270
+ unsigned int has_post : 1;
271
+ unsigned int has_kw : 1;
272
+ unsigned int has_kwrest : 1;
273
+ unsigned int has_block : 1;
274
+
275
+ unsigned int ambiguous_param0 : 1; /* {|a|} */
276
+ } flags;
277
+
278
+ int size;
279
+
280
+ int lead_num;
281
+ int opt_num;
282
+ int rest_start;
283
+ int post_start;
284
+ int post_num;
285
+ int block_start;
286
+
287
+ VALUE *opt_table; /* (opt_num + 1) entries. */
288
+ /* opt_num and opt_table:
289
+ *
290
+ * def foo o1=e1, o2=e2, ..., oN=eN
291
+ * #=>
292
+ * # prologue code
293
+ * A1: e1
294
+ * A2: e2
295
+ * ...
296
+ * AN: eN
297
+ * AL: body
298
+ * opt_num = N
299
+ * opt_table = [A1, A2, ..., AN, AL]
300
+ */
301
+
302
+ struct rb_iseq_param_keyword {
303
+ int num;
304
+ int required_num;
305
+ int bits_start;
306
+ int rest_start;
307
+ ID *table;
308
+ VALUE *default_values;
309
+ } *keyword;
310
+ } param;
311
+
312
+ /* catch table */
313
+ struct iseq_catch_table *catch_table;
314
+
315
+ /* for child iseq */
316
+ struct rb_iseq_struct *parent_iseq;
317
+ struct rb_iseq_struct *local_iseq;
318
+
319
+ /****************/
320
+ /* dynamic data */
321
+ /****************/
322
+
323
+ VALUE self;
324
+ const VALUE orig; /* non-NULL if its data have origin */
325
+
326
+ /* block inlining */
327
+ /*
328
+ * NODE *node;
329
+ * void *special_block_builder;
330
+ * void *cached_special_block_builder;
331
+ * VALUE cached_special_block;
332
+ */
333
+
334
+ /* klass/module nest information stack (cref) */
335
+ NODE * const cref_stack;
336
+ const VALUE klass;
337
+
338
+ /* misc */
339
+ ID defined_method_id; /* for define_method */
340
+ rb_num_t flip_cnt;
341
+
342
+ /* used at compile time */
343
+ struct iseq_compile_data *compile_data;
344
+
345
+ /* original iseq, before encoding
346
+ * used for debug/dump (TODO: union with compile_data) */
347
+ VALUE *iseq;
348
+ };
349
+
350
+ enum ruby_special_exceptions {
351
+ ruby_error_reenter,
352
+ ruby_error_nomemory,
353
+ ruby_error_sysstack,
354
+ ruby_error_closed_stream,
355
+ ruby_special_error_count
356
+ };
357
+
358
+ enum ruby_basic_operators {
359
+ BOP_PLUS,
360
+ BOP_MINUS,
361
+ BOP_MULT,
362
+ BOP_DIV,
363
+ BOP_MOD,
364
+ BOP_EQ,
365
+ BOP_EQQ,
366
+ BOP_LT,
367
+ BOP_LE,
368
+ BOP_LTLT,
369
+ BOP_AREF,
370
+ BOP_ASET,
371
+ BOP_LENGTH,
372
+ BOP_SIZE,
373
+ BOP_EMPTY_P,
374
+ BOP_SUCC,
375
+ BOP_GT,
376
+ BOP_GE,
377
+ BOP_NOT,
378
+ BOP_NEQ,
379
+ BOP_MATCH,
380
+ BOP_FREEZE,
381
+
382
+ BOP_LAST_
383
+ };
384
+
385
+ #define GetVMPtr(obj, ptr) \
386
+ GetCoreDataFromValue((obj), rb_vm_t, (ptr))
387
+
388
+ #if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
389
+ struct rb_objspace;
390
+ void rb_objspace_free(struct rb_objspace *);
391
+ #endif
392
+
393
+ typedef struct rb_hook_list_struct {
394
+ struct rb_event_hook_struct *hooks;
395
+ rb_event_flag_t events;
396
+ int need_clean;
397
+ } rb_hook_list_t;
398
+
399
+ typedef struct rb_vm_struct {
400
+ VALUE self;
401
+
402
+ rb_global_vm_lock_t gvl;
403
+ rb_nativethread_lock_t thread_destruct_lock;
404
+
405
+ struct rb_thread_struct *main_thread;
406
+ struct rb_thread_struct *running_thread;
407
+
408
+ struct list_head living_threads;
409
+ size_t living_thread_num;
410
+ VALUE thgroup_default;
411
+
412
+ int running;
413
+ int thread_abort_on_exception;
414
+ int trace_running;
415
+ volatile int sleeper;
416
+
417
+ /* object management */
418
+ VALUE mark_object_ary;
419
+
420
+ const VALUE special_exceptions[ruby_special_error_count];
421
+
422
+ /* load */
423
+ VALUE top_self;
424
+ VALUE load_path;
425
+ VALUE load_path_snapshot;
426
+ VALUE load_path_check_cache;
427
+ VALUE expanded_load_path;
428
+ VALUE loaded_features;
429
+ VALUE loaded_features_snapshot;
430
+ struct st_table *loaded_features_index;
431
+ struct st_table *loading_table;
432
+
433
+ /* signal */
434
+ struct {
435
+ VALUE cmd;
436
+ int safe;
437
+ } trap_list[RUBY_NSIG];
438
+
439
+ /* hook */
440
+ rb_hook_list_t event_hooks;
441
+
442
+ /* relation table of ensure - rollback for callcc */
443
+ struct st_table *ensure_rollback_table;
444
+
445
+ /* postponed_job */
446
+ struct rb_postponed_job_struct *postponed_job_buffer;
447
+ int postponed_job_index;
448
+
449
+ int src_encoding_index;
450
+
451
+ VALUE verbose, debug, orig_progname, progname;
452
+ VALUE coverages;
453
+
454
+ struct unlinked_method_entry_list_entry *unlinked_method_entry_list;
455
+
456
+ VALUE defined_module_hash;
457
+
458
+ #if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
459
+ struct rb_objspace *objspace;
460
+ #endif
461
+
462
+ /*
463
+ * @shyouhei notes that this is not for storing normal Ruby
464
+ * objects so do *NOT* mark this when you GC.
465
+ */
466
+ struct RArray at_exit;
467
+
468
+ VALUE *defined_strings;
469
+ st_table *frozen_strings;
470
+
471
+ /* params */
472
+ struct { /* size in byte */
473
+ size_t thread_vm_stack_size;
474
+ size_t thread_machine_stack_size;
475
+ size_t fiber_vm_stack_size;
476
+ size_t fiber_machine_stack_size;
477
+ } default_params;
478
+
479
+ short redefined_flag[BOP_LAST_];
480
+ } rb_vm_t;
481
+
482
+ /* default values */
483
+
484
+ #define RUBY_VM_SIZE_ALIGN 4096
485
+
486
+ #define RUBY_VM_THREAD_VM_STACK_SIZE ( 128 * 1024 * sizeof(VALUE)) /* 512 KB or 1024 KB */
487
+ #define RUBY_VM_THREAD_VM_STACK_SIZE_MIN ( 2 * 1024 * sizeof(VALUE)) /* 8 KB or 16 KB */
488
+ #define RUBY_VM_THREAD_MACHINE_STACK_SIZE ( 128 * 1024 * sizeof(VALUE)) /* 512 KB or 1024 KB */
489
+ #define RUBY_VM_THREAD_MACHINE_STACK_SIZE_MIN ( 16 * 1024 * sizeof(VALUE)) /* 64 KB or 128 KB */
490
+
491
+ #define RUBY_VM_FIBER_VM_STACK_SIZE ( 16 * 1024 * sizeof(VALUE)) /* 64 KB or 128 KB */
492
+ #define RUBY_VM_FIBER_VM_STACK_SIZE_MIN ( 2 * 1024 * sizeof(VALUE)) /* 8 KB or 16 KB */
493
+ #define RUBY_VM_FIBER_MACHINE_STACK_SIZE ( 64 * 1024 * sizeof(VALUE)) /* 256 KB or 512 KB */
494
+ #define RUBY_VM_FIBER_MACHINE_STACK_SIZE_MIN ( 16 * 1024 * sizeof(VALUE)) /* 64 KB or 128 KB */
495
+
496
+ /* optimize insn */
497
+ #define FIXNUM_REDEFINED_OP_FLAG (1 << 0)
498
+ #define FLOAT_REDEFINED_OP_FLAG (1 << 1)
499
+ #define STRING_REDEFINED_OP_FLAG (1 << 2)
500
+ #define ARRAY_REDEFINED_OP_FLAG (1 << 3)
501
+ #define HASH_REDEFINED_OP_FLAG (1 << 4)
502
+ #define BIGNUM_REDEFINED_OP_FLAG (1 << 5)
503
+ #define SYMBOL_REDEFINED_OP_FLAG (1 << 6)
504
+ #define TIME_REDEFINED_OP_FLAG (1 << 7)
505
+ #define REGEXP_REDEFINED_OP_FLAG (1 << 8)
506
+
507
+ #define BASIC_OP_UNREDEFINED_P(op, klass) (LIKELY((GET_VM()->redefined_flag[(op)]&(klass)) == 0))
508
+
509
+ #ifndef VM_DEBUG_BP_CHECK
510
+ #define VM_DEBUG_BP_CHECK 0
511
+ #endif
512
+
513
+ #ifndef VM_DEBUG_VERIFY_METHOD_CACHE
514
+ #define VM_DEBUG_VERIFY_METHOD_CACHE 0
515
+ #endif
516
+
517
+ typedef struct rb_control_frame_struct {
518
+ VALUE *pc; /* cfp[0] */
519
+ VALUE *sp; /* cfp[1] */
520
+ rb_iseq_t *iseq; /* cfp[2] */
521
+ VALUE flag; /* cfp[3] */
522
+ VALUE self; /* cfp[4] / block[0] */
523
+ VALUE klass; /* cfp[5] / block[1] */
524
+ VALUE *ep; /* cfp[6] / block[2] */
525
+ rb_iseq_t *block_iseq; /* cfp[7] / block[3] */
526
+ VALUE proc; /* cfp[8] / block[4] */
527
+ const rb_method_entry_t *me;/* cfp[9] */
528
+
529
+ #if VM_DEBUG_BP_CHECK
530
+ VALUE *bp_check; /* cfp[10] */
531
+ #endif
532
+ } rb_control_frame_t;
533
+
534
+ typedef struct rb_block_struct {
535
+ VALUE self; /* share with method frame if it's only block */
536
+ VALUE klass; /* share with method frame if it's only block */
537
+ VALUE *ep; /* share with method frame if it's only block */
538
+ rb_iseq_t *iseq;
539
+ VALUE proc;
540
+ } rb_block_t;
541
+
542
+ extern const rb_data_type_t ruby_threadptr_data_type;
543
+
544
+ #define GetThreadPtr(obj, ptr) \
545
+ TypedData_Get_Struct((obj), rb_thread_t, &ruby_threadptr_data_type, (ptr))
546
+
547
+ enum rb_thread_status {
548
+ THREAD_RUNNABLE,
549
+ THREAD_STOPPED,
550
+ THREAD_STOPPED_FOREVER,
551
+ THREAD_KILLED
552
+ };
553
+
554
+ typedef RUBY_JMP_BUF rb_jmpbuf_t;
555
+
556
+ /*
557
+ the members which are written in TH_PUSH_TAG() should be placed at
558
+ the beginning and the end, so that entire region is accessible.
559
+ */
560
+ struct rb_vm_tag {
561
+ VALUE tag;
562
+ VALUE retval;
563
+ rb_jmpbuf_t buf;
564
+ struct rb_vm_tag *prev;
565
+ };
566
+
567
+ struct rb_vm_protect_tag {
568
+ struct rb_vm_protect_tag *prev;
569
+ };
570
+
571
+ struct rb_unblock_callback {
572
+ rb_unblock_function_t *func;
573
+ void *arg;
574
+ };
575
+
576
+ struct rb_mutex_struct;
577
+
578
+ struct rb_thread_struct;
579
+ typedef struct rb_thread_list_struct{
580
+ struct rb_thread_list_struct *next;
581
+ struct rb_thread_struct *th;
582
+ } rb_thread_list_t;
583
+
584
+
585
+ typedef struct rb_ensure_entry {
586
+ VALUE marker;
587
+ VALUE (*e_proc)(ANYARGS);
588
+ VALUE data2;
589
+ } rb_ensure_entry_t;
590
+
591
+ typedef struct rb_ensure_list {
592
+ struct rb_ensure_list *next;
593
+ struct rb_ensure_entry entry;
594
+ } rb_ensure_list_t;
595
+
596
+ typedef char rb_thread_id_string_t[sizeof(rb_nativethread_id_t) * 2 + 3];
597
+
598
+ typedef struct rb_fiber_struct rb_fiber_t;
599
+
600
+ typedef struct rb_thread_struct {
601
+ struct list_node vmlt_node;
602
+ VALUE self;
603
+ rb_vm_t *vm;
604
+
605
+ /* execution information */
606
+ VALUE *stack; /* must free, must mark */
607
+ size_t stack_size; /* size in word (byte size / sizeof(VALUE)) */
608
+ rb_control_frame_t *cfp;
609
+ int safe_level;
610
+ int raised_flag;
611
+ VALUE last_status; /* $? */
612
+
613
+ /* passing state */
614
+ int state;
615
+
616
+ int waiting_fd;
617
+
618
+ /* for rb_iterate */
619
+ const rb_block_t *passed_block;
620
+
621
+ /* for bmethod */
622
+ const rb_method_entry_t *passed_bmethod_me;
623
+
624
+ /* for cfunc */
625
+ rb_call_info_t *passed_ci;
626
+
627
+ /* for load(true) */
628
+ VALUE top_self;
629
+ VALUE top_wrapper;
630
+
631
+ /* eval env */
632
+ rb_block_t *base_block;
633
+
634
+ VALUE *root_lep;
635
+ VALUE root_svar;
636
+
637
+ /* thread control */
638
+ rb_nativethread_id_t thread_id;
639
+ #ifdef NON_SCALAR_THREAD_ID
640
+ rb_thread_id_string_t thread_id_string;
641
+ #endif
642
+ enum rb_thread_status status;
643
+ int to_kill;
644
+ int priority;
645
+
646
+ native_thread_data_t native_thread_data;
647
+ void *blocking_region_buffer;
648
+
649
+ VALUE thgroup;
650
+ VALUE value;
651
+
652
+ /* temporary place of errinfo */
653
+ VALUE errinfo;
654
+
655
+ /* temporary place of retval on OPT_CALL_THREADED_CODE */
656
+ #if OPT_CALL_THREADED_CODE
657
+ VALUE retval;
658
+ #endif
659
+
660
+ /* async errinfo queue */
661
+ VALUE pending_interrupt_queue;
662
+ VALUE pending_interrupt_mask_stack;
663
+ int pending_interrupt_queue_checked;
664
+
665
+ rb_atomic_t interrupt_flag;
666
+ unsigned long interrupt_mask;
667
+ rb_nativethread_lock_t interrupt_lock;
668
+ rb_nativethread_cond_t interrupt_cond;
669
+ struct rb_unblock_callback unblock;
670
+ VALUE locking_mutex;
671
+ struct rb_mutex_struct *keeping_mutexes;
672
+
673
+ struct rb_vm_tag *tag;
674
+ struct rb_vm_protect_tag *protect_tag;
675
+
676
+ /*! Thread-local state of evaluation context.
677
+ *
678
+ * If negative, this thread is evaluating the main program.
679
+ * If positive, this thread is evaluating a program under Kernel::eval
680
+ * family.
681
+ */
682
+ int parse_in_eval;
683
+
684
+ /*! Thread-local state of compiling context.
685
+ *
686
+ * If non-zero, the parser does not automatically print error messages to
687
+ * stderr. */
688
+ int mild_compile_error;
689
+
690
+ /* storage */
691
+ st_table *local_storage;
692
+ VALUE local_storage_recursive_hash;
693
+ VALUE local_storage_recursive_hash_for_trace;
694
+
695
+ rb_thread_list_t *join_list;
696
+
697
+ VALUE first_proc;
698
+ VALUE first_args;
699
+ VALUE (*first_func)(ANYARGS);
700
+
701
+ /* for GC */
702
+ struct {
703
+ VALUE *stack_start;
704
+ VALUE *stack_end;
705
+ size_t stack_maxsize;
706
+ #ifdef __ia64
707
+ VALUE *register_stack_start;
708
+ VALUE *register_stack_end;
709
+ size_t register_stack_maxsize;
710
+ #endif
711
+ jmp_buf regs;
712
+ } machine;
713
+
714
+ /* statistics data for profiler */
715
+ VALUE stat_insn_usage;
716
+
717
+ /* tracer */
718
+ rb_hook_list_t event_hooks;
719
+ struct rb_trace_arg_struct *trace_arg; /* trace information */
720
+
721
+ /* fiber */
722
+ rb_fiber_t *fiber;
723
+ rb_fiber_t *root_fiber;
724
+ rb_jmpbuf_t root_jmpbuf;
725
+
726
+ /* ensure & callcc */
727
+ rb_ensure_list_t *ensure_list;
728
+
729
+ /* misc */
730
+ int method_missing_reason;
731
+ int abort_on_exception;
732
+ #ifdef USE_SIGALTSTACK
733
+ void *altstack;
734
+ #endif
735
+ unsigned long running_time_us;
736
+ } rb_thread_t;
737
+
738
+ typedef enum {
739
+ VM_DEFINECLASS_TYPE_CLASS = 0x00,
740
+ VM_DEFINECLASS_TYPE_SINGLETON_CLASS = 0x01,
741
+ VM_DEFINECLASS_TYPE_MODULE = 0x02,
742
+ /* 0x03..0x06 is reserved */
743
+ VM_DEFINECLASS_TYPE_MASK = 0x07
744
+ } rb_vm_defineclass_type_t;
745
+
746
+ #define VM_DEFINECLASS_TYPE(x) ((rb_vm_defineclass_type_t)(x) & VM_DEFINECLASS_TYPE_MASK)
747
+ #define VM_DEFINECLASS_FLAG_SCOPED 0x08
748
+ #define VM_DEFINECLASS_FLAG_HAS_SUPERCLASS 0x10
749
+ #define VM_DEFINECLASS_SCOPED_P(x) ((x) & VM_DEFINECLASS_FLAG_SCOPED)
750
+ #define VM_DEFINECLASS_HAS_SUPERCLASS_P(x) \
751
+ ((x) & VM_DEFINECLASS_FLAG_HAS_SUPERCLASS)
752
+
753
+ /* iseq.c */
754
+ RUBY_SYMBOL_EXPORT_BEGIN
755
+
756
+ /* node -> iseq */
757
+ VALUE rb_iseq_new(NODE*, VALUE, VALUE, VALUE, VALUE, enum iseq_type);
758
+ VALUE rb_iseq_new_top(NODE *node, VALUE name, VALUE path, VALUE absolute_path, VALUE parent);
759
+ VALUE rb_iseq_new_main(NODE *node, VALUE path, VALUE absolute_path);
760
+ VALUE rb_iseq_new_with_bopt(NODE*, VALUE, VALUE, VALUE, VALUE, VALUE, enum iseq_type, VALUE);
761
+ VALUE rb_iseq_new_with_opt(NODE*, VALUE, VALUE, VALUE, VALUE, VALUE, enum iseq_type, const rb_compile_option_t*);
762
+
763
+ /* src -> iseq */
764
+ VALUE rb_iseq_compile(VALUE src, VALUE file, VALUE line);
765
+ VALUE rb_iseq_compile_on_base(VALUE src, VALUE file, VALUE line, rb_block_t *base_block);
766
+ VALUE rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE absolute_path, VALUE line, rb_block_t *base_block, VALUE opt);
767
+
768
+ VALUE rb_iseq_disasm(VALUE self);
769
+ int rb_iseq_disasm_insn(VALUE str, const VALUE *iseqval, size_t pos, const rb_iseq_t *iseq, VALUE child);
770
+ const char *ruby_node_name(int node);
771
+
772
+ RUBY_EXTERN VALUE rb_cISeq;
773
+ RUBY_EXTERN VALUE rb_cRubyVM;
774
+ RUBY_EXTERN VALUE rb_cEnv;
775
+ RUBY_EXTERN VALUE rb_mRubyVMFrozenCore;
776
+ RUBY_SYMBOL_EXPORT_END
777
+
778
+ #define GetProcPtr(obj, ptr) \
779
+ GetCoreDataFromValue((obj), rb_proc_t, (ptr))
780
+
781
+ typedef struct {
782
+ rb_block_t block;
783
+
784
+ VALUE envval; /* for GC mark */
785
+ VALUE blockprocval;
786
+ int8_t safe_level; /* 0..3 */
787
+ int8_t is_from_method; /* bool */
788
+ int8_t is_lambda; /* bool */
789
+ } rb_proc_t;
790
+
791
+ #define GetEnvPtr(obj, ptr) \
792
+ GetCoreDataFromValue((obj), rb_env_t, (ptr))
793
+
794
+ typedef struct {
795
+ int env_size;
796
+ int local_size;
797
+ VALUE prev_envval; /* for GC mark */
798
+ rb_block_t block;
799
+ VALUE env[1]; /* flexible array */
800
+ } rb_env_t;
801
+
802
+ extern const rb_data_type_t ruby_binding_data_type;
803
+
804
+ #define GetBindingPtr(obj, ptr) \
805
+ GetCoreDataFromValue((obj), rb_binding_t, (ptr))
806
+
807
+ typedef struct {
808
+ VALUE env;
809
+ VALUE path;
810
+ VALUE blockprocval; /* for GC mark */
811
+ unsigned short first_lineno;
812
+ } rb_binding_t;
813
+
814
+ /* used by compile time and send insn */
815
+
816
+ enum vm_check_match_type {
817
+ VM_CHECKMATCH_TYPE_WHEN = 1,
818
+ VM_CHECKMATCH_TYPE_CASE = 2,
819
+ VM_CHECKMATCH_TYPE_RESCUE = 3
820
+ };
821
+
822
+ #define VM_CHECKMATCH_TYPE_MASK 0x03
823
+ #define VM_CHECKMATCH_ARRAY 0x04
824
+
825
+ #define VM_CALL_ARGS_SPLAT (0x01 << 1) /* m(*args) */
826
+ #define VM_CALL_ARGS_BLOCKARG (0x01 << 2) /* m(&block) */
827
+ #define VM_CALL_FCALL (0x01 << 3) /* m(...) */
828
+ #define VM_CALL_VCALL (0x01 << 4) /* m */
829
+ #define VM_CALL_TAILCALL (0x01 << 5) /* located at tail position */
830
+ #define VM_CALL_SUPER (0x01 << 6) /* super */
831
+ #define VM_CALL_OPT_SEND (0x01 << 7) /* internal flag */
832
+ #define VM_CALL_ARGS_SIMPLE (0x01 << 8) /* (ci->flag & (SPLAT|BLOCKARG)) && ci->blockiseq == NULL && ci->kw_arg == NULL */
833
+
834
+ enum vm_special_object_type {
835
+ VM_SPECIAL_OBJECT_VMCORE = 1,
836
+ VM_SPECIAL_OBJECT_CBASE,
837
+ VM_SPECIAL_OBJECT_CONST_BASE
838
+ };
839
+
840
+ #define VM_FRAME_MAGIC_METHOD 0x11
841
+ #define VM_FRAME_MAGIC_BLOCK 0x21
842
+ #define VM_FRAME_MAGIC_CLASS 0x31
843
+ #define VM_FRAME_MAGIC_TOP 0x41
844
+ #define VM_FRAME_MAGIC_CFUNC 0x61
845
+ #define VM_FRAME_MAGIC_PROC 0x71
846
+ #define VM_FRAME_MAGIC_IFUNC 0x81
847
+ #define VM_FRAME_MAGIC_EVAL 0x91
848
+ #define VM_FRAME_MAGIC_LAMBDA 0xa1
849
+ #define VM_FRAME_MAGIC_RESCUE 0xb1
850
+ #define VM_FRAME_MAGIC_MASK_BITS 8
851
+ #define VM_FRAME_MAGIC_MASK (~(~(VALUE)0<<VM_FRAME_MAGIC_MASK_BITS))
852
+
853
+ #define VM_FRAME_TYPE(cfp) ((cfp)->flag & VM_FRAME_MAGIC_MASK)
854
+
855
+ /* other frame flag */
856
+ #define VM_FRAME_FLAG_PASSED 0x0100
857
+ #define VM_FRAME_FLAG_FINISH 0x0200
858
+ #define VM_FRAME_FLAG_BMETHOD 0x0400
859
+ #define VM_FRAME_TYPE_FINISH_P(cfp) (((cfp)->flag & VM_FRAME_FLAG_FINISH) != 0)
860
+ #define VM_FRAME_TYPE_BMETHOD_P(cfp) (((cfp)->flag & VM_FRAME_FLAG_BMETHOD) != 0)
861
+
862
+ #define RUBYVM_CFUNC_FRAME_P(cfp) \
863
+ (VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_CFUNC)
864
+
865
+ /* inline cache */
866
+ typedef struct iseq_inline_cache_entry *IC;
867
+ typedef rb_call_info_t *CALL_INFO;
868
+
869
+ void rb_vm_change_state(void);
870
+
871
+ typedef VALUE CDHASH;
872
+
873
+ #ifndef FUNC_FASTCALL
874
+ #define FUNC_FASTCALL(x) x
875
+ #endif
876
+
877
+ typedef rb_control_frame_t *
878
+ (FUNC_FASTCALL(*rb_insn_func_t))(rb_thread_t *, rb_control_frame_t *);
879
+
880
+ #define GC_GUARDED_PTR(p) ((VALUE)((VALUE)(p) | 0x01))
881
+ #define GC_GUARDED_PTR_REF(p) ((void *)(((VALUE)(p)) & ~0x03))
882
+ #define GC_GUARDED_PTR_P(p) (((VALUE)(p)) & 0x01)
883
+
884
+ /*
885
+ * block frame:
886
+ * ep[ 0]: prev frame
887
+ * ep[-1]: CREF (for *_eval)
888
+ *
889
+ * method frame:
890
+ * ep[ 0]: block pointer (ptr | VM_ENVVAL_BLOCK_PTR_FLAG)
891
+ */
892
+
893
+ #define VM_ENVVAL_BLOCK_PTR_FLAG 0x02
894
+ #define VM_ENVVAL_BLOCK_PTR(v) (GC_GUARDED_PTR(v) | VM_ENVVAL_BLOCK_PTR_FLAG)
895
+ #define VM_ENVVAL_BLOCK_PTR_P(v) ((v) & VM_ENVVAL_BLOCK_PTR_FLAG)
896
+ #define VM_ENVVAL_PREV_EP_PTR(v) ((VALUE)GC_GUARDED_PTR(v))
897
+ #define VM_ENVVAL_PREV_EP_PTR_P(v) (!(VM_ENVVAL_BLOCK_PTR_P(v)))
898
+
899
+ #define VM_EP_PREV_EP(ep) ((VALUE *)GC_GUARDED_PTR_REF((ep)[0]))
900
+ #define VM_EP_BLOCK_PTR(ep) ((rb_block_t *)GC_GUARDED_PTR_REF((ep)[0]))
901
+ #define VM_EP_LEP_P(ep) VM_ENVVAL_BLOCK_PTR_P((ep)[0])
902
+
903
+ VALUE *rb_vm_ep_local_ep(VALUE *ep);
904
+ rb_block_t *rb_vm_control_frame_block_ptr(rb_control_frame_t *cfp);
905
+
906
+ #define RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp) ((cfp)+1)
907
+ #define RUBY_VM_NEXT_CONTROL_FRAME(cfp) ((cfp)-1)
908
+ #define RUBY_VM_END_CONTROL_FRAME(th) \
909
+ ((rb_control_frame_t *)((th)->stack + (th)->stack_size))
910
+ #define RUBY_VM_VALID_CONTROL_FRAME_P(cfp, ecfp) \
911
+ ((void *)(ecfp) > (void *)(cfp))
912
+ #define RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp) \
913
+ (!RUBY_VM_VALID_CONTROL_FRAME_P((cfp), RUBY_VM_END_CONTROL_FRAME(th)))
914
+
915
+ #define RUBY_VM_IFUNC_P(ptr) RB_TYPE_P((VALUE)(ptr), T_NODE)
916
+ #define RUBY_VM_NORMAL_ISEQ_P(ptr) \
917
+ ((ptr) && !RUBY_VM_IFUNC_P(ptr))
918
+
919
+ #define RUBY_VM_GET_BLOCK_PTR_IN_CFP(cfp) ((rb_block_t *)(&(cfp)->self))
920
+ #define RUBY_VM_GET_CFP_FROM_BLOCK_PTR(b) \
921
+ ((rb_control_frame_t *)((VALUE *)(b) - 4))
922
+ /* magic number `4' is depend on rb_control_frame_t layout. */
923
+
924
+ /* VM related object allocate functions */
925
+ VALUE rb_thread_alloc(VALUE klass);
926
+ VALUE rb_proc_wrap(VALUE klass, rb_proc_t *); /* may use with rb_proc_alloc */
927
+ VALUE rb_binding_alloc(VALUE klass);
928
+
929
+ /* for debug */
930
+ extern void rb_vmdebug_stack_dump_raw(rb_thread_t *, rb_control_frame_t *);
931
+ extern void rb_vmdebug_debug_print_pre(rb_thread_t *th, rb_control_frame_t *cfp, VALUE *_pc);
932
+ extern void rb_vmdebug_debug_print_post(rb_thread_t *th, rb_control_frame_t *cfp);
933
+
934
+ #define SDR() rb_vmdebug_stack_dump_raw(GET_THREAD(), GET_THREAD()->cfp)
935
+ #define SDR2(cfp) rb_vmdebug_stack_dump_raw(GET_THREAD(), (cfp))
936
+ void rb_vm_bugreport(const void *);
937
+ NORETURN(void rb_bug_context(const void *, const char *fmt, ...));
938
+
939
+ /* functions about thread/vm execution */
940
+ RUBY_SYMBOL_EXPORT_BEGIN
941
+ VALUE rb_iseq_eval(VALUE iseqval);
942
+ VALUE rb_iseq_eval_main(VALUE iseqval);
943
+ RUBY_SYMBOL_EXPORT_END
944
+ int rb_thread_method_id_and_class(rb_thread_t *th, ID *idp, VALUE *klassp);
945
+
946
+ VALUE rb_vm_invoke_proc(rb_thread_t *th, rb_proc_t *proc,
947
+ int argc, const VALUE *argv, const rb_block_t *blockptr);
948
+ VALUE rb_vm_make_proc_lambda(rb_thread_t *th, const rb_block_t *block, VALUE klass, int8_t is_lambda);
949
+ VALUE rb_vm_make_proc(rb_thread_t *th, const rb_block_t *block, VALUE klass);
950
+ VALUE rb_vm_make_binding(rb_thread_t *th, const rb_control_frame_t *src_cfp);
951
+ VALUE rb_vm_make_env_object(rb_thread_t *th, rb_control_frame_t *cfp);
952
+ VALUE rb_vm_env_local_variables(VALUE envval);
953
+ VALUE *rb_binding_add_dynavars(rb_binding_t *bind, int dyncount, const ID *dynvars);
954
+ void rb_vm_inc_const_missing_count(void);
955
+ void rb_vm_gvl_destroy(rb_vm_t *vm);
956
+ VALUE rb_vm_call(rb_thread_t *th, VALUE recv, VALUE id, int argc,
957
+ const VALUE *argv, const rb_method_entry_t *me,
958
+ VALUE defined_class);
959
+ void rb_unlink_method_entry(rb_method_entry_t *me);
960
+ void rb_gc_mark_unlinked_live_method_entries(void *pvm);
961
+
962
+ void rb_thread_start_timer_thread(void);
963
+ void rb_thread_stop_timer_thread(int);
964
+ void rb_thread_reset_timer_thread(void);
965
+ void rb_thread_wakeup_timer_thread(void);
966
+
967
+ static inline void
968
+ rb_vm_living_threads_init(rb_vm_t *vm)
969
+ {
970
+ list_head_init(&vm->living_threads);
971
+ vm->living_thread_num = 0;
972
+ }
973
+
974
+ static inline void
975
+ rb_vm_living_threads_insert(rb_vm_t *vm, rb_thread_t *th)
976
+ {
977
+ list_add_tail(&vm->living_threads, &th->vmlt_node);
978
+ vm->living_thread_num++;
979
+ }
980
+
981
+ static inline void
982
+ rb_vm_living_threads_remove(rb_vm_t *vm, rb_thread_t *th)
983
+ {
984
+ list_del(&th->vmlt_node);
985
+ vm->living_thread_num--;
986
+ }
987
+
988
+ int ruby_thread_has_gvl_p(void);
989
+ typedef int rb_backtrace_iter_func(void *, VALUE, int, VALUE);
990
+ rb_control_frame_t *rb_vm_get_ruby_level_next_cfp(const rb_thread_t *th, const rb_control_frame_t *cfp);
991
+ rb_control_frame_t *rb_vm_get_binding_creatable_next_cfp(const rb_thread_t *th, const rb_control_frame_t *cfp);
992
+ int rb_vm_get_sourceline(const rb_control_frame_t *);
993
+ VALUE rb_name_err_mesg_new(VALUE obj, VALUE mesg, VALUE recv, VALUE method);
994
+ void rb_vm_stack_to_heap(rb_thread_t *th);
995
+ void ruby_thread_init_stack(rb_thread_t *th);
996
+ int rb_vm_control_frame_id_and_class(const rb_control_frame_t *cfp, ID *idp, VALUE *klassp);
997
+ void rb_vm_rewind_cfp(rb_thread_t *th, rb_control_frame_t *cfp);
998
+
999
+ void rb_vm_register_special_exception(enum ruby_special_exceptions sp, VALUE exception_class, const char *mesg);
1000
+
1001
+ void rb_gc_mark_machine_stack(rb_thread_t *th);
1002
+
1003
+ int rb_autoloading_value(VALUE mod, ID id, VALUE* value);
1004
+
1005
+ void rb_vm_rewrite_cref_stack(NODE *node, VALUE old_klass, VALUE new_klass, NODE **new_cref_ptr);
1006
+
1007
+ #define sysstack_error GET_VM()->special_exceptions[ruby_error_sysstack]
1008
+
1009
+ #define RUBY_CONST_ASSERT(expr) (1/!!(expr)) /* expr must be a compile-time constant */
1010
+ #define VM_STACK_OVERFLOWED_P(cfp, sp, margin) \
1011
+ (!RUBY_CONST_ASSERT(sizeof(*(sp)) == sizeof(VALUE)) || \
1012
+ !RUBY_CONST_ASSERT(sizeof(*(cfp)) == sizeof(rb_control_frame_t)) || \
1013
+ ((rb_control_frame_t *)((sp) + (margin)) + 1) >= (cfp))
1014
+ #define WHEN_VM_STACK_OVERFLOWED(cfp, sp, margin) \
1015
+ if (LIKELY(!VM_STACK_OVERFLOWED_P(cfp, sp, margin))) {(void)0;} else /* overflowed */
1016
+ #define CHECK_VM_STACK_OVERFLOW0(cfp, sp, margin) \
1017
+ WHEN_VM_STACK_OVERFLOWED(cfp, sp, margin) vm_stackoverflow()
1018
+ #define CHECK_VM_STACK_OVERFLOW(cfp, margin) \
1019
+ WHEN_VM_STACK_OVERFLOWED(cfp, (cfp)->sp, margin) vm_stackoverflow()
1020
+
1021
+ /* for thread */
1022
+
1023
+ #if RUBY_VM_THREAD_MODEL == 2
1024
+ extern rb_thread_t *ruby_current_thread;
1025
+ extern rb_vm_t *ruby_current_vm;
1026
+ extern rb_event_flag_t ruby_vm_event_flags;
1027
+
1028
+ #define GET_VM() ruby_current_vm
1029
+
1030
+ #ifndef OPT_CALL_CFUNC_WITHOUT_FRAME
1031
+ #define OPT_CALL_CFUNC_WITHOUT_FRAME 0
1032
+ #endif
1033
+
1034
+ static inline rb_thread_t *
1035
+ GET_THREAD(void)
1036
+ {
1037
+ rb_thread_t *th = ruby_current_thread;
1038
+ #if OPT_CALL_CFUNC_WITHOUT_FRAME
1039
+ if (UNLIKELY(th->passed_ci != 0)) {
1040
+ void vm_call_cfunc_push_frame(rb_thread_t *th);
1041
+ vm_call_cfunc_push_frame(th);
1042
+ }
1043
+ #endif
1044
+ return th;
1045
+ }
1046
+
1047
+ #define rb_thread_set_current_raw(th) (void)(ruby_current_thread = (th))
1048
+ #define rb_thread_set_current(th) do { \
1049
+ if ((th)->vm->running_thread != (th)) { \
1050
+ (th)->running_time_us = 0; \
1051
+ } \
1052
+ rb_thread_set_current_raw(th); \
1053
+ (th)->vm->running_thread = (th); \
1054
+ } while (0)
1055
+
1056
+ #else
1057
+ #error "unsupported thread model"
1058
+ #endif
1059
+
1060
+ enum {
1061
+ TIMER_INTERRUPT_MASK = 0x01,
1062
+ PENDING_INTERRUPT_MASK = 0x02,
1063
+ POSTPONED_JOB_INTERRUPT_MASK = 0x04,
1064
+ TRAP_INTERRUPT_MASK = 0x08
1065
+ };
1066
+
1067
+ #define RUBY_VM_SET_TIMER_INTERRUPT(th) ATOMIC_OR((th)->interrupt_flag, TIMER_INTERRUPT_MASK)
1068
+ #define RUBY_VM_SET_INTERRUPT(th) ATOMIC_OR((th)->interrupt_flag, PENDING_INTERRUPT_MASK)
1069
+ #define RUBY_VM_SET_POSTPONED_JOB_INTERRUPT(th) ATOMIC_OR((th)->interrupt_flag, POSTPONED_JOB_INTERRUPT_MASK)
1070
+ #define RUBY_VM_SET_TRAP_INTERRUPT(th) ATOMIC_OR((th)->interrupt_flag, TRAP_INTERRUPT_MASK)
1071
+ #define RUBY_VM_INTERRUPTED(th) ((th)->interrupt_flag & ~(th)->interrupt_mask & (PENDING_INTERRUPT_MASK|TRAP_INTERRUPT_MASK))
1072
+ #define RUBY_VM_INTERRUPTED_ANY(th) ((th)->interrupt_flag & ~(th)->interrupt_mask)
1073
+
1074
+ int rb_signal_buff_size(void);
1075
+ void rb_signal_exec(rb_thread_t *th, int sig);
1076
+ void rb_threadptr_check_signal(rb_thread_t *mth);
1077
+ void rb_threadptr_signal_raise(rb_thread_t *th, int sig);
1078
+ void rb_threadptr_signal_exit(rb_thread_t *th);
1079
+ void rb_threadptr_execute_interrupts(rb_thread_t *, int);
1080
+ void rb_threadptr_interrupt(rb_thread_t *th);
1081
+ void rb_threadptr_unlock_all_locking_mutexes(rb_thread_t *th);
1082
+ void rb_threadptr_pending_interrupt_clear(rb_thread_t *th);
1083
+ void rb_threadptr_pending_interrupt_enque(rb_thread_t *th, VALUE v);
1084
+ int rb_threadptr_pending_interrupt_active_p(rb_thread_t *th);
1085
+
1086
+ #define RUBY_VM_CHECK_INTS_BLOCKING(th) do { \
1087
+ if (UNLIKELY(!rb_threadptr_pending_interrupt_empty_p(th))) { \
1088
+ th->pending_interrupt_queue_checked = 0; \
1089
+ RUBY_VM_SET_INTERRUPT(th); \
1090
+ rb_threadptr_execute_interrupts(th, 1); \
1091
+ } \
1092
+ else if (UNLIKELY(RUBY_VM_INTERRUPTED_ANY(th))) { \
1093
+ rb_threadptr_execute_interrupts(th, 1); \
1094
+ } \
1095
+ } while (0)
1096
+
1097
+ #define RUBY_VM_CHECK_INTS(th) do { \
1098
+ if (UNLIKELY(RUBY_VM_INTERRUPTED_ANY(th))) { \
1099
+ rb_threadptr_execute_interrupts(th, 0); \
1100
+ } \
1101
+ } while (0)
1102
+
1103
+ /* tracer */
1104
+ struct rb_trace_arg_struct {
1105
+ rb_event_flag_t event;
1106
+ rb_thread_t *th;
1107
+ rb_control_frame_t *cfp;
1108
+ VALUE self;
1109
+ ID id;
1110
+ VALUE klass;
1111
+ VALUE data;
1112
+
1113
+ int klass_solved;
1114
+
1115
+ /* calc from cfp */
1116
+ int lineno;
1117
+ VALUE path;
1118
+ };
1119
+
1120
+ void rb_threadptr_exec_event_hooks(struct rb_trace_arg_struct *trace_arg);
1121
+ void rb_threadptr_exec_event_hooks_and_pop_frame(struct rb_trace_arg_struct *trace_arg);
1122
+
1123
+ #define EXEC_EVENT_HOOK_ORIG(th_, flag_, self_, id_, klass_, data_, pop_p_) do { \
1124
+ if (UNLIKELY(ruby_vm_event_flags & (flag_))) { \
1125
+ if (((th)->event_hooks.events | (th)->vm->event_hooks.events) & (flag_)) { \
1126
+ struct rb_trace_arg_struct trace_arg; \
1127
+ trace_arg.event = (flag_); \
1128
+ trace_arg.th = (th_); \
1129
+ trace_arg.cfp = (trace_arg.th)->cfp; \
1130
+ trace_arg.self = (self_); \
1131
+ trace_arg.id = (id_); \
1132
+ trace_arg.klass = (klass_); \
1133
+ trace_arg.data = (data_); \
1134
+ trace_arg.path = Qundef; \
1135
+ trace_arg.klass_solved = 0; \
1136
+ if (pop_p_) rb_threadptr_exec_event_hooks_and_pop_frame(&trace_arg); \
1137
+ else rb_threadptr_exec_event_hooks(&trace_arg); \
1138
+ } \
1139
+ } \
1140
+ } while (0)
1141
+
1142
+ #define EXEC_EVENT_HOOK(th_, flag_, self_, id_, klass_, data_) \
1143
+ EXEC_EVENT_HOOK_ORIG(th_, flag_, self_, id_, klass_, data_, 0)
1144
+
1145
+ #define EXEC_EVENT_HOOK_AND_POP_FRAME(th_, flag_, self_, id_, klass_, data_) \
1146
+ EXEC_EVENT_HOOK_ORIG(th_, flag_, self_, id_, klass_, data_, 1)
1147
+
1148
+ RUBY_SYMBOL_EXPORT_BEGIN
1149
+
1150
+ int rb_thread_check_trap_pending(void);
1151
+
1152
+ extern VALUE rb_get_coverages(void);
1153
+ extern void rb_set_coverages(VALUE);
1154
+ extern void rb_reset_coverages(void);
1155
+
1156
+ void rb_postponed_job_flush(rb_vm_t *vm);
1157
+
1158
+ RUBY_SYMBOL_EXPORT_END
1159
+
1160
+ #endif /* RUBY_VM_CORE_H */