debase-ruby_core_source 0.10.15 → 0.10.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +28 -0
  3. data/debase-ruby_core_source.gemspec +1 -1
  4. data/lib/debase/ruby_core_source/{ruby-1.9.3-p550 → ruby-2.5.4-p155}/addr2line.h +1 -1
  5. data/lib/debase/ruby_core_source/ruby-2.5.4-p155/ccan/build_assert/build_assert.h +40 -0
  6. data/lib/debase/ruby_core_source/ruby-2.5.4-p155/ccan/check_type/check_type.h +63 -0
  7. data/lib/debase/ruby_core_source/ruby-2.5.4-p155/ccan/container_of/container_of.h +142 -0
  8. data/lib/debase/ruby_core_source/ruby-2.5.4-p155/ccan/list/list.h +773 -0
  9. data/lib/debase/ruby_core_source/ruby-2.5.4-p155/ccan/str/str.h +16 -0
  10. data/lib/debase/ruby_core_source/ruby-2.5.4-p155/constant.h +51 -0
  11. data/lib/debase/ruby_core_source/ruby-2.5.4-p155/debug_counter.h +109 -0
  12. data/lib/debase/ruby_core_source/{ruby-1.9.3-p550 → ruby-2.5.4-p155}/dln.h +10 -9
  13. data/lib/debase/ruby_core_source/ruby-2.5.4-p155/encindex.h +69 -0
  14. data/lib/debase/ruby_core_source/ruby-2.5.4-p155/eval_intern.h +334 -0
  15. data/lib/debase/ruby_core_source/{ruby-1.9.3-p550 → ruby-2.5.4-p155}/gc.h +27 -10
  16. data/lib/debase/ruby_core_source/ruby-2.5.4-p155/id.h +250 -0
  17. data/lib/debase/ruby_core_source/ruby-2.5.4-p155/id_table.h +31 -0
  18. data/lib/debase/ruby_core_source/ruby-2.5.4-p155/insns.inc +217 -0
  19. data/lib/debase/ruby_core_source/ruby-2.5.4-p155/insns_info.inc +1570 -0
  20. data/lib/debase/ruby_core_source/ruby-2.5.4-p155/internal.h +2036 -0
  21. data/lib/debase/ruby_core_source/ruby-2.5.4-p155/iseq.h +308 -0
  22. data/lib/debase/ruby_core_source/{ruby-1.9.3-p550 → ruby-2.5.4-p155}/known_errors.inc +16 -1
  23. data/lib/debase/ruby_core_source/ruby-2.5.4-p155/method.h +218 -0
  24. data/lib/debase/ruby_core_source/{ruby-1.9.3-p550 → ruby-2.5.4-p155}/node.h +115 -79
  25. data/lib/debase/ruby_core_source/{ruby-1.9.3-p550 → ruby-2.5.4-p155}/node_name.inc +12 -22
  26. data/lib/debase/ruby_core_source/ruby-2.5.4-p155/opt_sc.inc +1601 -0
  27. data/lib/debase/ruby_core_source/ruby-2.5.4-p155/optinsn.inc +103 -0
  28. data/lib/debase/ruby_core_source/{ruby-1.9.3-p550 → ruby-2.5.4-p155}/optunifs.inc +28 -83
  29. data/lib/debase/ruby_core_source/{ruby-1.9.3-p550 → ruby-2.5.4-p155}/parse.h +74 -60
  30. data/lib/debase/ruby_core_source/ruby-2.5.4-p155/probes_helper.h +43 -0
  31. data/lib/debase/ruby_core_source/ruby-2.5.4-p155/regenc.h +254 -0
  32. data/lib/debase/ruby_core_source/{ruby-1.9.3-p550 → ruby-2.5.4-p155}/regint.h +299 -211
  33. data/lib/debase/ruby_core_source/{ruby-1.9.3-p550 → ruby-2.5.4-p155}/regparse.h +45 -37
  34. data/lib/debase/ruby_core_source/ruby-2.5.4-p155/revision.h +1 -0
  35. data/lib/debase/ruby_core_source/ruby-2.5.4-p155/ruby_assert.h +54 -0
  36. data/lib/debase/ruby_core_source/{ruby-1.9.3-p550 → ruby-2.5.4-p155}/ruby_atomic.h +84 -26
  37. data/lib/debase/ruby_core_source/{ruby-1.9.3-p550 → ruby-2.5.4-p155}/siphash.h +1 -1
  38. data/lib/debase/ruby_core_source/ruby-2.5.4-p155/symbol.h +108 -0
  39. data/lib/debase/ruby_core_source/{ruby-1.9.3-p550 → ruby-2.5.4-p155}/thread_pthread.h +14 -11
  40. data/lib/debase/ruby_core_source/{ruby-1.9.3-p550 → ruby-2.5.4-p155}/thread_win32.h +2 -6
  41. data/lib/debase/ruby_core_source/ruby-2.5.4-p155/timev.h +42 -0
  42. data/lib/debase/ruby_core_source/{ruby-1.9.3-p550 → ruby-2.5.4-p155}/transcode_data.h +34 -12
  43. data/lib/debase/ruby_core_source/ruby-2.5.4-p155/version.h +73 -0
  44. data/lib/debase/ruby_core_source/ruby-2.5.4-p155/vm.inc +3667 -0
  45. data/lib/debase/ruby_core_source/ruby-2.5.4-p155/vm_call_iseq_optimized.inc +213 -0
  46. data/lib/debase/ruby_core_source/ruby-2.5.4-p155/vm_core.h +1768 -0
  47. data/lib/debase/ruby_core_source/{ruby-1.9.3-p550/debug.h → ruby-2.5.4-p155/vm_debug.h} +4 -8
  48. data/lib/debase/ruby_core_source/{ruby-1.9.3-p550 → ruby-2.5.4-p155}/vm_exec.h +38 -30
  49. data/lib/debase/ruby_core_source/ruby-2.5.4-p155/vm_insnhelper.h +255 -0
  50. data/lib/debase/ruby_core_source/{ruby-1.9.3-p550 → ruby-2.5.4-p155}/vm_opts.h +14 -9
  51. data/lib/debase/ruby_core_source/ruby-2.5.4-p155/vmtc.inc +214 -0
  52. data/lib/debase/ruby_core_source/version.rb +1 -1
  53. metadata +52 -42
  54. data/lib/debase/ruby_core_source/ruby-1.9.3-p550/constant.h +0 -34
  55. data/lib/debase/ruby_core_source/ruby-1.9.3-p550/encdb.h +0 -167
  56. data/lib/debase/ruby_core_source/ruby-1.9.3-p550/eval_intern.h +0 -234
  57. data/lib/debase/ruby_core_source/ruby-1.9.3-p550/id.h +0 -177
  58. data/lib/debase/ruby_core_source/ruby-1.9.3-p550/insns.inc +0 -179
  59. data/lib/debase/ruby_core_source/ruby-1.9.3-p550/insns_info.inc +0 -695
  60. data/lib/debase/ruby_core_source/ruby-1.9.3-p550/internal.h +0 -242
  61. data/lib/debase/ruby_core_source/ruby-1.9.3-p550/iseq.h +0 -126
  62. data/lib/debase/ruby_core_source/ruby-1.9.3-p550/method.h +0 -105
  63. data/lib/debase/ruby_core_source/ruby-1.9.3-p550/opt_sc.inc +0 -670
  64. data/lib/debase/ruby_core_source/ruby-1.9.3-p550/optinsn.inc +0 -30
  65. data/lib/debase/ruby_core_source/ruby-1.9.3-p550/regenc.h +0 -219
  66. data/lib/debase/ruby_core_source/ruby-1.9.3-p550/revision.h +0 -1
  67. data/lib/debase/ruby_core_source/ruby-1.9.3-p550/timev.h +0 -21
  68. data/lib/debase/ruby_core_source/ruby-1.9.3-p550/transdb.h +0 -189
  69. data/lib/debase/ruby_core_source/ruby-1.9.3-p550/version.h +0 -52
  70. data/lib/debase/ruby_core_source/ruby-1.9.3-p550/vm.inc +0 -3054
  71. data/lib/debase/ruby_core_source/ruby-1.9.3-p550/vm_core.h +0 -763
  72. data/lib/debase/ruby_core_source/ruby-1.9.3-p550/vm_insnhelper.h +0 -220
  73. data/lib/debase/ruby_core_source/ruby-1.9.3-p550/vmtc.inc +0 -97
