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