Ruby 2.1.5p273(2014-11-13revision48405)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

iseq.c
Go to the documentation of this file.
1 /**********************************************************************
2
3 iseq.c -
4
5 $Author: nagachika $
6 created at: 2006-07-11(Tue) 09:00:03 +0900
7
8 Copyright (C) 2006 Koichi Sasada
9
10 **********************************************************************/
11
12 #include "ruby/ruby.h"
13 #include "internal.h"
14 #include "eval_intern.h"
15
16 /* #define RUBY_MARK_FREE_DEBUG 1 */
17 #include "gc.h"
18 #include "vm_core.h"
19 #include "iseq.h"
20
21 #include "insns.inc"
22 #include "insns_info.inc"
23
24 #define ISEQ_MAJOR_VERSION 2
25 #define ISEQ_MINOR_VERSION 1
26
27 VALUE rb_cISeq;
28
29 #define hidden_obj_p(obj) (!SPECIAL_CONST_P(obj) && !RBASIC(obj)->klass)
30
31 static inline VALUE
32 obj_resurrect(VALUE obj)
33 {
34 if (hidden_obj_p(obj)) {
35 switch (BUILTIN_TYPE(obj)) {
36 case T_STRING:
37 obj = rb_str_resurrect(obj);
38 break;
39 case T_ARRAY:
40 obj = rb_ary_resurrect(obj);
41 break;
42 }
43 }
44 return obj;
45 }
46
47 static void
48 compile_data_free(struct iseq_compile_data *compile_data)
49 {
50 if (compile_data) {
51 struct iseq_compile_data_storage *cur, *next;
52 cur = compile_data->storage_head;
53 while (cur) {
54 next = cur->next;
55 ruby_xfree(cur);
56 cur = next;
57 }
58 ruby_xfree(compile_data);
59 }
60 }
61
62 static void
63 iseq_free(void *ptr)
64 {
65 rb_iseq_t *iseq;
66 RUBY_FREE_ENTER("iseq");
67
68 if (ptr) {
69 iseq = ptr;
70 if (!iseq->orig) {
71 /* It's possible that strings are freed */
72 if (0) {
73 RUBY_GC_INFO("%s @ %s\n", RSTRING_PTR(iseq->location.label),
74 RSTRING_PTR(iseq->location.path));
75 }
76
77 if (iseq->iseq != iseq->iseq_encoded) {
78 RUBY_FREE_UNLESS_NULL(iseq->iseq_encoded);
79 }
80
81 RUBY_FREE_UNLESS_NULL(iseq->iseq);
82 RUBY_FREE_UNLESS_NULL(iseq->line_info_table);
83 RUBY_FREE_UNLESS_NULL(iseq->local_table);
84 RUBY_FREE_UNLESS_NULL(iseq->is_entries);
85 RUBY_FREE_UNLESS_NULL(iseq->callinfo_entries);
86 RUBY_FREE_UNLESS_NULL(iseq->catch_table);
87 RUBY_FREE_UNLESS_NULL(iseq->arg_opt_table);
88 RUBY_FREE_UNLESS_NULL(iseq->arg_keyword_table);
89 compile_data_free(iseq->compile_data);
90 }
91 ruby_xfree(ptr);
92 }
93 RUBY_FREE_LEAVE("iseq");
94 }
95
96 static void
97 iseq_mark(void *ptr)
98 {
99 RUBY_MARK_ENTER("iseq");
100
101 if (ptr) {
102 rb_iseq_t *iseq = ptr;
103
104 RUBY_GC_INFO("%s @ %s\n", RSTRING_PTR(iseq->location.label), RSTRING_PTR(iseq->location.path));
105 RUBY_MARK_UNLESS_NULL(iseq->mark_ary);
106
107 RUBY_MARK_UNLESS_NULL(iseq->location.label);
108 RUBY_MARK_UNLESS_NULL(iseq->location.base_label);
109 RUBY_MARK_UNLESS_NULL(iseq->location.path);
110 RUBY_MARK_UNLESS_NULL(iseq->location.absolute_path);
111
112 RUBY_MARK_UNLESS_NULL((VALUE)iseq->cref_stack);
113 RUBY_MARK_UNLESS_NULL(iseq->klass);
114 RUBY_MARK_UNLESS_NULL(iseq->coverage);
115 RUBY_MARK_UNLESS_NULL(iseq->orig);
116
117 if (iseq->compile_data != 0) {
118 struct iseq_compile_data *const compile_data = iseq->compile_data;
119 RUBY_MARK_UNLESS_NULL(compile_data->mark_ary);
120 RUBY_MARK_UNLESS_NULL(compile_data->err_info);
121 RUBY_MARK_UNLESS_NULL(compile_data->catch_table_ary);
122 }
123 }
124 RUBY_MARK_LEAVE("iseq");
125 }
126
127 static size_t
128 iseq_memsize(const void *ptr)
129 {
130 size_t size = sizeof(rb_iseq_t);
131 const rb_iseq_t *iseq;
132
133 if (ptr) {
134 iseq = ptr;
135 if (!iseq->orig) {
136 if (iseq->iseq != iseq->iseq_encoded) {
137 size += iseq->iseq_size * sizeof(VALUE);
138 }
139
140 size += iseq->iseq_size * sizeof(VALUE);
141 size += iseq->line_info_size * sizeof(struct iseq_line_info_entry);
142 size += iseq->local_table_size * sizeof(ID);
143 size += iseq->catch_table_size * sizeof(struct iseq_catch_table_entry);
144 size += iseq->arg_opts * sizeof(VALUE);
145 size += iseq->is_size * sizeof(union iseq_inline_storage_entry);
146 size += iseq->callinfo_size * sizeof(rb_call_info_t);
147
148 if (iseq->compile_data) {
149 struct iseq_compile_data_storage *cur;
150
151 cur = iseq->compile_data->storage_head;
152 while (cur) {
153 size += cur->size + sizeof(struct iseq_compile_data_storage);
154 cur = cur->next;
155 }
156 size += sizeof(struct iseq_compile_data);
157 }
158 }
159 }
160
161 return size;
162 }
163
164 static const rb_data_type_t iseq_data_type = {
165 "iseq",
166 {
167 iseq_mark,
168 iseq_free,
169 iseq_memsize,
170 }, /* functions */
171 NULL, NULL,
172 RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED
173 };
174
175 static VALUE
176 iseq_alloc(VALUE klass)
177 {
178 rb_iseq_t *iseq;
179 return TypedData_Make_Struct(klass, rb_iseq_t, &iseq_data_type, iseq);
180 }
181
182 static rb_iseq_location_t *
183 iseq_location_setup(rb_iseq_t *iseq, VALUE path, VALUE absolute_path, VALUE name, size_t first_lineno)
184 {
185 rb_iseq_location_t *loc = &iseq->location;
186 RB_OBJ_WRITE(iseq->self, &loc->path, path);
187 if (RTEST(absolute_path) && rb_str_cmp(path, absolute_path) == 0) {
188 RB_OBJ_WRITE(iseq->self, &loc->absolute_path, path);
189 }
190 else {
191 RB_OBJ_WRITE(iseq->self, &loc->absolute_path, absolute_path);
192 }
193 RB_OBJ_WRITE(iseq->self, &loc->label, name);
194 RB_OBJ_WRITE(iseq->self, &loc->base_label, name);
195 loc->first_lineno = first_lineno;
196 return loc;
197 }
198
199 #define ISEQ_SET_CREF(iseq, cref) RB_OBJ_WRITE((iseq)->self, &(iseq)->cref_stack, (cref))
200
201 static void
202 set_relation(rb_iseq_t *iseq, const VALUE parent)
203 {
204 const VALUE type = iseq->type;
205 rb_thread_t *th = GET_THREAD();
206 rb_iseq_t *piseq;
207
208 /* set class nest stack */
209 if (type == ISEQ_TYPE_TOP) {
210 /* toplevel is private */
211 RB_OBJ_WRITE(iseq->self, &iseq->cref_stack, NEW_CREF(rb_cObject));
212 iseq->cref_stack->nd_refinements = Qnil;
213 iseq->cref_stack->nd_visi = NOEX_PRIVATE;
214 if (th->top_wrapper) {
215 NODE *cref = NEW_CREF(th->top_wrapper);
216 cref->nd_refinements = Qnil;
217 cref->nd_visi = NOEX_PRIVATE;
218 RB_OBJ_WRITE(cref, &cref->nd_next, iseq->cref_stack);
219 ISEQ_SET_CREF(iseq, cref);
220 }
221 iseq->local_iseq = iseq;
222 }
223 else if (type == ISEQ_TYPE_METHOD || type == ISEQ_TYPE_CLASS) {
224 ISEQ_SET_CREF(iseq, NEW_CREF(0)); /* place holder */
225 iseq->cref_stack->nd_refinements = Qnil;
226 iseq->local_iseq = iseq;
227 }
228 else if (RTEST(parent)) {
229 GetISeqPtr(parent, piseq);
230 ISEQ_SET_CREF(iseq, piseq->cref_stack);
231 iseq->local_iseq = piseq->local_iseq;
232 }
233
234 if (RTEST(parent)) {
235 GetISeqPtr(parent, piseq);
236 iseq->parent_iseq = piseq;
237 }
238
239 if (type == ISEQ_TYPE_MAIN) {
240 iseq->local_iseq = iseq;
241 }
242 }
243
244 void
245 rb_iseq_add_mark_object(rb_iseq_t *iseq, VALUE obj)
246 {
247 if (!RTEST(iseq->mark_ary)) {
248 RB_OBJ_WRITE(iseq->self, &iseq->mark_ary, rb_ary_tmp_new(3));
249 RBASIC_CLEAR_CLASS(iseq->mark_ary);
250 }
251 rb_ary_push(iseq->mark_ary, obj);
252 }
253
254 static VALUE
255 prepare_iseq_build(rb_iseq_t *iseq,
256 VALUE name, VALUE path, VALUE absolute_path, VALUE first_lineno,
257 VALUE parent, enum iseq_type type, VALUE block_opt,
258 const rb_compile_option_t *option)
259 {
260 iseq->type = type;
261 iseq->arg_rest = -1;
262 iseq->arg_block = -1;
263 iseq->arg_keyword = -1;
264 RB_OBJ_WRITE(iseq->self, &iseq->klass, 0);
265 set_relation(iseq, parent);
266
267 name = rb_fstring(name);
268 path = rb_fstring(path);
269 if (RTEST(absolute_path))
270 absolute_path = rb_fstring(absolute_path);
271
272 iseq_location_setup(iseq, path, absolute_path, name, first_lineno);
273 if (iseq != iseq->local_iseq) {
274 RB_OBJ_WRITE(iseq->self, &iseq->location.base_label, iseq->local_iseq->location.label);
275 }
276
277 iseq->defined_method_id = 0;
278 RB_OBJ_WRITE(iseq->self, &iseq->mark_ary, 0);
279
280 /*
281 * iseq->special_block_builder = GC_GUARDED_PTR_REF(block_opt);
282 * iseq->cached_special_block_builder = 0;
283 * iseq->cached_special_block = 0;
284 */
285
286 iseq->compile_data = ALLOC(struct iseq_compile_data);
287 MEMZERO(iseq->compile_data, struct iseq_compile_data, 1);
288 RB_OBJ_WRITE(iseq->self, &iseq->compile_data->err_info, Qnil);
289 RB_OBJ_WRITE(iseq->self, &iseq->compile_data->mark_ary, rb_ary_tmp_new(3));
290
291 iseq->compile_data->storage_head = iseq->compile_data->storage_current =
292 (struct iseq_compile_data_storage *)
293 ALLOC_N(char, INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE +
294 sizeof(struct iseq_compile_data_storage));
295
296 RB_OBJ_WRITE(iseq->self, &iseq->compile_data->catch_table_ary, rb_ary_new());
297 iseq->compile_data->storage_head->pos = 0;
298 iseq->compile_data->storage_head->next = 0;
299 iseq->compile_data->storage_head->size =
300 INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE;
301 iseq->compile_data->storage_head->buff =
302 (char *)(&iseq->compile_data->storage_head->buff + 1);
303 iseq->compile_data->option = option;
304 iseq->compile_data->last_coverable_line = -1;
305
306 RB_OBJ_WRITE(iseq->self, &iseq->coverage, Qfalse);
307 if (!GET_THREAD()->parse_in_eval) {
308 VALUE coverages = rb_get_coverages();
309 if (RTEST(coverages)) {
310 RB_OBJ_WRITE(iseq->self, &iseq->coverage, rb_hash_lookup(coverages, path));
311 if (NIL_P(iseq->coverage)) RB_OBJ_WRITE(iseq->self, &iseq->coverage, Qfalse);
312 }
313 }
314
315 return Qtrue;
316 }
317
318 static VALUE
319 cleanup_iseq_build(rb_iseq_t *iseq)
320 {
321 struct iseq_compile_data *data = iseq->compile_data;
322 VALUE err = data->err_info;
323 iseq->compile_data = 0;
324 compile_data_free(data);
325
326 if (RTEST(err)) {
327 rb_funcall2(err, rb_intern("set_backtrace"), 1, &iseq->location.path);
328 rb_exc_raise(err);
329 }
330 return Qtrue;
331 }
332
333 static rb_compile_option_t COMPILE_OPTION_DEFAULT = {
334 OPT_INLINE_CONST_CACHE, /* int inline_const_cache; */
335 OPT_PEEPHOLE_OPTIMIZATION, /* int peephole_optimization; */
336 OPT_TAILCALL_OPTIMIZATION, /* int tailcall_optimization */
337 OPT_SPECIALISED_INSTRUCTION, /* int specialized_instruction; */
338 OPT_OPERANDS_UNIFICATION, /* int operands_unification; */
339 OPT_INSTRUCTIONS_UNIFICATION, /* int instructions_unification; */
340 OPT_STACK_CACHING, /* int stack_caching; */
341 OPT_TRACE_INSTRUCTION, /* int trace_instruction */
342 };
343 static const rb_compile_option_t COMPILE_OPTION_FALSE = {0};
344
345 static void
346 make_compile_option(rb_compile_option_t *option, VALUE opt)
347 {
348 if (opt == Qnil) {
349 *option = COMPILE_OPTION_DEFAULT;
350 }
351 else if (opt == Qfalse) {
352 *option = COMPILE_OPTION_FALSE;
353 }
354 else if (opt == Qtrue) {
355 int i;
356 for (i = 0; i < (int)(sizeof(rb_compile_option_t) / sizeof(int)); ++i)
357 ((int *)option)[i] = 1;
358 }
359 else if (CLASS_OF(opt) == rb_cHash) {
360 *option = COMPILE_OPTION_DEFAULT;
361
362 #define SET_COMPILE_OPTION(o, h, mem) \
363 { VALUE flag = rb_hash_aref((h), ID2SYM(rb_intern(#mem))); \
364 if (flag == Qtrue) { (o)->mem = 1; } \
365 else if (flag == Qfalse) { (o)->mem = 0; } \
366 }
367 #define SET_COMPILE_OPTION_NUM(o, h, mem) \
368 { VALUE num = rb_hash_aref(opt, ID2SYM(rb_intern(#mem))); \
369 if (!NIL_P(num)) (o)->mem = NUM2INT(num); \
370 }
371 SET_COMPILE_OPTION(option, opt, inline_const_cache);
372 SET_COMPILE_OPTION(option, opt, peephole_optimization);
373 SET_COMPILE_OPTION(option, opt, tailcall_optimization);
374 SET_COMPILE_OPTION(option, opt, specialized_instruction);
375 SET_COMPILE_OPTION(option, opt, operands_unification);
376 SET_COMPILE_OPTION(option, opt, instructions_unification);
377 SET_COMPILE_OPTION(option, opt, stack_caching);
378 SET_COMPILE_OPTION(option, opt, trace_instruction);
379 SET_COMPILE_OPTION_NUM(option, opt, debug_level);
380 #undef SET_COMPILE_OPTION
381 #undef SET_COMPILE_OPTION_NUM
382 }
383 else {
384 rb_raise(rb_eTypeError, "Compile option must be Hash/true/false/nil");
385 }
386 }
387
388 static VALUE
389 make_compile_option_value(rb_compile_option_t *option)
390 {
391 VALUE opt = rb_hash_new();
392 #define SET_COMPILE_OPTION(o, h, mem) \
393 rb_hash_aset((h), ID2SYM(rb_intern(#mem)), (o)->mem ? Qtrue : Qfalse)
394 #define SET_COMPILE_OPTION_NUM(o, h, mem) \
395 rb_hash_aset((h), ID2SYM(rb_intern(#mem)), INT2NUM((o)->mem))
396 {
397 SET_COMPILE_OPTION(option, opt, inline_const_cache);
398 SET_COMPILE_OPTION(option, opt, peephole_optimization);
399 SET_COMPILE_OPTION(option, opt, tailcall_optimization);
400 SET_COMPILE_OPTION(option, opt, specialized_instruction);
401 SET_COMPILE_OPTION(option, opt, operands_unification);
402 SET_COMPILE_OPTION(option, opt, instructions_unification);
403 SET_COMPILE_OPTION(option, opt, stack_caching);
404 SET_COMPILE_OPTION(option, opt, trace_instruction);
405 SET_COMPILE_OPTION_NUM(option, opt, debug_level);
406 }
407 #undef SET_COMPILE_OPTION
408 #undef SET_COMPILE_OPTION_NUM
409 return opt;
410 }
411
412 VALUE
413 rb_iseq_new(NODE *node, VALUE name, VALUE path, VALUE absolute_path,
414 VALUE parent, enum iseq_type type)
415 {
416 return rb_iseq_new_with_opt(node, name, path, absolute_path, INT2FIX(0), parent, type,
417 &COMPILE_OPTION_DEFAULT);
418 }
419
420 VALUE
421 rb_iseq_new_top(NODE *node, VALUE name, VALUE path, VALUE absolute_path, VALUE parent)
422 {
423 return rb_iseq_new_with_opt(node, name, path, absolute_path, INT2FIX(0), parent, ISEQ_TYPE_TOP,
424 &COMPILE_OPTION_DEFAULT);
425 }
426
427 VALUE
428 rb_iseq_new_main(NODE *node, VALUE path, VALUE absolute_path)
429 {
430 rb_thread_t *th = GET_THREAD();
431 VALUE parent = th->base_block->iseq->self;
432 return rb_iseq_new_with_opt(node, rb_str_new2("<main>"), path, absolute_path, INT2FIX(0),
433 parent, ISEQ_TYPE_MAIN, &COMPILE_OPTION_DEFAULT);
434 }
435
436 static VALUE
437 rb_iseq_new_with_bopt_and_opt(NODE *node, VALUE name, VALUE path, VALUE absolute_path, VALUE first_lineno,
438 VALUE parent, enum iseq_type type, VALUE bopt,
439 const rb_compile_option_t *option)
440 {
441 rb_iseq_t *iseq;
442 VALUE self = iseq_alloc(rb_cISeq);
443
444 GetISeqPtr(self, iseq);
445 iseq->self = self;
446
447 prepare_iseq_build(iseq, name, path, absolute_path, first_lineno, parent, type, bopt, option);
448 rb_iseq_compile_node(self, node);
449 cleanup_iseq_build(iseq);
450 return self;
451 }
452
453 VALUE
454 rb_iseq_new_with_opt(NODE *node, VALUE name, VALUE path, VALUE absolute_path, VALUE first_lineno,
455 VALUE parent, enum iseq_type type,
456 const rb_compile_option_t *option)
457 {
458 /* TODO: argument check */
459 return rb_iseq_new_with_bopt_and_opt(node, name, path, absolute_path, first_lineno, parent, type,
460 Qfalse, option);
461 }
462
463 VALUE
464 rb_iseq_new_with_bopt(NODE *node, VALUE name, VALUE path, VALUE absolute_path, VALUE first_lineno,
465 VALUE parent, enum iseq_type type, VALUE bopt)
466 {
467 /* TODO: argument check */
468 return rb_iseq_new_with_bopt_and_opt(node, name, path, absolute_path, first_lineno, parent, type,
469 bopt, &COMPILE_OPTION_DEFAULT);
470 }
471
472 #define CHECK_ARRAY(v) rb_convert_type((v), T_ARRAY, "Array", "to_ary")
473 #define CHECK_STRING(v) rb_convert_type((v), T_STRING, "String", "to_str")
474 #define CHECK_SYMBOL(v) rb_convert_type((v), T_SYMBOL, "Symbol", "to_sym")
475 static inline VALUE CHECK_INTEGER(VALUE v) {(void)NUM2LONG(v); return v;}
476 static VALUE
477 iseq_load(VALUE self, VALUE data, VALUE parent, VALUE opt)
478 {
479 VALUE iseqval = iseq_alloc(self);
480
481 VALUE magic, version1, version2, format_type, misc;
482 VALUE name, path, absolute_path, first_lineno;
483 VALUE type, body, locals, args, exception;
484
485 st_data_t iseq_type;
486 static struct st_table *type_map_cache = 0;
487 struct st_table *type_map = 0;
488 rb_iseq_t *iseq;
489 rb_compile_option_t option;
490 int i = 0;
491
492 /* [magic, major_version, minor_version, format_type, misc,
493 * label, path, first_lineno,
494 * type, locals, args, exception_table, body]
495 */
496
497 data = CHECK_ARRAY(data);
498
499 magic = CHECK_STRING(rb_ary_entry(data, i++));
500 version1 = CHECK_INTEGER(rb_ary_entry(data, i++));
501 version2 = CHECK_INTEGER(rb_ary_entry(data, i++));
502 format_type = CHECK_INTEGER(rb_ary_entry(data, i++));
503 misc = rb_ary_entry(data, i++); /* TODO */
504 ((void)magic, (void)version1, (void)version2, (void)format_type, (void)misc);
505
506 name = CHECK_STRING(rb_ary_entry(data, i++));
507 path = CHECK_STRING(rb_ary_entry(data, i++));
508 absolute_path = rb_ary_entry(data, i++);
509 absolute_path = NIL_P(absolute_path) ? Qnil : CHECK_STRING(absolute_path);
510 first_lineno = CHECK_INTEGER(rb_ary_entry(data, i++));
511
512 type = CHECK_SYMBOL(rb_ary_entry(data, i++));
513 locals = CHECK_ARRAY(rb_ary_entry(data, i++));
514
515 args = rb_ary_entry(data, i++);
516 if (FIXNUM_P(args) || (args = CHECK_ARRAY(args))) {
517 /* */
518 }
519
520 exception = CHECK_ARRAY(rb_ary_entry(data, i++));
521 body = CHECK_ARRAY(rb_ary_entry(data, i++));
522
523 GetISeqPtr(iseqval, iseq);
524 iseq->self = iseqval;
525 iseq->local_iseq = iseq;
526
527 type_map = type_map_cache;
528 if (type_map == 0) {
529 struct st_table *cached_map;
530 type_map = st_init_numtable();
531 st_insert(type_map, ID2SYM(rb_intern("top")), ISEQ_TYPE_TOP);
532 st_insert(type_map, ID2SYM(rb_intern("method")), ISEQ_TYPE_METHOD);
533 st_insert(type_map, ID2SYM(rb_intern("block")), ISEQ_TYPE_BLOCK);
534 st_insert(type_map, ID2SYM(rb_intern("class")), ISEQ_TYPE_CLASS);
535 st_insert(type_map, ID2SYM(rb_intern("rescue")), ISEQ_TYPE_RESCUE);
536 st_insert(type_map, ID2SYM(rb_intern("ensure")), ISEQ_TYPE_ENSURE);
537 st_insert(type_map, ID2SYM(rb_intern("eval")), ISEQ_TYPE_EVAL);
538 st_insert(type_map, ID2SYM(rb_intern("main")), ISEQ_TYPE_MAIN);
539 st_insert(type_map, ID2SYM(rb_intern("defined_guard")), ISEQ_TYPE_DEFINED_GUARD);
540 cached_map = ATOMIC_PTR_CAS(type_map_cache, (struct st_table *)0, type_map);
541 if (cached_map) {
542 st_free_table(type_map);
543 type_map = cached_map;
544 }
545 }
546
547 if (st_lookup(type_map, type, &iseq_type) == 0) {
548 ID typeid = SYM2ID(type);
549 VALUE typename = rb_id2str(typeid);
550 if (typename)
551 rb_raise(rb_eTypeError, "unsupport type: :%"PRIsVALUE, typename);
552 else
553 rb_raise(rb_eTypeError, "unsupport type: %p", (void *)typeid);
554 }
555
556 if (parent == Qnil) {
557 parent = 0;
558 }
559
560 make_compile_option(&option, opt);
561 prepare_iseq_build(iseq, name, path, absolute_path, first_lineno,
562 parent, (enum iseq_type)iseq_type, 0, &option);
563
564 rb_iseq_build_from_ary(iseq, locals, args, exception, body);
565
566 cleanup_iseq_build(iseq);
567 return iseqval;
568 }
569
570 /*
571 * :nodoc:
572 */
573 static VALUE
574 iseq_s_load(int argc, VALUE *argv, VALUE self)
575 {
576 VALUE data, opt=Qnil;
577 rb_scan_args(argc, argv, "11", &data, &opt);
578
579 return iseq_load(self, data, 0, opt);
580 }
581
582 VALUE
583 rb_iseq_load(VALUE data, VALUE parent, VALUE opt)
584 {
585 return iseq_load(rb_cISeq, data, parent, opt);
586 }
587
588 VALUE
589 rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE absolute_path, VALUE line, rb_block_t *base_block, VALUE opt)
590 {
591 int state;
592 rb_thread_t *th = GET_THREAD();
593 rb_block_t *prev_base_block = th->base_block;
594 VALUE iseqval = Qundef;
595
596 th->base_block = base_block;
597
598 TH_PUSH_TAG(th);
599 if ((state = EXEC_TAG()) == 0) {
600 VALUE parser;
601 int ln = NUM2INT(line);
602 NODE *node;
603 rb_compile_option_t option;
604
605 StringValueCStr(file);
606 make_compile_option(&option, opt);
607
608 parser = rb_parser_new();
609
610 if (RB_TYPE_P((src), T_FILE))
611 node = rb_parser_compile_file_path(parser, file, src, ln);
612 else {
613 node = rb_parser_compile_string_path(parser, file, src, ln);
614
615 if (!node) {
616 rb_exc_raise(GET_THREAD()->errinfo); /* TODO: check err */
617 }
618 }
619
620 if (base_block && base_block->iseq) {
621 iseqval = rb_iseq_new_with_opt(node, base_block->iseq->location.label,
622 file, absolute_path, line, base_block->iseq->self,
623 ISEQ_TYPE_EVAL, &option);
624 }
625 else {
626 iseqval = rb_iseq_new_with_opt(node, rb_str_new2("<compiled>"), file, absolute_path, line, Qfalse,
627 ISEQ_TYPE_TOP, &option);
628 }
629 }
630 TH_POP_TAG();
631
632 th->base_block = prev_base_block;
633
634 if (state) {
635 JUMP_TAG(state);
636 }
637
638 return iseqval;
639 }
640
641 VALUE
642 rb_iseq_compile(VALUE src, VALUE file, VALUE line)
643 {
644 return rb_iseq_compile_with_option(src, file, Qnil, line, 0, Qnil);
645 }
646
647 VALUE
648 rb_iseq_compile_on_base(VALUE src, VALUE file, VALUE line, rb_block_t *base_block)
649 {
650 return rb_iseq_compile_with_option(src, file, Qnil, line, base_block, Qnil);
651 }
652
653 /*
654 * call-seq:
655 * InstructionSequence.compile(source[, file[, path[, line[, options]]]]) -> iseq
656 * InstructionSequence.new(source[, file[, path[, line[, options]]]]) -> iseq
657 *
658 * Takes +source+, a String of Ruby code and compiles it to an
659 * InstructionSequence.
660 *
661 * Optionally takes +file+, +path+, and +line+ which describe the filename,
662 * absolute path and first line number of the ruby code in +source+ which are
663 * metadata attached to the returned +iseq+.
664 *
665 * +options+, which can be +true+, +false+ or a +Hash+, is used to
666 * modify the default behavior of the Ruby iseq compiler.
667 *
668 * For details regarding valid compile options see ::compile_option=.
669 *
670 * RubyVM::InstructionSequence.compile("a = 1 + 2")
671 * #=> <RubyVM::InstructionSequence:<compiled>@<compiled>>
672 *
673 */
674 static VALUE
675 iseq_s_compile(int argc, VALUE *argv, VALUE self)
676 {
677 VALUE src, file = Qnil, path = Qnil, line = INT2FIX(1), opt = Qnil;
678
679 rb_secure(1);
680
681 rb_scan_args(argc, argv, "14", &src, &file, &path, &line, &opt);
682 if (NIL_P(file)) file = rb_str_new2("<compiled>");
683 if (NIL_P(line)) line = INT2FIX(1);
684
685 return rb_iseq_compile_with_option(src, file, path, line, 0, opt);
686 }
687
688 /*
689 * call-seq:
690 * InstructionSequence.compile_file(file[, options]) -> iseq
691 *
692 * Takes +file+, a String with the location of a Ruby source file, reads,
693 * parses and compiles the file, and returns +iseq+, the compiled
694 * InstructionSequence with source location metadata set.
695 *
696 * Optionally takes +options+, which can be +true+, +false+ or a +Hash+, to
697 * modify the default behavior of the Ruby iseq compiler.
698 *
699 * For details regarding valid compile options see ::compile_option=.
700 *
701 * # /tmp/hello.rb
702 * puts "Hello, world!"
703 *
704 * # elsewhere
705 * RubyVM::InstructionSequence.compile_file("/tmp/hello.rb")
706 * #=> <RubyVM::InstructionSequence:<main>@/tmp/hello.rb>
707 */
708 static VALUE
709 iseq_s_compile_file(int argc, VALUE *argv, VALUE self)
710 {
711 VALUE file, line = INT2FIX(1), opt = Qnil;
712 VALUE parser;
713 VALUE f;
714 NODE *node;
715 const char *fname;
716 rb_compile_option_t option;
717
718 rb_secure(1);
719 rb_scan_args(argc, argv, "11", &file, &opt);
720 FilePathValue(file);
721 fname = StringValueCStr(file);
722
723 f = rb_file_open_str(file, "r");
724
725 parser = rb_parser_new();
726 node = rb_parser_compile_file(parser, fname, f, NUM2INT(line));
727 make_compile_option(&option, opt);
728 return rb_iseq_new_with_opt(node, rb_str_new2("<main>"), file,
729 rb_realpath_internal(Qnil, file, 1), line, Qfalse,
730 ISEQ_TYPE_TOP, &option);
731 }
732
733 /*
734 * call-seq:
735 * InstructionSequence.compile_option = options
736 *
737 * Sets the default values for various optimizations in the Ruby iseq
738 * compiler.
739 *
740 * Possible values for +options+ include +true+, which enables all options,
741 * +false+ which disables all options, and +nil+ which leaves all options
742 * unchanged.
743 *
744 * You can also pass a +Hash+ of +options+ that you want to change, any
745 * options not present in the hash will be left unchanged.
746 *
747 * Possible option names (which are keys in +options+) which can be set to
748 * +true+ or +false+ include:
749 *
750 * * +:inline_const_cache+
751 * * +:instructions_unification+
752 * * +:operands_unification+
753 * * +:peephole_optimization+
754 * * +:specialized_instruction+
755 * * +:stack_caching+
756 * * +:tailcall_optimization+
757 * * +:trace_instruction+
758 *
759 * Additionally, +:debug_level+ can be set to an integer.
760 *
761 * These default options can be overwritten for a single run of the iseq
762 * compiler by passing any of the above values as the +options+ parameter to
763 * ::new, ::compile and ::compile_file.
764 */
765 static VALUE
766 iseq_s_compile_option_set(VALUE self, VALUE opt)
767 {
768 rb_compile_option_t option;
769 rb_secure(1);
770 make_compile_option(&option, opt);
771 COMPILE_OPTION_DEFAULT = option;
772 return opt;
773 }
774
775 /*
776 * call-seq:
777 * InstructionSequence.compile_option -> options
778 *
779 * Returns a hash of default options used by the Ruby iseq compiler.
780 *
781 * For details, see InstructionSequence.compile_option=.
782 */
783 static VALUE
784 iseq_s_compile_option_get(VALUE self)
785 {
786 return make_compile_option_value(&COMPILE_OPTION_DEFAULT);
787 }
788
789 static rb_iseq_t *
790 iseq_check(VALUE val)
791 {
792 rb_iseq_t *iseq;
793 GetISeqPtr(val, iseq);
794 if (!iseq->location.label) {
795 rb_raise(rb_eTypeError, "uninitialized InstructionSequence");
796 }
797 return iseq;
798 }
799
800 /*
801 * call-seq:
802 * iseq.eval -> obj
803 *
804 * Evaluates the instruction sequence and returns the result.
805 *
806 * RubyVM::InstructionSequence.compile("1 + 2").eval #=> 3
807 */
808 static VALUE
809 iseq_eval(VALUE self)
810 {
811 rb_secure(1);
812 return rb_iseq_eval(self);
813 }
814
815 /*
816 * Returns a human-readable string representation of this instruction
817 * sequence, including the #label and #path.
818 */
819 static VALUE
820 iseq_inspect(VALUE self)
821 {
822 rb_iseq_t *iseq;
823 GetISeqPtr(self, iseq);
824 if (!iseq->location.label) {
825 return rb_sprintf("#<%s: uninitialized>", rb_obj_classname(self));
826 }
827
828 return rb_sprintf("<%s:%s@%s>",
829 rb_obj_classname(self),
830 RSTRING_PTR(iseq->location.label), RSTRING_PTR(iseq->location.path));
831 }
832
833 /*
834 * Returns the path of this instruction sequence.
835 *
836 * <code><compiled></code> if the iseq was evaluated from a string.
837 *
838 * For example, using irb:
839 *
840 * iseq = RubyVM::InstructionSequence.compile('num = 1 + 2')
841 * #=> <RubyVM::InstructionSequence:<compiled>@<compiled>>
842 * iseq.path
843 * #=> "<compiled>"
844 *
845 * Using ::compile_file:
846 *
847 * # /tmp/method.rb
848 * def hello
849 * puts "hello, world"
850 * end
851 *
852 * # in irb
853 * > iseq = RubyVM::InstructionSequence.compile_file('/tmp/method.rb')
854 * > iseq.path #=> /tmp/method.rb
855 */
856 VALUE
857 rb_iseq_path(VALUE self)
858 {
859 rb_iseq_t *iseq;
860 GetISeqPtr(self, iseq);
861 return iseq->location.path;
862 }
863
864 /*
865 * Returns the absolute path of this instruction sequence.
866 *
867 * +nil+ if the iseq was evaluated from a string.
868 *
869 * For example, using ::compile_file:
870 *
871 * # /tmp/method.rb
872 * def hello
873 * puts "hello, world"
874 * end
875 *
876 * # in irb
877 * > iseq = RubyVM::InstructionSequence.compile_file('/tmp/method.rb')
878 * > iseq.absolute_path #=> /tmp/method.rb
879 */
880 VALUE
881 rb_iseq_absolute_path(VALUE self)
882 {
883 rb_iseq_t *iseq;
884 GetISeqPtr(self, iseq);
885 return iseq->location.absolute_path;
886 }
887
888 /* Returns the label of this instruction sequence.
889 *
890 * <code><main></code> if it's at the top level, <code><compiled></code> if it
891 * was evaluated from a string.
892 *
893 * For example, using irb:
894 *
895 * iseq = RubyVM::InstructionSequence.compile('num = 1 + 2')
896 * #=> <RubyVM::InstructionSequence:<compiled>@<compiled>>
897 * iseq.label
898 * #=> "<compiled>"
899 *
900 * Using ::compile_file:
901 *
902 * # /tmp/method.rb
903 * def hello
904 * puts "hello, world"
905 * end
906 *
907 * # in irb
908 * > iseq = RubyVM::InstructionSequence.compile_file('/tmp/method.rb')
909 * > iseq.label #=> <main>
910 */
911 VALUE
912 rb_iseq_label(VALUE self)
913 {
914 rb_iseq_t *iseq;
915 GetISeqPtr(self, iseq);
916 return iseq->location.label;
917 }
918
919 /* Returns the base label of this instruction sequence.
920 *
921 * For example, using irb:
922 *
923 * iseq = RubyVM::InstructionSequence.compile('num = 1 + 2')
924 * #=> <RubyVM::InstructionSequence:<compiled>@<compiled>>
925 * iseq.base_label
926 * #=> "<compiled>"
927 *
928 * Using ::compile_file:
929 *
930 * # /tmp/method.rb
931 * def hello
932 * puts "hello, world"
933 * end
934 *
935 * # in irb
936 * > iseq = RubyVM::InstructionSequence.compile_file('/tmp/method.rb')
937 * > iseq.base_label #=> <main>
938 */
939 VALUE
940 rb_iseq_base_label(VALUE self)
941 {
942 rb_iseq_t *iseq;
943 GetISeqPtr(self, iseq);
944 return iseq->location.base_label;
945 }
946
947 /* Returns the number of the first source line where the instruction sequence
948 * was loaded from.
949 *
950 * For example, using irb:
951 *
952 * iseq = RubyVM::InstructionSequence.compile('num = 1 + 2')
953 * #=> <RubyVM::InstructionSequence:<compiled>@<compiled>>
954 * iseq.first_lineno
955 * #=> 1
956 */
957 VALUE
958 rb_iseq_first_lineno(VALUE self)
959 {
960 rb_iseq_t *iseq;
961 GetISeqPtr(self, iseq);
962 return iseq->location.first_lineno;
963 }
964
965 VALUE
966 rb_iseq_klass(VALUE self)
967 {
968 rb_iseq_t *iseq;
969 GetISeqPtr(self, iseq);
970 return iseq->local_iseq->klass;
971 }
972
973 VALUE
974 rb_iseq_method_name(VALUE self)
975 {
976 rb_iseq_t *iseq, *local_iseq;
977 GetISeqPtr(self, iseq);
978 local_iseq = iseq->local_iseq;
979 if (local_iseq->type == ISEQ_TYPE_METHOD) {
980 return local_iseq->location.base_label;
981 }
982 else {
983 return Qnil;
984 }
985 }
986
987 static
988 VALUE iseq_data_to_ary(rb_iseq_t *iseq);
989
990 /*
991 * call-seq:
992 * iseq.to_a -> ary
993 *
994 * Returns an Array with 14 elements representing the instruction sequence
995 * with the following data:
996 *
997 * [magic]
998 * A string identifying the data format. <b>Always
999 * +YARVInstructionSequence/SimpleDataFormat+.</b>
1000 *
1001 * [major_version]
1002 * The major version of the instruction sequence.
1003 *
1004 * [minor_version]
1005 * The minor version of the instruction sequence.
1006 *
1007 * [format_type]
1008 * A number identifying the data format. <b>Always 1</b>.
1009 *
1010 * [misc]
1011 * A hash containing:
1012 *
1013 * [+:arg_size+]
1014 * the total number of arguments taken by the method or the block (0 if
1015 * _iseq_ doesn't represent a method or block)
1016 * [+:local_size+]
1017 * the number of local variables + 1
1018 * [+:stack_max+]
1019 * used in calculating the stack depth at which a SystemStackError is
1020 * thrown.
1021 *
1022 * [#label]
1023 * The name of the context (block, method, class, module, etc.) that this
1024 * instruction sequence belongs to.
1025 *
1026 * <code><main></code> if it's at the top level, <code><compiled></code> if
1027 * it was evaluated from a string.
1028 *
1029 * [#path]
1030 * The relative path to the Ruby file where the instruction sequence was
1031 * loaded from.
1032 *
1033 * <code><compiled></code> if the iseq was evaluated from a string.
1034 *
1035 * [#absolute_path]
1036 * The absolute path to the Ruby file where the instruction sequence was
1037 * loaded from.
1038 *
1039 * +nil+ if the iseq was evaluated from a string.
1040 *
1041 * [#first_lineno]
1042 * The number of the first source line where the instruction sequence was
1043 * loaded from.
1044 *
1045 * [type]
1046 * The type of the instruction sequence.
1047 *
1048 * Valid values are +:top+, +:method+, +:block+, +:class+, +:rescue+,
1049 * +:ensure+, +:eval+, +:main+, and +:defined_guard+.
1050 *
1051 * [locals]
1052 * An array containing the names of all arguments and local variables as
1053 * symbols.
1054 *
1055 * [args]
1056 * The arity if the method or block only has required arguments.
1057 *
1058 * Otherwise an array of:
1059 *
1060 * [required_argc, [optional_arg_labels, ...],
1061 * splat_index, post_splat_argc, post_splat_index,
1062 * block_index, simple]
1063 *
1064 * More info about these values can be found in +vm_core.h+.
1065 *
1066 * [catch_table]
1067 * A list of exceptions and control flow operators (rescue, next, redo,
1068 * break, etc.).
1069 *
1070 * [bytecode]
1071 * An array of arrays containing the instruction names and operands that
1072 * make up the body of the instruction sequence.
1073 *
1074 */
1075 static VALUE
1076 iseq_to_a(VALUE self)
1077 {
1078 rb_iseq_t *iseq = iseq_check(self);
1079 rb_secure(1);
1080 return iseq_data_to_ary(iseq);
1081 }
1082
1083 /* TODO: search algorithm is brute force.
1084 this should be binary search or so. */
1085
1086 static struct iseq_line_info_entry *
1087 get_line_info(const rb_iseq_t *iseq, size_t pos)
1088 {
1089 size_t i = 0, size = iseq->line_info_size;
1090 struct iseq_line_info_entry *table = iseq->line_info_table;
1091 const int debug = 0;
1092
1093 if (debug) {
1094 printf("size: %"PRIdSIZE"\n", size);
1095 printf("table[%"PRIdSIZE"]: position: %d, line: %d, pos: %"PRIdSIZE"\n",
1096 i, table[i].position, table[i].line_no, pos);
1097 }
1098
1099 if (size == 0) {
1100 return 0;
1101 }
1102 else if (size == 1) {
1103 return &table[0];
1104 }
1105 else {
1106 for (i=1; i<size; i++) {
1107 if (debug) printf("table[%"PRIdSIZE"]: position: %d, line: %d, pos: %"PRIdSIZE"\n",
1108 i, table[i].position, table[i].line_no, pos);
1109
1110 if (table[i].position == pos) {
1111 return &table[i];
1112 }
1113 if (table[i].position > pos) {
1114 return &table[i-1];
1115 }
1116 }
1117 }
1118 return &table[i-1];
1119 }
1120
1121 static unsigned int
1122 find_line_no(const rb_iseq_t *iseq, size_t pos)
1123 {
1124 struct iseq_line_info_entry *entry = get_line_info(iseq, pos);
1125 if (entry) {
1126 return entry->line_no;
1127 }
1128 else {
1129 return 0;
1130 }
1131 }
1132
1133 unsigned int
1134 rb_iseq_line_no(const rb_iseq_t *iseq, size_t pos)
1135 {
1136 if (pos == 0) {
1137 return find_line_no(iseq, pos);
1138 }
1139 else {
1140 return find_line_no(iseq, pos - 1);
1141 }
1142 }
1143
1144 static VALUE
1145 id_to_name(ID id, VALUE default_value)
1146 {
1147 VALUE str = rb_id2str(id);
1148 if (!str) {
1149 str = default_value;
1150 }
1151 else if (!rb_str_symname_p(str)) {
1152 str = rb_str_inspect(str);
1153 }
1154 return str;
1155 }
1156
1157 VALUE
1158 rb_insn_operand_intern(rb_iseq_t *iseq,
1159 VALUE insn, int op_no, VALUE op,
1160 int len, size_t pos, VALUE *pnop, VALUE child)
1161 {
1162 const char *types = insn_op_types(insn);
1163 char type = types[op_no];
1164 VALUE ret;
1165
1166 switch (type) {
1167 case TS_OFFSET: /* LONG */
1168 ret = rb_sprintf("%"PRIdVALUE, (VALUE)(pos + len + op));
1169 break;
1170
1171 case TS_NUM: /* ULONG */
1172 ret = rb_sprintf("%"PRIuVALUE, op);
1173 break;
1174
1175 case TS_LINDEX:{
1176 if (insn == BIN(getlocal) || insn == BIN(setlocal)) {
1177 if (pnop) {
1178 rb_iseq_t *diseq = iseq;
1179 VALUE level = *pnop, i;
1180
1181 for (i = 0; i < level; i++) {
1182 diseq = diseq->parent_iseq;
1183 }
1184 ret = id_to_name(diseq->local_table[diseq->local_size - op], INT2FIX('*'));
1185 }
1186 else {
1187 ret = rb_sprintf("%"PRIuVALUE, op);
1188 }
1189 }
1190 else {
1191 ret = rb_inspect(INT2FIX(op));
1192 }
1193 break;
1194 }
1195 case TS_ID: /* ID (symbol) */
1196 op = ID2SYM(op);
1197
1198 case TS_VALUE: /* VALUE */
1199 op = obj_resurrect(op);
1200 ret = rb_inspect(op);
1201 if (CLASS_OF(op) == rb_cISeq) {
1202 if (child) {
1203 rb_ary_push(child, op);
1204 }
1205 }
1206 break;
1207
1208 case TS_ISEQ: /* iseq */
1209 {
1210 rb_iseq_t *iseq = (rb_iseq_t *)op;
1211 if (iseq) {
1212 ret = iseq->location.label;
1213 if (child) {
1214 rb_ary_push(child, iseq->self);
1215 }
1216 }
1217 else {
1218 ret = rb_str_new2("nil");
1219 }
1220 break;
1221 }
1222 case TS_GENTRY:
1223 {
1224 struct rb_global_entry *entry = (struct rb_global_entry *)op;
1225 ret = rb_str_dup(rb_id2str(entry->id));
1226 }
1227 break;
1228
1229 case TS_IC:
1230 ret = rb_sprintf("<is:%"PRIdPTRDIFF">", (union iseq_inline_storage_entry *)op - iseq->is_entries);
1231 break;
1232
1233 case TS_CALLINFO:
1234 {
1235 rb_call_info_t *ci = (rb_call_info_t *)op;
1236 VALUE ary = rb_ary_new();
1237
1238 if (ci->mid) {
1239 rb_ary_push(ary, rb_sprintf("mid:%s", rb_id2name(ci->mid)));
1240 }
1241
1242 rb_ary_push(ary, rb_sprintf("argc:%d", ci->orig_argc));
1243
1244 if (ci->blockiseq) {
1245 if (child) {
1246 rb_ary_push(child, ci->blockiseq->self);
1247 }
1248 rb_ary_push(ary, rb_sprintf("block:%"PRIsVALUE, ci->blockiseq->location.label));
1249 }
1250
1251 if (ci->flag) {
1252 VALUE flags = rb_ary_new();
1253 if (ci->flag & VM_CALL_ARGS_SPLAT) rb_ary_push(flags, rb_str_new2("ARGS_SPLAT"));
1254 if (ci->flag & VM_CALL_ARGS_BLOCKARG) rb_ary_push(flags, rb_str_new2("ARGS_BLOCKARG"));
1255 if (ci->flag & VM_CALL_FCALL) rb_ary_push(flags, rb_str_new2("FCALL"));
1256 if (ci->flag & VM_CALL_VCALL) rb_ary_push(flags, rb_str_new2("VCALL"));
1257 if (ci->flag & VM_CALL_TAILCALL) rb_ary_push(flags, rb_str_new2("TAILCALL"));
1258 if (ci->flag & VM_CALL_SUPER) rb_ary_push(flags, rb_str_new2("SUPER"));
1259 if (ci->flag & VM_CALL_OPT_SEND) rb_ary_push(flags, rb_str_new2("SNED")); /* maybe not reachable */
1260 if (ci->flag & VM_CALL_ARGS_SKIP_SETUP) rb_ary_push(flags, rb_str_new2("ARGS_SKIP")); /* maybe not reachable */
1261 rb_ary_push(ary, rb_ary_join(flags, rb_str_new2("|")));
1262 }
1263 ret = rb_sprintf("<callinfo!%"PRIsVALUE">", rb_ary_join(ary, rb_str_new2(", ")));
1264 }
1265 break;
1266
1267 case TS_CDHASH:
1268 ret = rb_str_new2("<cdhash>");
1269 break;
1270
1271 case TS_FUNCPTR:
1272 ret = rb_str_new2("<funcptr>");
1273 break;
1274
1275 default:
1276 rb_bug("insn_operand_intern: unknown operand type: %c", type);
1277 }
1278 return ret;
1279 }
1280
1285 int
1286 rb_iseq_disasm_insn(VALUE ret, VALUE *iseq, size_t pos,
1287 rb_iseq_t *iseqdat, VALUE child)
1288 {
1289 VALUE insn = iseq[pos];
1290 int len = insn_len(insn);
1291 int j;
1292 const char *types = insn_op_types(insn);
1293 VALUE str = rb_str_new(0, 0);
1294 const char *insn_name_buff;
1295
1296 insn_name_buff = insn_name(insn);
1297 if (1) {
1298 rb_str_catf(str, "%04"PRIdSIZE" %-16s ", pos, insn_name_buff);
1299 }
1300 else {
1301 rb_str_catf(str, "%04"PRIdSIZE" %-16.*s ", pos,
1302 (int)strcspn(insn_name_buff, "_"), insn_name_buff);
1303 }
1304
1305 for (j = 0; types[j]; j++) {
1306 const char *types = insn_op_types(insn);
1307 VALUE opstr = rb_insn_operand_intern(iseqdat, insn, j, iseq[pos + j + 1],
1308 len, pos, &iseq[pos + j + 2],
1309 child);
1310 rb_str_concat(str, opstr);
1311
1312 if (types[j + 1]) {
1313 rb_str_cat2(str, ", ");
1314 }
1315 }
1316
1317 {
1318 unsigned int line_no = find_line_no(iseqdat, pos);
1319 unsigned int prev = pos == 0 ? 0 : find_line_no(iseqdat, pos - 1);
1320 if (line_no && line_no != prev) {
1321 long slen = RSTRING_LEN(str);
1322 slen = (slen > 70) ? 0 : (70 - slen);
1323 str = rb_str_catf(str, "%*s(%4d)", (int)slen, "", line_no);
1324 }
1325 }
1326
1327 if (ret) {
1328 rb_str_cat2(str, "\n");
1329 rb_str_concat(ret, str);
1330 }
1331 else {
1332 printf("%s\n", RSTRING_PTR(str));
1333 }
1334 return len;
1335 }
1336
1337 static const char *
1338 catch_type(int type)
1339 {
1340 switch (type) {
1341 case CATCH_TYPE_RESCUE:
1342 return "rescue";
1343 case CATCH_TYPE_ENSURE:
1344 return "ensure";
1345 case CATCH_TYPE_RETRY:
1346 return "retry";
1347 case CATCH_TYPE_BREAK:
1348 return "break";
1349 case CATCH_TYPE_REDO:
1350 return "redo";
1351 case CATCH_TYPE_NEXT:
1352 return "next";
1353 default:
1354 rb_bug("unknown catch type (%d)", type);
1355 return 0;
1356 }
1357 }
1358
1359 /*
1360 * call-seq:
1361 * iseq.disasm -> str
1362 * iseq.disassemble -> str
1363 *
1364 * Returns the instruction sequence as a +String+ in human readable form.
1365 *
1366 * puts RubyVM::InstructionSequence.compile('1 + 2').disasm
1367 *
1368 * Produces:
1369 *
1370 * == disasm: <RubyVM::InstructionSequence:<compiled>@<compiled>>==========
1371 * 0000 trace 1 ( 1)
1372 * 0002 putobject 1
1373 * 0004 putobject 2
1374 * 0006 opt_plus <ic:1>
1375 * 0008 leave
1376 */
1377 VALUE
1378 rb_iseq_disasm(VALUE self)
1379 {
1380 rb_iseq_t *iseqdat = iseq_check(self);
1381 VALUE *iseq;
1382 VALUE str = rb_str_new(0, 0);
1383 VALUE child = rb_ary_new();
1384 unsigned long size;
1385 int i;
1386 long l;
1387 ID *tbl;
1388 size_t n;
1389 enum {header_minlen = 72};
1390
1391 rb_secure(1);
1392
1393 iseq = iseqdat->iseq;
1394 size = iseqdat->iseq_size;
1395
1396 rb_str_cat2(str, "== disasm: ");
1397
1398 rb_str_concat(str, iseq_inspect(iseqdat->self));
1399 if ((l = RSTRING_LEN(str)) < header_minlen) {
1400 rb_str_resize(str, header_minlen);
1401 memset(RSTRING_PTR(str) + l, '=', header_minlen - l);
1402 }
1403 rb_str_cat2(str, "\n");
1404
1405 /* show catch table information */
1406 if (iseqdat->catch_table_size != 0) {
1407 rb_str_cat2(str, "== catch table\n");
1408 }
1409 for (i = 0; i < iseqdat->catch_table_size; i++) {
1410 struct iseq_catch_table_entry *entry = &iseqdat->catch_table[i];
1411 rb_str_catf(str,
1412 "| catch type: %-6s st: %04d ed: %04d sp: %04d cont: %04d\n",
1413 catch_type((int)entry->type), (int)entry->start,
1414 (int)entry->end, (int)entry->sp, (int)entry->cont);
1415 if (entry->iseq) {
1416 rb_str_concat(str, rb_iseq_disasm(entry->iseq));
1417 }
1418 }
1419 if (iseqdat->catch_table_size != 0) {
1420 rb_str_cat2(str, "|-------------------------------------"
1421 "-----------------------------------\n");
1422 }
1423
1424 /* show local table information */
1425 tbl = iseqdat->local_table;
1426
1427 if (tbl) {
1428 rb_str_catf(str,
1429 "local table (size: %d, argc: %d "
1430 "[opts: %d, rest: %d, post: %d, block: %d, keyword: %d@%d] s%d)\n",
1431 iseqdat->local_size, iseqdat->argc,
1432 iseqdat->arg_opts, iseqdat->arg_rest,
1433 iseqdat->arg_post_len, iseqdat->arg_block,
1434 iseqdat->arg_keywords, iseqdat->local_size-iseqdat->arg_keyword,
1435 iseqdat->arg_simple);
1436
1437 for (i = 0; i < iseqdat->local_table_size; i++) {
1438 long width;
1439 VALUE name = id_to_name(tbl[i], 0);
1440 char argi[0x100] = "";
1441 char opti[0x100] = "";
1442
1443 if (iseqdat->arg_opts) {
1444 int argc = iseqdat->argc;
1445 int opts = iseqdat->arg_opts;
1446 if (i >= argc && i < argc + opts - 1) {
1447 snprintf(opti, sizeof(opti), "Opt=%"PRIdVALUE,
1448 iseqdat->arg_opt_table[i - argc]);
1449 }
1450 }
1451
1452 snprintf(argi, sizeof(argi), "%s%s%s%s%s", /* arg, opts, rest, post block */
1453 iseqdat->argc > i ? "Arg" : "",
1454 opti,
1455 iseqdat->arg_rest == i ? "Rest" : "",
1456 (iseqdat->arg_post_start <= i &&
1457 i < iseqdat->arg_post_start + iseqdat->arg_post_len) ? "Post" : "",
1458 iseqdat->arg_block == i ? "Block" : "");
1459
1460 rb_str_catf(str, "[%2d] ", iseqdat->local_size - i);
1461 width = RSTRING_LEN(str) + 11;
1462 if (name)
1463 rb_str_append(str, name);
1464 else
1465 rb_str_cat2(str, "?");
1466 if (*argi) rb_str_catf(str, "<%s>", argi);
1467 if ((width -= RSTRING_LEN(str)) > 0) rb_str_catf(str, "%*s", (int)width, "");
1468 }
1469 rb_str_cat2(str, "\n");
1470 }
1471
1472 /* show each line */
1473 for (n = 0; n < size;) {
1474 n += rb_iseq_disasm_insn(str, iseq, n, iseqdat, child);
1475 }
1476
1477 for (i = 0; i < RARRAY_LEN(child); i++) {
1478 VALUE isv = rb_ary_entry(child, i);
1479 rb_str_concat(str, rb_iseq_disasm(isv));
1480 }
1481
1482 return str;
1483 }
1484
1485 /*
1486 * Returns the instruction sequence containing the given proc or method.
1487 *
1488 * For example, using irb:
1489 *
1490 * # a proc
1491 * > p = proc { num = 1 + 2 }
1492 * > RubyVM::InstructionSequence.of(p)
1493 * > #=> <RubyVM::InstructionSequence:block in irb_binding@(irb)>
1494 *
1495 * # for a method
1496 * > def foo(bar); puts bar; end
1497 * > RubyVM::InstructionSequence.of(method(:foo))
1498 * > #=> <RubyVM::InstructionSequence:foo@(irb)>
1499 *
1500 * Using ::compile_file:
1501 *
1502 * # /tmp/iseq_of.rb
1503 * def hello
1504 * puts "hello, world"
1505 * end
1506 *
1507 * $a_global_proc = proc { str = 'a' + 'b' }
1508 *
1509 * # in irb
1510 * > require '/tmp/iseq_of.rb'
1511 *
1512 * # first the method hello
1513 * > RubyVM::InstructionSequence.of(method(:hello))
1514 * > #=> #<RubyVM::InstructionSequence:0x007fb73d7cb1d0>
1515 *
1516 * # then the global proc
1517 * > RubyVM::InstructionSequence.of($a_global_proc)
1518 * > #=> #<RubyVM::InstructionSequence:0x007fb73d7caf78>
1519 */
1520 static VALUE
1521 iseq_s_of(VALUE klass, VALUE body)
1522 {
1523 VALUE ret = Qnil;
1524 rb_iseq_t *iseq;
1525
1526 rb_secure(1);
1527
1528 if (rb_obj_is_proc(body)) {
1529 rb_proc_t *proc;
1530 GetProcPtr(body, proc);
1531 iseq = proc->block.iseq;
1532 if (RUBY_VM_NORMAL_ISEQ_P(iseq)) {
1533 ret = iseq->self;
1534 }
1535 }
1536 else if ((iseq = rb_method_get_iseq(body)) != 0) {
1537 ret = iseq->self;
1538 }
1539 return ret;
1540 }
1541
1542 /*
1543 * call-seq:
1544 * InstructionSequence.disasm(body) -> str
1545 * InstructionSequence.disassemble(body) -> str
1546 *
1547 * Takes +body+, a Method or Proc object, and returns a String with the
1548 * human readable instructions for +body+.
1549 *
1550 * For a Method object:
1551 *
1552 * # /tmp/method.rb
1553 * def hello
1554 * puts "hello, world"
1555 * end
1556 *
1557 * puts RubyVM::InstructionSequence.disasm(method(:hello))
1558 *
1559 * Produces:
1560 *
1561 * == disasm: <RubyVM::InstructionSequence:hello@/tmp/method.rb>============
1562 * 0000 trace 8 ( 1)
1563 * 0002 trace 1 ( 2)
1564 * 0004 putself
1565 * 0005 putstring "hello, world"
1566 * 0007 send :puts, 1, nil, 8, <ic:0>
1567 * 0013 trace 16 ( 3)
1568 * 0015 leave ( 2)
1569 *
1570 * For a Proc:
1571 *
1572 * # /tmp/proc.rb
1573 * p = proc { num = 1 + 2 }
1574 * puts RubyVM::InstructionSequence.disasm(p)
1575 *
1576 * Produces:
1577 *
1578 * == disasm: <RubyVM::InstructionSequence:block in <main>@/tmp/proc.rb>===
1579 * == catch table
1580 * | catch type: redo st: 0000 ed: 0012 sp: 0000 cont: 0000
1581 * | catch type: next st: 0000 ed: 0012 sp: 0000 cont: 0012
1582 * |------------------------------------------------------------------------
1583 * local table (size: 2, argc: 0 [opts: 0, rest: -1, post: 0, block: -1] s1)
1584 * [ 2] num
1585 * 0000 trace 1 ( 1)
1586 * 0002 putobject 1
1587 * 0004 putobject 2
1588 * 0006 opt_plus <ic:1>
1589 * 0008 dup
1590 * 0009 setlocal num, 0
1591 * 0012 leave
1592 *
1593 */
1594
1595 static VALUE
1596 iseq_s_disasm(VALUE klass, VALUE body)
1597 {
1598 VALUE iseqval = iseq_s_of(klass, body);
1599 return NIL_P(iseqval) ? Qnil : rb_iseq_disasm(iseqval);
1600 }
1601
1602 const char *
1603 ruby_node_name(int node)
1604 {
1605 switch (node) {
1606 #include "node_name.inc"
1607 default:
1608 rb_bug("unknown node (%d)", node);
1609 return 0;
1610 }
1611 }
1612
1613 #define DECL_SYMBOL(name) \
1614 static VALUE sym_##name
1615
1616 #define INIT_SYMBOL(name) \
1617 sym_##name = ID2SYM(rb_intern(#name))
1618
1619 static VALUE
1620 register_label(struct st_table *table, unsigned long idx)
1621 {
1622 VALUE sym;
1623 char buff[8 + (sizeof(idx) * CHAR_BIT * 32 / 100)];
1624
1625 snprintf(buff, sizeof(buff), "label_%lu", idx);
1626 sym = ID2SYM(rb_intern(buff));
1627 st_insert(table, idx, sym);
1628 return sym;
1629 }
1630
1631 static VALUE
1632 exception_type2symbol(VALUE type)
1633 {
1634 ID id;
1635 switch (type) {
1636 case CATCH_TYPE_RESCUE: CONST_ID(id, "rescue"); break;
1637 case CATCH_TYPE_ENSURE: CONST_ID(id, "ensure"); break;
1638 case CATCH_TYPE_RETRY: CONST_ID(id, "retry"); break;
1639 case CATCH_TYPE_BREAK: CONST_ID(id, "break"); break;
1640 case CATCH_TYPE_REDO: CONST_ID(id, "redo"); break;
1641 case CATCH_TYPE_NEXT: CONST_ID(id, "next"); break;
1642 default:
1643 rb_bug("...");
1644 }
1645 return ID2SYM(id);
1646 }
1647
1648 static int
1649 cdhash_each(VALUE key, VALUE value, VALUE ary)
1650 {
1651 rb_ary_push(ary, obj_resurrect(key));
1652 rb_ary_push(ary, value);
1653 return ST_CONTINUE;
1654 }
1655
1656 static VALUE
1657 iseq_data_to_ary(rb_iseq_t *iseq)
1658 {
1659 long i;
1660 size_t ti;
1661 unsigned int pos;
1662 unsigned int line = 0;
1663 VALUE *seq;
1664
1665 VALUE val = rb_ary_new();
1666 VALUE type; /* Symbol */
1667 VALUE locals = rb_ary_new();
1668 VALUE args = rb_ary_new();
1669 VALUE body = rb_ary_new(); /* [[:insn1, ...], ...] */
1670 VALUE nbody;
1671 VALUE exception = rb_ary_new(); /* [[....]] */
1672 VALUE misc = rb_hash_new();
1673
1674 static VALUE insn_syms[VM_INSTRUCTION_SIZE];
1675 struct st_table *labels_table = st_init_numtable();
1676
1677 DECL_SYMBOL(top);
1678 DECL_SYMBOL(method);
1679 DECL_SYMBOL(block);
1680 DECL_SYMBOL(class);
1681 DECL_SYMBOL(rescue);
1682 DECL_SYMBOL(ensure);
1683 DECL_SYMBOL(eval);
1684 DECL_SYMBOL(main);
1685 DECL_SYMBOL(defined_guard);
1686
1687 if (sym_top == 0) {
1688 int i;
1689 for (i=0; i<VM_INSTRUCTION_SIZE; i++) {
1690 insn_syms[i] = ID2SYM(rb_intern(insn_name(i)));
1691 }
1692 INIT_SYMBOL(top);
1693 INIT_SYMBOL(method);
1694 INIT_SYMBOL(block);
1695 INIT_SYMBOL(class);
1696 INIT_SYMBOL(rescue);
1697 INIT_SYMBOL(ensure);
1698 INIT_SYMBOL(eval);
1699 INIT_SYMBOL(main);
1700 INIT_SYMBOL(defined_guard);
1701 }
1702
1703 /* type */
1704 switch (iseq->type) {
1705 case ISEQ_TYPE_TOP: type = sym_top; break;
1706 case ISEQ_TYPE_METHOD: type = sym_method; break;
1707 case ISEQ_TYPE_BLOCK: type = sym_block; break;
1708 case ISEQ_TYPE_CLASS: type = sym_class; break;
1709 case ISEQ_TYPE_RESCUE: type = sym_rescue; break;
1710 case ISEQ_TYPE_ENSURE: type = sym_ensure; break;
1711 case ISEQ_TYPE_EVAL: type = sym_eval; break;
1712 case ISEQ_TYPE_MAIN: type = sym_main; break;
1713 case ISEQ_TYPE_DEFINED_GUARD: type = sym_defined_guard; break;
1714 default: rb_bug("unsupported iseq type");
1715 };
1716
1717 /* locals */
1718 for (i=0; i<iseq->local_table_size; i++) {
1719 ID lid = iseq->local_table[i];
1720 if (lid) {
1721 if (rb_id2str(lid)) rb_ary_push(locals, ID2SYM(lid));
1722 }
1723 else {
1724 rb_ary_push(locals, ID2SYM(rb_intern("#arg_rest")));
1725 }
1726 }
1727
1728 /* args */
1729 {
1730 /*
1731 * [argc, # argc
1732 * [label1, label2, ...] # opts
1733 * rest index,
1734 * post_len
1735 * post_start
1736 * block index,
1737 * simple,
1738 * ]
1739 */
1740 VALUE arg_opt_labels = rb_ary_new();
1741 int j;
1742
1743 for (j=0; j<iseq->arg_opts; j++) {
1744 rb_ary_push(arg_opt_labels,
1745 register_label(labels_table, iseq->arg_opt_table[j]));
1746 }
1747
1748 /* commit */
1749 if (iseq->arg_simple == 1) {
1750 args = INT2FIX(iseq->argc);
1751 }
1752 else {
1753 rb_ary_push(args, INT2FIX(iseq->argc));
1754 rb_ary_push(args, arg_opt_labels);
1755 rb_ary_push(args, INT2FIX(iseq->arg_post_len));
1756 rb_ary_push(args, INT2FIX(iseq->arg_post_start));
1757 rb_ary_push(args, INT2FIX(iseq->arg_rest));
1758 rb_ary_push(args, INT2FIX(iseq->arg_block));
1759 rb_ary_push(args, INT2FIX(iseq->arg_simple));
1760 }
1761 }
1762
1763 /* body */
1764 for (seq = iseq->iseq; seq < iseq->iseq + iseq->iseq_size; ) {
1765 VALUE insn = *seq++;
1766 int j, len = insn_len(insn);
1767 VALUE *nseq = seq + len - 1;
1768 VALUE ary = rb_ary_new2(len);
1769
1770 rb_ary_push(ary, insn_syms[insn]);
1771 for (j=0; j<len-1; j++, seq++) {
1772 switch (insn_op_type(insn, j)) {
1773 case TS_OFFSET: {
1774 unsigned long idx = nseq - iseq->iseq + *seq;
1775 rb_ary_push(ary, register_label(labels_table, idx));
1776 break;
1777 }
1778 case TS_LINDEX:
1779 case TS_NUM:
1780 rb_ary_push(ary, INT2FIX(*seq));
1781 break;
1782 case TS_VALUE:
1783 rb_ary_push(ary, obj_resurrect(*seq));
1784 break;
1785 case TS_ISEQ:
1786 {
1787 rb_iseq_t *iseq = (rb_iseq_t *)*seq;
1788 if (iseq) {
1789 VALUE val = iseq_data_to_ary(iseq);
1790 rb_ary_push(ary, val);
1791 }
1792 else {
1793 rb_ary_push(ary, Qnil);
1794 }
1795 }
1796 break;
1797 case TS_GENTRY:
1798 {
1799 struct rb_global_entry *entry = (struct rb_global_entry *)*seq;
1800 rb_ary_push(ary, ID2SYM(entry->id));
1801 }
1802 break;
1803 case TS_IC:
1804 {
1805 union iseq_inline_storage_entry *is = (union iseq_inline_storage_entry *)*seq;
1806 rb_ary_push(ary, INT2FIX(is - iseq->is_entries));
1807 }
1808 break;
1809 case TS_CALLINFO:
1810 {
1811 rb_call_info_t *ci = (rb_call_info_t *)*seq;
1812 VALUE e = rb_hash_new();
1813 rb_hash_aset(e, ID2SYM(rb_intern("mid")), ci->mid ? ID2SYM(ci->mid) : Qnil);
1814 rb_hash_aset(e, ID2SYM(rb_intern("flag")), ULONG2NUM(ci->flag));
1815 rb_hash_aset(e, ID2SYM(rb_intern("orig_argc")), INT2FIX(ci->orig_argc));
1816 rb_hash_aset(e, ID2SYM(rb_intern("blockptr")), ci->blockiseq ? iseq_data_to_ary(ci->blockiseq) : Qnil);
1817 rb_ary_push(ary, e);
1818 }
1819 break;
1820 case TS_ID:
1821 rb_ary_push(ary, ID2SYM(*seq));
1822 break;
1823 case TS_CDHASH:
1824 {
1825 VALUE hash = *seq;
1826 VALUE val = rb_ary_new();
1827 int i;
1828
1829 rb_hash_foreach(hash, cdhash_each, val);
1830
1831 for (i=0; i<RARRAY_LEN(val); i+=2) {
1832 VALUE pos = FIX2INT(rb_ary_entry(val, i+1));
1833 unsigned long idx = nseq - iseq->iseq + pos;
1834
1835 rb_ary_store(val, i+1,
1836 register_label(labels_table, idx));
1837 }
1838 rb_ary_push(ary, val);
1839 }
1840 break;
1841 default:
1842 rb_bug("unknown operand: %c", insn_op_type(insn, j));
1843 }
1844 }
1845 rb_ary_push(body, ary);
1846 }
1847
1848 nbody = body;
1849
1850 /* exception */
1851 for (i=0; i<iseq->catch_table_size; i++) {
1852 VALUE ary = rb_ary_new();
1853 struct iseq_catch_table_entry *entry = &iseq->catch_table[i];
1854 rb_ary_push(ary, exception_type2symbol(entry->type));
1855 if (entry->iseq) {
1856 rb_iseq_t *eiseq;
1857 GetISeqPtr(entry->iseq, eiseq);
1858 rb_ary_push(ary, iseq_data_to_ary(eiseq));
1859 }
1860 else {
1861 rb_ary_push(ary, Qnil);
1862 }
1863 rb_ary_push(ary, register_label(labels_table, entry->start));
1864 rb_ary_push(ary, register_label(labels_table, entry->end));
1865 rb_ary_push(ary, register_label(labels_table, entry->cont));
1866 rb_ary_push(ary, INT2FIX(entry->sp));
1867 rb_ary_push(exception, ary);
1868 }
1869
1870 /* make body with labels and insert line number */
1871 body = rb_ary_new();
1872 ti = 0;
1873
1874 for (i=0, pos=0; i<RARRAY_LEN(nbody); i++) {
1875 VALUE ary = RARRAY_AREF(nbody, i);
1876 st_data_t label;
1877
1878 if (st_lookup(labels_table, pos, &label)) {
1879 rb_ary_push(body, (VALUE)label);
1880 }
1881
1882 if (ti < iseq->line_info_size && iseq->line_info_table[ti].position == pos) {
1883 line = iseq->line_info_table[ti].line_no;
1884 rb_ary_push(body, INT2FIX(line));
1885 ti++;
1886 }
1887
1888 rb_ary_push(body, ary);
1889 pos += RARRAY_LENINT(ary); /* reject too huge data */
1890 }
1891
1892 st_free_table(labels_table);
1893
1894 rb_hash_aset(misc, ID2SYM(rb_intern("arg_size")), INT2FIX(iseq->arg_size));
1895 rb_hash_aset(misc, ID2SYM(rb_intern("local_size")), INT2FIX(iseq->local_size));
1896 rb_hash_aset(misc, ID2SYM(rb_intern("stack_max")), INT2FIX(iseq->stack_max));
1897
1898 /* TODO: compatibility issue */
1899 /*
1900 * [:magic, :major_version, :minor_version, :format_type, :misc,
1901 * :name, :path, :absolute_path, :start_lineno, :type, :locals, :args,
1902 * :catch_table, :bytecode]
1903 */
1904 rb_ary_push(val, rb_str_new2("YARVInstructionSequence/SimpleDataFormat"));
1905 rb_ary_push(val, INT2FIX(ISEQ_MAJOR_VERSION)); /* major */
1906 rb_ary_push(val, INT2FIX(ISEQ_MINOR_VERSION)); /* minor */
1907 rb_ary_push(val, INT2FIX(1));
1908 rb_ary_push(val, misc);
1909 rb_ary_push(val, iseq->location.label);
1910 rb_ary_push(val, iseq->location.path);
1911 rb_ary_push(val, iseq->location.absolute_path);
1912 rb_ary_push(val, iseq->location.first_lineno);
1913 rb_ary_push(val, type);
1914 rb_ary_push(val, locals);
1915 rb_ary_push(val, args);
1916 rb_ary_push(val, exception);
1917 rb_ary_push(val, body);
1918 return val;
1919 }
1920
1921 VALUE
1922 rb_iseq_clone(VALUE iseqval, VALUE newcbase)
1923 {
1924 VALUE newiseq = iseq_alloc(rb_cISeq);
1925 rb_iseq_t *iseq0, *iseq1;
1926
1927 GetISeqPtr(iseqval, iseq0);
1928 GetISeqPtr(newiseq, iseq1);
1929
1930 MEMCPY(iseq1, iseq0, rb_iseq_t, 1); /* TODO: write barrier? */
1931
1932 iseq1->self = newiseq;
1933 if (!iseq1->orig) {
1934 RB_OBJ_WRITE(iseq1->self, &iseq1->orig, iseqval);
1935 }
1936 if (iseq0->local_iseq == iseq0) {
1937 iseq1->local_iseq = iseq1;
1938 }
1939 if (newcbase) {
1940 ISEQ_SET_CREF(iseq1, NEW_CREF(newcbase));
1941 RB_OBJ_WRITE(iseq1->cref_stack, &iseq1->cref_stack->nd_refinements, iseq0->cref_stack->nd_refinements);
1942 iseq1->cref_stack->nd_visi = iseq0->cref_stack->nd_visi;
1943 if (iseq0->cref_stack->nd_next) {
1944 RB_OBJ_WRITE(iseq1->cref_stack, &iseq1->cref_stack->nd_next, iseq0->cref_stack->nd_next);
1945 }
1946 RB_OBJ_WRITE(iseq1->self, &iseq1->klass, newcbase);
1947 }
1948
1949 return newiseq;
1950 }
1951
1952 VALUE
1953 rb_iseq_parameters(const rb_iseq_t *iseq, int is_proc)
1954 {
1955 int i, r;
1956 VALUE a, args = rb_ary_new2(iseq->arg_size);
1957 ID req, opt, rest, block, key, keyrest;
1958 #define PARAM_TYPE(type) rb_ary_push(a = rb_ary_new2(2), ID2SYM(type))
1959 #define PARAM_ID(i) iseq->local_table[(i)]
1960 #define PARAM(i, type) ( \
1961 PARAM_TYPE(type), \
1962 rb_id2str(PARAM_ID(i)) ? \
1963 rb_ary_push(a, ID2SYM(PARAM_ID(i))) : \
1964 a)
1965
1966 CONST_ID(req, "req");
1967 CONST_ID(opt, "opt");
1968 if (is_proc) {
1969 for (i = 0; i < iseq->argc; i++) {
1970 PARAM_TYPE(opt);
1971 rb_ary_push(a, rb_id2str(PARAM_ID(i)) ? ID2SYM(PARAM_ID(i)) : Qnil);
1972 rb_ary_push(args, a);
1973 }
1974 }
1975 else {
1976 for (i = 0; i < iseq->argc; i++) {
1977 rb_ary_push(args, PARAM(i, req));
1978 }
1979 }
1980 r = iseq->argc + iseq->arg_opts - 1;
1981 for (; i < r; i++) {
1982 PARAM_TYPE(opt);
1983 if (rb_id2str(PARAM_ID(i))) {
1984 rb_ary_push(a, ID2SYM(PARAM_ID(i)));
1985 }
1986 rb_ary_push(args, a);
1987 }
1988 if (iseq->arg_rest != -1) {
1989 CONST_ID(rest, "rest");
1990 rb_ary_push(args, PARAM(iseq->arg_rest, rest));
1991 }
1992 r = iseq->arg_post_start + iseq->arg_post_len;
1993 if (is_proc) {
1994 for (i = iseq->arg_post_start; i < r; i++) {
1995 PARAM_TYPE(opt);
1996 rb_ary_push(a, rb_id2str(PARAM_ID(i)) ? ID2SYM(PARAM_ID(i)) : Qnil);
1997 rb_ary_push(args, a);
1998 }
1999 }
2000 else {
2001 for (i = iseq->arg_post_start; i < r; i++) {
2002 rb_ary_push(args, PARAM(i, req));
2003 }
2004 }
2005 if (iseq->arg_keyword != -1) {
2006 i = 0;
2007 if (iseq->arg_keyword_required) {
2008 ID keyreq;
2009 CONST_ID(keyreq, "keyreq");
2010 for (; i < iseq->arg_keyword_required; i++) {
2011 PARAM_TYPE(keyreq);
2012 if (rb_id2str(iseq->arg_keyword_table[i])) {
2013 rb_ary_push(a, ID2SYM(iseq->arg_keyword_table[i]));
2014 }
2015 rb_ary_push(args, a);
2016 }
2017 }
2018 CONST_ID(key, "key");
2019 for (; i < iseq->arg_keywords; i++) {
2020 PARAM_TYPE(key);
2021 if (rb_id2str(iseq->arg_keyword_table[i])) {
2022 rb_ary_push(a, ID2SYM(iseq->arg_keyword_table[i]));
2023 }
2024 rb_ary_push(args, a);
2025 }
2026 if (!iseq->arg_keyword_check) {
2027 CONST_ID(keyrest, "keyrest");
2028 rb_ary_push(args, PARAM(iseq->arg_keyword, keyrest));
2029 }
2030 }
2031 if (iseq->arg_block != -1) {
2032 CONST_ID(block, "block");
2033 rb_ary_push(args, PARAM(iseq->arg_block, block));
2034 }
2035 return args;
2036 }
2037
2038 VALUE
2039 rb_iseq_defined_string(enum defined_type type)
2040 {
2041 static const char expr_names[][18] = {
2042 "nil",
2043 "instance-variable",
2044 "local-variable",
2045 "global-variable",
2046 "class variable",
2047 "constant",
2048 "method",
2049 "yield",
2050 "super",
2051 "self",
2052 "true",
2053 "false",
2054 "assignment",
2055 "expression",
2056 };
2057 const char *estr;
2058 VALUE *defs, str;
2059
2060 if ((unsigned)(type - 1) >= (unsigned)numberof(expr_names)) return 0;
2061 estr = expr_names[type - 1];
2062 if (!estr[0]) return 0;
2063 defs = GET_VM()->defined_strings;
2064 if (!defs) {
2065 defs = ruby_xcalloc(numberof(expr_names), sizeof(VALUE));
2066 GET_VM()->defined_strings = defs;
2067 }
2068 str = defs[type-1];
2069 if (!str) {
2070 str = rb_str_new_cstr(estr);;
2071 OBJ_FREEZE(str);
2072 defs[type-1] = str;
2073 }
2074 return str;
2075 }
2076
2077 /* ruby2cext */
2078
2079 VALUE
2080 rb_iseq_build_for_ruby2cext(
2081 const rb_iseq_t *iseq_template,
2082 const rb_insn_func_t *func,
2083 const struct iseq_line_info_entry *line_info_table,
2084 const char **local_table,
2085 const VALUE *arg_opt_table,
2086 const struct iseq_catch_table_entry *catch_table,
2087 const char *name,
2088 const char *path,
2089 const unsigned short first_lineno)
2090 {
2091 unsigned long i;
2092 VALUE iseqval = iseq_alloc(rb_cISeq);
2093 rb_iseq_t *iseq;
2094 GetISeqPtr(iseqval, iseq);
2095
2096 /* copy iseq */
2097 MEMCPY(iseq, iseq_template, rb_iseq_t, 1); /* TODO: write barrier, *iseq = *iseq_template; */
2098 RB_OBJ_WRITE(iseq->self, &iseq->location.label, rb_str_new2(name));
2099 RB_OBJ_WRITE(iseq->self, &iseq->location.path, rb_str_new2(path));
2100 iseq->location.first_lineno = first_lineno;
2101 RB_OBJ_WRITE(iseq->self, &iseq->mark_ary, 0);
2102 iseq->self = iseqval;
2103
2104 iseq->iseq = ALLOC_N(VALUE, iseq->iseq_size);
2105
2106 for (i=0; i<iseq->iseq_size; i+=2) {
2107 iseq->iseq[i] = BIN(opt_call_c_function);
2108 iseq->iseq[i+1] = (VALUE)func;
2109 }
2110
2111 rb_iseq_translate_threaded_code(iseq);
2112
2113 #define ALLOC_AND_COPY(dst, src, type, size) do { \
2114 if (size) { \
2115 (dst) = ALLOC_N(type, (size)); \
2116 MEMCPY((dst), (src), type, (size)); \
2117 } \
2118 } while (0)
2119
2120 ALLOC_AND_COPY(iseq->line_info_table, line_info_table,
2121 struct iseq_line_info_entry, iseq->line_info_size);
2122
2123 ALLOC_AND_COPY(iseq->catch_table, catch_table,
2124 struct iseq_catch_table_entry, iseq->catch_table_size);
2125
2126 ALLOC_AND_COPY(iseq->arg_opt_table, arg_opt_table,
2127 VALUE, iseq->arg_opts);
2128
2129 set_relation(iseq, 0);
2130
2131 return iseqval;
2132 }
2133
2134 /* Experimental tracing support: trace(line) -> trace(specified_line)
2135 * MRI Specific.
2136 */
2137
2138 int
2139 rb_iseq_line_trace_each(VALUE iseqval, int (*func)(int line, rb_event_flag_t *events_ptr, void *d), void *data)
2140 {
2141 int trace_num = 0;
2142 size_t pos, insn;
2143 rb_iseq_t *iseq;
2144 int cont = 1;
2145 GetISeqPtr(iseqval, iseq);
2146
2147 for (pos = 0; cont && pos < iseq->iseq_size; pos += insn_len(insn)) {
2148 insn = iseq->iseq[pos];
2149
2150 if (insn == BIN(trace)) {
2151 rb_event_flag_t current_events = (VALUE)iseq->iseq[pos+1];
2152
2153 if (current_events & RUBY_EVENT_LINE) {
2154 rb_event_flag_t events = current_events & RUBY_EVENT_SPECIFIED_LINE;
2155 trace_num++;
2156
2157 if (func) {
2158 int line = find_line_no(iseq, pos);
2159 /* printf("line: %d\n", line); */
2160 cont = (*func)(line, &events, data);
2161 if (current_events != events) {
2162 iseq->iseq[pos+1] = iseq->iseq_encoded[pos+1] =
2163 (VALUE)(current_events | (events & RUBY_EVENT_SPECIFIED_LINE));
2164 }
2165 }
2166 }
2167 }
2168 }
2169 return trace_num;
2170 }
2171
2172 static int
2173 collect_trace(int line, rb_event_flag_t *events_ptr, void *ptr)
2174 {
2175 VALUE result = (VALUE)ptr;
2176 rb_ary_push(result, INT2NUM(line));
2177 return 1;
2178 }
2179
2180 /*
2181 * <b>Experimental MRI specific feature, only available as C level api.</b>
2182 *
2183 * Returns all +specified_line+ events.
2184 */
2185 VALUE
2186 rb_iseq_line_trace_all(VALUE iseqval)
2187 {
2188 VALUE result = rb_ary_new();
2189 rb_iseq_line_trace_each(iseqval, collect_trace, (void *)result);
2190 return result;
2191 }
2192
2193 struct set_specifc_data {
2194 int pos;
2195 int set;
2196 int prev; /* 1: set, 2: unset, 0: not found */
2197 };
2198
2199 static int
2200 line_trace_specify(int line, rb_event_flag_t *events_ptr, void *ptr)
2201 {
2202 struct set_specifc_data *data = (struct set_specifc_data *)ptr;
2203
2204 if (data->pos == 0) {
2205 data->prev = *events_ptr & RUBY_EVENT_SPECIFIED_LINE ? 1 : 2;
2206 if (data->set) {
2207 *events_ptr = *events_ptr | RUBY_EVENT_SPECIFIED_LINE;
2208 }
2209 else {
2210 *events_ptr = *events_ptr & ~RUBY_EVENT_SPECIFIED_LINE;
2211 }
2212 return 0; /* found */
2213 }
2214 else {
2215 data->pos--;
2216 return 1;
2217 }
2218 }
2219
2220 /*
2221 * <b>Experimental MRI specific feature, only available as C level api.</b>
2222 *
2223 * Set a +specified_line+ event at the given line position, if the +set+
2224 * parameter is +true+.
2225 *
2226 * This method is useful for building a debugger breakpoint at a specific line.
2227 *
2228 * A TypeError is raised if +set+ is not boolean.
2229 *
2230 * If +pos+ is a negative integer a TypeError exception is raised.
2231 */
2232 VALUE
2233 rb_iseq_line_trace_specify(VALUE iseqval, VALUE pos, VALUE set)
2234 {
2235 struct set_specifc_data data;
2236
2237 data.prev = 0;
2238 data.pos = NUM2INT(pos);
2239 if (data.pos < 0) rb_raise(rb_eTypeError, "`pos' is negative");
2240
2241 switch (set) {
2242 case Qtrue: data.set = 1; break;
2243 case Qfalse: data.set = 0; break;
2244 default:
2245 rb_raise(rb_eTypeError, "`set' should be true/false");
2246 }
2247
2248 rb_iseq_line_trace_each(iseqval, line_trace_specify, (void *)&data);
2249
2250 if (data.prev == 0) {
2251 rb_raise(rb_eTypeError, "`pos' is out of range.");
2252 }
2253 return data.prev == 1 ? Qtrue : Qfalse;
2254 }
2255
2256 /*
2257 * Document-class: RubyVM::InstructionSequence
2258 *
2259 * The InstructionSequence class represents a compiled sequence of
2260 * instructions for the Ruby Virtual Machine.
2261 *
2262 * With it, you can get a handle to the instructions that make up a method or
2263 * a proc, compile strings of Ruby code down to VM instructions, and
2264 * disassemble instruction sequences to strings for easy inspection. It is
2265 * mostly useful if you want to learn how the Ruby VM works, but it also lets
2266 * you control various settings for the Ruby iseq compiler.
2267 *
2268 * You can find the source for the VM instructions in +insns.def+ in the Ruby
2269 * source.
2270 *
2271 * The instruction sequence results will almost certainly change as Ruby
2272 * changes, so example output in this documentation may be different from what
2273 * you see.
2274 */
2275
2276 void
2277 Init_ISeq(void)
2278 {
2279 /* declare ::RubyVM::InstructionSequence */
2280 rb_cISeq = rb_define_class_under(rb_cRubyVM, "InstructionSequence", rb_cObject);
2281 rb_define_alloc_func(rb_cISeq, iseq_alloc);
2282 rb_define_method(rb_cISeq, "inspect", iseq_inspect, 0);
2283 rb_define_method(rb_cISeq, "disasm", rb_iseq_disasm, 0);
2284 rb_define_method(rb_cISeq, "disassemble", rb_iseq_disasm, 0);
2285 rb_define_method(rb_cISeq, "to_a", iseq_to_a, 0);
2286 rb_define_method(rb_cISeq, "eval", iseq_eval, 0);
2287
2288 /* location APIs */
2289 rb_define_method(rb_cISeq, "path", rb_iseq_path, 0);
2290 rb_define_method(rb_cISeq, "absolute_path", rb_iseq_absolute_path, 0);
2291 rb_define_method(rb_cISeq, "label", rb_iseq_label, 0);
2292 rb_define_method(rb_cISeq, "base_label", rb_iseq_base_label, 0);
2293 rb_define_method(rb_cISeq, "first_lineno", rb_iseq_first_lineno, 0);
2294
2295 #if 0
2296 /* Now, it is experimental. No discussions, no tests. */
2297 /* They can be used from C level. Please give us feedback. */
2298 rb_define_method(rb_cISeq, "line_trace_all", rb_iseq_line_trace_all, 0);
2299 rb_define_method(rb_cISeq, "line_trace_specify", rb_iseq_line_trace_specify, 2);
2300 #else
2301 (void)rb_iseq_line_trace_all;
2302 (void)rb_iseq_line_trace_specify;
2303 #endif
2304
2305 #if 0 /* TBD */
2306 rb_define_private_method(rb_cISeq, "marshal_dump", iseq_marshal_dump, 0);
2307 rb_define_private_method(rb_cISeq, "marshal_load", iseq_marshal_load, 1);
2308 #endif
2309
2310 /* disable this feature because there is no verifier. */
2311 /* rb_define_singleton_method(rb_cISeq, "load", iseq_s_load, -1); */
2312 (void)iseq_s_load;
2313
2314 rb_define_singleton_method(rb_cISeq, "compile", iseq_s_compile, -1);
2315 rb_define_singleton_method(rb_cISeq, "new", iseq_s_compile, -1);
2316 rb_define_singleton_method(rb_cISeq, "compile_file", iseq_s_compile_file, -1);
2317 rb_define_singleton_method(rb_cISeq, "compile_option", iseq_s_compile_option_get, 0);
2318 rb_define_singleton_method(rb_cISeq, "compile_option=", iseq_s_compile_option_set, 1);
2319 rb_define_singleton_method(rb_cISeq, "disasm", iseq_s_disasm, 1);
2320 rb_define_singleton_method(rb_cISeq, "disassemble", iseq_s_disasm, 1);
2321 rb_define_singleton_method(rb_cISeq, "of", iseq_s_of, 1);
2322 }
RBASIC_CLEAR_CLASS
#define RBASIC_CLEAR_CLASS(obj)
Definition: internal.h:607
VM_CALL_ARGS_BLOCKARG
#define VM_CALL_ARGS_BLOCKARG
Definition: vm_core.h:745
rb_iseq_disasm_insn
int rb_iseq_disasm_insn(VALUE ret, VALUE *iseq, size_t pos, rb_iseq_t *iseqdat, VALUE child)
Disassemble a instruction Iseq -> Iseq inspect object.
Definition: iseq.c:1286
prepare_iseq_build
static VALUE prepare_iseq_build(rb_iseq_t *iseq, VALUE name, VALUE path, VALUE absolute_path, VALUE first_lineno, VALUE parent, enum iseq_type type, VALUE block_opt, const rb_compile_option_t *option)
Definition: iseq.c:255
rb_iseq_struct::arg_simple
int arg_simple
Definition: vm_core.h:275
rb_call_info_struct::mid
ID mid
Definition: vm_core.h:157
rb_iseq_line_no
unsigned int rb_iseq_line_no(const rb_iseq_t *iseq, size_t pos)
Definition: iseq.c:1134
rb_iseq_struct::cref_stack
NODE *const cref_stack
Definition: vm_core.h:315
rb_ary_entry
VALUE rb_ary_entry(VALUE ary, long offset)
Definition: array.c:1171
RARRAY_LEN
#define RARRAY_LEN(a)
Definition: ruby.h:878
rb_bug
void rb_bug(const char *fmt,...)
Definition: error.c:327
RUBY_TYPED_FREE_IMMEDIATELY
#define RUBY_TYPED_FREE_IMMEDIATELY
Definition: ruby.h:1015
DECL_SYMBOL
#define DECL_SYMBOL(name)
Definition: iseq.c:1613
rb_hash_lookup
#define rb_hash_lookup
Definition: tcltklib.c:269
rb_iseq_struct::arg_rest
int arg_rest
Definition: vm_core.h:276
rb_parser_compile_file
NODE * rb_parser_compile_file(volatile VALUE vparser, const char *f, VALUE file, int start)
Definition: ripper.c:12115
iseq_mark
static void iseq_mark(void *ptr)
Definition: iseq.c:97
INT2NUM
#define INT2NUM(x)
Definition: ruby.h:1288
iseq_compile_data_storage::size
unsigned long size
Definition: iseq.h:76
rb_iseq_new
VALUE rb_iseq_new(NODE *node, VALUE name, VALUE path, VALUE absolute_path, VALUE parent, enum iseq_type type)
Definition: iseq.c:413
VM_CALL_FCALL
#define VM_CALL_FCALL
Definition: vm_core.h:746
st_table
Definition: st.h:69
rb_id2str
VALUE rb_id2str(ID id)
Definition: ripper.c:17160
rb_iseq_struct::arg_keyword_table
ID * arg_keyword_table
Definition: vm_core.h:287
rb_iseq_line_trace_all
VALUE rb_iseq_line_trace_all(VALUE iseqval)
Definition: iseq.c:2186
iseq_catch_table_entry::end
unsigned long end
Definition: iseq.h:66
NUM2INT
#define NUM2INT(x)
Definition: ruby.h:630
iseq.h
make_compile_option
static void make_compile_option(rb_compile_option_t *option, VALUE opt)
Definition: iseq.c:346
rb_define_singleton_method
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
Definition: class.c:1655
iseq_catch_table_entry::CATCH_TYPE_RETRY
Definition: iseq.h:59
GetProcPtr
#define GetProcPtr(obj, ptr)
Definition: vm_core.h:697
rb_iseq_struct::coverage
const VALUE coverage
Definition: vm_core.h:229
ruby.h
RUBY_VM_NORMAL_ISEQ_P
#define RUBY_VM_NORMAL_ISEQ_P(ptr)
Definition: vm_core.h:835
rb_iseq_line_trace_each
int rb_iseq_line_trace_each(VALUE iseqval, int(*func)(int line, rb_event_flag_t *events_ptr, void *d), void *data)
Definition: iseq.c:2139
FilePathValue
#define FilePathValue(v)
Definition: ruby.h:560
set_relation
static void set_relation(rb_iseq_t *iseq, const VALUE parent)
Definition: iseq.c:202
CLASS_OF
#define CLASS_OF(v)
Definition: ruby.h:440
ATOMIC_PTR_CAS
#define ATOMIC_PTR_CAS(var, oldval, val)
Definition: ruby_atomic.h:166
Qtrue
#define Qtrue
Definition: ruby.h:426
st_insert
int st_insert(st_table *, st_data_t, st_data_t)
rb_iseq_struct::compile_data
struct iseq_compile_data * compile_data
Definition: vm_core.h:323
rb_cHash
VALUE rb_cHash
Definition: hash.c:67
rb_block_struct::iseq
rb_iseq_t * iseq
Definition: vm_core.h:466
iseq_compile_data::storage_head
struct iseq_compile_data_storage * storage_head
Definition: iseq.h:96
ST_CONTINUE
Definition: st.h:100
id
const int id
Definition: nkf.c:209
eval_intern.h
rb_iseq_struct::is_size
int is_size
Definition: vm_core.h:242
rb_call_info_struct::flag
VALUE flag
Definition: vm_core.h:158
rb_define_private_method
void rb_define_private_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1500
rb_iseq_struct::callinfo_entries
rb_call_info_t * callinfo_entries
Definition: vm_core.h:244
iseq_s_compile
static VALUE iseq_s_compile(int argc, VALUE *argv, VALUE self)
Definition: iseq.c:675
rb_block_struct
Definition: vm_core.h:462
rb_eTypeError
VALUE rb_eTypeError
Definition: error.c:548
id_to_name
static VALUE id_to_name(ID id, VALUE default_value)
Definition: iseq.c:1145
rb_iseq_translate_threaded_code
int rb_iseq_translate_threaded_code(rb_iseq_t *iseq)
Definition: compile.c:561
ULONG2NUM
#define ULONG2NUM(x)
Definition: ruby.h:1319
rb_ary_push
VALUE rb_ary_push(VALUE ary, VALUE item)
Definition: array.c:896
st_free_table
void st_free_table(st_table *)
Definition: st.c:334
rb_str_concat
VALUE rb_str_concat(VALUE, VALUE)
Definition: string.c:2340
SYM2ID
#define SYM2ID(x)
Definition: ruby.h:356
OPT_INLINE_CONST_CACHE
#define OPT_INLINE_CONST_CACHE
Definition: vm_opts.h:25
rb_ary_tmp_new
VALUE rb_ary_tmp_new(long capa)
Definition: array.c:534
rb_iseq_defined_string
VALUE rb_iseq_defined_string(enum defined_type type)
Definition: iseq.c:2039
rb_iseq_compile_with_option
VALUE rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE absolute_path, VALUE line, rb_block_t *base_block, VALUE opt)
Definition: iseq.c:589
rb_iseq_struct::local_table_size
int local_table_size
Definition: vm_core.h:236
cdhash_each
static int cdhash_each(VALUE key, VALUE value, VALUE ary)
Definition: iseq.c:1649
rb_iseq_struct::local_iseq
struct rb_iseq_struct * local_iseq
Definition: vm_core.h:297
rb_define_class_under
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:676
rb_raise
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:1857
RUBY_MARK_LEAVE
#define RUBY_MARK_LEAVE(msg)
Definition: gc.h:54
iseq_compile_data_storage::next
struct iseq_compile_data_storage * next
Definition: iseq.h:74
gc.h
rb_define_alloc_func
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
VM_CALL_ARGS_SPLAT
#define VM_CALL_ARGS_SPLAT
Definition: vm_core.h:744
rb_iseq_struct::klass
const VALUE klass
Definition: vm_core.h:316
rb_iseq_new_with_bopt_and_opt
static VALUE rb_iseq_new_with_bopt_and_opt(NODE *node, VALUE name, VALUE path, VALUE absolute_path, VALUE first_lineno, VALUE parent, enum iseq_type type, VALUE bopt, const rb_compile_option_t *option)
Definition: iseq.c:437
rb_iseq_struct::stack_max
size_t stack_max
Definition: vm_core.h:289
rb_iseq_struct::arg_keyword
int arg_keyword
Definition: vm_core.h:283
rb_iseq_struct::defined_method_id
ID defined_method_id
Definition: vm_core.h:319
RUBY_GC_INFO
#define RUBY_GC_INFO
Definition: gc.h:57
T_ARRAY
#define T_ARRAY
Definition: ruby.h:484
rb_iseq_compile_node
VALUE rb_iseq_compile_node(VALUE self, NODE *node)
Definition: compile.c:459
rb_global_entry::id
ID id
Definition: node.h:501
ALLOC_AND_COPY
#define ALLOC_AND_COPY(dst, src, type, size)
rb_file_open_str
VALUE rb_file_open_str(VALUE, const char *)
Definition: io.c:5554
rb_str_cmp
int rb_str_cmp(VALUE, VALUE)
Definition: string.c:2486
FIXNUM_P
#define FIXNUM_P(f)
Definition: ruby.h:347
rb_thread_struct
Definition: vm_core.h:524
rb_iseq_struct::arg_post_len
int arg_post_len
Definition: vm_core.h:279
VM_CALL_VCALL
#define VM_CALL_VCALL
Definition: vm_core.h:747
rb_obj_classname
const char * rb_obj_classname(VALUE)
Definition: variable.c:406
OPT_TAILCALL_OPTIMIZATION
#define OPT_TAILCALL_OPTIMIZATION
Definition: vm_opts.h:22
rb_ary_new2
#define rb_ary_new2
Definition: intern.h:90
rb_iseq_struct::mark_ary
const VALUE mark_ary
Definition: vm_core.h:228
iseq_compile_data::option
const rb_compile_option_t * option
Definition: iseq.h:102
iseq_location_setup
static rb_iseq_location_t * iseq_location_setup(rb_iseq_t *iseq, VALUE path, VALUE absolute_path, VALUE name, size_t first_lineno)
Definition: iseq.c:183
sym
#define sym(x)
Definition: date_core.c:3695
iseq_compile_data::catch_table_ary
const VALUE catch_table_ary
Definition: iseq.h:84
st_data_t
RUBY_SYMBOL_EXPORT_BEGIN typedef unsigned long st_data_t
Definition: st.h:20
RNode
Definition: node.h:239
iseq_catch_table_entry::type
enum iseq_catch_table_entry::catch_type type
iseq_compile_data_storage::pos
unsigned long pos
Definition: iseq.h:75
rb_cISeq
VALUE rb_cISeq
Definition: iseq.c:27
rb_hash_foreach
void rb_hash_foreach(VALUE hash, int(*func)(ANYARGS), VALUE farg)
Definition: hash.c:264
rb_exc_raise
void rb_exc_raise(VALUE mesg)
Definition: eval.c:567
SET_COMPILE_OPTION_NUM
#define SET_COMPILE_OPTION_NUM(o, h, mem)
rb_iseq_struct::iseq
VALUE * iseq
Definition: vm_core.h:225
iseq_s_compile_file
static VALUE iseq_s_compile_file(int argc, VALUE *argv, VALUE self)
Definition: iseq.c:709
CHECK_SYMBOL
#define CHECK_SYMBOL(v)
Definition: iseq.c:474
RB_TYPE_P
#define RB_TYPE_P(obj, type)
Definition: ruby.h:1664
ruby_xcalloc
void * ruby_xcalloc(size_t n, size_t size)
Definition: gc.c:6191
rb_iseq_struct::type
enum rb_iseq_struct::iseq_type type
iseq_load
static VALUE iseq_load(VALUE self, VALUE data, VALUE parent, VALUE opt)
Definition: iseq.c:477
TH_POP_TAG
#define TH_POP_TAG()
Definition: eval_intern.h:128
st_lookup
int st_lookup(st_table *, st_data_t, st_data_t *)
MEMZERO
#define MEMZERO(p, type, n)
Definition: ruby.h:1351
COMPILE_OPTION_DEFAULT
static rb_compile_option_t COMPILE_OPTION_DEFAULT
Definition: iseq.c:333
OPT_PEEPHOLE_OPTIMIZATION
#define OPT_PEEPHOLE_OPTIMIZATION
Definition: vm_opts.h:23
get_line_info
static struct iseq_line_info_entry * get_line_info(const rb_iseq_t *iseq, size_t pos)
Definition: iseq.c:1087
rb_iseq_struct::arg_keyword_required
int arg_keyword_required
Definition: vm_core.h:286
rb_str_symname_p
int rb_str_symname_p(VALUE)
Definition: string.c:8381
RUBY_TYPED_WB_PROTECTED
#define RUBY_TYPED_WB_PROTECTED
Definition: ruby.h:1016
iseq_catch_table_entry::CATCH_TYPE_RESCUE
Definition: iseq.h:57
rb_iseq_new_main
VALUE rb_iseq_new_main(NODE *node, VALUE path, VALUE absolute_path)
Definition: iseq.c:428
rb_iseq_new_top
VALUE rb_iseq_new_top(NODE *node, VALUE name, VALUE path, VALUE absolute_path, VALUE parent)
Definition: iseq.c:421
CHECK_INTEGER
static VALUE CHECK_INTEGER(VALUE v)
Definition: iseq.c:475
ALLOC_N
#define ALLOC_N(type, n)
Definition: ruby.h:1333
rb_hash_aset
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
Definition: hash.c:1393
EXEC_TAG
#define EXEC_TAG()
Definition: eval_intern.h:168
VM_CALL_ARGS_SKIP_SETUP
#define VM_CALL_ARGS_SKIP_SETUP
Definition: vm_core.h:751
iseq_compile_data::mark_ary
VALUE mark_ary
Definition: iseq.h:83
val
#define val
rb_global_entry
Definition: node.h:499
rb_cObject
RUBY_EXTERN VALUE rb_cObject
Definition: ruby.h:1553
PRIdVALUE
#define PRIdVALUE
Definition: ruby.h:132
PARAM
#define PARAM(i, type)
register_label
static VALUE register_label(struct st_table *table, unsigned long idx)
Definition: iseq.c:1620
rb_get_coverages
VALUE rb_get_coverages(void)
Definition: thread.c:5287
rb_str_cat2
VALUE rb_str_cat2(VALUE, const char *)
Definition: string.c:2159
rb_ary_new
VALUE rb_ary_new(void)
Definition: array.c:495
find_line_no
static unsigned int find_line_no(const rb_iseq_t *iseq, size_t pos)
Definition: iseq.c:1122
obj_resurrect
static VALUE obj_resurrect(VALUE obj)
Definition: iseq.c:32
make_compile_option_value
static VALUE make_compile_option_value(rb_compile_option_t *option)
Definition: iseq.c:389
rb_iseq_struct::argc
int argc
argument information
Definition: vm_core.h:274
iseq_compile_data::err_info
const VALUE err_info
Definition: iseq.h:82
iseq_s_of
static VALUE iseq_s_of(VALUE klass, VALUE body)
Definition: iseq.c:1521
snprintf
#define snprintf
Definition: subst.h:6
JUMP_TAG
#define JUMP_TAG(st)
Definition: eval_intern.h:173
rb_iseq_struct::arg_post_start
int arg_post_start
Definition: vm_core.h:280
rb_iseq_absolute_path
VALUE rb_iseq_absolute_path(VALUE self)
Definition: iseq.c:881
NIL_P
#define NIL_P(v)
Definition: ruby.h:438
rb_iseq_method_name
VALUE rb_iseq_method_name(VALUE self)
Definition: iseq.c:974
iseq_eval
static VALUE iseq_eval(VALUE self)
Definition: iseq.c:809
CHECK_ARRAY
#define CHECK_ARRAY(v)
Definition: iseq.c:472
rb_call_info_struct::orig_argc
int orig_argc
Definition: vm_core.h:159
rb_ary_store
void rb_ary_store(VALUE ary, long idx, VALUE val)
Definition: array.c:790
rb_iseq_struct::arg_opt_table
VALUE * arg_opt_table
Definition: vm_core.h:282
iseq_compile_data_storage
Definition: iseq.h:73
rb_iseq_struct::arg_keywords
int arg_keywords
Definition: vm_core.h:285
rb_cRubyVM
VALUE rb_cRubyVM
Definition: vm.c:97
iseq_inline_storage_entry
Definition: vm_core.h:141
RUBY_MARK_ENTER
#define RUBY_MARK_ENTER(msg)
Definition: gc.h:53
argc
int argc
Definition: ruby.c:131
Qfalse
#define Qfalse
Definition: ruby.h:425
rb_call_info_struct::blockiseq
rb_iseq_t * blockiseq
Definition: vm_core.h:160
if
if((ID)(DISPID) nameid!=nameid)
Definition: win32ole.c:770
rb_thread_struct::base_block
rb_block_t * base_block
Definition: vm_core.h:555
MEMCPY
#define MEMCPY(p1, p2, type, n)
Definition: ruby.h:1352
rb_iseq_klass
VALUE rb_iseq_klass(VALUE self)
Definition: iseq.c:966
set_specifc_data::set
int set
Definition: iseq.c:2195
rb_str_new2
#define rb_str_new2
Definition: intern.h:840
err
int err
Definition: win32.c:114
OBJ_FREEZE
#define OBJ_FREEZE(x)
Definition: ruby.h:1186
OPT_INSTRUCTIONS_UNIFICATION
#define OPT_INSTRUCTIONS_UNIFICATION
Definition: vm_opts.h:45
PRIdPTRDIFF
#define PRIdPTRDIFF
Definition: ruby.h:161
rb_iseq_struct::local_table
ID * local_table
Definition: vm_core.h:235
iseq_catch_table_entry::start
unsigned long start
Definition: iseq.h:65
numberof
#define numberof(array)
Definition: etc.c:595
rb_iseq_struct::arg_block
int arg_block
Definition: vm_core.h:277
ALLOC
#define ALLOC(type)
Definition: ruby.h:1334
rb_str_resurrect
VALUE rb_str_resurrect(VALUE str)
Definition: string.c:1068
Init_ISeq
void Init_ISeq(void)
Definition: iseq.c:2277
PRIuVALUE
#define PRIuVALUE
Definition: ruby.h:134
rb_iseq_struct::arg_opts
int arg_opts
Definition: vm_core.h:278
rb_str_resize
VALUE rb_str_resize(VALUE, long)
Definition: string.c:2025
VM_CALL_SUPER
#define VM_CALL_SUPER
Definition: vm_core.h:749
exception_type2symbol
static VALUE exception_type2symbol(VALUE type)
Definition: iseq.c:1632
INIT_SYMBOL
#define INIT_SYMBOL(name)
Definition: iseq.c:1616
iseq_catch_table_entry::CATCH_TYPE_ENSURE
Definition: iseq.h:58
RSTRING_LEN
#define RSTRING_LEN(str)
Definition: ruby.h:841
ISEQ_SET_CREF
#define ISEQ_SET_CREF(iseq, cref)
Definition: iseq.c:199
RUBY_EVENT_SPECIFIED_LINE
#define RUBY_EVENT_SPECIFIED_LINE
Definition: ruby.h:1725
hidden_obj_p
#define hidden_obj_p(obj)
Definition: iseq.c:29
iseq_catch_table_entry::CATCH_TYPE_NEXT
Definition: iseq.h:62
func
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:113
defined_type
defined_type
Definition: iseq.h:110
rb_obj_is_proc
VALUE rb_obj_is_proc(VALUE)
Definition: proc.c:94
ISEQ_MINOR_VERSION
#define ISEQ_MINOR_VERSION
Definition: iseq.c:25
rb_sprintf
VALUE rb_sprintf(const char *format,...)
Definition: sprintf.c:1250
rb_proc_t
Definition: vm_core.h:700
rb_iseq_location_struct
Definition: vm_core.h:196
rb_hash_new
VALUE rb_hash_new(void)
Definition: hash.c:298
ruby_xfree
void ruby_xfree(void *x)
Definition: gc.c:6242
OPT_TRACE_INSTRUCTION
#define OPT_TRACE_INSTRUCTION
Definition: vm_opts.h:21
rb_iseq_build_from_ary
VALUE rb_iseq_build_from_ary(rb_iseq_t *iseq, VALUE locals, VALUE args, VALUE exception, VALUE body)
Definition: compile.c:5885
iseq_data_to_ary
static VALUE iseq_data_to_ary(rb_iseq_t *iseq)
Definition: iseq.c:1657
rb_scan_args
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:1728
RUBY_EVENT_LINE
#define RUBY_EVENT_LINE
Definition: ruby.h:1707
rb_iseq_struct::parent_iseq
struct rb_iseq_struct * parent_iseq
Definition: vm_core.h:296
PRIsVALUE
#define PRIsVALUE
Definition: ruby.h:137
internal.h
rb_iseq_location_struct::path
const VALUE path
Definition: vm_core.h:197
ID
unsigned long ID
Definition: ruby.h:89
rb_iseq_struct::orig
const VALUE orig
Definition: vm_core.h:304
iseq_s_compile_option_set
static VALUE iseq_s_compile_option_set(VALUE self, VALUE opt)
Definition: iseq.c:766
Qnil
#define Qnil
Definition: ruby.h:427
rb_iseq_first_lineno
VALUE rb_iseq_first_lineno(VALUE self)
Definition: iseq.c:958
type
int type
Definition: tcltklib.c:112
rb_iseq_build_for_ruby2cext
VALUE rb_iseq_build_for_ruby2cext(const rb_iseq_t *iseq_template, const rb_insn_func_t *func, const struct iseq_line_info_entry *line_info_table, const char **local_table, const VALUE *arg_opt_table, const struct iseq_catch_table_entry *catch_table, const char *name, const char *path, const unsigned short first_lineno)
Definition: iseq.c:2080
SET_COMPILE_OPTION
#define SET_COMPILE_OPTION(o, h, mem)
vm_core.h
rb_iseq_struct::iseq_encoded
VALUE * iseq_encoded
Definition: vm_core.h:226
BUILTIN_TYPE
#define BUILTIN_TYPE(x)
Definition: ruby.h:502
debug
#define debug(x)
Definition: _sdbm.c:52
VALUE
unsigned long VALUE
Definition: ruby.h:88
iseq_compile_data
Definition: iseq.h:80
rb_iseq_eval
VALUE rb_iseq_eval(VALUE iseqval)
Definition: vm.c:1642
rb_funcall2
#define rb_funcall2
Definition: ruby.h:1456
result
static VALUE result
Definition: nkf.c:40
rb_iseq_struct::catch_table_size
int catch_table_size
Definition: vm_core.h:293
iseq_catch_table_entry
Definition: iseq.h:55
FIX2INT
#define FIX2INT(x)
Definition: ruby.h:632
VM_CALL_OPT_SEND
#define VM_CALL_OPT_SEND
Definition: vm_core.h:750
rb_iseq_path
VALUE rb_iseq_path(VALUE self)
Definition: iseq.c:857
rb_iseq_struct::location
rb_iseq_location_t location
Definition: vm_core.h:223
TH_PUSH_TAG
#define TH_PUSH_TAG(th)
Definition: eval_intern.h:122
rb_iseq_load
VALUE rb_iseq_load(VALUE data, VALUE parent, VALUE opt)
Definition: iseq.c:583
INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE
#define INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE
Definition: iseq.h:71
OPT_STACK_CACHING
#define OPT_STACK_CACHING
Definition: vm_opts.h:47
rb_str_new_cstr
VALUE rb_str_new_cstr(const char *)
Definition: string.c:560
iseq_catch_table_entry::CATCH_TYPE_BREAK
Definition: iseq.h:60
RARRAY_LENINT
#define RARRAY_LENINT(ary)
Definition: ruby.h:884
st_init_numtable
st_table * st_init_numtable(void)
Definition: st.c:272
rb_fstring
VALUE rb_fstring(VALUE)
Definition: string.c:201
rb_str_dup
VALUE rb_str_dup(VALUE)
Definition: string.c:1062
cleanup_iseq_build
static VALUE cleanup_iseq_build(rb_iseq_t *iseq)
Definition: iseq.c:319
CHAR_BIT
#define CHAR_BIT
Definition: ruby.h:198
iseq_compile_data_storage::buff
char * buff
Definition: iseq.h:77
PARAM_ID
#define PARAM_ID(i)
iseq_catch_table_entry::CATCH_TYPE_REDO
Definition: iseq.h:61
rb_iseq_new_with_bopt
VALUE rb_iseq_new_with_bopt(NODE *node, VALUE name, VALUE path, VALUE absolute_path, VALUE first_lineno, VALUE parent, enum iseq_type type, VALUE bopt)
Definition: iseq.c:464
StringValueCStr
#define StringValueCStr(v)
Definition: ruby.h:541
rb_iseq_add_mark_object
void rb_iseq_add_mark_object(rb_iseq_t *iseq, VALUE obj)
Definition: iseq.c:245
iseq_s_disasm
static VALUE iseq_s_disasm(VALUE klass, VALUE body)
Definition: iseq.c:1596
iseq_s_load
static VALUE iseq_s_load(int argc, VALUE *argv, VALUE self)
Definition: iseq.c:574
RUBY_FREE_UNLESS_NULL
#define RUBY_FREE_UNLESS_NULL(ptr)
Definition: gc.h:61
rb_iseq_line_trace_specify
VALUE rb_iseq_line_trace_specify(VALUE iseqval, VALUE pos, VALUE set)
Definition: iseq.c:2233
RSTRING_PTR
#define RSTRING_PTR(str)
Definition: ruby.h:845
rb_iseq_t
struct rb_iseq_struct rb_iseq_t
Definition: method.h:76
top
unsigned int top
Definition: nkf.c:4309
rb_iseq_struct::callinfo_size
int callinfo_size
Definition: vm_core.h:245
OPT_SPECIALISED_INSTRUCTION
#define OPT_SPECIALISED_INSTRUCTION
Definition: vm_opts.h:24
iseq_alloc
static VALUE iseq_alloc(VALUE klass)
Definition: iseq.c:176
ISEQ_MAJOR_VERSION
#define ISEQ_MAJOR_VERSION
Definition: iseq.c:24
iseq_catch_table_entry::sp
unsigned long sp
Definition: iseq.h:68
size
int size
Definition: encoding.c:49
PARAM_TYPE
#define PARAM_TYPE(type)
f
#define f
INT2FIX
#define INT2FIX(i)
Definition: ruby.h:231
rb_thread_struct::top_wrapper
VALUE top_wrapper
Definition: vm_core.h:552
rb_iseq_struct::arg_size
int arg_size
Definition: vm_core.h:281
line_trace_specify
static int line_trace_specify(int line, rb_event_flag_t *events_ptr, void *ptr)
Definition: iseq.c:2200
rb_iseq_struct::arg_keyword_check
int arg_keyword_check
Definition: vm_core.h:284
rb_proc_t::block
rb_block_t block
Definition: vm_core.h:701
RARRAY_AREF
#define RARRAY_AREF(a, i)
Definition: ruby.h:901
iseq_line_info_entry::position
unsigned int position
Definition: iseq.h:51
rb_iseq_struct::line_info_size
size_t line_info_size
Definition: vm_core.h:233
RUBY_FREE_LEAVE
#define RUBY_FREE_LEAVE(msg)
Definition: gc.h:56
rb_data_type_struct
Definition: ruby.h:966
rb_event_flag_t
unsigned long rb_event_flag_t
Definition: ruby.h:1740
RUBY_FREE_ENTER
#define RUBY_FREE_ENTER(msg)
Definition: gc.h:55
ruby_node_name
const char * ruby_node_name(int node)
Definition: iseq.c:1603
rb_str_catf
VALUE rb_str_catf(VALUE str, const char *format,...)
Definition: sprintf.c:1290
iseq_compile_data::storage_current
struct iseq_compile_data_storage * storage_current
Definition: iseq.h:97
rb_call_info_struct
Definition: vm_core.h:155
rb_iseq_struct::catch_table
struct iseq_catch_table_entry * catch_table
Definition: vm_core.h:292
rb_insn_func_t
rb_control_frame_t *FUNC_FASTCALL rb_insn_func_t(rb_thread_t *, rb_control_frame_t *)
Definition: vm_core.h:797
NEW_CREF
#define NEW_CREF(a)
Definition: node.h:452
key
uint8_t key[16]
Definition: random.c:1250
rb_iseq_compile_on_base
VALUE rb_iseq_compile_on_base(VALUE src, VALUE file, VALUE line, rb_block_t *base_block)
Definition: iseq.c:648
rb_iseq_location_struct::first_lineno
size_t first_lineno
Definition: vm_core.h:201
iseq_to_a
static VALUE iseq_to_a(VALUE self)
Definition: iseq.c:1076
RTEST
#define RTEST(v)
Definition: ruby.h:437
iseq_inspect
static VALUE iseq_inspect(VALUE self)
Definition: iseq.c:820
T_STRING
#define T_STRING
Definition: ruby.h:482
rb_iseq_struct::local_size
int local_size
Definition: vm_core.h:239
set_specifc_data::pos
int pos
Definition: iseq.c:2194
RUBY_MARK_UNLESS_NULL
#define RUBY_MARK_UNLESS_NULL(ptr)
Definition: gc.h:60
T_FILE
#define T_FILE
Definition: ruby.h:488
rb_iseq_struct::line_info_table
struct iseq_line_info_entry * line_info_table
Definition: vm_core.h:232
iseq_compile_data::last_coverable_line
int last_coverable_line
Definition: iseq.h:99
iseq_data_type
static const rb_data_type_t iseq_data_type
Definition: iseq.c:164
rb_iseq_struct::iseq_size
unsigned long iseq_size
Definition: vm_core.h:227
TypedData_Make_Struct
#define TypedData_Make_Struct(klass, type, data_type, sval)
Definition: ruby.h:1030
rb_str_inspect
VALUE rb_str_inspect(VALUE)
Definition: string.c:4792
VM_CALL_TAILCALL
#define VM_CALL_TAILCALL
Definition: vm_core.h:748
rb_method_get_iseq
rb_iseq_t * rb_method_get_iseq(VALUE body)
Definition: proc.c:2136
hash
static unsigned int hash(const char *str, unsigned int len)
Definition: lex.c:56
rb_ary_join
VALUE rb_ary_join(VALUE ary, VALUE sep)
Definition: array.c:1995
CHECK_STRING
#define CHECK_STRING(v)
Definition: iseq.c:473
catch_type
static const char * catch_type(int type)
Definition: iseq.c:1338
rb_parser_new
VALUE rb_parser_new(void)
Definition: ripper.c:17590
PRIdSIZE
#define PRIdSIZE
Definition: ruby.h:176
rb_realpath_internal
VALUE rb_realpath_internal(VALUE basedir, VALUE path, int strict)
Definition: file.c:3620
rb_compile_option_struct
Definition: iseq.h:38
main
int main(int argc, char **argv)
Definition: nkf.c:6920
name
const char * name
Definition: nkf.c:208
rb_iseq_struct::self
VALUE self
Definition: vm_core.h:303
rb_iseq_struct
Definition: vm_core.h:206
ID2SYM
#define ID2SYM(x)
Definition: ruby.h:355
GetISeqPtr
#define GetISeqPtr(obj, ptr)
Definition: vm_core.h:193
iseq_catch_table_entry::cont
unsigned long cont
Definition: iseq.h:67
rb_iseq_clone
VALUE rb_iseq_clone(VALUE iseqval, VALUE newcbase)
Definition: iseq.c:1922
rb_id2name
const char * rb_id2name(ID id)
Definition: ripper.c:17230
COMPILE_OPTION_FALSE
static const rb_compile_option_t COMPILE_OPTION_FALSE
Definition: iseq.c:343
rb_iseq_location_struct::absolute_path
const VALUE absolute_path
Definition: vm_core.h:198
rb_inspect
VALUE rb_inspect(VALUE)
Definition: object.c:470
iseq_catch_table_entry::iseq
VALUE iseq
Definition: iseq.h:64
rb_parser_compile_string_path
NODE * rb_parser_compile_string_path(volatile VALUE vparser, VALUE f, VALUE s, int line)
Definition: ripper.c:12080
rb_iseq_base_label
VALUE rb_iseq_base_label(VALUE self)
Definition: iseq.c:940
rb_secure
void rb_secure(int)
Definition: safe.c:88
set_specifc_data::prev
int prev
Definition: iseq.c:2196
CONST_ID
#define CONST_ID(var, str)
Definition: ruby.h:1428
rb_call_info_t
struct rb_call_info_struct rb_call_info_t
rb_iseq_label
VALUE rb_iseq_label(VALUE self)
Definition: iseq.c:912
iseq_line_info_entry
Definition: iseq.h:50
rb_ary_resurrect
VALUE rb_ary_resurrect(VALUE ary)
Definition: array.c:1898
rb_intern
#define rb_intern(str)
rb_insn_operand_intern
VALUE rb_insn_operand_intern(rb_iseq_t *iseq, VALUE insn, int op_no, VALUE op, int len, size_t pos, VALUE *pnop, VALUE child)
Definition: iseq.c:1158
collect_trace
static int collect_trace(int line, rb_event_flag_t *events_ptr, void *ptr)
Definition: iseq.c:2173
NULL
#define NULL
Definition: _sdbm.c:103
iseq_line_info_entry::line_no
unsigned int line_no
Definition: iseq.h:52
Qundef
#define Qundef
Definition: ruby.h:428
set_specifc_data
Definition: iseq.c:2193
iseq_free
static void iseq_free(void *ptr)
Definition: iseq.c:63
rb_iseq_location_struct::label
const VALUE label
Definition: vm_core.h:200
rb_iseq_location_struct::base_label
const VALUE base_label
Definition: vm_core.h:199
GET_THREAD
static rb_thread_t * GET_THREAD(void)
Definition: vm_core.h:927
rb_define_method
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1488
rb_str_append
VALUE rb_str_append(VALUE, VALUE)
Definition: string.c:2298
rb_iseq_disasm
VALUE rb_iseq_disasm(VALUE self)
Definition: iseq.c:1378
rb_iseq_parameters
VALUE rb_iseq_parameters(const rb_iseq_t *iseq, int is_proc)
Definition: iseq.c:1953
rb_parser_compile_file_path
NODE * rb_parser_compile_file_path(volatile VALUE vparser, VALUE fname, VALUE file, int start)
Definition: ripper.c:12121
OPT_OPERANDS_UNIFICATION
#define OPT_OPERANDS_UNIFICATION
Definition: vm_opts.h:44
NOEX_PRIVATE
Definition: method.h:27
NUM2LONG
#define NUM2LONG(x)
Definition: ruby.h:600
iseq_memsize
static size_t iseq_memsize(const void *ptr)
Definition: iseq.c:128
rb_iseq_compile
VALUE rb_iseq_compile(VALUE src, VALUE file, VALUE line)
Definition: iseq.c:642
compile_data_free
static void compile_data_free(struct iseq_compile_data *compile_data)
Definition: iseq.c:48
rb_iseq_new_with_opt
VALUE rb_iseq_new_with_opt(NODE *node, VALUE name, VALUE path, VALUE absolute_path, VALUE first_lineno, VALUE parent, enum iseq_type type, const rb_compile_option_t *option)
Definition: iseq.c:454
RB_OBJ_WRITE
#define RB_OBJ_WRITE(a, slot, b)
Definition: ruby.h:1213
iseq_check
static rb_iseq_t * iseq_check(VALUE val)
Definition: iseq.c:790
argv
char ** argv
Definition: ruby.c:132
iseq_s_compile_option_get
static VALUE iseq_s_compile_option_get(VALUE self)
Definition: iseq.c:784
rb_iseq_struct::is_entries
union iseq_inline_storage_entry * is_entries
Definition: vm_core.h:241
rb_str_new
VALUE rb_str_new(const char *, long)
Definition: string.c:534
GET_VM
#define GET_VM()
Definition: vm_core.h:920