@@ -0,0 +1,1768 @@
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
+ /*
16
+ * Enable check mode.
17
+ * 1: enable local assertions.
18
+ */
19
+ #ifndef VM_CHECK_MODE
20
+ #define VM_CHECK_MODE 0
21
+ #endif
22
+
23
+ /**
24
+ * VM Debug Level
25
+ *
26
+ * debug level:
27
+ * 0: no debug output
28
+ * 1: show instruction name
29
+ * 2: show stack frame when control stack frame is changed
30
+ * 3: show stack status
31
+ * 4: show register
32
+ * 5:
33
+ * 10: gc check
34
+ */
35
+
36
+ #ifndef VMDEBUG
37
+ #define VMDEBUG 0
38
+ #endif
39
+
40
+ #if 0
41
+ #undef VMDEBUG
42
+ #define VMDEBUG 3
43
+ #endif
44
+
45
+ #include "ruby_assert.h"
46
+
47
+ #if VM_CHECK_MODE > 0
48
+ #define VM_ASSERT(expr) RUBY_ASSERT_MESG_WHEN(VM_CHECK_MODE > 0, expr, #expr)
49
+
50
+ #define VM_UNREACHABLE(func) rb_bug(#func ": unreachable")
51
+
52
+ #else
53
+ #define VM_ASSERT(expr) ((void)0)
54
+ #define VM_UNREACHABLE(func) UNREACHABLE
55
+ #endif
56
+
57
+ #define RUBY_VM_THREAD_MODEL 2
58
+
59
+ #include "ruby/ruby.h"
60
+ #include "ruby/st.h"
61
+
62
+ #include "node.h"
63
+ #include "vm_debug.h"
64
+ #include "vm_opts.h"
65
+ #include "id.h"
66
+ #include "method.h"
67
+ #include "ruby_atomic.h"
68
+ #include "ccan/list/list.h"
69
+
70
+ #include "ruby/thread_native.h"
71
+ #if defined(_WIN32)
72
+ #include "thread_win32.h"
73
+ #elif defined(HAVE_PTHREAD_H)
74
+ #include "thread_pthread.h"
75
+ #endif
76
+
77
+ #include <setjmp.h>
78
+ #include <signal.h>
79
+
80
+ #ifndef NSIG
81
+ # define NSIG (_SIGMAX + 1) /* For QNX */
82
+ #endif
83
+
84
+ #define RUBY_NSIG NSIG
85
+
86
+ #ifdef HAVE_STDARG_PROTOTYPES
87
+ #include <stdarg.h>
88
+ #define va_init_list(a,b) va_start((a),(b))
89
+ #else
90
+ #include <varargs.h>
91
+ #define va_init_list(a,b) va_start((a))
92
+ #endif
93
+
94
+ #if defined(SIGSEGV) && defined(HAVE_SIGALTSTACK) && defined(SA_SIGINFO) && !defined(__NetBSD__)
95
+ #define USE_SIGALTSTACK
96
+ #endif
97
+
98
+ /*****************/
99
+ /* configuration */
100
+ /*****************/
101
+
102
+ /* gcc ver. check */
103
+ #if defined(__GNUC__) && __GNUC__ >= 2
104
+
105
+ #if OPT_TOKEN_THREADED_CODE
106
+ #if OPT_DIRECT_THREADED_CODE
107
+ #undef OPT_DIRECT_THREADED_CODE
108
+ #endif
109
+ #endif
110
+
111
+ #else /* defined(__GNUC__) && __GNUC__ >= 2 */
112
+
113
+ /* disable threaded code options */
114
+ #if OPT_DIRECT_THREADED_CODE
115
+ #undef OPT_DIRECT_THREADED_CODE
116
+ #endif
117
+ #if OPT_TOKEN_THREADED_CODE
118
+ #undef OPT_TOKEN_THREADED_CODE
119
+ #endif
120
+ #endif
121
+
122
+ /* call threaded code */
123
+ #if OPT_CALL_THREADED_CODE
124
+ #if OPT_DIRECT_THREADED_CODE
125
+ #undef OPT_DIRECT_THREADED_CODE
126
+ #endif /* OPT_DIRECT_THREADED_CODE */
127
+ #if OPT_STACK_CACHING
128
+ #undef OPT_STACK_CACHING
129
+ #endif /* OPT_STACK_CACHING */
130
+ #endif /* OPT_CALL_THREADED_CODE */
131
+
132
+ typedef unsigned long rb_num_t;
133
+
134
+ enum ruby_tag_type {
135
+ RUBY_TAG_NONE = 0x0,
136
+ RUBY_TAG_RETURN = 0x1,
137
+ RUBY_TAG_BREAK = 0x2,
138
+ RUBY_TAG_NEXT = 0x3,
139
+ RUBY_TAG_RETRY = 0x4,
140
+ RUBY_TAG_REDO = 0x5,
141
+ RUBY_TAG_RAISE = 0x6,
142
+ RUBY_TAG_THROW = 0x7,
143
+ RUBY_TAG_FATAL = 0x8,
144
+ RUBY_TAG_MASK = 0xf
145
+ };
146
+
147
+ #define TAG_NONE RUBY_TAG_NONE
148
+ #define TAG_RETURN RUBY_TAG_RETURN
149
+ #define TAG_BREAK RUBY_TAG_BREAK
150
+ #define TAG_NEXT RUBY_TAG_NEXT
151
+ #define TAG_RETRY RUBY_TAG_RETRY
152
+ #define TAG_REDO RUBY_TAG_REDO
153
+ #define TAG_RAISE RUBY_TAG_RAISE
154
+ #define TAG_THROW RUBY_TAG_THROW
155
+ #define TAG_FATAL RUBY_TAG_FATAL
156
+ #define TAG_MASK RUBY_TAG_MASK
157
+
158
+ enum ruby_vm_throw_flags {
159
+ VM_THROW_NO_ESCAPE_FLAG = 0x8000,
160
+ VM_THROW_LEVEL_SHIFT = 16,
161
+ VM_THROW_STATE_MASK = 0xff
162
+ };
163
+
164
+ /* forward declarations */
165
+ struct rb_thread_struct;
166
+ struct rb_control_frame_struct;
167
+
168
+ /* iseq data type */
169
+ typedef struct rb_compile_option_struct rb_compile_option_t;
170
+
171
+ struct iseq_inline_cache_entry {
172
+ rb_serial_t ic_serial;
173
+ const rb_cref_t *ic_cref;
174
+ union {
175
+ size_t index;
176
+ VALUE value;
177
+ } ic_value;
178
+ };
179
+
180
+ union iseq_inline_storage_entry {
181
+ struct {
182
+ struct rb_thread_struct *running_thread;
183
+ VALUE value;
184
+ } once;
185
+ struct iseq_inline_cache_entry cache;
186
+ };
187
+
188
+ enum method_missing_reason {
189
+ MISSING_NOENTRY = 0x00,
190
+ MISSING_PRIVATE = 0x01,
191
+ MISSING_PROTECTED = 0x02,
192
+ MISSING_FCALL = 0x04,
193
+ MISSING_VCALL = 0x08,
194
+ MISSING_SUPER = 0x10,
195
+ MISSING_MISSING = 0x20,
196
+ MISSING_NONE = 0x40
197
+ };
198
+
199
+ struct rb_call_info {
200
+ /* fixed at compile time */
201
+ ID mid;
202
+ unsigned int flag;
203
+ int orig_argc;
204
+ };
205
+
206
+ struct rb_call_info_kw_arg {
207
+ int keyword_len;
208
+ VALUE keywords[1];
209
+ };
210
+
211
+ struct rb_call_info_with_kwarg {
212
+ struct rb_call_info ci;
213
+ struct rb_call_info_kw_arg *kw_arg;
214
+ };
215
+
216
+ struct rb_calling_info {
217
+ VALUE block_handler;
218
+ VALUE recv;
219
+ int argc;
220
+ };
221
+
222
+ struct rb_call_cache;
223
+ struct rb_execution_context_struct;
224
+ typedef VALUE (*vm_call_handler)(struct rb_execution_context_struct *ec, struct rb_control_frame_struct *cfp, struct rb_calling_info *calling, const struct rb_call_info *ci, struct rb_call_cache *cc);
225
+
226
+ struct rb_call_cache {
227
+ /* inline cache: keys */
228
+ rb_serial_t method_state;
229
+ rb_serial_t class_serial;
230
+
231
+ /* inline cache: values */
232
+ const rb_callable_method_entry_t *me;
233
+
234
+ vm_call_handler call;
235
+
236
+ union {
237
+ unsigned int index; /* used by ivar */
238
+ enum method_missing_reason method_missing_reason; /* used by method_missing */
239
+ int inc_sp; /* used by cfunc */
240
+ } aux;
241
+ };
242
+
243
+ #if 1
244
+ #define CoreDataFromValue(obj, type) (type*)DATA_PTR(obj)
245
+ #else
246
+ #define CoreDataFromValue(obj, type) (type*)rb_data_object_get(obj)
247
+ #endif
248
+ #define GetCoreDataFromValue(obj, type, ptr) ((ptr) = CoreDataFromValue((obj), type))
249
+
250
+ typedef struct rb_iseq_location_struct {
251
+ VALUE pathobj; /* String (path) or Array [path, realpath]. Frozen. */
252
+ VALUE base_label; /* String */
253
+ VALUE label; /* String */
254
+ VALUE first_lineno; /* TODO: may be unsigned short */
255
+ rb_code_range_t code_range;
256
+ } rb_iseq_location_t;
257
+
258
+ #define PATHOBJ_PATH 0
259
+ #define PATHOBJ_REALPATH 1
260
+
261
+ static inline VALUE
262
+ pathobj_path(VALUE pathobj)
263
+ {
264
+ if (RB_TYPE_P(pathobj, T_STRING)) {
265
+ return pathobj;
266
+ }
267
+ else {
268
+ VM_ASSERT(RB_TYPE_P(pathobj, T_ARRAY));
269
+ return RARRAY_AREF(pathobj, PATHOBJ_PATH);
270
+ }
271
+ }
272
+
273
+ static inline VALUE
274
+ pathobj_realpath(VALUE pathobj)
275
+ {
276
+ if (RB_TYPE_P(pathobj, T_STRING)) {
277
+ return pathobj;
278
+ }
279
+ else {
280
+ VM_ASSERT(RB_TYPE_P(pathobj, T_ARRAY));
281
+ return RARRAY_AREF(pathobj, PATHOBJ_REALPATH);
282
+ }
283
+ }
284
+
285
+ struct rb_iseq_constant_body {
286
+ enum iseq_type {
287
+ ISEQ_TYPE_TOP,
288
+ ISEQ_TYPE_METHOD,
289
+ ISEQ_TYPE_BLOCK,
290
+ ISEQ_TYPE_CLASS,
291
+ ISEQ_TYPE_RESCUE,
292
+ ISEQ_TYPE_ENSURE,
293
+ ISEQ_TYPE_EVAL,
294
+ ISEQ_TYPE_MAIN,
295
+ ISEQ_TYPE_DEFINED_GUARD
296
+ } type; /* instruction sequence type */
297
+
298
+ unsigned int iseq_size;
299
+ const VALUE *iseq_encoded; /* encoded iseq (insn addr and operands) */
300
+
301
+ /**
302
+ * parameter information
303
+ *
304
+ * def m(a1, a2, ..., aM, # mandatory
305
+ * b1=(...), b2=(...), ..., bN=(...), # optional
306
+ * *c, # rest
307
+ * d1, d2, ..., dO, # post
308
+ * e1:(...), e2:(...), ..., eK:(...), # keyword
309
+ * **f, # keyword_rest
310
+ * &g) # block
311
+ * =>
312
+ *
313
+ * lead_num = M
314
+ * opt_num = N
315
+ * rest_start = M+N
316
+ * post_start = M+N+(*1)
317
+ * post_num = O
318
+ * keyword_num = K
319
+ * block_start = M+N+(*1)+O+K
320
+ * keyword_bits = M+N+(*1)+O+K+(&1)
321
+ * size = M+N+O+(*1)+K+(&1)+(**1) // parameter size.
322
+ */
323
+
324
+ struct {
325
+ struct {
326
+ unsigned int has_lead : 1;
327
+ unsigned int has_opt : 1;
328
+ unsigned int has_rest : 1;
329
+ unsigned int has_post : 1;
330
+ unsigned int has_kw : 1;
331
+ unsigned int has_kwrest : 1;
332
+ unsigned int has_block : 1;
333
+
334
+ unsigned int ambiguous_param0 : 1; /* {|a|} */
335
+ } flags;
336
+
337
+ unsigned int size;
338
+
339
+ int lead_num;
340
+ int opt_num;
341
+ int rest_start;
342
+ int post_start;
343
+ int post_num;
344
+ int block_start;
345
+
346
+ const VALUE *opt_table; /* (opt_num + 1) entries. */
347
+ /* opt_num and opt_table:
348
+ *
349
+ * def foo o1=e1, o2=e2, ..., oN=eN
350
+ * #=>
351
+ * # prologue code
352
+ * A1: e1
353
+ * A2: e2
354
+ * ...
355
+ * AN: eN
356
+ * AL: body
357
+ * opt_num = N
358
+ * opt_table = [A1, A2, ..., AN, AL]
359
+ */
360
+
361
+ const struct rb_iseq_param_keyword {
362
+ int num;
363
+ int required_num;
364
+ int bits_start;
365
+ int rest_start;
366
+ const ID *table;
367
+ const VALUE *default_values;
368
+ } *keyword;
369
+ } param;
370
+
371
+ rb_iseq_location_t location;
372
+
373
+ /* insn info, must be freed */
374
+ const struct iseq_insn_info_entry *insns_info;
375
+
376
+ const ID *local_table; /* must free */
377
+
378
+ /* catch table */
379
+ const struct iseq_catch_table *catch_table;
380
+
381
+ /* for child iseq */
382
+ const struct rb_iseq_struct *parent_iseq;
383
+ struct rb_iseq_struct *local_iseq; /* local_iseq->flip_cnt can be modified */
384
+
385
+ union iseq_inline_storage_entry *is_entries;
386
+ struct rb_call_info *ci_entries; /* struct rb_call_info ci_entries[ci_size];
387
+ * struct rb_call_info_with_kwarg cikw_entries[ci_kw_size];
388
+ * So that:
389
+ * struct rb_call_info_with_kwarg *cikw_entries = &body->ci_entries[ci_size];
390
+ */
391
+ struct rb_call_cache *cc_entries; /* size is ci_size = ci_kw_size */
392
+
393
+ VALUE mark_ary; /* Array: includes operands which should be GC marked */
394
+
395
+ unsigned int local_table_size;
396
+ unsigned int is_size;
397
+ unsigned int ci_size;
398
+ unsigned int ci_kw_size;
399
+ unsigned int insns_info_size;
400
+ unsigned int stack_max; /* for stack overflow check */
401
+ };
402
+
403
+ /* T_IMEMO/iseq */
404
+ /* typedef rb_iseq_t is in method.h */
405
+ struct rb_iseq_struct {
406
+ VALUE flags;
407
+ VALUE reserved1;
408
+ struct rb_iseq_constant_body *body;
409
+
410
+ union { /* 4, 5 words */
411
+ struct iseq_compile_data *compile_data; /* used at compile time */
412
+
413
+ struct {
414
+ VALUE obj;
415
+ int index;
416
+ } loader;
417
+
418
+ rb_event_flag_t trace_events;
419
+ } aux;
420
+ };
421
+
422
+ #ifndef USE_LAZY_LOAD
423
+ #define USE_LAZY_LOAD 0
424
+ #endif
425
+
426
+ #if USE_LAZY_LOAD
427
+ const rb_iseq_t *rb_iseq_complete(const rb_iseq_t *iseq);
428
+ #endif
429
+
430
+ static inline const rb_iseq_t *
431
+ rb_iseq_check(const rb_iseq_t *iseq)
432
+ {
433
+ #if USE_LAZY_LOAD
434
+ if (iseq->body == NULL) {
435
+ rb_iseq_complete((rb_iseq_t *)iseq);
436
+ }
437
+ #endif
438
+ return iseq;
439
+ }
440
+
441
+ enum ruby_special_exceptions {
442
+ ruby_error_reenter,
443
+ ruby_error_nomemory,
444
+ ruby_error_sysstack,
445
+ ruby_error_stackfatal,
446
+ ruby_error_stream_closed,
447
+ ruby_special_error_count
448
+ };
449
+
450
+ enum ruby_basic_operators {
451
+ BOP_PLUS,
452
+ BOP_MINUS,
453
+ BOP_MULT,
454
+ BOP_DIV,
455
+ BOP_MOD,
456
+ BOP_EQ,
457
+ BOP_EQQ,
458
+ BOP_LT,
459
+ BOP_LE,
460
+ BOP_LTLT,
461
+ BOP_AREF,
462
+ BOP_ASET,
463
+ BOP_LENGTH,
464
+ BOP_SIZE,
465
+ BOP_EMPTY_P,
466
+ BOP_SUCC,
467
+ BOP_GT,
468
+ BOP_GE,
469
+ BOP_NOT,
470
+ BOP_NEQ,
471
+ BOP_MATCH,
472
+ BOP_FREEZE,
473
+ BOP_UMINUS,
474
+ BOP_MAX,
475
+ BOP_MIN,
476
+
477
+ BOP_LAST_
478
+ };
479
+
480
+ #define GetVMPtr(obj, ptr) \
481
+ GetCoreDataFromValue((obj), rb_vm_t, (ptr))
482
+
483
+ struct rb_vm_struct;
484
+ typedef void rb_vm_at_exit_func(struct rb_vm_struct*);
485
+
486
+ typedef struct rb_at_exit_list {
487
+ rb_vm_at_exit_func *func;
488
+ struct rb_at_exit_list *next;
489
+ } rb_at_exit_list;
490
+
491
+ struct rb_objspace;
492
+ struct rb_objspace *rb_objspace_alloc(void);
493
+ void rb_objspace_free(struct rb_objspace *);
494
+
495
+ typedef struct rb_hook_list_struct {
496
+ struct rb_event_hook_struct *hooks;
497
+ rb_event_flag_t events;
498
+ int need_clean;
499
+ } rb_hook_list_t;
500
+
501
+ typedef struct rb_vm_struct {
502
+ VALUE self;
503
+
504
+ rb_global_vm_lock_t gvl;
505
+ rb_nativethread_lock_t thread_destruct_lock;
506
+
507
+ struct rb_thread_struct *main_thread;
508
+ struct rb_thread_struct *running_thread;
509
+
510
+ rb_serial_t fork_gen;
511
+ struct list_head waiting_fds; /* <=> struct waiting_fd */
512
+ struct list_head living_threads;
513
+ size_t living_thread_num;
514
+ VALUE thgroup_default;
515
+
516
+ unsigned int running: 1;
517
+ unsigned int thread_abort_on_exception: 1;
518
+ unsigned int thread_report_on_exception: 1;
519
+ int trace_running;
520
+ volatile int sleeper;
521
+
522
+ /* object management */
523
+ VALUE mark_object_ary;
524
+ const VALUE special_exceptions[ruby_special_error_count];
525
+
526
+ /* load */
527
+ VALUE top_self;
528
+ VALUE load_path;
529
+ VALUE load_path_snapshot;
530
+ VALUE load_path_check_cache;
531
+ VALUE expanded_load_path;
532
+ VALUE loaded_features;
533
+ VALUE loaded_features_snapshot;
534
+ struct st_table *loaded_features_index;
535
+ struct st_table *loading_table;
536
+
537
+ /* signal */
538
+ struct {
539
+ VALUE cmd[RUBY_NSIG];
540
+ unsigned char safe[RUBY_NSIG];
541
+ } trap_list;
542
+
543
+ /* hook */
544
+ rb_hook_list_t event_hooks;
545
+
546
+ /* relation table of ensure - rollback for callcc */
547
+ struct st_table *ensure_rollback_table;
548
+
549
+ /* postponed_job */
550
+ struct rb_postponed_job_struct *postponed_job_buffer;
551
+ int postponed_job_index;
552
+
553
+ int src_encoding_index;
554
+
555
+ VALUE verbose, debug, orig_progname, progname;
556
+ VALUE coverages;
557
+ int coverage_mode;
558
+
559
+ VALUE defined_module_hash;
560
+
561
+ struct rb_objspace *objspace;
562
+
563
+ rb_at_exit_list *at_exit;
564
+
565
+ VALUE *defined_strings;
566
+ st_table *frozen_strings;
567
+
568
+ /* params */
569
+ struct { /* size in byte */
570
+ size_t thread_vm_stack_size;
571
+ size_t thread_machine_stack_size;
572
+ size_t fiber_vm_stack_size;
573
+ size_t fiber_machine_stack_size;
574
+ } default_params;
575
+
576
+ short redefined_flag[BOP_LAST_];
577
+ } rb_vm_t;
578
+
579
+ /* default values */
580
+
581
+ #define RUBY_VM_SIZE_ALIGN 4096
582
+
583
+ #define RUBY_VM_THREAD_VM_STACK_SIZE ( 128 * 1024 * sizeof(VALUE)) /* 512 KB or 1024 KB */
584
+ #define RUBY_VM_THREAD_VM_STACK_SIZE_MIN ( 2 * 1024 * sizeof(VALUE)) /* 8 KB or 16 KB */
585
+ #define RUBY_VM_THREAD_MACHINE_STACK_SIZE ( 128 * 1024 * sizeof(VALUE)) /* 512 KB or 1024 KB */
586
+ #define RUBY_VM_THREAD_MACHINE_STACK_SIZE_MIN ( 16 * 1024 * sizeof(VALUE)) /* 64 KB or 128 KB */
587
+
588
+ #define RUBY_VM_FIBER_VM_STACK_SIZE ( 16 * 1024 * sizeof(VALUE)) /* 64 KB or 128 KB */
589
+ #define RUBY_VM_FIBER_VM_STACK_SIZE_MIN ( 2 * 1024 * sizeof(VALUE)) /* 8 KB or 16 KB */
590
+ #define RUBY_VM_FIBER_MACHINE_STACK_SIZE ( 64 * 1024 * sizeof(VALUE)) /* 256 KB or 512 KB */
591
+ #if defined(__powerpc64__)
592
+ #define RUBY_VM_FIBER_MACHINE_STACK_SIZE_MIN ( 32 * 1024 * sizeof(VALUE)) /* 128 KB or 256 KB */
593
+ #else
594
+ #define RUBY_VM_FIBER_MACHINE_STACK_SIZE_MIN ( 16 * 1024 * sizeof(VALUE)) /* 64 KB or 128 KB */
595
+ #endif
596
+
597
+ /* optimize insn */
598
+ #define INTEGER_REDEFINED_OP_FLAG (1 << 0)
599
+ #define FLOAT_REDEFINED_OP_FLAG (1 << 1)
600
+ #define STRING_REDEFINED_OP_FLAG (1 << 2)
601
+ #define ARRAY_REDEFINED_OP_FLAG (1 << 3)
602
+ #define HASH_REDEFINED_OP_FLAG (1 << 4)
603
+ /* #define BIGNUM_REDEFINED_OP_FLAG (1 << 5) */
604
+ #define SYMBOL_REDEFINED_OP_FLAG (1 << 6)
605
+ #define TIME_REDEFINED_OP_FLAG (1 << 7)
606
+ #define REGEXP_REDEFINED_OP_FLAG (1 << 8)
607
+ #define NIL_REDEFINED_OP_FLAG (1 << 9)
608
+ #define TRUE_REDEFINED_OP_FLAG (1 << 10)
609
+ #define FALSE_REDEFINED_OP_FLAG (1 << 11)
610
+
611
+ #define BASIC_OP_UNREDEFINED_P(op, klass) (LIKELY((GET_VM()->redefined_flag[(op)]&(klass)) == 0))
612
+
613
+ #ifndef VM_DEBUG_BP_CHECK
614
+ #define VM_DEBUG_BP_CHECK 0
615
+ #endif
616
+
617
+ #ifndef VM_DEBUG_VERIFY_METHOD_CACHE
618
+ #define VM_DEBUG_VERIFY_METHOD_CACHE (VM_DEBUG_MODE != 0)
619
+ #endif
620
+
621
+ struct rb_captured_block {
622
+ VALUE self;
623
+ const VALUE *ep;
624
+ union {
625
+ const rb_iseq_t *iseq;
626
+ const struct vm_ifunc *ifunc;
627
+ VALUE val;
628
+ } code;
629
+ };
630
+
631
+ enum rb_block_handler_type {
632
+ block_handler_type_iseq,
633
+ block_handler_type_ifunc,
634
+ block_handler_type_symbol,
635
+ block_handler_type_proc
636
+ };
637
+
638
+ enum rb_block_type {
639
+ block_type_iseq,
640
+ block_type_ifunc,
641
+ block_type_symbol,
642
+ block_type_proc
643
+ };
644
+
645
+ struct rb_block {
646
+ union {
647
+ struct rb_captured_block captured;
648
+ VALUE symbol;
649
+ VALUE proc;
650
+ } as;
651
+ enum rb_block_type type;
652
+ };
653
+
654
+ typedef struct rb_control_frame_struct {
655
+ const VALUE *pc; /* cfp[0] */
656
+ VALUE *sp; /* cfp[1] */
657
+ const rb_iseq_t *iseq; /* cfp[2] */
658
+ VALUE self; /* cfp[3] / block[0] */
659
+ const VALUE *ep; /* cfp[4] / block[1] */
660
+ const void *block_code; /* cfp[5] / block[2] */ /* iseq or ifunc */
661
+
662
+ #if VM_DEBUG_BP_CHECK
663
+ VALUE *bp_check; /* cfp[6] */
664
+ #endif
665
+ } rb_control_frame_t;
666
+
667
+ extern const rb_data_type_t ruby_threadptr_data_type;
668
+
669
+ static inline struct rb_thread_struct *
670
+ rb_thread_ptr(VALUE thval)
671
+ {
672
+ return (struct rb_thread_struct *)rb_check_typeddata(thval, &ruby_threadptr_data_type);
673
+ }
674
+
675
+ enum rb_thread_status {
676
+ THREAD_RUNNABLE,
677
+ THREAD_STOPPED,
678
+ THREAD_STOPPED_FOREVER,
679
+ THREAD_KILLED
680
+ };
681
+
682
+ typedef RUBY_JMP_BUF rb_jmpbuf_t;
683
+
684
+ /*
685
+ the members which are written in EC_PUSH_TAG() should be placed at
686
+ the beginning and the end, so that entire region is accessible.
687
+ */
688
+ struct rb_vm_tag {
689
+ VALUE tag;
690
+ VALUE retval;
691
+ rb_jmpbuf_t buf;
692
+ struct rb_vm_tag *prev;
693
+ enum ruby_tag_type state;
694
+ };
695
+
696
+ STATIC_ASSERT(rb_vm_tag_buf_offset, offsetof(struct rb_vm_tag, buf) > 0);
697
+ STATIC_ASSERT(rb_vm_tag_buf_end,
698
+ offsetof(struct rb_vm_tag, buf) + sizeof(rb_jmpbuf_t) <
699
+ sizeof(struct rb_vm_tag));
700
+
701
+ struct rb_vm_protect_tag {
702
+ struct rb_vm_protect_tag *prev;
703
+ };
704
+
705
+ struct rb_unblock_callback {
706
+ rb_unblock_function_t *func;
707
+ void *arg;
708
+ };
709
+
710
+ struct rb_mutex_struct;
711
+
712
+ typedef struct rb_thread_list_struct{
713
+ struct rb_thread_list_struct *next;
714
+ struct rb_thread_struct *th;
715
+ } rb_thread_list_t;
716
+
717
+ typedef struct rb_ensure_entry {
718
+ VALUE marker;
719
+ VALUE (*e_proc)(ANYARGS);
720
+ VALUE data2;
721
+ } rb_ensure_entry_t;
722
+
723
+ typedef struct rb_ensure_list {
724
+ struct rb_ensure_list *next;
725
+ struct rb_ensure_entry entry;
726
+ } rb_ensure_list_t;
727
+
728
+ typedef char rb_thread_id_string_t[sizeof(rb_nativethread_id_t) * 2 + 3];
729
+
730
+ typedef struct rb_fiber_struct rb_fiber_t;
731
+
732
+ typedef struct rb_execution_context_struct {
733
+ /* execution information */
734
+ VALUE *vm_stack; /* must free, must mark */
735
+ size_t vm_stack_size; /* size in word (byte size / sizeof(VALUE)) */
736
+ rb_control_frame_t *cfp;
737
+
738
+ struct rb_vm_tag *tag;
739
+ struct rb_vm_protect_tag *protect_tag;
740
+ int safe_level;
741
+ int raised_flag;
742
+
743
+ /* interrupt flags */
744
+ rb_atomic_t interrupt_flag;
745
+ unsigned long interrupt_mask;
746
+
747
+ rb_fiber_t *fiber_ptr;
748
+ struct rb_thread_struct *thread_ptr;
749
+
750
+ /* storage (ec (fiber) local) */
751
+ st_table *local_storage;
752
+ VALUE local_storage_recursive_hash;
753
+ VALUE local_storage_recursive_hash_for_trace;
754
+
755
+ /* eval env */
756
+ const VALUE *root_lep;
757
+ VALUE root_svar;
758
+
759
+ /* ensure & callcc */
760
+ rb_ensure_list_t *ensure_list;
761
+
762
+ /* trace information */
763
+ struct rb_trace_arg_struct *trace_arg;
764
+
765
+ /* temporary places */
766
+ VALUE errinfo;
767
+ VALUE passed_block_handler; /* for rb_iterate */
768
+ const rb_callable_method_entry_t *passed_bmethod_me; /* for bmethod */
769
+ enum method_missing_reason method_missing_reason;
770
+
771
+ /* for GC */
772
+ struct {
773
+ VALUE *stack_start;
774
+ VALUE *stack_end;
775
+ size_t stack_maxsize;
776
+ #ifdef __ia64
777
+ VALUE *register_stack_start;
778
+ VALUE *register_stack_end;
779
+ size_t register_stack_maxsize;
780
+ #endif
781
+ jmp_buf regs;
782
+ } machine;
783
+ } rb_execution_context_t;
784
+
785
+ void ec_set_vm_stack(rb_execution_context_t *ec, VALUE *stack, size_t size);
786
+
787
+ typedef struct rb_thread_struct {
788
+ struct list_node vmlt_node;
789
+ VALUE self;
790
+ rb_vm_t *vm;
791
+
792
+ rb_execution_context_t *ec;
793
+
794
+ VALUE last_status; /* $? */
795
+
796
+ /* for cfunc */
797
+ struct rb_calling_info *calling;
798
+
799
+ /* for load(true) */
800
+ VALUE top_self;
801
+ VALUE top_wrapper;
802
+
803
+ /* thread control */
804
+ rb_nativethread_id_t thread_id;
805
+ #ifdef NON_SCALAR_THREAD_ID
806
+ rb_thread_id_string_t thread_id_string;
807
+ #endif
808
+ enum rb_thread_status status;
809
+ int to_kill;
810
+ int priority;
811
+
812
+ native_thread_data_t native_thread_data;
813
+ void *blocking_region_buffer;
814
+
815
+ VALUE thgroup;
816
+ VALUE value;
817
+
818
+ /* temporary place of retval on OPT_CALL_THREADED_CODE */
819
+ #if OPT_CALL_THREADED_CODE
820
+ VALUE retval;
821
+ #endif
822
+
823
+ /* async errinfo queue */
824
+ VALUE pending_interrupt_queue;
825
+ VALUE pending_interrupt_mask_stack;
826
+ int pending_interrupt_queue_checked;
827
+
828
+ /* interrupt management */
829
+ rb_nativethread_lock_t interrupt_lock;
830
+ struct rb_unblock_callback unblock;
831
+ VALUE locking_mutex;
832
+ struct rb_mutex_struct *keeping_mutexes;
833
+
834
+ rb_thread_list_t *join_list;
835
+
836
+ VALUE first_proc;
837
+ VALUE first_args;
838
+ VALUE (*first_func)(ANYARGS);
839
+
840
+ /* statistics data for profiler */
841
+ VALUE stat_insn_usage;
842
+
843
+ /* fiber */
844
+ rb_fiber_t *root_fiber;
845
+ rb_jmpbuf_t root_jmpbuf;
846
+
847
+ /* misc */
848
+ unsigned int abort_on_exception: 1;
849
+ unsigned int report_on_exception: 1;
850
+ #ifdef USE_SIGALTSTACK
851
+ void *altstack;
852
+ #endif
853
+ uint32_t running_time_us; /* 12500..800000 */
854
+ VALUE name;
855
+ } rb_thread_t;
856
+
857
+ typedef enum {
858
+ VM_DEFINECLASS_TYPE_CLASS = 0x00,
859
+ VM_DEFINECLASS_TYPE_SINGLETON_CLASS = 0x01,
860
+ VM_DEFINECLASS_TYPE_MODULE = 0x02,
861
+ /* 0x03..0x06 is reserved */
862
+ VM_DEFINECLASS_TYPE_MASK = 0x07
863
+ } rb_vm_defineclass_type_t;
864
+
865
+ #define VM_DEFINECLASS_TYPE(x) ((rb_vm_defineclass_type_t)(x) & VM_DEFINECLASS_TYPE_MASK)
866
+ #define VM_DEFINECLASS_FLAG_SCOPED 0x08
867
+ #define VM_DEFINECLASS_FLAG_HAS_SUPERCLASS 0x10
868
+ #define VM_DEFINECLASS_SCOPED_P(x) ((x) & VM_DEFINECLASS_FLAG_SCOPED)
869
+ #define VM_DEFINECLASS_HAS_SUPERCLASS_P(x) \
870
+ ((x) & VM_DEFINECLASS_FLAG_HAS_SUPERCLASS)
871
+
872
+ /* iseq.c */
873
+ RUBY_SYMBOL_EXPORT_BEGIN
874
+
875
+ /* node -> iseq */
876
+ rb_iseq_t *rb_iseq_new (const NODE *node, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent, enum iseq_type);
877
+ rb_iseq_t *rb_iseq_new_top (const NODE *node, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent);
878
+ rb_iseq_t *rb_iseq_new_main (const NODE *node, VALUE path, VALUE realpath, const rb_iseq_t *parent);
879
+ rb_iseq_t *rb_iseq_new_with_opt(const NODE *node, VALUE name, VALUE path, VALUE realpath, VALUE first_lineno,
880
+ const rb_iseq_t *parent, enum iseq_type, const rb_compile_option_t*);
881
+
882
+ /* src -> iseq */
883
+ rb_iseq_t *rb_iseq_compile(VALUE src, VALUE file, VALUE line);
884
+ rb_iseq_t *rb_iseq_compile_on_base(VALUE src, VALUE file, VALUE line, const struct rb_block *base_block);
885
+ rb_iseq_t *rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE realpath, VALUE line, const struct rb_block *base_block, VALUE opt);
886
+
887
+ VALUE rb_iseq_disasm(const rb_iseq_t *iseq);
888
+ int rb_iseq_disasm_insn(VALUE str, const VALUE *iseqval, size_t pos, const rb_iseq_t *iseq, VALUE child);
889
+ const char *ruby_node_name(int node);
890
+
891
+ VALUE rb_iseq_coverage(const rb_iseq_t *iseq);
892
+
893
+ RUBY_EXTERN VALUE rb_cISeq;
894
+ RUBY_EXTERN VALUE rb_cRubyVM;
895
+ RUBY_EXTERN VALUE rb_mRubyVMFrozenCore;
896
+ RUBY_SYMBOL_EXPORT_END
897
+
898
+ #define GetProcPtr(obj, ptr) \
899
+ GetCoreDataFromValue((obj), rb_proc_t, (ptr))
900
+
901
+ typedef struct {
902
+ const struct rb_block block;
903
+ int8_t safe_level; /* 0..1 */
904
+ int8_t is_from_method; /* bool */
905
+ int8_t is_lambda; /* bool */
906
+ } rb_proc_t;
907
+
908
+ typedef struct {
909
+ VALUE flags; /* imemo header */
910
+ const rb_iseq_t *iseq;
911
+ const VALUE *ep;
912
+ const VALUE *env;
913
+ unsigned int env_size;
914
+ } rb_env_t;
915
+
916
+ extern const rb_data_type_t ruby_binding_data_type;
917
+
918
+ #define GetBindingPtr(obj, ptr) \
919
+ GetCoreDataFromValue((obj), rb_binding_t, (ptr))
920
+
921
+ typedef struct {
922
+ const struct rb_block block;
923
+ const VALUE pathobj;
924
+ unsigned short first_lineno;
925
+ } rb_binding_t;
926
+
927
+ /* used by compile time and send insn */
928
+
929
+ enum vm_check_match_type {
930
+ VM_CHECKMATCH_TYPE_WHEN = 1,
931
+ VM_CHECKMATCH_TYPE_CASE = 2,
932
+ VM_CHECKMATCH_TYPE_RESCUE = 3
933
+ };
934
+
935
+ #define VM_CHECKMATCH_TYPE_MASK 0x03
936
+ #define VM_CHECKMATCH_ARRAY 0x04
937
+
938
+ enum vm_call_flag_bits {
939
+ VM_CALL_ARGS_SPLAT_bit, /* m(*args) */
940
+ VM_CALL_ARGS_BLOCKARG_bit, /* m(&block) */
941
+ VM_CALL_ARGS_BLOCKARG_BLOCKPARAM_bit, /* m(&block) and block is a passed block parameter */
942
+ VM_CALL_FCALL_bit, /* m(...) */
943
+ VM_CALL_VCALL_bit, /* m */
944
+ VM_CALL_ARGS_SIMPLE_bit, /* (ci->flag & (SPLAT|BLOCKARG)) && blockiseq == NULL && ci->kw_arg == NULL */
945
+ VM_CALL_BLOCKISEQ_bit, /* has blockiseq */
946
+ VM_CALL_KWARG_bit, /* has kwarg */
947
+ VM_CALL_KW_SPLAT_bit, /* m(**opts) */
948
+ VM_CALL_TAILCALL_bit, /* located at tail position */
949
+ VM_CALL_SUPER_bit, /* super */
950
+ VM_CALL_OPT_SEND_bit, /* internal flag */
951
+ VM_CALL__END
952
+ };
953
+
954
+ #define VM_CALL_ARGS_SPLAT (0x01 << VM_CALL_ARGS_SPLAT_bit)
955
+ #define VM_CALL_ARGS_BLOCKARG (0x01 << VM_CALL_ARGS_BLOCKARG_bit)
956
+ #define VM_CALL_ARGS_BLOCKARG_BLOCKPARAM (0x01 << VM_CALL_ARGS_BLOCKARG_BLOCKPARAM_bit)
957
+ #define VM_CALL_FCALL (0x01 << VM_CALL_FCALL_bit)
958
+ #define VM_CALL_VCALL (0x01 << VM_CALL_VCALL_bit)
959
+ #define VM_CALL_ARGS_SIMPLE (0x01 << VM_CALL_ARGS_SIMPLE_bit)
960
+ #define VM_CALL_BLOCKISEQ (0x01 << VM_CALL_BLOCKISEQ_bit)
961
+ #define VM_CALL_KWARG (0x01 << VM_CALL_KWARG_bit)
962
+ #define VM_CALL_KW_SPLAT (0x01 << VM_CALL_KW_SPLAT_bit)
963
+ #define VM_CALL_TAILCALL (0x01 << VM_CALL_TAILCALL_bit)
964
+ #define VM_CALL_SUPER (0x01 << VM_CALL_SUPER_bit)
965
+ #define VM_CALL_OPT_SEND (0x01 << VM_CALL_OPT_SEND_bit)
966
+
967
+ enum vm_special_object_type {
968
+ VM_SPECIAL_OBJECT_VMCORE = 1,
969
+ VM_SPECIAL_OBJECT_CBASE,
970
+ VM_SPECIAL_OBJECT_CONST_BASE
971
+ };
972
+
973
+ enum vm_svar_index {
974
+ VM_SVAR_LASTLINE = 0, /* $_ */
975
+ VM_SVAR_BACKREF = 1, /* $~ */
976
+
977
+ VM_SVAR_EXTRA_START = 2,
978
+ VM_SVAR_FLIPFLOP_START = 2 /* flipflop */
979
+ };
980
+
981
+ /* inline cache */
982
+ typedef struct iseq_inline_cache_entry *IC;
983
+ typedef struct rb_call_info *CALL_INFO;
984
+ typedef struct rb_call_cache *CALL_CACHE;
985
+
986
+ void rb_vm_change_state(void);
987
+
988
+ typedef VALUE CDHASH;
989
+
990
+ #ifndef FUNC_FASTCALL
991
+ #define FUNC_FASTCALL(x) x
992
+ #endif
993
+
994
+ typedef rb_control_frame_t *
995
+ (FUNC_FASTCALL(*rb_insn_func_t))(rb_execution_context_t *, rb_control_frame_t *);
996
+
997
+ #define VM_TAGGED_PTR_SET(p, tag) ((VALUE)(p) | (tag))
998
+ #define VM_TAGGED_PTR_REF(v, mask) ((void *)((v) & ~mask))
999
+
1000
+ #define GC_GUARDED_PTR(p) VM_TAGGED_PTR_SET((p), 0x01)
1001
+ #define GC_GUARDED_PTR_REF(p) VM_TAGGED_PTR_REF((p), 0x03)
1002
+ #define GC_GUARDED_PTR_P(p) (((VALUE)(p)) & 0x01)
1003
+
1004
+ enum {
1005
+ /* Frame/Environment flag bits:
1006
+ * MMMM MMMM MMMM MMMM ____ __FF FFFF EEEX (LSB)
1007
+ *
1008
+ * X : tag for GC marking (It seems as Fixnum)
1009
+ * EEE : 3 bits Env flags
1010
+ * FF..: 6 bits Frame flags
1011
+ * MM..: 16 bits frame magic (to check frame corruption)
1012
+ */
1013
+
1014
+ /* frame types */
1015
+ VM_FRAME_MAGIC_METHOD = 0x11110001,
1016
+ VM_FRAME_MAGIC_BLOCK = 0x22220001,
1017
+ VM_FRAME_MAGIC_CLASS = 0x33330001,
1018
+ VM_FRAME_MAGIC_TOP = 0x44440001,
1019
+ VM_FRAME_MAGIC_CFUNC = 0x55550001,
1020
+ VM_FRAME_MAGIC_IFUNC = 0x66660001,
1021
+ VM_FRAME_MAGIC_EVAL = 0x77770001,
1022
+ VM_FRAME_MAGIC_RESCUE = 0x88880001,
1023
+ VM_FRAME_MAGIC_DUMMY = 0x99990001,
1024
+
1025
+ VM_FRAME_MAGIC_MASK = 0xffff0001,
1026
+
1027
+ /* frame flag */
1028
+ VM_FRAME_FLAG_PASSED = 0x0010,
1029
+ VM_FRAME_FLAG_FINISH = 0x0020,
1030
+ VM_FRAME_FLAG_BMETHOD = 0x0040,
1031
+ VM_FRAME_FLAG_CFRAME = 0x0080,
1032
+ VM_FRAME_FLAG_LAMBDA = 0x0100,
1033
+ VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM = 0x0200,
1034
+
1035
+ /* env flag */
1036
+ VM_ENV_FLAG_LOCAL = 0x0002,
1037
+ VM_ENV_FLAG_ESCAPED = 0x0004,
1038
+ VM_ENV_FLAG_WB_REQUIRED = 0x0008
1039
+ };
1040
+
1041
+ #define VM_ENV_DATA_SIZE ( 3)
1042
+
1043
+ #define VM_ENV_DATA_INDEX_ME_CREF (-2) /* ep[-2] */
1044
+ #define VM_ENV_DATA_INDEX_SPECVAL (-1) /* ep[-1] */
1045
+ #define VM_ENV_DATA_INDEX_FLAGS ( 0) /* ep[ 0] */
1046
+ #define VM_ENV_DATA_INDEX_ENV ( 1) /* ep[ 1] */
1047
+ #define VM_ENV_DATA_INDEX_ENV_PROC ( 2) /* ep[ 2] */
1048
+
1049
+ #define VM_ENV_INDEX_LAST_LVAR (-VM_ENV_DATA_SIZE)
1050
+
1051
+ static inline void VM_FORCE_WRITE_SPECIAL_CONST(const VALUE *ptr, VALUE special_const_value);
1052
+
1053
+ static inline void
1054
+ VM_ENV_FLAGS_SET(const VALUE *ep, VALUE flag)
1055
+ {
1056
+ VALUE flags = ep[VM_ENV_DATA_INDEX_FLAGS];
1057
+ VM_ASSERT(FIXNUM_P(flags));
1058
+ VM_FORCE_WRITE_SPECIAL_CONST(&ep[VM_ENV_DATA_INDEX_FLAGS], flags | flag);
1059
+ }
1060
+
1061
+ static inline void
1062
+ VM_ENV_FLAGS_UNSET(const VALUE *ep, VALUE flag)
1063
+ {
1064
+ VALUE flags = ep[VM_ENV_DATA_INDEX_FLAGS];
1065
+ VM_ASSERT(FIXNUM_P(flags));
1066
+ VM_FORCE_WRITE_SPECIAL_CONST(&ep[VM_ENV_DATA_INDEX_FLAGS], flags & ~flag);
1067
+ }
1068
+
1069
+ static inline unsigned long
1070
+ VM_ENV_FLAGS(const VALUE *ep, long flag)
1071
+ {
1072
+ VALUE flags = ep[VM_ENV_DATA_INDEX_FLAGS];
1073
+ VM_ASSERT(FIXNUM_P(flags));
1074
+ return flags & flag;
1075
+ }
1076
+
1077
+ static inline unsigned long
1078
+ VM_FRAME_TYPE(const rb_control_frame_t *cfp)
1079
+ {
1080
+ return VM_ENV_FLAGS(cfp->ep, VM_FRAME_MAGIC_MASK);
1081
+ }
1082
+
1083
+ static inline int
1084
+ VM_FRAME_LAMBDA_P(const rb_control_frame_t *cfp)
1085
+ {
1086
+ return VM_ENV_FLAGS(cfp->ep, VM_FRAME_FLAG_LAMBDA) != 0;
1087
+ }
1088
+
1089
+ static inline int
1090
+ VM_FRAME_FINISHED_P(const rb_control_frame_t *cfp)
1091
+ {
1092
+ return VM_ENV_FLAGS(cfp->ep, VM_FRAME_FLAG_FINISH) != 0;
1093
+ }
1094
+
1095
+ static inline int
1096
+ VM_FRAME_BMETHOD_P(const rb_control_frame_t *cfp)
1097
+ {
1098
+ return VM_ENV_FLAGS(cfp->ep, VM_FRAME_FLAG_BMETHOD) != 0;
1099
+ }
1100
+
1101
+ static inline int
1102
+ rb_obj_is_iseq(VALUE iseq)
1103
+ {
1104
+ return imemo_type_p(iseq, imemo_iseq);
1105
+ }
1106
+
1107
+ #if VM_CHECK_MODE > 0
1108
+ #define RUBY_VM_NORMAL_ISEQ_P(iseq) rb_obj_is_iseq((VALUE)iseq)
1109
+ #endif
1110
+
1111
+ static inline int
1112
+ VM_FRAME_CFRAME_P(const rb_control_frame_t *cfp)
1113
+ {
1114
+ int cframe_p = VM_ENV_FLAGS(cfp->ep, VM_FRAME_FLAG_CFRAME) != 0;
1115
+ VM_ASSERT(RUBY_VM_NORMAL_ISEQ_P(cfp->iseq) != cframe_p);
1116
+ return cframe_p;
1117
+ }
1118
+
1119
+ static inline int
1120
+ VM_FRAME_RUBYFRAME_P(const rb_control_frame_t *cfp)
1121
+ {
1122
+ return !VM_FRAME_CFRAME_P(cfp);
1123
+ }
1124
+
1125
+ #define RUBYVM_CFUNC_FRAME_P(cfp) \
1126
+ (VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_CFUNC)
1127
+
1128
+ #define VM_GUARDED_PREV_EP(ep) GC_GUARDED_PTR(ep)
1129
+ #define VM_BLOCK_HANDLER_NONE 0
1130
+
1131
+ static inline int
1132
+ VM_ENV_LOCAL_P(const VALUE *ep)
1133
+ {
1134
+ return VM_ENV_FLAGS(ep, VM_ENV_FLAG_LOCAL) ? 1 : 0;
1135
+ }
1136
+
1137
+ static inline const VALUE *
1138
+ VM_ENV_PREV_EP(const VALUE *ep)
1139
+ {
1140
+ VM_ASSERT(VM_ENV_LOCAL_P(ep) == 0);
1141
+ return GC_GUARDED_PTR_REF(ep[VM_ENV_DATA_INDEX_SPECVAL]);
1142
+ }
1143
+
1144
+ static inline VALUE
1145
+ VM_ENV_BLOCK_HANDLER(const VALUE *ep)
1146
+ {
1147
+ VM_ASSERT(VM_ENV_LOCAL_P(ep));
1148
+ return ep[VM_ENV_DATA_INDEX_SPECVAL];
1149
+ }
1150
+
1151
+ #if VM_CHECK_MODE > 0
1152
+ int rb_vm_ep_in_heap_p(const VALUE *ep);
1153
+ #endif
1154
+
1155
+ static inline int
1156
+ VM_ENV_ESCAPED_P(const VALUE *ep)
1157
+ {
1158
+ VM_ASSERT(rb_vm_ep_in_heap_p(ep) == !!VM_ENV_FLAGS(ep, VM_ENV_FLAG_ESCAPED));
1159
+ return VM_ENV_FLAGS(ep, VM_ENV_FLAG_ESCAPED) ? 1 : 0;
1160
+ }
1161
+
1162
+ #if VM_CHECK_MODE > 0
1163
+ static inline int
1164
+ vm_assert_env(VALUE obj)
1165
+ {
1166
+ VM_ASSERT(imemo_type_p(obj, imemo_env));
1167
+ return 1;
1168
+ }
1169
+ #endif
1170
+
1171
+ static inline VALUE
1172
+ VM_ENV_ENVVAL(const VALUE *ep)
1173
+ {
1174
+ VALUE envval = ep[VM_ENV_DATA_INDEX_ENV];
1175
+ VM_ASSERT(VM_ENV_ESCAPED_P(ep));
1176
+ VM_ASSERT(vm_assert_env(envval));
1177
+ return envval;
1178
+ }
1179
+
1180
+ static inline const rb_env_t *
1181
+ VM_ENV_ENVVAL_PTR(const VALUE *ep)
1182
+ {
1183
+ return (const rb_env_t *)VM_ENV_ENVVAL(ep);
1184
+ }
1185
+
1186
+ static inline VALUE
1187
+ VM_ENV_PROCVAL(const VALUE *ep)
1188
+ {
1189
+ VM_ASSERT(VM_ENV_ESCAPED_P(ep));
1190
+ VM_ASSERT(VM_ENV_LOCAL_P(ep));
1191
+ VM_ASSERT(VM_ENV_BLOCK_HANDLER(ep) != VM_BLOCK_HANDLER_NONE);
1192
+
1193
+ return ep[VM_ENV_DATA_INDEX_ENV_PROC];
1194
+ }
1195
+
1196
+ static inline const rb_env_t *
1197
+ vm_env_new(VALUE *env_ep, VALUE *env_body, unsigned int env_size, const rb_iseq_t *iseq)
1198
+ {
1199
+ rb_env_t *env = (rb_env_t *)rb_imemo_new(imemo_env, (VALUE)env_ep, (VALUE)env_body, 0, (VALUE)iseq);
1200
+ env->env_size = env_size;
1201
+ env_ep[VM_ENV_DATA_INDEX_ENV] = (VALUE)env;
1202
+ return env;
1203
+ }
1204
+
1205
+ static inline void
1206
+ VM_FORCE_WRITE(const VALUE *ptr, VALUE v)
1207
+ {
1208
+ *((VALUE *)ptr) = v;
1209
+ }
1210
+
1211
+ static inline void
1212
+ VM_FORCE_WRITE_SPECIAL_CONST(const VALUE *ptr, VALUE special_const_value)
1213
+ {
1214
+ VM_ASSERT(RB_SPECIAL_CONST_P(special_const_value));
1215
+ VM_FORCE_WRITE(ptr, special_const_value);
1216
+ }
1217
+
1218
+ static inline void
1219
+ VM_STACK_ENV_WRITE(const VALUE *ep, int index, VALUE v)
1220
+ {
1221
+ VM_ASSERT(VM_ENV_FLAGS(ep, VM_ENV_FLAG_WB_REQUIRED) == 0);
1222
+ VM_FORCE_WRITE(&ep[index], v);
1223
+ }
1224
+
1225
+ const VALUE *rb_vm_ep_local_ep(const VALUE *ep);
1226
+ const VALUE *rb_vm_proc_local_ep(VALUE proc);
1227
+ void rb_vm_block_ep_update(VALUE obj, const struct rb_block *dst, const VALUE *ep);
1228
+ void rb_vm_block_copy(VALUE obj, const struct rb_block *dst, const struct rb_block *src);
1229
+
1230
+ VALUE rb_vm_frame_block_handler(const rb_control_frame_t *cfp);
1231
+
1232
+ #define RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp) ((cfp)+1)
1233
+ #define RUBY_VM_NEXT_CONTROL_FRAME(cfp) ((cfp)-1)
1234
+
1235
+ #define RUBY_VM_VALID_CONTROL_FRAME_P(cfp, ecfp) \
1236
+ ((void *)(ecfp) > (void *)(cfp))
1237
+
1238
+ static inline const rb_control_frame_t *
1239
+ RUBY_VM_END_CONTROL_FRAME(const rb_execution_context_t *ec)
1240
+ {
1241
+ return (rb_control_frame_t *)(ec->vm_stack + ec->vm_stack_size);
1242
+ }
1243
+
1244
+ static inline int
1245
+ RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(const rb_execution_context_t *ec, const rb_control_frame_t *cfp)
1246
+ {
1247
+ return !RUBY_VM_VALID_CONTROL_FRAME_P(cfp, RUBY_VM_END_CONTROL_FRAME(ec));
1248
+ }
1249
+
1250
+ static inline int
1251
+ VM_BH_ISEQ_BLOCK_P(VALUE block_handler)
1252
+ {
1253
+ if ((block_handler & 0x03) == 0x01) {
1254
+ #if VM_CHECK_MODE > 0
1255
+ struct rb_captured_block *captured = VM_TAGGED_PTR_REF(block_handler, 0x03);
1256
+ VM_ASSERT(imemo_type_p(captured->code.val, imemo_iseq));
1257
+ #endif
1258
+ return 1;
1259
+ }
1260
+ else {
1261
+ return 0;
1262
+ }
1263
+ }
1264
+
1265
+ static inline VALUE
1266
+ VM_BH_FROM_ISEQ_BLOCK(const struct rb_captured_block *captured)
1267
+ {
1268
+ VALUE block_handler = VM_TAGGED_PTR_SET(captured, 0x01);
1269
+ VM_ASSERT(VM_BH_ISEQ_BLOCK_P(block_handler));
1270
+ return block_handler;
1271
+ }
1272
+
1273
+ static inline const struct rb_captured_block *
1274
+ VM_BH_TO_ISEQ_BLOCK(VALUE block_handler)
1275
+ {
1276
+ struct rb_captured_block *captured = VM_TAGGED_PTR_REF(block_handler, 0x03);
1277
+ VM_ASSERT(VM_BH_ISEQ_BLOCK_P(block_handler));
1278
+ return captured;
1279
+ }
1280
+
1281
+ static inline int
1282
+ VM_BH_IFUNC_P(VALUE block_handler)
1283
+ {
1284
+ if ((block_handler & 0x03) == 0x03) {
1285
+ #if VM_CHECK_MODE > 0
1286
+ struct rb_captured_block *captured = (void *)(block_handler & ~0x03);
1287
+ VM_ASSERT(imemo_type_p(captured->code.val, imemo_ifunc));
1288
+ #endif
1289
+ return 1;
1290
+ }
1291
+ else {
1292
+ return 0;
1293
+ }
1294
+ }
1295
+
1296
+ static inline VALUE
1297
+ VM_BH_FROM_IFUNC_BLOCK(const struct rb_captured_block *captured)
1298
+ {
1299
+ VALUE block_handler = VM_TAGGED_PTR_SET(captured, 0x03);
1300
+ VM_ASSERT(VM_BH_IFUNC_P(block_handler));
1301
+ return block_handler;
1302
+ }
1303
+
1304
+ static inline const struct rb_captured_block *
1305
+ VM_BH_TO_IFUNC_BLOCK(VALUE block_handler)
1306
+ {
1307
+ struct rb_captured_block *captured = VM_TAGGED_PTR_REF(block_handler, 0x03);
1308
+ VM_ASSERT(VM_BH_IFUNC_P(block_handler));
1309
+ return captured;
1310
+ }
1311
+
1312
+ static inline const struct rb_captured_block *
1313
+ VM_BH_TO_CAPT_BLOCK(VALUE block_handler)
1314
+ {
1315
+ struct rb_captured_block *captured = VM_TAGGED_PTR_REF(block_handler, 0x03);
1316
+ VM_ASSERT(VM_BH_IFUNC_P(block_handler) || VM_BH_ISEQ_BLOCK_P(block_handler));
1317
+ return captured;
1318
+ }
1319
+
1320
+ static inline enum rb_block_handler_type
1321
+ vm_block_handler_type(VALUE block_handler)
1322
+ {
1323
+ if (VM_BH_ISEQ_BLOCK_P(block_handler)) {
1324
+ return block_handler_type_iseq;
1325
+ }
1326
+ else if (VM_BH_IFUNC_P(block_handler)) {
1327
+ return block_handler_type_ifunc;
1328
+ }
1329
+ else if (SYMBOL_P(block_handler)) {
1330
+ return block_handler_type_symbol;
1331
+ }
1332
+ else {
1333
+ VM_ASSERT(rb_obj_is_proc(block_handler));
1334
+ return block_handler_type_proc;
1335
+ }
1336
+ }
1337
+
1338
+ static inline void
1339
+ vm_block_handler_verify(MAYBE_UNUSED(VALUE block_handler))
1340
+ {
1341
+ VM_ASSERT(block_handler == VM_BLOCK_HANDLER_NONE ||
1342
+ (vm_block_handler_type(block_handler), 1));
1343
+ }
1344
+
1345
+ static inline enum rb_block_type
1346
+ vm_block_type(const struct rb_block *block)
1347
+ {
1348
+ #if VM_CHECK_MODE > 0
1349
+ switch (block->type) {
1350
+ case block_type_iseq:
1351
+ VM_ASSERT(imemo_type_p(block->as.captured.code.val, imemo_iseq));
1352
+ break;
1353
+ case block_type_ifunc:
1354
+ VM_ASSERT(imemo_type_p(block->as.captured.code.val, imemo_ifunc));
1355
+ break;
1356
+ case block_type_symbol:
1357
+ VM_ASSERT(SYMBOL_P(block->as.symbol));
1358
+ break;
1359
+ case block_type_proc:
1360
+ VM_ASSERT(rb_obj_is_proc(block->as.proc));
1361
+ break;
1362
+ }
1363
+ #endif
1364
+ return block->type;
1365
+ }
1366
+
1367
+ static inline void
1368
+ vm_block_type_set(const struct rb_block *block, enum rb_block_type type)
1369
+ {
1370
+ struct rb_block *mb = (struct rb_block *)block;
1371
+ mb->type = type;
1372
+ }
1373
+
1374
+ static inline const struct rb_block *
1375
+ vm_proc_block(VALUE procval)
1376
+ {
1377
+ VM_ASSERT(rb_obj_is_proc(procval));
1378
+ return &((rb_proc_t *)RTYPEDDATA_DATA(procval))->block;
1379
+ }
1380
+
1381
+ static inline const rb_iseq_t *vm_block_iseq(const struct rb_block *block);
1382
+ static inline const VALUE *vm_block_ep(const struct rb_block *block);
1383
+
1384
+ static inline const rb_iseq_t *
1385
+ vm_proc_iseq(VALUE procval)
1386
+ {
1387
+ return vm_block_iseq(vm_proc_block(procval));
1388
+ }
1389
+
1390
+ static inline const VALUE *
1391
+ vm_proc_ep(VALUE procval)
1392
+ {
1393
+ return vm_block_ep(vm_proc_block(procval));
1394
+ }
1395
+
1396
+ static inline const rb_iseq_t *
1397
+ vm_block_iseq(const struct rb_block *block)
1398
+ {
1399
+ switch (vm_block_type(block)) {
1400
+ case block_type_iseq: return rb_iseq_check(block->as.captured.code.iseq);
1401
+ case block_type_proc: return vm_proc_iseq(block->as.proc);
1402
+ case block_type_ifunc:
1403
+ case block_type_symbol: return NULL;
1404
+ }
1405
+ VM_UNREACHABLE(vm_block_iseq);
1406
+ return NULL;
1407
+ }
1408
+
1409
+ static inline const VALUE *
1410
+ vm_block_ep(const struct rb_block *block)
1411
+ {
1412
+ switch (vm_block_type(block)) {
1413
+ case block_type_iseq:
1414
+ case block_type_ifunc: return block->as.captured.ep;
1415
+ case block_type_proc: return vm_proc_ep(block->as.proc);
1416
+ case block_type_symbol: return NULL;
1417
+ }
1418
+ VM_UNREACHABLE(vm_block_ep);
1419
+ return NULL;
1420
+ }
1421
+
1422
+ static inline VALUE
1423
+ vm_block_self(const struct rb_block *block)
1424
+ {
1425
+ switch (vm_block_type(block)) {
1426
+ case block_type_iseq:
1427
+ case block_type_ifunc:
1428
+ return block->as.captured.self;
1429
+ case block_type_proc:
1430
+ return vm_block_self(vm_proc_block(block->as.proc));
1431
+ case block_type_symbol:
1432
+ return Qundef;
1433
+ }
1434
+ VM_UNREACHABLE(vm_block_self);
1435
+ return Qundef;
1436
+ }
1437
+
1438
+ static inline VALUE
1439
+ VM_BH_TO_SYMBOL(VALUE block_handler)
1440
+ {
1441
+ VM_ASSERT(SYMBOL_P(block_handler));
1442
+ return block_handler;
1443
+ }
1444
+
1445
+ static inline VALUE
1446
+ VM_BH_FROM_SYMBOL(VALUE symbol)
1447
+ {
1448
+ VM_ASSERT(SYMBOL_P(symbol));
1449
+ return symbol;
1450
+ }
1451
+
1452
+ static inline VALUE
1453
+ VM_BH_TO_PROC(VALUE block_handler)
1454
+ {
1455
+ VM_ASSERT(rb_obj_is_proc(block_handler));
1456
+ return block_handler;
1457
+ }
1458
+
1459
+ static inline VALUE
1460
+ VM_BH_FROM_PROC(VALUE procval)
1461
+ {
1462
+ VM_ASSERT(rb_obj_is_proc(procval));
1463
+ return procval;
1464
+ }
1465
+
1466
+ /* VM related object allocate functions */
1467
+ VALUE rb_thread_alloc(VALUE klass);
1468
+ VALUE rb_proc_alloc(VALUE klass);
1469
+ VALUE rb_binding_alloc(VALUE klass);
1470
+
1471
+ /* for debug */
1472
+ extern void rb_vmdebug_stack_dump_raw(const rb_execution_context_t *ec, const rb_control_frame_t *cfp);
1473
+ extern void rb_vmdebug_debug_print_pre(const rb_execution_context_t *ec, const rb_control_frame_t *cfp, const VALUE *_pc);
1474
+ extern void rb_vmdebug_debug_print_post(const rb_execution_context_t *ec, const rb_control_frame_t *cfp);
1475
+
1476
+ #define SDR() rb_vmdebug_stack_dump_raw(GET_EC(), GET_EC()->cfp)
1477
+ #define SDR2(cfp) rb_vmdebug_stack_dump_raw(GET_EC(), (cfp))
1478
+ void rb_vm_bugreport(const void *);
1479
+ NORETURN(void rb_bug_context(const void *, const char *fmt, ...));
1480
+
1481
+ /* functions about thread/vm execution */
1482
+ RUBY_SYMBOL_EXPORT_BEGIN
1483
+ VALUE rb_iseq_eval(const rb_iseq_t *iseq);
1484
+ VALUE rb_iseq_eval_main(const rb_iseq_t *iseq);
1485
+ VALUE rb_iseq_path(const rb_iseq_t *iseq);
1486
+ VALUE rb_iseq_realpath(const rb_iseq_t *iseq);
1487
+ RUBY_SYMBOL_EXPORT_END
1488
+
1489
+ VALUE rb_iseq_pathobj_new(VALUE path, VALUE realpath);
1490
+ void rb_iseq_pathobj_set(const rb_iseq_t *iseq, VALUE path, VALUE realpath);
1491
+
1492
+ int rb_ec_frame_method_id_and_class(const rb_execution_context_t *ec, ID *idp, ID *called_idp, VALUE *klassp);
1493
+ void rb_ec_setup_exception(const rb_execution_context_t *ec, VALUE mesg, VALUE cause);
1494
+
1495
+ VALUE rb_vm_invoke_proc(rb_execution_context_t *ec, rb_proc_t *proc, int argc, const VALUE *argv, VALUE block_handler);
1496
+
1497
+ VALUE rb_vm_make_proc_lambda(const rb_execution_context_t *ec, const struct rb_captured_block *captured, VALUE klass, int8_t is_lambda);
1498
+ static inline VALUE
1499
+ rb_vm_make_proc(const rb_execution_context_t *ec, const struct rb_captured_block *captured, VALUE klass)
1500
+ {
1501
+ return rb_vm_make_proc_lambda(ec, captured, klass, 0);
1502
+ }
1503
+
1504
+ static inline VALUE
1505
+ rb_vm_make_lambda(const rb_execution_context_t *ec, const struct rb_captured_block *captured, VALUE klass)
1506
+ {
1507
+ return rb_vm_make_proc_lambda(ec, captured, klass, 1);
1508
+ }
1509
+
1510
+ VALUE rb_vm_make_binding(const rb_execution_context_t *ec, const rb_control_frame_t *src_cfp);
1511
+ VALUE rb_vm_env_local_variables(const rb_env_t *env);
1512
+ const rb_env_t *rb_vm_env_prev_env(const rb_env_t *env);
1513
+ const VALUE *rb_binding_add_dynavars(VALUE bindval, rb_binding_t *bind, int dyncount, const ID *dynvars);
1514
+ void rb_vm_inc_const_missing_count(void);
1515
+ void rb_vm_gvl_destroy(rb_vm_t *vm);
1516
+ VALUE rb_vm_call(rb_execution_context_t *ec, VALUE recv, VALUE id, int argc,
1517
+ const VALUE *argv, const rb_callable_method_entry_t *me);
1518
+ void rb_vm_pop_frame(rb_execution_context_t *ec);
1519
+
1520
+ void rb_thread_start_timer_thread(void);
1521
+ void rb_thread_stop_timer_thread(void);
1522
+ void rb_thread_reset_timer_thread(void);
1523
+ void rb_thread_wakeup_timer_thread(void);
1524
+
1525
+ static inline void
1526
+ rb_vm_living_threads_init(rb_vm_t *vm)
1527
+ {
1528
+ list_head_init(&vm->waiting_fds);
1529
+ list_head_init(&vm->living_threads);
1530
+ vm->living_thread_num = 0;
1531
+ }
1532
+
1533
+ static inline void
1534
+ rb_vm_living_threads_insert(rb_vm_t *vm, rb_thread_t *th)
1535
+ {
1536
+ list_add_tail(&vm->living_threads, &th->vmlt_node);
1537
+ vm->living_thread_num++;
1538
+ }
1539
+
1540
+ static inline void
1541
+ rb_vm_living_threads_remove(rb_vm_t *vm, rb_thread_t *th)
1542
+ {
1543
+ list_del(&th->vmlt_node);
1544
+ vm->living_thread_num--;
1545
+ }
1546
+
1547
+ typedef int rb_backtrace_iter_func(void *, VALUE, int, VALUE);
1548
+ rb_control_frame_t *rb_vm_get_ruby_level_next_cfp(const rb_execution_context_t *ec, const rb_control_frame_t *cfp);
1549
+ rb_control_frame_t *rb_vm_get_binding_creatable_next_cfp(const rb_execution_context_t *ec, const rb_control_frame_t *cfp);
1550
+ int rb_vm_get_sourceline(const rb_control_frame_t *);
1551
+ VALUE rb_name_err_mesg_new(VALUE mesg, VALUE recv, VALUE method);
1552
+ void rb_vm_stack_to_heap(rb_execution_context_t *ec);
1553
+ void ruby_thread_init_stack(rb_thread_t *th);
1554
+ int rb_vm_control_frame_id_and_class(const rb_control_frame_t *cfp, ID *idp, ID *called_idp, VALUE *klassp);
1555
+ void rb_vm_rewind_cfp(rb_execution_context_t *ec, rb_control_frame_t *cfp);
1556
+ VALUE rb_vm_bh_to_procval(const rb_execution_context_t *ec, VALUE block_handler);
1557
+
1558
+ void rb_vm_register_special_exception_str(enum ruby_special_exceptions sp, VALUE exception_class, VALUE mesg);
1559
+
1560
+ #define rb_vm_register_special_exception(sp, e, m) \
1561
+ rb_vm_register_special_exception_str(sp, e, rb_usascii_str_new_static((m), (long)rb_strlen_lit(m)))
1562
+
1563
+ void rb_gc_mark_machine_stack(const rb_execution_context_t *ec);
1564
+
1565
+ void rb_vm_rewrite_cref(rb_cref_t *node, VALUE old_klass, VALUE new_klass, rb_cref_t **new_cref_ptr);
1566
+
1567
+ const rb_callable_method_entry_t *rb_vm_frame_method_entry(const rb_control_frame_t *cfp);
1568
+
1569
+ #define sysstack_error GET_VM()->special_exceptions[ruby_error_sysstack]
1570
+
1571
+ #define RUBY_CONST_ASSERT(expr) (1/!!(expr)) /* expr must be a compile-time constant */
1572
+ #define VM_STACK_OVERFLOWED_P(cfp, sp, margin) \
1573
+ (!RUBY_CONST_ASSERT(sizeof(*(sp)) == sizeof(VALUE)) || \
1574
+ !RUBY_CONST_ASSERT(sizeof(*(cfp)) == sizeof(rb_control_frame_t)) || \
1575
+ ((rb_control_frame_t *)((sp) + (margin)) + 1) >= (cfp))
1576
+ #define WHEN_VM_STACK_OVERFLOWED(cfp, sp, margin) \
1577
+ if (LIKELY(!VM_STACK_OVERFLOWED_P(cfp, sp, margin))) {(void)0;} else /* overflowed */
1578
+ #define CHECK_VM_STACK_OVERFLOW0(cfp, sp, margin) \
1579
+ WHEN_VM_STACK_OVERFLOWED(cfp, sp, margin) vm_stackoverflow()
1580
+ #define CHECK_VM_STACK_OVERFLOW(cfp, margin) \
1581
+ WHEN_VM_STACK_OVERFLOWED(cfp, (cfp)->sp, margin) vm_stackoverflow()
1582
+
1583
+ VALUE rb_catch_protect(VALUE t, rb_block_call_func *func, VALUE data, enum ruby_tag_type *stateptr);
1584
+
1585
+ /* for thread */
1586
+
1587
+ #if RUBY_VM_THREAD_MODEL == 2
1588
+ RUBY_SYMBOL_EXPORT_BEGIN
1589
+
1590
+ extern rb_vm_t *ruby_current_vm_ptr;
1591
+ extern rb_execution_context_t *ruby_current_execution_context_ptr;
1592
+ extern rb_event_flag_t ruby_vm_event_flags;
1593
+ extern rb_event_flag_t ruby_vm_event_enabled_flags;
1594
+
1595
+ RUBY_SYMBOL_EXPORT_END
1596
+
1597
+ #define GET_VM() rb_current_vm()
1598
+ #define GET_THREAD() rb_current_thread()
1599
+ #define GET_EC() rb_current_execution_context()
1600
+
1601
+ static inline rb_thread_t *
1602
+ rb_ec_thread_ptr(const rb_execution_context_t *ec)
1603
+ {
1604
+ return ec->thread_ptr;
1605
+ }
1606
+
1607
+ static inline rb_vm_t *
1608
+ rb_ec_vm_ptr(const rb_execution_context_t *ec)
1609
+ {
1610
+ const rb_thread_t *th = rb_ec_thread_ptr(ec);
1611
+ if (th) {
1612
+ return th->vm;
1613
+ }
1614
+ else {
1615
+ return NULL;
1616
+ }
1617
+ }
1618
+
1619
+ static inline rb_execution_context_t *
1620
+ rb_current_execution_context(void)
1621
+ {
1622
+ return ruby_current_execution_context_ptr;
1623
+ }
1624
+
1625
+ static inline rb_thread_t *
1626
+ rb_current_thread(void)
1627
+ {
1628
+ const rb_execution_context_t *ec = GET_EC();
1629
+ return rb_ec_thread_ptr(ec);
1630
+ }
1631
+
1632
+ static inline rb_vm_t *
1633
+ rb_current_vm(void)
1634
+ {
1635
+ VM_ASSERT(ruby_current_vm_ptr == NULL ||
1636
+ ruby_current_execution_context_ptr == NULL ||
1637
+ rb_ec_thread_ptr(GET_EC()) == NULL ||
1638
+ rb_ec_vm_ptr(GET_EC()) == ruby_current_vm_ptr);
1639
+ return ruby_current_vm_ptr;
1640
+ }
1641
+
1642
+ #define rb_thread_set_current_raw(th) (void)(ruby_current_execution_context_ptr = (th)->ec)
1643
+ #define rb_thread_set_current(th) do { \
1644
+ if ((th)->vm->running_thread != (th)) { \
1645
+ (th)->running_time_us = 0; \
1646
+ } \
1647
+ rb_thread_set_current_raw(th); \
1648
+ (th)->vm->running_thread = (th); \
1649
+ } while (0)
1650
+
1651
+ #else
1652
+ #error "unsupported thread model"
1653
+ #endif
1654
+
1655
+ enum {
1656
+ TIMER_INTERRUPT_MASK = 0x01,
1657
+ PENDING_INTERRUPT_MASK = 0x02,
1658
+ POSTPONED_JOB_INTERRUPT_MASK = 0x04,
1659
+ TRAP_INTERRUPT_MASK = 0x08
1660
+ };
1661
+
1662
+ #define RUBY_VM_SET_TIMER_INTERRUPT(ec) ATOMIC_OR((ec)->interrupt_flag, TIMER_INTERRUPT_MASK)
1663
+ #define RUBY_VM_SET_INTERRUPT(ec) ATOMIC_OR((ec)->interrupt_flag, PENDING_INTERRUPT_MASK)
1664
+ #define RUBY_VM_SET_POSTPONED_JOB_INTERRUPT(ec) ATOMIC_OR((ec)->interrupt_flag, POSTPONED_JOB_INTERRUPT_MASK)
1665
+ #define RUBY_VM_SET_TRAP_INTERRUPT(ec) ATOMIC_OR((ec)->interrupt_flag, TRAP_INTERRUPT_MASK)
1666
+ #define RUBY_VM_INTERRUPTED(ec) ((ec)->interrupt_flag & ~(ec)->interrupt_mask & \
1667
+ (PENDING_INTERRUPT_MASK|TRAP_INTERRUPT_MASK))
1668
+ #define RUBY_VM_INTERRUPTED_ANY(ec) ((ec)->interrupt_flag & ~(ec)->interrupt_mask)
1669
+
1670
+ VALUE rb_exc_set_backtrace(VALUE exc, VALUE bt);
1671
+ int rb_signal_buff_size(void);
1672
+ void rb_signal_exec(rb_thread_t *th, int sig);
1673
+ void rb_threadptr_check_signal(rb_thread_t *mth);
1674
+ void rb_threadptr_signal_raise(rb_thread_t *th, int sig);
1675
+ void rb_threadptr_signal_exit(rb_thread_t *th);
1676
+ void rb_threadptr_execute_interrupts(rb_thread_t *, int);
1677
+ void rb_threadptr_interrupt(rb_thread_t *th);
1678
+ void rb_threadptr_unlock_all_locking_mutexes(rb_thread_t *th);
1679
+ void rb_threadptr_pending_interrupt_clear(rb_thread_t *th);
1680
+ void rb_threadptr_pending_interrupt_enque(rb_thread_t *th, VALUE v);
1681
+ void rb_ec_error_print(rb_execution_context_t * volatile ec, volatile VALUE errinfo);
1682
+ void rb_execution_context_mark(const rb_execution_context_t *ec);
1683
+ void rb_fiber_close(rb_fiber_t *fib);
1684
+ void Init_native_thread(rb_thread_t *th);
1685
+
1686
+ #define RUBY_VM_CHECK_INTS(ec) rb_vm_check_ints(ec)
1687
+ static inline void
1688
+ rb_vm_check_ints(rb_execution_context_t *ec)
1689
+ {
1690
+ VM_ASSERT(ec == GET_EC());
1691
+ if (UNLIKELY(RUBY_VM_INTERRUPTED_ANY(ec))) {
1692
+ rb_threadptr_execute_interrupts(rb_ec_thread_ptr(ec), 0);
1693
+ }
1694
+ }
1695
+
1696
+ /* tracer */
1697
+ struct rb_trace_arg_struct {
1698
+ rb_event_flag_t event;
1699
+ rb_execution_context_t *ec;
1700
+ const rb_control_frame_t *cfp;
1701
+ VALUE self;
1702
+ ID id;
1703
+ ID called_id;
1704
+ VALUE klass;
1705
+ VALUE data;
1706
+
1707
+ int klass_solved;
1708
+
1709
+ /* calc from cfp */
1710
+ int lineno;
1711
+ VALUE path;
1712
+ };
1713
+
1714
+ void rb_exec_event_hooks(struct rb_trace_arg_struct *trace_arg, int pop_p);
1715
+
1716
+ #define EXEC_EVENT_HOOK_ORIG(ec_, flag_, vm_flags_, self_, id_, called_id_, klass_, data_, pop_p_) do { \
1717
+ const rb_event_flag_t flag_arg_ = (flag_); \
1718
+ if (UNLIKELY(vm_flags_ & (flag_arg_))) { \
1719
+ /* defer evaluating the other arguments */ \
1720
+ rb_exec_event_hook_orig(ec_, flag_arg_, self_, id_, called_id_, klass_, data_, pop_p_); \
1721
+ } \
1722
+ } while (0)
1723
+
1724
+ static inline void
1725
+ rb_exec_event_hook_orig(rb_execution_context_t *ec, const rb_event_flag_t flag,
1726
+ VALUE self, ID id, ID called_id, VALUE klass, VALUE data, int pop_p)
1727
+ {
1728
+ struct rb_trace_arg_struct trace_arg;
1729
+
1730
+ VM_ASSERT(rb_ec_vm_ptr(ec)->event_hooks.events == ruby_vm_event_flags);
1731
+ VM_ASSERT(rb_ec_vm_ptr(ec)->event_hooks.events & flag);
1732
+
1733
+ trace_arg.event = flag;
1734
+ trace_arg.ec = ec;
1735
+ trace_arg.cfp = ec->cfp;
1736
+ trace_arg.self = self;
1737
+ trace_arg.id = id;
1738
+ trace_arg.called_id = called_id;
1739
+ trace_arg.klass = klass;
1740
+ trace_arg.data = data;
1741
+ trace_arg.path = Qundef;
1742
+ trace_arg.klass_solved = 0;
1743
+ rb_exec_event_hooks(&trace_arg, pop_p);
1744
+ }
1745
+
1746
+ #define EXEC_EVENT_HOOK(ec_, flag_, self_, id_, called_id_, klass_, data_) \
1747
+ EXEC_EVENT_HOOK_ORIG(ec_, flag_, ruby_vm_event_flags, self_, id_, called_id_, klass_, data_, 0)
1748
+
1749
+ #define EXEC_EVENT_HOOK_AND_POP_FRAME(ec_, flag_, self_, id_, called_id_, klass_, data_) \
1750
+ EXEC_EVENT_HOOK_ORIG(ec_, flag_, ruby_vm_event_flags, self_, id_, called_id_, klass_, data_, 1)
1751
+
1752
+ RUBY_SYMBOL_EXPORT_BEGIN
1753
+
1754
+ int rb_thread_check_trap_pending(void);
1755
+
1756
+ /* #define RUBY_EVENT_RESERVED_FOR_INTERNAL_USE 0x030000 */ /* from vm_core.h */
1757
+ #define RUBY_EVENT_COVERAGE_LINE 0x010000
1758
+ #define RUBY_EVENT_COVERAGE_BRANCH 0x020000
1759
+
1760
+ extern VALUE rb_get_coverages(void);
1761
+ extern void rb_set_coverages(VALUE, int, VALUE);
1762
+ extern void rb_reset_coverages(void);
1763
+
1764
+ void rb_postponed_job_flush(rb_vm_t *vm);
1765
+
1766
+ RUBY_SYMBOL_EXPORT_END
1767
+
1768
+ #endif /* RUBY_VM_CORE_H */