bindex 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/.travis.yml +48 -0
  4. data/CONTRIBUTING.md +15 -0
  5. data/Gemfile +10 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +38 -0
  8. data/Rakefile +48 -0
  9. data/bindex.gemspec +27 -0
  10. data/ext/bindex/bindex.h +11 -0
  11. data/ext/bindex/bindings.c +106 -0
  12. data/ext/bindex/com/gsamokovarov/bindex/BindingBuilder.java.erb +17 -0
  13. data/ext/bindex/com/gsamokovarov/bindex/CurrentBindingsIterator.java +54 -0
  14. data/ext/bindex/com/gsamokovarov/bindex/RubyBindingsCollector.java +34 -0
  15. data/ext/bindex/com/gsamokovarov/bindex/SetExceptionBindingsEventHook.java +21 -0
  16. data/ext/bindex/com/gsamokovarov/bindex/ThreadContextInterfaceException.java +14 -0
  17. data/ext/bindex/com/gsamokovarov/bindex/ThreadContextInternals.java +54 -0
  18. data/ext/bindex/cruby.c +34 -0
  19. data/ext/bindex/extconf.rb +29 -0
  20. data/ext/bindex/ruby_193.h +101 -0
  21. data/ext/bindex/ruby_193/addr2line.h +21 -0
  22. data/ext/bindex/ruby_193/constant.h +34 -0
  23. data/ext/bindex/ruby_193/debug.h +41 -0
  24. data/ext/bindex/ruby_193/dln.h +50 -0
  25. data/ext/bindex/ruby_193/encdb.h +167 -0
  26. data/ext/bindex/ruby_193/eval_intern.h +234 -0
  27. data/ext/bindex/ruby_193/gc.h +99 -0
  28. data/ext/bindex/ruby_193/id.h +177 -0
  29. data/ext/bindex/ruby_193/internal.h +242 -0
  30. data/ext/bindex/ruby_193/iseq.h +126 -0
  31. data/ext/bindex/ruby_193/method.h +105 -0
  32. data/ext/bindex/ruby_193/node.h +504 -0
  33. data/ext/bindex/ruby_193/parse.h +302 -0
  34. data/ext/bindex/ruby_193/probes.h +369 -0
  35. data/ext/bindex/ruby_193/regenc.h +219 -0
  36. data/ext/bindex/ruby_193/regint.h +850 -0
  37. data/ext/bindex/ruby_193/regparse.h +362 -0
  38. data/ext/bindex/ruby_193/revision.h +1 -0
  39. data/ext/bindex/ruby_193/ruby_atomic.h +175 -0
  40. data/ext/bindex/ruby_193/siphash.h +48 -0
  41. data/ext/bindex/ruby_193/thread_pthread.h +51 -0
  42. data/ext/bindex/ruby_193/thread_win32.h +40 -0
  43. data/ext/bindex/ruby_193/timev.h +21 -0
  44. data/ext/bindex/ruby_193/transcode_data.h +117 -0
  45. data/ext/bindex/ruby_193/transdb.h +186 -0
  46. data/ext/bindex/ruby_193/verconf.h +12 -0
  47. data/ext/bindex/ruby_193/version.h +52 -0
  48. data/ext/bindex/ruby_193/vm_core.h +763 -0
  49. data/ext/bindex/ruby_193/vm_exec.h +184 -0
  50. data/ext/bindex/ruby_193/vm_insnhelper.h +220 -0
  51. data/ext/bindex/ruby_193/vm_opts.h +51 -0
  52. data/ext/bindex/ruby_20.h +142 -0
  53. data/ext/bindex/ruby_20/addr2line.h +21 -0
  54. data/ext/bindex/ruby_20/constant.h +36 -0
  55. data/ext/bindex/ruby_20/dln.h +50 -0
  56. data/ext/bindex/ruby_20/encdb.h +169 -0
  57. data/ext/bindex/ruby_20/eval_intern.h +241 -0
  58. data/ext/bindex/ruby_20/gc.h +104 -0
  59. data/ext/bindex/ruby_20/id.h +135 -0
  60. data/ext/bindex/ruby_20/internal.h +395 -0
  61. data/ext/bindex/ruby_20/iseq.h +140 -0
  62. data/ext/bindex/ruby_20/method.h +138 -0
  63. data/ext/bindex/ruby_20/node.h +541 -0
  64. data/ext/bindex/ruby_20/parse.h +292 -0
  65. data/ext/bindex/ruby_20/probes.h +369 -0
  66. data/ext/bindex/ruby_20/probes_helper.h +67 -0
  67. data/ext/bindex/ruby_20/regenc.h +227 -0
  68. data/ext/bindex/ruby_20/regint.h +915 -0
  69. data/ext/bindex/ruby_20/regparse.h +367 -0
  70. data/ext/bindex/ruby_20/revision.h +1 -0
  71. data/ext/bindex/ruby_20/ruby_atomic.h +170 -0
  72. data/ext/bindex/ruby_20/siphash.h +48 -0
  73. data/ext/bindex/ruby_20/thread_pthread.h +56 -0
  74. data/ext/bindex/ruby_20/thread_win32.h +45 -0
  75. data/ext/bindex/ruby_20/timev.h +21 -0
  76. data/ext/bindex/ruby_20/transcode_data.h +127 -0
  77. data/ext/bindex/ruby_20/transdb.h +190 -0
  78. data/ext/bindex/ruby_20/verconf.h +12 -0
  79. data/ext/bindex/ruby_20/version.h +52 -0
  80. data/ext/bindex/ruby_20/vm_core.h +1018 -0
  81. data/ext/bindex/ruby_20/vm_debug.h +41 -0
  82. data/ext/bindex/ruby_20/vm_exec.h +173 -0
  83. data/ext/bindex/ruby_20/vm_insnhelper.h +274 -0
  84. data/ext/bindex/ruby_20/vm_opts.h +56 -0
  85. data/ext/bindex/ruby_21.h +142 -0
  86. data/ext/bindex/ruby_21/addr2line.h +21 -0
  87. data/ext/bindex/ruby_21/constant.h +36 -0
  88. data/ext/bindex/ruby_21/dln.h +51 -0
  89. data/ext/bindex/ruby_21/encdb.h +170 -0
  90. data/ext/bindex/ruby_21/eval_intern.h +260 -0
  91. data/ext/bindex/ruby_21/gc.h +101 -0
  92. data/ext/bindex/ruby_21/id.h +210 -0
  93. data/ext/bindex/ruby_21/internal.h +889 -0
  94. data/ext/bindex/ruby_21/iseq.h +136 -0
  95. data/ext/bindex/ruby_21/method.h +142 -0
  96. data/ext/bindex/ruby_21/node.h +543 -0
  97. data/ext/bindex/ruby_21/parse.h +298 -0
  98. data/ext/bindex/ruby_21/probes.h +401 -0
  99. data/ext/bindex/ruby_21/probes_helper.h +67 -0
  100. data/ext/bindex/ruby_21/regenc.h +223 -0
  101. data/ext/bindex/ruby_21/regint.h +911 -0
  102. data/ext/bindex/ruby_21/regparse.h +363 -0
  103. data/ext/bindex/ruby_21/revision.h +1 -0
  104. data/ext/bindex/ruby_21/ruby_atomic.h +170 -0
  105. data/ext/bindex/ruby_21/siphash.h +48 -0
  106. data/ext/bindex/ruby_21/thread_native.h +23 -0
  107. data/ext/bindex/ruby_21/thread_pthread.h +56 -0
  108. data/ext/bindex/ruby_21/thread_win32.h +45 -0
  109. data/ext/bindex/ruby_21/timev.h +42 -0
  110. data/ext/bindex/ruby_21/transcode_data.h +123 -0
  111. data/ext/bindex/ruby_21/transdb.h +190 -0
  112. data/ext/bindex/ruby_21/verconf.h +13 -0
  113. data/ext/bindex/ruby_21/version.h +52 -0
  114. data/ext/bindex/ruby_21/vm_core.h +1043 -0
  115. data/ext/bindex/ruby_21/vm_debug.h +37 -0
  116. data/ext/bindex/ruby_21/vm_exec.h +182 -0
  117. data/ext/bindex/ruby_21/vm_insnhelper.h +273 -0
  118. data/ext/bindex/ruby_21/vm_opts.h +56 -0
  119. data/ext/bindex/ruby_21preview.h +146 -0
  120. data/ext/bindex/ruby_21preview/addr2line.h +21 -0
  121. data/ext/bindex/ruby_21preview/constant.h +36 -0
  122. data/ext/bindex/ruby_21preview/dln.h +51 -0
  123. data/ext/bindex/ruby_21preview/encdb.h +270 -0
  124. data/ext/bindex/ruby_21preview/eval_intern.h +217 -0
  125. data/ext/bindex/ruby_21preview/gc.h +100 -0
  126. data/ext/bindex/ruby_21preview/id.h +169 -0
  127. data/ext/bindex/ruby_21preview/internal.h +765 -0
  128. data/ext/bindex/ruby_21preview/iseq.h +136 -0
  129. data/ext/bindex/ruby_21preview/method.h +141 -0
  130. data/ext/bindex/ruby_21preview/node.h +543 -0
  131. data/ext/bindex/ruby_21preview/parse.h +298 -0
  132. data/ext/bindex/ruby_21preview/probes.h +385 -0
  133. data/ext/bindex/ruby_21preview/probes_helper.h +67 -0
  134. data/ext/bindex/ruby_21preview/regenc.h +223 -0
  135. data/ext/bindex/ruby_21preview/regint.h +911 -0
  136. data/ext/bindex/ruby_21preview/regparse.h +363 -0
  137. data/ext/bindex/ruby_21preview/revision.h +1 -0
  138. data/ext/bindex/ruby_21preview/ruby_atomic.h +130 -0
  139. data/ext/bindex/ruby_21preview/siphash.h +48 -0
  140. data/ext/bindex/ruby_21preview/thread_native.h +23 -0
  141. data/ext/bindex/ruby_21preview/thread_pthread.h +56 -0
  142. data/ext/bindex/ruby_21preview/thread_win32.h +45 -0
  143. data/ext/bindex/ruby_21preview/timev.h +42 -0
  144. data/ext/bindex/ruby_21preview/transcode_data.h +123 -0
  145. data/ext/bindex/ruby_21preview/transdb.h +190 -0
  146. data/ext/bindex/ruby_21preview/verconf.h +13 -0
  147. data/ext/bindex/ruby_21preview/version.h +53 -0
  148. data/ext/bindex/ruby_21preview/vm_core.h +1017 -0
  149. data/ext/bindex/ruby_21preview/vm_debug.h +37 -0
  150. data/ext/bindex/ruby_21preview/vm_exec.h +180 -0
  151. data/ext/bindex/ruby_21preview/vm_insnhelper.h +272 -0
  152. data/ext/bindex/ruby_21preview/vm_opts.h +56 -0
  153. data/lib/bindex.rb +10 -0
  154. data/lib/bindex/jruby.rb +20 -0
  155. data/lib/bindex/jruby_internals.jar +0 -0
  156. data/lib/bindex/jruby_internals_9k.jar +0 -0
  157. data/lib/bindex/rubinius.rb +56 -0
  158. data/lib/bindex/version.rb +3 -0
  159. data/test/exception_test.rb +45 -0
  160. data/test/fixtures/basic_nested_fixture.rb +13 -0
  161. data/test/fixtures/custom_error_fixture.rb +9 -0
  162. data/test/fixtures/eval_nested_fixture.rb +13 -0
  163. data/test/fixtures/flat_fixture.rb +7 -0
  164. data/test/test_helper.rb +17 -0
  165. metadata +270 -0
