debase-ruby_core_source 0.9.10 → 0.9.11

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