@@ -0,0 +1,13 @@
1
+ #define RUBY_BASE_NAME "ruby"
2
+ #define RUBY_VERSION_NAME RUBY_BASE_NAME"-"RUBY_LIB_VERSION
3
+ #define RUBY_LIB_VERSION_STYLE 3 /* full */
4
+ #define RUBY_EXEC_PREFIX "/usr/local"
5
+ #define RUBY_LIB_PREFIX RUBY_EXEC_PREFIX"/lib/ruby"
6
+ #define RUBY_ARCH_PREFIX_FOR(arch) RUBY_LIB_PREFIX"/"arch
7
+ #define RUBY_SITEARCH_PREFIX_FOR(arch) RUBY_LIB_PREFIX"/"arch
8
+ #define RUBY_LIB RUBY_LIB_PREFIX"/"RUBY_LIB_VERSION
9
+ #define RUBY_ARCH_LIB_FOR(arch) RUBY_LIB"/"arch
10
+ #define RUBY_SITE_LIB RUBY_LIB_PREFIX"/site_ruby"
11
+ #define RUBY_SITE_ARCH_LIB_FOR(arch) RUBY_SITE_LIB2"/"arch
12
+ #define RUBY_VENDOR_LIB RUBY_LIB_PREFIX"/vendor_ruby"
13
+ #define RUBY_VENDOR_ARCH_LIB_FOR(arch) RUBY_VENDOR_LIB2"/"arch
@@ -0,0 +1,53 @@
1
+ #define RUBY_VERSION "2.1.0"
2
+ #define RUBY_RELEASE_DATE "2013-09-22"
3
+ #define RUBY_PATCHLEVEL -1
4
+ #define RUBY_BRANCH_NAME "trunk"
5
+
6
+ #define RUBY_RELEASE_YEAR 2013
7
+ #define RUBY_RELEASE_MONTH 9
8
+ #define RUBY_RELEASE_DAY 22
9
+
10
+ #include "ruby/version.h"
11
+
12
+ #if !defined RUBY_LIB_VERSION && defined RUBY_LIB_VERSION_STYLE
13
+ # if RUBY_LIB_VERSION_STYLE == 3
14
+ # define RUBY_LIB_VERSION STRINGIZE(RUBY_API_VERSION_MAJOR)"."STRINGIZE(RUBY_API_VERSION_MINOR)"."STRINGIZE(RUBY_API_VERSION_TEENY)
15
+ # elif RUBY_LIB_VERSION_STYLE == 2
16
+ # define RUBY_LIB_VERSION STRINGIZE(RUBY_API_VERSION_MAJOR)"."STRINGIZE(RUBY_API_VERSION_MINOR)
17
+ # endif
18
+ #endif
19
+
20
+ #if RUBY_PATCHLEVEL == -1
21
+ #define RUBY_PATCHLEVEL_STR "dev"
22
+ #else
23
+ #define RUBY_PATCHLEVEL_STR "p"STRINGIZE(RUBY_PATCHLEVEL)
24
+ #endif
25
+
26
+ #ifndef RUBY_REVISION
27
+ # include "revision.h"
28
+ #endif
29
+ #ifndef RUBY_REVISION
30
+ # define RUBY_REVISION 0
31
+ #endif
32
+
33
+ #if RUBY_REVISION
34
+ # ifdef RUBY_BRANCH_NAME
35
+ # define RUBY_REVISION_STR " "RUBY_BRANCH_NAME" "STRINGIZE(RUBY_REVISION)
36
+ # else
37
+ # define RUBY_REVISION_STR " revision "STRINGIZE(RUBY_REVISION)
38
+ # endif
39
+ #else
40
+ # define RUBY_REVISION_STR ""
41
+ #endif
42
+
43
+ # define RUBY_DESCRIPTION \
44
+ "ruby "RUBY_VERSION \
45
+ RUBY_PATCHLEVEL_STR \
46
+ " ("RUBY_RELEASE_DATE \
47
+ RUBY_REVISION_STR") " \
48
+ "["RUBY_PLATFORM"]"
49
+ # define RUBY_COPYRIGHT \
50
+ "ruby - Copyright (C) " \
51
+ STRINGIZE(RUBY_BIRTH_YEAR)"-" \
52
+ STRINGIZE(RUBY_RELEASE_YEAR)" " \
53
+ RUBY_AUTHOR
@@ -0,0 +1,1017 @@
1
+ /**********************************************************************
2
+
3
+ vm_core.h -
4
+
5
+ $Author$
6
+ created at: 04/01/01 19:41:38 JST
7
+
8
+ Copyright (C) 2004-2007 Koichi Sasada
9
+
10
+ **********************************************************************/
11
+
12
+ #ifndef RUBY_VM_CORE_H
13
+ #define RUBY_VM_CORE_H
14
+
15
+ #define RUBY_VM_THREAD_MODEL 2
16
+
17
+ #include "ruby/ruby.h"
18
+ #include "ruby/st.h"
19
+
20
+ #include "node.h"
21
+ #include "vm_debug.h"
22
+ #include "vm_opts.h"
23
+ #include "id.h"
24
+ #include "method.h"
25
+ #include "ruby_atomic.h"
26
+
27
+ #include "thread_native.h"
28
+
29
+ #ifndef ENABLE_VM_OBJSPACE
30
+ #ifdef _WIN32
31
+ /*
32
+ * TODO: object space independent st_table.
33
+ * socklist needs st_table in rb_w32_sysinit(), before object space
34
+ * initialization.
35
+ * It is too early now to change st_hash_type, since it breaks binary
36
+ * compatibility.
37
+ */
38
+ #define ENABLE_VM_OBJSPACE 0
39
+ #else
40
+ #define ENABLE_VM_OBJSPACE 1
41
+ #endif
42
+ #endif
43
+
44
+ #include <setjmp.h>
45
+ #include <signal.h>
46
+
47
+ #ifndef NSIG
48
+ # define NSIG (_SIGMAX + 1) /* For QNX */
49
+ #endif
50
+
51
+ #define RUBY_NSIG NSIG
52
+
53
+ #ifdef HAVE_STDARG_PROTOTYPES
54
+ #include <stdarg.h>
55
+ #define va_init_list(a,b) va_start((a),(b))
56
+ #else
57
+ #include <varargs.h>
58
+ #define va_init_list(a,b) va_start((a))
59
+ #endif
60
+
61
+ #if defined(SIGSEGV) && defined(HAVE_SIGALTSTACK) && defined(SA_SIGINFO) && !defined(__NetBSD__)
62
+ #define USE_SIGALTSTACK
63
+ #endif
64
+
65
+ /*****************/
66
+ /* configuration */
67
+ /*****************/
68
+
69
+ /* gcc ver. check */
70
+ #if defined(__GNUC__) && __GNUC__ >= 2
71
+
72
+ #if OPT_TOKEN_THREADED_CODE
73
+ #if OPT_DIRECT_THREADED_CODE
74
+ #undef OPT_DIRECT_THREADED_CODE
75
+ #endif
76
+ #endif
77
+
78
+ #else /* defined(__GNUC__) && __GNUC__ >= 2 */
79
+
80
+ /* disable threaded code options */
81
+ #if OPT_DIRECT_THREADED_CODE
82
+ #undef OPT_DIRECT_THREADED_CODE
83
+ #endif
84
+ #if OPT_TOKEN_THREADED_CODE
85
+ #undef OPT_TOKEN_THREADED_CODE
86
+ #endif
87
+ #endif
88
+
89
+ #ifdef __native_client__
90
+ #undef OPT_DIRECT_THREADED_CODE
91
+ #endif
92
+
93
+ /* call threaded code */
94
+ #if OPT_CALL_THREADED_CODE
95
+ #if OPT_DIRECT_THREADED_CODE
96
+ #undef OPT_DIRECT_THREADED_CODE
97
+ #endif /* OPT_DIRECT_THREADED_CODE */
98
+ #if OPT_STACK_CACHING
99
+ #undef OPT_STACK_CACHING
100
+ #endif /* OPT_STACK_CACHING */
101
+ #endif /* OPT_CALL_THREADED_CODE */
102
+
103
+ /* likely */
104
+ #if __GNUC__ >= 3
105
+ #define LIKELY(x) (__builtin_expect((x), 1))
106
+ #define UNLIKELY(x) (__builtin_expect((x), 0))
107
+ #else /* __GNUC__ >= 3 */
108
+ #define LIKELY(x) (x)
109
+ #define UNLIKELY(x) (x)
110
+ #endif /* __GNUC__ >= 3 */
111
+
112
+ #if (defined(__clang__) && (__clang_major__ == 4 && __clang_minor__ == 2))
113
+ #define UNINITIALIZED_VAR(x) x __attribute__((unused))
114
+ #elif defined(__GNUC__) && __GNUC__ >= 3
115
+ #define UNINITIALIZED_VAR(x) x = x
116
+ #else
117
+ #define UNINITIALIZED_VAR(x) x
118
+ #endif
119
+
120
+ typedef unsigned long rb_num_t;
121
+
122
+ /* iseq data type */
123
+
124
+ struct iseq_compile_data_ensure_node_stack;
125
+
126
+ typedef struct rb_compile_option_struct rb_compile_option_t;
127
+
128
+
129
+ struct iseq_inline_cache_entry {
130
+ vm_state_version_t ic_vmstat;
131
+ vm_state_version_t ic_seq;
132
+ VALUE ic_class;
133
+ union {
134
+ size_t index;
135
+ VALUE value;
136
+ } ic_value;
137
+ };
138
+
139
+ union iseq_inline_storage_entry {
140
+ struct {
141
+ struct rb_thread_struct *running_thread;
142
+ VALUE value;
143
+ VALUE done;
144
+ } once;
145
+ struct iseq_inline_cache_entry cache;
146
+ };
147
+
148
+ /* to avoid warning */
149
+ struct rb_thread_struct;
150
+ struct rb_control_frame_struct;
151
+
152
+ /* rb_call_info_t contains calling information including inline cache */
153
+ typedef struct rb_call_info_struct {
154
+ /* fixed at compile time */
155
+ ID mid;
156
+ VALUE flag;
157
+ int orig_argc;
158
+ rb_iseq_t *blockiseq;
159
+
160
+ /* inline cache: keys */
161
+ vm_state_version_t vmstat;
162
+ vm_state_version_t seq;
163
+ VALUE klass;
164
+
165
+ /* inline cache: values */
166
+ const rb_method_entry_t *me;
167
+ VALUE defined_class;
168
+
169
+ /* temporary values for method calling */
170
+ int argc;
171
+ struct rb_block_struct *blockptr;
172
+ VALUE recv;
173
+ union {
174
+ int opt_pc; /* used by iseq */
175
+ long index; /* used by ivar */
176
+ int missing_reason; /* used by method_missing */
177
+ int inc_sp; /* used by cfunc */
178
+ } aux;
179
+
180
+ VALUE (*call)(struct rb_thread_struct *th, struct rb_control_frame_struct *cfp, struct rb_call_info_struct *ci);
181
+ } rb_call_info_t;
182
+
183
+ #if 1
184
+ #define GetCoreDataFromValue(obj, type, ptr) do { \
185
+ (ptr) = (type*)DATA_PTR(obj); \
186
+ } while (0)
187
+ #else
188
+ #define GetCoreDataFromValue(obj, type, ptr) Data_Get_Struct((obj), type, (ptr))
189
+ #endif
190
+
191
+ #define GetISeqPtr(obj, ptr) \
192
+ GetCoreDataFromValue((obj), rb_iseq_t, (ptr))
193
+
194
+ typedef struct rb_iseq_location_struct {
195
+ const VALUE path;
196
+ const VALUE absolute_path;
197
+ const VALUE base_label;
198
+ const VALUE label;
199
+ size_t first_lineno;
200
+ } rb_iseq_location_t;
201
+
202
+ struct rb_iseq_struct;
203
+
204
+ struct rb_iseq_struct {
205
+ /***************/
206
+ /* static data */
207
+ /***************/
208
+
209
+ enum iseq_type {
210
+ ISEQ_TYPE_TOP,
211
+ ISEQ_TYPE_METHOD,
212
+ ISEQ_TYPE_BLOCK,
213
+ ISEQ_TYPE_CLASS,
214
+ ISEQ_TYPE_RESCUE,
215
+ ISEQ_TYPE_ENSURE,
216
+ ISEQ_TYPE_EVAL,
217
+ ISEQ_TYPE_MAIN,
218
+ ISEQ_TYPE_DEFINED_GUARD
219
+ } type; /* instruction sequence type */
220
+
221
+ rb_iseq_location_t location;
222
+
223
+ VALUE *iseq; /* iseq (insn number and operands) */
224
+ VALUE *iseq_encoded; /* encoded iseq */
225
+ unsigned long iseq_size;
226
+ const VALUE mark_ary; /* Array: includes operands which should be GC marked */
227
+ const VALUE coverage; /* coverage array */
228
+
229
+ /* insn info, must be freed */
230
+ struct iseq_line_info_entry *line_info_table;
231
+ size_t line_info_size;
232
+
233
+ ID *local_table; /* must free */
234
+ int local_table_size;
235
+
236
+ /* sizeof(vars) + 1 */
237
+ int local_size;
238
+
239
+ union iseq_inline_storage_entry *is_entries;
240
+ int is_size;
241
+
242
+ rb_call_info_t *callinfo_entries;
243
+ int callinfo_size;
244
+
245
+ /**
246
+ * argument information
247
+ *
248
+ * def m(a1, a2, ..., aM, # mandatory
249
+ * b1=(...), b2=(...), ..., bN=(...), # optional
250
+ * *c, # rest
251
+ * d1, d2, ..., dO, # post
252
+ * e1:(...), e2:(...), ..., eK:(...), # keyword
253
+ * **f, # keyword rest
254
+ * &g) # block
255
+ * =>
256
+ *
257
+ * argc = M // or 0 if no mandatory arg
258
+ * arg_opts = N+1 // or 0 if no optional arg
259
+ * arg_rest = M+N // or -1 if no rest arg
260
+ * arg_opt_table = [ (arg_opts entries) ]
261
+ * arg_post_start = M+N+(*1) // or 0 if no post arguments
262
+ * arg_post_len = O // or 0 if no post arguments
263
+ * arg_keywords = K // or 0 if no keyword arg
264
+ * arg_block = M+N+(*1)+O+K // or -1 if no block arg
265
+ * arg_keyword = M+N+(*1)+O+K+(&1) // or -1 if no keyword arg/rest
266
+ * arg_simple = 0 if not simple arguments.
267
+ * = 1 if no opt, rest, post, block.
268
+ * = 2 if ambiguous block parameter ({|a|}).
269
+ * arg_size = M+N+O+(*1)+K+(&1)+(**1) argument size.
270
+ */
271
+
272
+ int argc;
273
+ int arg_simple;
274
+ int arg_rest;
275
+ int arg_block;
276
+ int arg_opts;
277
+ int arg_post_len;
278
+ int arg_post_start;
279
+ int arg_size;
280
+ VALUE *arg_opt_table;
281
+ int arg_keyword;
282
+ int arg_keyword_check; /* if this is true, raise an ArgumentError when unknown keyword argument is passed */
283
+ int arg_keywords;
284
+ int arg_keyword_required;
285
+ ID *arg_keyword_table;
286
+
287
+ size_t stack_max; /* for stack overflow check */
288
+
289
+ /* catch table */
290
+ struct iseq_catch_table_entry *catch_table;
291
+ int catch_table_size;
292
+
293
+ /* for child iseq */
294
+ struct rb_iseq_struct *parent_iseq;
295
+ struct rb_iseq_struct *local_iseq;
296
+
297
+ /****************/
298
+ /* dynamic data */
299
+ /****************/
300
+
301
+ VALUE self;
302
+ const VALUE orig; /* non-NULL if its data have origin */
303
+
304
+ /* block inlining */
305
+ /*
306
+ * NODE *node;
307
+ * void *special_block_builder;
308
+ * void *cached_special_block_builder;
309
+ * VALUE cached_special_block;
310
+ */
311
+
312
+ /* klass/module nest information stack (cref) */
313
+ NODE * const cref_stack;
314
+ const VALUE klass;
315
+
316
+ /* misc */
317
+ ID defined_method_id; /* for define_method */
318
+ rb_num_t flip_cnt;
319
+
320
+ /* used at compile time */
321
+ struct iseq_compile_data *compile_data;
322
+ };
323
+
324
+ enum ruby_special_exceptions {
325
+ ruby_error_reenter,
326
+ ruby_error_nomemory,
327
+ ruby_error_sysstack,
328
+ ruby_error_closed_stream,
329
+ ruby_special_error_count
330
+ };
331
+
332
+ #define GetVMPtr(obj, ptr) \
333
+ GetCoreDataFromValue((obj), rb_vm_t, (ptr))
334
+
335
+ #if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
336
+ struct rb_objspace;
337
+ void rb_objspace_free(struct rb_objspace *);
338
+ #endif
339
+
340
+ typedef struct rb_hook_list_struct {
341
+ struct rb_event_hook_struct *hooks;
342
+ rb_event_flag_t events;
343
+ int need_clean;
344
+ } rb_hook_list_t;
345
+
346
+ typedef struct rb_vm_struct {
347
+ VALUE self;
348
+
349
+ rb_global_vm_lock_t gvl;
350
+ rb_nativethread_lock_t thread_destruct_lock;
351
+
352
+ struct rb_thread_struct *main_thread;
353
+ struct rb_thread_struct *running_thread;
354
+
355
+ st_table *living_threads;
356
+ VALUE thgroup_default;
357
+
358
+ int running;
359
+ int thread_abort_on_exception;
360
+ int trace_running;
361
+ volatile int sleeper;
362
+
363
+ /* object management */
364
+ VALUE mark_object_ary;
365
+
366
+ VALUE special_exceptions[ruby_special_error_count];
367
+
368
+ /* load */
369
+ VALUE top_self;
370
+ VALUE load_path;
371
+ VALUE load_path_snapshot;
372
+ VALUE load_path_check_cache;
373
+ VALUE expanded_load_path;
374
+ VALUE loaded_features;
375
+ VALUE loaded_features_snapshot;
376
+ struct st_table *loaded_features_index;
377
+ struct st_table *loading_table;
378
+
379
+ /* signal */
380
+ struct {
381
+ VALUE cmd;
382
+ int safe;
383
+ } trap_list[RUBY_NSIG];
384
+
385
+ /* hook */
386
+ rb_hook_list_t event_hooks;
387
+
388
+ struct rb_postponed_job_struct *postponed_job;
389
+
390
+ int src_encoding_index;
391
+
392
+ VALUE verbose, debug, orig_progname, progname;
393
+ VALUE coverages;
394
+
395
+ struct unlinked_method_entry_list_entry *unlinked_method_entry_list;
396
+
397
+ #if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
398
+ struct rb_objspace *objspace;
399
+ #endif
400
+
401
+ /*
402
+ * @shyouhei notes that this is not for storing normal Ruby
403
+ * objects so do *NOT* mark this when you GC.
404
+ */
405
+ struct RArray at_exit;
406
+
407
+ VALUE *defined_strings;
408
+
409
+ /* params */
410
+ struct { /* size in byte */
411
+ size_t thread_vm_stack_size;
412
+ size_t thread_machine_stack_size;
413
+ size_t fiber_vm_stack_size;
414
+ size_t fiber_machine_stack_size;
415
+ } default_params;
416
+ } rb_vm_t;
417
+
418
+ /* default values */
419
+
420
+ #define RUBY_VM_SIZE_ALIGN 4096
421
+
422
+ #define RUBY_VM_THREAD_VM_STACK_SIZE ( 128 * 1024 * sizeof(VALUE)) /* 512 KB or 1024 KB */
423
+ #define RUBY_VM_THREAD_VM_STACK_SIZE_MIN ( 2 * 1024 * sizeof(VALUE)) /* 8 KB or 16 KB */
424
+ #define RUBY_VM_THREAD_MACHINE_STACK_SIZE ( 128 * 1024 * sizeof(VALUE)) /* 512 KB or 1024 KB */
425
+ #define RUBY_VM_THREAD_MACHINE_STACK_SIZE_MIN ( 16 * 1024 * sizeof(VALUE)) /* 64 KB or 128 KB */
426
+
427
+ #define RUBY_VM_FIBER_VM_STACK_SIZE ( 16 * 1024 * sizeof(VALUE)) /* 64 KB or 128 KB */
428
+ #define RUBY_VM_FIBER_VM_STACK_SIZE_MIN ( 2 * 1024 * sizeof(VALUE)) /* 8 KB or 16 KB */
429
+ #define RUBY_VM_FIBER_MACHINE_STACK_SIZE ( 64 * 1024 * sizeof(VALUE)) /* 256 KB or 512 KB */
430
+ #define RUBY_VM_FIBER_MACHINE_STACK_SIZE_MIN ( 16 * 1024 * sizeof(VALUE)) /* 64 KB or 128 KB */
431
+
432
+ #ifndef VM_DEBUG_BP_CHECK
433
+ #define VM_DEBUG_BP_CHECK 0
434
+ #endif
435
+
436
+ typedef struct rb_control_frame_struct {
437
+ VALUE *pc; /* cfp[0] */
438
+ VALUE *sp; /* cfp[1] */
439
+ rb_iseq_t *iseq; /* cfp[2] */
440
+ VALUE flag; /* cfp[3] */
441
+ VALUE self; /* cfp[4] / block[0] */
442
+ VALUE klass; /* cfp[5] / block[1] */
443
+ VALUE *ep; /* cfp[6] / block[2] */
444
+ rb_iseq_t *block_iseq; /* cfp[7] / block[3] */
445
+ VALUE proc; /* cfp[8] / block[4] */
446
+ const rb_method_entry_t *me;/* cfp[9] */
447
+
448
+ #if VM_DEBUG_BP_CHECK
449
+ VALUE *bp_check; /* cfp[10] */
450
+ #endif
451
+ } rb_control_frame_t;
452
+
453
+ typedef struct rb_block_struct {
454
+ VALUE self; /* share with method frame if it's only block */
455
+ VALUE klass; /* share with method frame if it's only block */
456
+ VALUE *ep; /* share with method frame if it's only block */
457
+ rb_iseq_t *iseq;
458
+ VALUE proc;
459
+ } rb_block_t;
460
+
461
+ extern const rb_data_type_t ruby_threadptr_data_type;
462
+
463
+ #define GetThreadPtr(obj, ptr) \
464
+ TypedData_Get_Struct((obj), rb_thread_t, &ruby_threadptr_data_type, (ptr))
465
+
466
+ enum rb_thread_status {
467
+ THREAD_RUNNABLE,
468
+ THREAD_STOPPED,
469
+ THREAD_STOPPED_FOREVER,
470
+ THREAD_KILLED
471
+ };
472
+
473
+ typedef RUBY_JMP_BUF rb_jmpbuf_t;
474
+
475
+ /*
476
+ the members which are written in TH_PUSH_TAG() should be placed at
477
+ the beginning and the end, so that entire region is accessible.
478
+ */
479
+ struct rb_vm_tag {
480
+ VALUE tag;
481
+ VALUE retval;
482
+ rb_jmpbuf_t buf;
483
+ struct rb_vm_tag *prev;
484
+ };
485
+
486
+ struct rb_vm_protect_tag {
487
+ struct rb_vm_protect_tag *prev;
488
+ };
489
+
490
+ struct rb_unblock_callback {
491
+ rb_unblock_function_t *func;
492
+ void *arg;
493
+ };
494
+
495
+ struct rb_mutex_struct;
496
+
497
+ struct rb_thread_struct;
498
+ typedef struct rb_thread_list_struct{
499
+ struct rb_thread_list_struct *next;
500
+ struct rb_thread_struct *th;
501
+ } rb_thread_list_t;
502
+
503
+
504
+ typedef struct rb_thread_struct {
505
+ VALUE self;
506
+ rb_vm_t *vm;
507
+
508
+ /* execution information */
509
+ VALUE *stack; /* must free, must mark */
510
+ size_t stack_size; /* size in word (byte size / sizeof(VALUE)) */
511
+ rb_control_frame_t *cfp;
512
+ int safe_level;
513
+ int raised_flag;
514
+ VALUE last_status; /* $? */
515
+
516
+ /* passing state */
517
+ int state;
518
+
519
+ int waiting_fd;
520
+
521
+ /* for rb_iterate */
522
+ const rb_block_t *passed_block;
523
+
524
+ /* for bmethod */
525
+ const rb_method_entry_t *passed_me;
526
+
527
+ /* for cfunc */
528
+ rb_call_info_t *passed_ci;
529
+
530
+ /* for load(true) */
531
+ VALUE top_self;
532
+ VALUE top_wrapper;
533
+
534
+ /* eval env */
535
+ rb_block_t *base_block;
536
+
537
+ VALUE *root_lep;
538
+ VALUE root_svar;
539
+
540
+ /* thread control */
541
+ rb_nativethread_id_t thread_id;
542
+ enum rb_thread_status status;
543
+ int to_kill;
544
+ int priority;
545
+
546
+ native_thread_data_t native_thread_data;
547
+ void *blocking_region_buffer;
548
+
549
+ VALUE thgroup;
550
+ VALUE value;
551
+
552
+ /* temporary place of errinfo */
553
+ VALUE errinfo;
554
+
555
+ /* temporary place of retval on OPT_CALL_THREADED_CODE */
556
+ #if OPT_CALL_THREADED_CODE
557
+ VALUE retval;
558
+ #endif
559
+
560
+ /* async errinfo queue */
561
+ VALUE pending_interrupt_queue;
562
+ int pending_interrupt_queue_checked;
563
+ VALUE pending_interrupt_mask_stack;
564
+
565
+ rb_atomic_t interrupt_flag;
566
+ unsigned long interrupt_mask;
567
+ rb_nativethread_lock_t interrupt_lock;
568
+ rb_nativethread_cond_t interrupt_cond;
569
+ struct rb_unblock_callback unblock;
570
+ VALUE locking_mutex;
571
+ struct rb_mutex_struct *keeping_mutexes;
572
+
573
+ struct rb_vm_tag *tag;
574
+ struct rb_vm_protect_tag *protect_tag;
575
+
576
+ /*! Thread-local state of evaluation context.
577
+ *
578
+ * If negative, this thread is evaluating the main program.
579
+ * If positive, this thread is evaluating a program under Kernel::eval
580
+ * family.
581
+ */
582
+ int parse_in_eval;
583
+
584
+ /*! Thread-local state of compiling context.
585
+ *
586
+ * If non-zero, the parser does not automatically print error messages to
587
+ * stderr. */
588
+ int mild_compile_error;
589
+
590
+ /* storage */
591
+ st_table *local_storage;
592
+
593
+ rb_thread_list_t *join_list;
594
+
595
+ VALUE first_proc;
596
+ VALUE first_args;
597
+ VALUE (*first_func)(ANYARGS);
598
+
599
+ /* for GC */
600
+ VALUE *machine_stack_start;
601
+ VALUE *machine_stack_end;
602
+ size_t machine_stack_maxsize;
603
+ #ifdef __ia64
604
+ VALUE *machine_register_stack_start;
605
+ VALUE *machine_register_stack_end;
606
+ size_t machine_register_stack_maxsize;
607
+ #endif
608
+ jmp_buf machine_regs;
609
+ int mark_stack_len;
610
+
611
+ /* statistics data for profiler */
612
+ VALUE stat_insn_usage;
613
+
614
+ /* tracer */
615
+ rb_hook_list_t event_hooks;
616
+ struct rb_trace_arg_struct *trace_arg; /* trace information */
617
+
618
+ /* fiber */
619
+ VALUE fiber;
620
+ VALUE root_fiber;
621
+ rb_jmpbuf_t root_jmpbuf;
622
+
623
+ /* misc */
624
+ int method_missing_reason;
625
+ int abort_on_exception;
626
+ #ifdef USE_SIGALTSTACK
627
+ void *altstack;
628
+ #endif
629
+ unsigned long running_time_us;
630
+ } rb_thread_t;
631
+
632
+ typedef enum {
633
+ VM_DEFINECLASS_TYPE_CLASS = 0x00,
634
+ VM_DEFINECLASS_TYPE_SINGLETON_CLASS = 0x01,
635
+ VM_DEFINECLASS_TYPE_MODULE = 0x02,
636
+ /* 0x03..0x06 is reserved */
637
+ VM_DEFINECLASS_TYPE_MASK = 0x07,
638
+ } rb_vm_defineclass_type_t;
639
+
640
+ #define VM_DEFINECLASS_TYPE(x) ((rb_vm_defineclass_type_t)(x) & VM_DEFINECLASS_TYPE_MASK)
641
+ #define VM_DEFINECLASS_FLAG_SCOPED 0x08
642
+ #define VM_DEFINECLASS_FLAG_HAS_SUPERCLASS 0x10
643
+ #define VM_DEFINECLASS_SCOPED_P(x) ((x) & VM_DEFINECLASS_FLAG_SCOPED)
644
+ #define VM_DEFINECLASS_HAS_SUPERCLASS_P(x) \
645
+ ((x) & VM_DEFINECLASS_FLAG_HAS_SUPERCLASS)
646
+
647
+ /* iseq.c */
648
+ RUBY_SYMBOL_EXPORT_BEGIN
649
+
650
+ /* node -> iseq */
651
+ VALUE rb_iseq_new(NODE*, VALUE, VALUE, VALUE, VALUE, enum iseq_type);
652
+ VALUE rb_iseq_new_top(NODE *node, VALUE name, VALUE path, VALUE absolute_path, VALUE parent);
653
+ VALUE rb_iseq_new_main(NODE *node, VALUE path, VALUE absolute_path);
654
+ VALUE rb_iseq_new_with_bopt(NODE*, VALUE, VALUE, VALUE, VALUE, VALUE, enum iseq_type, VALUE);
655
+ VALUE rb_iseq_new_with_opt(NODE*, VALUE, VALUE, VALUE, VALUE, VALUE, enum iseq_type, const rb_compile_option_t*);
656
+
657
+ /* src -> iseq */
658
+ VALUE rb_iseq_compile(VALUE src, VALUE file, VALUE line);
659
+ VALUE rb_iseq_compile_on_base(VALUE src, VALUE file, VALUE line, rb_block_t *base_block);
660
+ VALUE rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE absolute_path, VALUE line, rb_block_t *base_block, VALUE opt);
661
+
662
+ VALUE rb_iseq_disasm(VALUE self);
663
+ int rb_iseq_disasm_insn(VALUE str, VALUE *iseqval, size_t pos, rb_iseq_t *iseq, VALUE child);
664
+ const char *ruby_node_name(int node);
665
+ int rb_iseq_first_lineno(const rb_iseq_t *iseq);
666
+
667
+ RUBY_EXTERN VALUE rb_cISeq;
668
+ RUBY_EXTERN VALUE rb_cRubyVM;
669
+ RUBY_EXTERN VALUE rb_cEnv;
670
+ RUBY_EXTERN VALUE rb_mRubyVMFrozenCore;
671
+ RUBY_SYMBOL_EXPORT_END
672
+
673
+ #define GetProcPtr(obj, ptr) \
674
+ GetCoreDataFromValue((obj), rb_proc_t, (ptr))
675
+
676
+ typedef struct {
677
+ rb_block_t block;
678
+
679
+ VALUE envval; /* for GC mark */
680
+ VALUE blockprocval;
681
+ int safe_level;
682
+ int is_from_method;
683
+ int is_lambda;
684
+ } rb_proc_t;
685
+
686
+ #define GetEnvPtr(obj, ptr) \
687
+ GetCoreDataFromValue((obj), rb_env_t, (ptr))
688
+
689
+ typedef struct {
690
+ VALUE *env;
691
+ int env_size;
692
+ int local_size;
693
+ VALUE prev_envval; /* for GC mark */
694
+ rb_block_t block;
695
+ } rb_env_t;
696
+
697
+ extern const rb_data_type_t ruby_binding_data_type;
698
+
699
+ #define GetBindingPtr(obj, ptr) \
700
+ GetCoreDataFromValue((obj), rb_binding_t, (ptr))
701
+
702
+ typedef struct {
703
+ VALUE env;
704
+ VALUE path;
705
+ unsigned short first_lineno;
706
+ } rb_binding_t;
707
+
708
+ /* used by compile time and send insn */
709
+
710
+ enum vm_check_match_type {
711
+ VM_CHECKMATCH_TYPE_WHEN = 1,
712
+ VM_CHECKMATCH_TYPE_CASE = 2,
713
+ VM_CHECKMATCH_TYPE_RESCUE = 3
714
+ };
715
+
716
+ #define VM_CHECKMATCH_TYPE_MASK 0x03
717
+ #define VM_CHECKMATCH_ARRAY 0x04
718
+
719
+ #define VM_CALL_ARGS_SPLAT (0x01 << 1) /* m(*args) */
720
+ #define VM_CALL_ARGS_BLOCKARG (0x01 << 2) /* m(&block) */
721
+ #define VM_CALL_FCALL (0x01 << 3) /* m(...) */
722
+ #define VM_CALL_VCALL (0x01 << 4) /* m */
723
+ #define VM_CALL_TAILCALL (0x01 << 5) /* located at tail position */
724
+ #define VM_CALL_SUPER (0x01 << 6) /* super */
725
+ #define VM_CALL_OPT_SEND (0x01 << 7) /* internal flag */
726
+ #define VM_CALL_ARGS_SKIP_SETUP (0x01 << 8) /* (flag & (SPLAT|BLOCKARG)) && blockiseq == 0 */
727
+
728
+ enum vm_special_object_type {
729
+ VM_SPECIAL_OBJECT_VMCORE = 1,
730
+ VM_SPECIAL_OBJECT_CBASE,
731
+ VM_SPECIAL_OBJECT_CONST_BASE
732
+ };
733
+
734
+ #define VM_FRAME_MAGIC_METHOD 0x11
735
+ #define VM_FRAME_MAGIC_BLOCK 0x21
736
+ #define VM_FRAME_MAGIC_CLASS 0x31
737
+ #define VM_FRAME_MAGIC_TOP 0x41
738
+ #define VM_FRAME_MAGIC_CFUNC 0x61
739
+ #define VM_FRAME_MAGIC_PROC 0x71
740
+ #define VM_FRAME_MAGIC_IFUNC 0x81
741
+ #define VM_FRAME_MAGIC_EVAL 0x91
742
+ #define VM_FRAME_MAGIC_LAMBDA 0xa1
743
+ #define VM_FRAME_MAGIC_MASK_BITS 8
744
+ #define VM_FRAME_MAGIC_MASK (~(~0<<VM_FRAME_MAGIC_MASK_BITS))
745
+
746
+ #define VM_FRAME_TYPE(cfp) ((cfp)->flag & VM_FRAME_MAGIC_MASK)
747
+
748
+ /* other frame flag */
749
+ #define VM_FRAME_FLAG_PASSED 0x0100
750
+ #define VM_FRAME_FLAG_FINISH 0x0200
751
+ #define VM_FRAME_TYPE_FINISH_P(cfp) (((cfp)->flag & VM_FRAME_FLAG_FINISH) != 0)
752
+
753
+ #define RUBYVM_CFUNC_FRAME_P(cfp) \
754
+ (VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_CFUNC)
755
+
756
+ /* inline cache */
757
+ typedef struct iseq_inline_cache_entry *IC;
758
+ typedef rb_call_info_t *CALL_INFO;
759
+
760
+ void rb_vm_change_state(void);
761
+
762
+ typedef VALUE CDHASH;
763
+
764
+ #ifndef FUNC_FASTCALL
765
+ #define FUNC_FASTCALL(x) x
766
+ #endif
767
+
768
+ typedef rb_control_frame_t *
769
+ (FUNC_FASTCALL(*rb_insn_func_t))(rb_thread_t *, rb_control_frame_t *);
770
+
771
+ #define GC_GUARDED_PTR(p) ((VALUE)((VALUE)(p) | 0x01))
772
+ #define GC_GUARDED_PTR_REF(p) ((void *)(((VALUE)(p)) & ~0x03))
773
+ #define GC_GUARDED_PTR_P(p) (((VALUE)(p)) & 0x01)
774
+
775
+ /*
776
+ * block frame:
777
+ * ep[ 0]: prev frame
778
+ * ep[-1]: CREF (for *_eval)
779
+ *
780
+ * method frame:
781
+ * ep[ 0]: block pointer (ptr | VM_ENVVAL_BLOCK_PTR_FLAG)
782
+ */
783
+
784
+ #define VM_ENVVAL_BLOCK_PTR_FLAG 0x02
785
+ #define VM_ENVVAL_BLOCK_PTR(v) (GC_GUARDED_PTR(v) | VM_ENVVAL_BLOCK_PTR_FLAG)
786
+ #define VM_ENVVAL_BLOCK_PTR_P(v) ((v) & VM_ENVVAL_BLOCK_PTR_FLAG)
787
+ #define VM_ENVVAL_PREV_EP_PTR(v) ((VALUE)GC_GUARDED_PTR(v))
788
+ #define VM_ENVVAL_PREV_EP_PTR_P(v) (!(VM_ENVVAL_BLOCK_PTR_P(v)))
789
+
790
+ #define VM_EP_PREV_EP(ep) ((VALUE *)GC_GUARDED_PTR_REF((ep)[0]))
791
+ #define VM_EP_BLOCK_PTR(ep) ((rb_block_t *)GC_GUARDED_PTR_REF((ep)[0]))
792
+ #define VM_EP_LEP_P(ep) VM_ENVVAL_BLOCK_PTR_P((ep)[0])
793
+
794
+ VALUE *rb_vm_ep_local_ep(VALUE *ep);
795
+ rb_block_t *rb_vm_control_frame_block_ptr(rb_control_frame_t *cfp);
796
+
797
+ #define RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp) ((cfp)+1)
798
+ #define RUBY_VM_NEXT_CONTROL_FRAME(cfp) ((cfp)-1)
799
+ #define RUBY_VM_END_CONTROL_FRAME(th) \
800
+ ((rb_control_frame_t *)((th)->stack + (th)->stack_size))
801
+ #define RUBY_VM_VALID_CONTROL_FRAME_P(cfp, ecfp) \
802
+ ((void *)(ecfp) > (void *)(cfp))
803
+ #define RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp) \
804
+ (!RUBY_VM_VALID_CONTROL_FRAME_P((cfp), RUBY_VM_END_CONTROL_FRAME(th)))
805
+
806
+ #define RUBY_VM_IFUNC_P(ptr) (BUILTIN_TYPE(ptr) == T_NODE)
807
+ #define RUBY_VM_NORMAL_ISEQ_P(ptr) \
808
+ ((ptr) && !RUBY_VM_IFUNC_P(ptr))
809
+
810
+ #define RUBY_VM_GET_BLOCK_PTR_IN_CFP(cfp) ((rb_block_t *)(&(cfp)->self))
811
+ #define RUBY_VM_GET_CFP_FROM_BLOCK_PTR(b) \
812
+ ((rb_control_frame_t *)((VALUE *)(b) - 4))
813
+ /* magic number `4' is depend on rb_control_frame_t layout. */
814
+
815
+ /* VM related object allocate functions */
816
+ VALUE rb_thread_alloc(VALUE klass);
817
+ VALUE rb_proc_alloc(VALUE klass);
818
+
819
+ /* for debug */
820
+ extern void rb_vmdebug_stack_dump_raw(rb_thread_t *, rb_control_frame_t *);
821
+ extern void rb_vmdebug_debug_print_pre(rb_thread_t *th, rb_control_frame_t *cfp);
822
+ extern void rb_vmdebug_debug_print_post(rb_thread_t *th, rb_control_frame_t *cfp);
823
+
824
+ #define SDR() rb_vmdebug_stack_dump_raw(GET_THREAD(), GET_THREAD()->cfp)
825
+ #define SDR2(cfp) rb_vmdebug_stack_dump_raw(GET_THREAD(), (cfp))
826
+ void rb_vm_bugreport(void);
827
+
828
+ /* functions about thread/vm execution */
829
+ RUBY_SYMBOL_EXPORT_BEGIN
830
+ VALUE rb_iseq_eval(VALUE iseqval);
831
+ VALUE rb_iseq_eval_main(VALUE iseqval);
832
+ RUBY_SYMBOL_EXPORT_END
833
+ int rb_thread_method_id_and_class(rb_thread_t *th, ID *idp, VALUE *klassp);
834
+
835
+ VALUE rb_vm_invoke_proc(rb_thread_t *th, rb_proc_t *proc,
836
+ int argc, const VALUE *argv, const rb_block_t *blockptr);
837
+ VALUE rb_vm_make_proc(rb_thread_t *th, const rb_block_t *block, VALUE klass);
838
+ VALUE rb_vm_make_env_object(rb_thread_t *th, rb_control_frame_t *cfp);
839
+ VALUE rb_binding_new_with_cfp(rb_thread_t *th, const rb_control_frame_t *src_cfp);
840
+ VALUE *rb_binding_add_dynavars(rb_binding_t *bind, int dyncount, const ID *dynvars);
841
+ void rb_vm_inc_const_missing_count(void);
842
+ void rb_vm_gvl_destroy(rb_vm_t *vm);
843
+ VALUE rb_vm_call(rb_thread_t *th, VALUE recv, VALUE id, int argc,
844
+ const VALUE *argv, const rb_method_entry_t *me,
845
+ VALUE defined_class);
846
+ void rb_unlink_method_entry(rb_method_entry_t *me);
847
+ void rb_gc_mark_unlinked_live_method_entries(void *pvm);
848
+
849
+ void rb_thread_start_timer_thread(void);
850
+ void rb_thread_stop_timer_thread(int);
851
+ void rb_thread_reset_timer_thread(void);
852
+ void rb_thread_wakeup_timer_thread(void);
853
+
854
+ int ruby_thread_has_gvl_p(void);
855
+ typedef int rb_backtrace_iter_func(void *, VALUE, int, VALUE);
856
+ rb_control_frame_t *rb_vm_get_ruby_level_next_cfp(rb_thread_t *th, const rb_control_frame_t *cfp);
857
+ rb_control_frame_t *rb_vm_get_binding_creatable_next_cfp(rb_thread_t *th, const rb_control_frame_t *cfp);
858
+ int rb_vm_get_sourceline(const rb_control_frame_t *);
859
+ VALUE rb_name_err_mesg_new(VALUE obj, VALUE mesg, VALUE recv, VALUE method);
860
+ void rb_vm_stack_to_heap(rb_thread_t *th);
861
+ void ruby_thread_init_stack(rb_thread_t *th);
862
+ int rb_vm_control_frame_id_and_class(const rb_control_frame_t *cfp, ID *idp, VALUE *klassp);
863
+
864
+ void rb_gc_mark_machine_stack(rb_thread_t *th);
865
+
866
+ int rb_autoloading_value(VALUE mod, ID id, VALUE* value);
867
+
868
+ #define sysstack_error GET_VM()->special_exceptions[ruby_error_sysstack]
869
+
870
+ #define CHECK_VM_STACK_OVERFLOW0(cfp, sp, margin) do { \
871
+ if ((VALUE *)((char *)((VALUE *)(sp) + (margin)) + sizeof(rb_control_frame_t)) >= ((VALUE *)(cfp))) { \
872
+ vm_stackoverflow(); \
873
+ } \
874
+ } while (0)
875
+
876
+ #define CHECK_VM_STACK_OVERFLOW(cfp, margin) CHECK_VM_STACK_OVERFLOW0((cfp), (cfp)->sp, margin)
877
+
878
+ /* for thread */
879
+
880
+ #if RUBY_VM_THREAD_MODEL == 2
881
+ extern rb_thread_t *ruby_current_thread;
882
+ extern rb_vm_t *ruby_current_vm;
883
+ extern rb_event_flag_t ruby_vm_event_flags;
884
+
885
+ #define GET_VM() ruby_current_vm
886
+
887
+ #ifndef OPT_CALL_CFUNC_WITHOUT_FRAME
888
+ #define OPT_CALL_CFUNC_WITHOUT_FRAME 0
889
+ #endif
890
+
891
+ static inline rb_thread_t *
892
+ GET_THREAD(void)
893
+ {
894
+ rb_thread_t *th = ruby_current_thread;
895
+ #if OPT_CALL_CFUNC_WITHOUT_FRAME
896
+ if (UNLIKELY(th->passed_ci != 0)) {
897
+ void vm_call_cfunc_push_frame(rb_thread_t *th);
898
+ vm_call_cfunc_push_frame(th);
899
+ }
900
+ #endif
901
+ return th;
902
+ }
903
+
904
+ #define rb_thread_set_current_raw(th) (void)(ruby_current_thread = (th))
905
+ #define rb_thread_set_current(th) do { \
906
+ if ((th)->vm->running_thread != (th)) { \
907
+ (th)->running_time_us = 0; \
908
+ } \
909
+ rb_thread_set_current_raw(th); \
910
+ (th)->vm->running_thread = (th); \
911
+ } while (0)
912
+
913
+ #else
914
+ #error "unsupported thread model"
915
+ #endif
916
+
917
+ enum {
918
+ TIMER_INTERRUPT_MASK = 0x01,
919
+ PENDING_INTERRUPT_MASK = 0x02,
920
+ POSTPONED_JOB_INTERRUPT_MASK = 0x04,
921
+ TRAP_INTERRUPT_MASK = 0x08
922
+ };
923
+
924
+ #define RUBY_VM_SET_TIMER_INTERRUPT(th) ATOMIC_OR((th)->interrupt_flag, TIMER_INTERRUPT_MASK)
925
+ #define RUBY_VM_SET_INTERRUPT(th) ATOMIC_OR((th)->interrupt_flag, PENDING_INTERRUPT_MASK)
926
+ #define RUBY_VM_SET_POSTPONED_JOB_INTERRUPT(th) ATOMIC_OR((th)->interrupt_flag, POSTPONED_JOB_INTERRUPT_MASK)
927
+ #define RUBY_VM_SET_TRAP_INTERRUPT(th) ATOMIC_OR((th)->interrupt_flag, TRAP_INTERRUPT_MASK)
928
+ #define RUBY_VM_INTERRUPTED(th) ((th)->interrupt_flag & ~(th)->interrupt_mask & (PENDING_INTERRUPT_MASK|TRAP_INTERRUPT_MASK))
929
+ #define RUBY_VM_INTERRUPTED_ANY(th) ((th)->interrupt_flag & ~(th)->interrupt_mask)
930
+
931
+ int rb_signal_buff_size(void);
932
+ void rb_signal_exec(rb_thread_t *th, int sig);
933
+ void rb_threadptr_check_signal(rb_thread_t *mth);
934
+ void rb_threadptr_signal_raise(rb_thread_t *th, int sig);
935
+ void rb_threadptr_signal_exit(rb_thread_t *th);
936
+ void rb_threadptr_execute_interrupts(rb_thread_t *, int);
937
+ void rb_threadptr_interrupt(rb_thread_t *th);
938
+ void rb_threadptr_unlock_all_locking_mutexes(rb_thread_t *th);
939
+ void rb_threadptr_pending_interrupt_clear(rb_thread_t *th);
940
+ void rb_threadptr_pending_interrupt_enque(rb_thread_t *th, VALUE v);
941
+ int rb_threadptr_pending_interrupt_active_p(rb_thread_t *th);
942
+
943
+ #define RUBY_VM_CHECK_INTS_BLOCKING(th) do { \
944
+ if (UNLIKELY(!rb_threadptr_pending_interrupt_empty_p(th))) { \
945
+ th->pending_interrupt_queue_checked = 0; \
946
+ RUBY_VM_SET_INTERRUPT(th); \
947
+ rb_threadptr_execute_interrupts(th, 1); \
948
+ } \
949
+ else if (UNLIKELY(RUBY_VM_INTERRUPTED_ANY(th))) { \
950
+ rb_threadptr_execute_interrupts(th, 1); \
951
+ } \
952
+ } while (0)
953
+
954
+ #define RUBY_VM_CHECK_INTS(th) do { \
955
+ if (UNLIKELY(RUBY_VM_INTERRUPTED_ANY(th))) { \
956
+ rb_threadptr_execute_interrupts(th, 0); \
957
+ } \
958
+ } while (0)
959
+
960
+ /* tracer */
961
+ struct rb_trace_arg_struct {
962
+ rb_event_flag_t event;
963
+ rb_thread_t *th;
964
+ rb_control_frame_t *cfp;
965
+ VALUE self;
966
+ ID id;
967
+ VALUE klass;
968
+ VALUE data;
969
+
970
+ int klass_solved;
971
+
972
+ /* calc from cfp */
973
+ int lineno;
974
+ VALUE path;
975
+ };
976
+
977
+ void rb_threadptr_exec_event_hooks(struct rb_trace_arg_struct *trace_arg);
978
+ void rb_threadptr_exec_event_hooks_and_pop_frame(struct rb_trace_arg_struct *trace_arg);
979
+
980
+ #define EXEC_EVENT_HOOK_ORIG(th_, flag_, self_, id_, klass_, data_, pop_p_) do { \
981
+ if (UNLIKELY(ruby_vm_event_flags & (flag_))) { \
982
+ if (((th)->event_hooks.events | (th)->vm->event_hooks.events) & (flag_)) { \
983
+ struct rb_trace_arg_struct trace_arg; \
984
+ trace_arg.event = (flag_); \
985
+ trace_arg.th = (th_); \
986
+ trace_arg.cfp = (trace_arg.th)->cfp; \
987
+ trace_arg.self = (self_); \
988
+ trace_arg.id = (id_); \
989
+ trace_arg.klass = (klass_); \
990
+ trace_arg.data = (data_); \
991
+ trace_arg.path = Qundef; \
992
+ trace_arg.klass_solved = 0; \
993
+ if (pop_p_) rb_threadptr_exec_event_hooks_and_pop_frame(&trace_arg); \
994
+ else rb_threadptr_exec_event_hooks(&trace_arg); \
995
+ } \
996
+ } \
997
+ } while (0)
998
+
999
+ #define EXEC_EVENT_HOOK(th_, flag_, self_, id_, klass_, data_) \
1000
+ EXEC_EVENT_HOOK_ORIG(th_, flag_, self_, id_, klass_, data_, 0)
1001
+
1002
+ #define EXEC_EVENT_HOOK_AND_POP_FRAME(th_, flag_, self_, id_, klass_, data_) \
1003
+ EXEC_EVENT_HOOK_ORIG(th_, flag_, self_, id_, klass_, data_, 1)
1004
+
1005
+ RUBY_SYMBOL_EXPORT_BEGIN
1006
+
1007
+ int rb_thread_check_trap_pending(void);
1008
+
1009
+ extern VALUE rb_get_coverages(void);
1010
+ extern void rb_set_coverages(VALUE);
1011
+ extern void rb_reset_coverages(void);
1012
+
1013
+ void rb_postponed_job_flush(rb_vm_t *vm);
1014
+
1015
+ RUBY_SYMBOL_EXPORT_END
1016
+
1017
+ #endif /* RUBY_VM_CORE_H */