12#define RUBY_VM_INSNS_INFO 1
15#include "ruby/internal/config.h"
21#include "eval_intern.h"
24#include "internal/bits.h"
25#include "internal/class.h"
26#include "internal/compile.h"
27#include "internal/error.h"
28#include "internal/file.h"
29#include "internal/gc.h"
30#include "internal/hash.h"
31#include "internal/io.h"
32#include "internal/ruby_parser.h"
33#include "internal/sanitizers.h"
34#include "internal/set_table.h"
35#include "internal/symbol.h"
36#include "internal/thread.h"
37#include "internal/variable.h"
41#include "vm_callinfo.h"
46#include "insns_info.inc"
53#if VM_INSN_INFO_TABLE_IMPL == 2
54static struct succ_index_table *succ_index_table_create(
int max_pos,
int *data,
int size);
55static unsigned int *succ_index_table_invert(
int max_pos,
struct succ_index_table *sd,
int size);
56static int succ_index_lookup(
const struct succ_index_table *sd,
int x);
59#define hidden_obj_p(obj) (!SPECIAL_CONST_P(obj) && !RBASIC(obj)->klass)
62obj_resurrect(
VALUE obj)
64 if (hidden_obj_p(obj)) {
73 obj = rb_hash_resurrect(obj);
98 free_arena(compile_data->node.storage_head);
99 free_arena(compile_data->insn.storage_head);
100 if (compile_data->ivar_cache_table) {
101 rb_id_table_free(compile_data->ivar_cache_table);
103 ruby_xfree(compile_data);
108remove_from_constant_cache(
ID id,
IC ic)
112 st_data_t ic_data = (st_data_t)ic;
114 if (rb_id_table_lookup(vm->constant_cache,
id, &lookup_result)) {
116 set_table_delete(ics, &ic_data);
118 if (ics->num_entries == 0 &&
120 id != vm->inserting_constant_cache_id) {
121 rb_id_table_delete(vm->constant_cache,
id);
131iseq_clear_ic_references(
const rb_iseq_t *iseq)
137 if (!ISEQ_BODY(iseq)->is_entries) {
141 for (
unsigned int ic_idx = 0; ic_idx < ISEQ_BODY(iseq)->ic_size; ic_idx++) {
142 IC ic = &ISEQ_IS_IC_ENTRY(ISEQ_BODY(iseq), ic_idx);
150 if (segments == NULL)
153 for (
int i = 0; segments[i]; i++) {
155 if (
id == idNULL)
continue;
156 remove_from_constant_cache(
id, ic);
159 ruby_xfree((
void *)segments);
166 RUBY_FREE_ENTER(
"iseq");
168 if (iseq && ISEQ_BODY(iseq)) {
169 iseq_clear_ic_references(iseq);
172 rb_yjit_iseq_free(iseq);
175 rb_yjit_live_iseq_count--;
178 ruby_xfree((
void *)body->iseq_encoded);
179 ruby_xfree((
void *)body->insns_info.body);
180 ruby_xfree((
void *)body->insns_info.positions);
181#if VM_INSN_INFO_TABLE_IMPL == 2
182 ruby_xfree(body->insns_info.succ_index_table);
184 ruby_xfree((
void *)body->is_entries);
185 ruby_xfree(body->call_data);
186 ruby_xfree((
void *)body->catch_table);
187 ruby_xfree((
void *)body->
param.opt_table);
188 if (ISEQ_MBITS_BUFLEN(body->iseq_size) > 1 && body->mark_bits.list) {
189 ruby_xfree((
void *)body->mark_bits.list);
192 ruby_xfree(body->variable.original_iseq);
194 if (body->
param.keyword != NULL) {
195 if (body->
param.keyword->table != &body->local_table[body->
param.keyword->bits_start - body->
param.keyword->num])
196 ruby_xfree((
void *)body->
param.keyword->table);
197 if (body->
param.keyword->default_values) {
198 ruby_xfree((
void *)body->
param.keyword->default_values);
200 ruby_xfree((
void *)body->
param.keyword);
202 if (LIKELY(body->local_table != rb_iseq_shared_exc_local_tbl))
203 ruby_xfree((
void *)body->local_table);
204 compile_data_free(ISEQ_COMPILE_DATA(iseq));
205 if (body->outer_variables) rb_id_table_free(body->outer_variables);
209 if (iseq && ISEQ_EXECUTABLE_P(iseq) && iseq->aux.exec.local_hooks) {
210 rb_hook_list_free(iseq->aux.exec.local_hooks);
213 RUBY_FREE_LEAVE(
"iseq");
216typedef VALUE iseq_value_itr_t(
void *ctx,
VALUE obj);
219iseq_scan_bits(
unsigned int page, iseq_bits_t bits,
VALUE *code,
VALUE *original_iseq)
222 unsigned int page_offset = (page * ISEQ_MBITS_BITLENGTH);
225 offset = ntz_intptr(bits);
226 VALUE op = code[page_offset + offset];
227 rb_gc_mark_and_move(&code[page_offset + offset]);
228 VALUE newop = code[page_offset + offset];
229 if (original_iseq && newop != op) {
230 original_iseq[page_offset + offset] = newop;
237rb_iseq_mark_and_move_each_compile_data_value(
const rb_iseq_t *iseq,
VALUE *original_iseq)
243 size = compile_data->iseq_size;
244 code = compile_data->iseq_encoded;
247 if (compile_data->mark_bits.list) {
248 if(compile_data->is_single_mark_bit) {
249 iseq_scan_bits(0, compile_data->mark_bits.single, code, original_iseq);
252 for (
unsigned int i = 0; i < ISEQ_MBITS_BUFLEN(size); i++) {
253 iseq_bits_t bits = compile_data->mark_bits.list[i];
254 iseq_scan_bits(i, bits, code, original_iseq);
260rb_iseq_mark_and_move_each_body_value(
const rb_iseq_t *iseq,
VALUE *original_iseq)
266 size = body->iseq_size;
267 code = body->iseq_encoded;
271 if (body->is_entries) {
273 is_entries += body->ivc_size;
276 for (
unsigned int i = 0; i < body->icvarc_size; i++, is_entries++) {
281 rb_gc_mark_and_move(&icvarc->entry->class_value);
286 for (
unsigned int i = 0; i < body->ise_size; i++, is_entries++) {
288 if (is->once.value) {
289 rb_gc_mark_and_move(&is->once.value);
294 for (
unsigned int i = 0; i < body->ic_size; i++, is_entries++) {
295 IC ic = (
IC)is_entries;
297 rb_gc_mark_and_move_ptr(&ic->entry);
303 if (body->mark_bits.list) {
304 if (ISEQ_MBITS_BUFLEN(size) == 1) {
305 iseq_scan_bits(0, body->mark_bits.single, code, original_iseq);
308 for (
unsigned int i = 0; i < ISEQ_MBITS_BUFLEN(size); i++) {
309 iseq_bits_t bits = body->mark_bits.list[i];
310 iseq_scan_bits(i, bits, code, original_iseq);
317cc_is_active(
const struct rb_callcache *cc,
bool reference_updating)
320 if (cc == rb_vm_empty_cc() || rb_vm_empty_cc_for_super()) {
324 if (reference_updating) {
328 if (vm_cc_markable(cc) && vm_cc_valid(cc)) {
330 if (reference_updating) {
333 if (!METHOD_ENTRY_INVALIDATED(cme)) {
342rb_iseq_mark_and_move(
rb_iseq_t *iseq,
bool reference_updating)
344 RUBY_MARK_ENTER(
"iseq");
346 rb_gc_mark_and_move(&iseq->wrapper);
348 if (ISEQ_BODY(iseq)) {
351 rb_iseq_mark_and_move_each_body_value(iseq, reference_updating ? ISEQ_ORIGINAL_ISEQ(iseq) : NULL);
353 rb_gc_mark_and_move(&body->variable.coverage);
354 rb_gc_mark_and_move(&body->variable.pc2branchindex);
355 rb_gc_mark_and_move(&body->variable.script_lines);
356 rb_gc_mark_and_move(&body->location.label);
357 rb_gc_mark_and_move(&body->location.base_label);
358 rb_gc_mark_and_move(&body->location.pathobj);
359 if (body->local_iseq) rb_gc_mark_and_move_ptr(&body->local_iseq);
360 if (body->parent_iseq) rb_gc_mark_and_move_ptr(&body->parent_iseq);
361 if (body->mandatory_only_iseq) rb_gc_mark_and_move_ptr(&body->mandatory_only_iseq);
363 if (body->call_data) {
364 for (
unsigned int i = 0; i < body->ci_size; i++) {
367 if (cds[i].ci) rb_gc_mark_and_move_ptr(&cds[i].ci);
369 if (cc_is_active(cds[i].cc, reference_updating)) {
370 rb_gc_mark_and_move_ptr(&cds[i].cc);
372 else if (cds[i].cc != rb_vm_empty_cc()) {
373 cds[i].cc = rb_vm_empty_cc();
378 if (body->
param.flags.has_kw && body->
param.keyword != NULL) {
379 const struct rb_iseq_param_keyword *
const keyword = body->
param.keyword;
381 if (keyword->default_values != NULL) {
382 for (
int j = 0, i = keyword->required_num; i < keyword->num; i++, j++) {
383 rb_gc_mark_and_move(&keyword->default_values[j]);
388 if (body->catch_table) {
391 for (
unsigned int i = 0; i < table->size; i++) {
393 entry = UNALIGNED_MEMBER_PTR(table, entries[i]);
395 rb_gc_mark_and_move_ptr(&entry->iseq);
400 if (reference_updating) {
402 rb_yjit_iseq_update_references(iseq);
405 rb_zjit_iseq_update_references(body->zjit_payload);
410 rb_yjit_iseq_mark(body->yjit_payload);
413 rb_zjit_iseq_mark(body->zjit_payload);
419 rb_gc_mark_and_move(&iseq->aux.loader.obj);
424 rb_iseq_mark_and_move_insn_storage(compile_data->insn.storage_head);
425 rb_iseq_mark_and_move_each_compile_data_value(iseq, reference_updating ? ISEQ_ORIGINAL_ISEQ(iseq) : NULL);
427 rb_gc_mark_and_move((
VALUE *)&compile_data->err_info);
428 rb_gc_mark_and_move((
VALUE *)&compile_data->catch_table_ary);
432 VM_ASSERT(ISEQ_EXECUTABLE_P(iseq));
434 if (iseq->aux.exec.local_hooks) {
435 rb_hook_list_mark_and_update(iseq->aux.exec.local_hooks);
439 RUBY_MARK_LEAVE(
"iseq");
443param_keyword_size(
const struct rb_iseq_param_keyword *pkw)
447 if (!pkw)
return size;
449 size +=
sizeof(
struct rb_iseq_param_keyword);
450 size +=
sizeof(
VALUE) * (pkw->num - pkw->required_num);
464 if (ISEQ_EXECUTABLE_P(iseq) && body) {
466 size += body->iseq_size *
sizeof(
VALUE);
468 size += body->local_table_size *
sizeof(
ID);
469 size += ISEQ_MBITS_BUFLEN(body->iseq_size) * ISEQ_MBITS_SIZE;
470 if (body->catch_table) {
471 size += iseq_catch_table_bytes(body->catch_table->size);
473 size += (body->
param.opt_num + 1) *
sizeof(
VALUE);
474 size += param_keyword_size(body->
param.keyword);
479 if (ISEQ_BODY(iseq)->is_entries) {
481 for (
unsigned int ic_idx = 0; ic_idx < body->ic_size; ic_idx++) {
482 IC ic = &ISEQ_IS_IC_ENTRY(body, ic_idx);
497 compile_data = ISEQ_COMPILE_DATA(iseq);
503 cur = compile_data->node.storage_head;
514rb_iseq_constant_body_alloc(
void)
525 ISEQ_BODY(iseq) = rb_iseq_constant_body_alloc();
530rb_iseq_pathobj_new(
VALUE path,
VALUE realpath)
536 if (path == realpath ||
538 pathobj = rb_fstring(path);
541 if (!
NIL_P(realpath)) realpath = rb_fstring(realpath);
542 pathobj = rb_ary_new_from_args(2, rb_fstring(path), realpath);
552 rb_iseq_pathobj_new(path, realpath));
557rb_iseq_alloc_with_dummy_path(
VALUE fname)
561 ISEQ_BODY(dummy_iseq)->type = ISEQ_TYPE_TOP;
562 RB_OBJ_WRITE(dummy_iseq, &ISEQ_BODY(dummy_iseq)->location.pathobj, fname);
563 RB_OBJ_WRITE(dummy_iseq, &ISEQ_BODY(dummy_iseq)->location.label, fname);
573 rb_iseq_pathobj_set(iseq, path, realpath);
576 loc->first_lineno = first_lineno;
578 if (ISEQ_BODY(iseq)->local_iseq == iseq && strcmp(RSTRING_PTR(name),
"initialize") == 0) {
579 ISEQ_BODY(iseq)->param.flags.use_block = 1;
583 loc->node_id = node_id;
584 loc->code_location = *code_location;
587 loc->code_location.beg_pos.lineno = 0;
588 loc->code_location.beg_pos.column = 0;
589 loc->code_location.end_pos.lineno = -1;
590 loc->code_location.end_pos.column = -1;
603 if (
type == ISEQ_TYPE_TOP) {
604 body->local_iseq = iseq;
606 else if (
type == ISEQ_TYPE_METHOD ||
type == ISEQ_TYPE_CLASS) {
607 body->local_iseq = iseq;
610 RB_OBJ_WRITE(iseq, &body->local_iseq, ISEQ_BODY(piseq)->local_iseq);
617 if (
type == ISEQ_TYPE_MAIN) {
618 body->local_iseq = iseq;
627 ALLOC_N(
char, INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE +
632 new_arena->size = INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE;
640 const rb_iseq_t *parent,
int isolated_depth,
enum rb_iseq_type
type,
647 if (parent && (
type == ISEQ_TYPE_MAIN ||
type == ISEQ_TYPE_TOP))
651 set_relation(iseq, parent);
653 name = rb_fstring(name);
654 iseq_location_setup(iseq, name, path, realpath, first_lineno, code_location, node_id);
655 if (iseq != body->local_iseq) {
656 RB_OBJ_WRITE(iseq, &body->location.base_label, ISEQ_BODY(body->local_iseq)->location.label);
658 ISEQ_COVERAGE_SET(iseq,
Qnil);
659 ISEQ_ORIGINAL_ISEQ_CLEAR(iseq);
660 body->variable.flip_count = 0;
662 if (
NIL_P(script_lines)) {
669 ISEQ_COMPILE_DATA_ALLOC(iseq);
670 RB_OBJ_WRITE(iseq, &ISEQ_COMPILE_DATA(iseq)->err_info, err_info);
673 ISEQ_COMPILE_DATA(iseq)->node.storage_head = ISEQ_COMPILE_DATA(iseq)->node.storage_current = new_arena();
674 ISEQ_COMPILE_DATA(iseq)->insn.storage_head = ISEQ_COMPILE_DATA(iseq)->insn.storage_current = new_arena();
675 ISEQ_COMPILE_DATA(iseq)->isolated_depth = isolated_depth;
676 ISEQ_COMPILE_DATA(iseq)->option = option;
677 ISEQ_COMPILE_DATA(iseq)->ivar_cache_table = NULL;
678 ISEQ_COMPILE_DATA(iseq)->builtin_function_table = GET_VM()->builtin_function_table;
680 if (option->coverage_enabled) {
681 VALUE coverages = rb_get_coverages();
682 if (
RTEST(coverages)) {
683 coverage = rb_hash_lookup(coverages, rb_iseq_path(iseq));
687 ISEQ_COVERAGE_SET(iseq, coverage);
688 if (coverage && ISEQ_BRANCH_COVERAGE(iseq))
694#if VM_CHECK_MODE > 0 && VM_INSN_INFO_TABLE_IMPL > 0
695static void validate_get_insn_info(
const rb_iseq_t *iseq);
699rb_iseq_insns_info_encode_positions(
const rb_iseq_t *iseq)
701#if VM_INSN_INFO_TABLE_IMPL == 2
704 int size = body->insns_info.size;
705 int max_pos = body->iseq_size;
706 int *data = (
int *)body->insns_info.positions;
707 if (body->insns_info.succ_index_table) ruby_xfree(body->insns_info.succ_index_table);
708 body->insns_info.succ_index_table = succ_index_table_create(max_pos, data, size);
709#if VM_CHECK_MODE == 0
710 ruby_xfree(body->insns_info.positions);
711 body->insns_info.positions = NULL;
716#if VM_INSN_INFO_TABLE_IMPL == 2
720 int size = body->insns_info.size;
721 int max_pos = body->iseq_size;
722 struct succ_index_table *sd = body->insns_info.succ_index_table;
723 return succ_index_table_invert(max_pos, sd, size);
730 iseq->aux.exec.global_trace_events = 0;
731 if (ruby_vm_event_enabled_global_flags & ISEQ_TRACE_EVENTS) {
732 rb_iseq_trace_set(iseq, ruby_vm_event_enabled_global_flags & ISEQ_TRACE_EVENTS);
741 VALUE err = data->err_info;
742 ISEQ_COMPILE_DATA_CLEAR(iseq);
743 compile_data_free(data);
745#if VM_CHECK_MODE > 0 && VM_INSN_INFO_TABLE_IMPL > 0
746 validate_get_insn_info(iseq);
750 VALUE path = pathobj_path(body->location.pathobj);
752 rb_funcallv(err, rb_intern(
"set_backtrace"), 1, &path);
756 RB_DEBUG_COUNTER_INC(iseq_num);
757 RB_DEBUG_COUNTER_ADD(iseq_cd_num, ISEQ_BODY(iseq)->ci_size);
759 rb_iseq_init_trace(iseq);
764 .inline_const_cache = OPT_INLINE_CONST_CACHE,
765 .peephole_optimization = OPT_PEEPHOLE_OPTIMIZATION,
766 .tailcall_optimization = OPT_TAILCALL_OPTIMIZATION,
767 .specialized_instruction = OPT_SPECIALISED_INSTRUCTION,
768 .operands_unification = OPT_OPERANDS_UNIFICATION,
769 .instructions_unification = OPT_INSTRUCTIONS_UNIFICATION,
770 .frozen_string_literal = OPT_FROZEN_STRING_LITERAL,
771 .debug_frozen_string_literal = OPT_DEBUG_FROZEN_STRING_LITERAL,
772 .coverage_enabled = TRUE,
776 .frozen_string_literal = -1,
780rb_iseq_opt_frozen_string_literal(
void)
782 return COMPILE_OPTION_DEFAULT.frozen_string_literal;
788#define SET_COMPILE_OPTION(o, h, mem) \
789 { VALUE flag = rb_hash_aref((h), ID2SYM(rb_intern(#mem))); \
790 if (flag == Qtrue) { (o)->mem = 1; } \
791 else if (flag == Qfalse) { (o)->mem = 0; } \
793#define SET_COMPILE_OPTION_NUM(o, h, mem) \
794 { VALUE num = rb_hash_aref((h), ID2SYM(rb_intern(#mem))); \
795 if (!NIL_P(num)) (o)->mem = NUM2INT(num); \
797 SET_COMPILE_OPTION(option, opt, inline_const_cache);
798 SET_COMPILE_OPTION(option, opt, peephole_optimization);
799 SET_COMPILE_OPTION(option, opt, tailcall_optimization);
800 SET_COMPILE_OPTION(option, opt, specialized_instruction);
801 SET_COMPILE_OPTION(option, opt, operands_unification);
802 SET_COMPILE_OPTION(option, opt, instructions_unification);
803 SET_COMPILE_OPTION(option, opt, frozen_string_literal);
804 SET_COMPILE_OPTION(option, opt, debug_frozen_string_literal);
805 SET_COMPILE_OPTION(option, opt, coverage_enabled);
806 SET_COMPILE_OPTION_NUM(option, opt, debug_level);
807#undef SET_COMPILE_OPTION
808#undef SET_COMPILE_OPTION_NUM
814#define SET_COMPILE_OPTION(o, a, mem) \
815 ((a)->mem < 0 ? 0 : ((o)->mem = (a)->mem > 0))
816 SET_COMPILE_OPTION(option, ast, coverage_enabled);
817#undef SET_COMPILE_OPTION
818 if (ast->frozen_string_literal >= 0) {
819 option->frozen_string_literal = ast->frozen_string_literal;
828 *option = COMPILE_OPTION_DEFAULT;
831 *option = COMPILE_OPTION_FALSE;
833 else if (opt ==
Qtrue) {
836 ((
int *)option)[i] = 1;
839 *option = COMPILE_OPTION_DEFAULT;
840 set_compile_option_from_hash(option, opt);
843 rb_raise(
rb_eTypeError,
"Compile option must be Hash/true/false/nil");
850 VALUE opt = rb_hash_new_with_size(11);
851#define SET_COMPILE_OPTION(o, h, mem) \
852 rb_hash_aset((h), ID2SYM(rb_intern(#mem)), RBOOL((o)->mem))
853#define SET_COMPILE_OPTION_NUM(o, h, mem) \
854 rb_hash_aset((h), ID2SYM(rb_intern(#mem)), INT2NUM((o)->mem))
856 SET_COMPILE_OPTION(option, opt, inline_const_cache);
857 SET_COMPILE_OPTION(option, opt, peephole_optimization);
858 SET_COMPILE_OPTION(option, opt, tailcall_optimization);
859 SET_COMPILE_OPTION(option, opt, specialized_instruction);
860 SET_COMPILE_OPTION(option, opt, operands_unification);
861 SET_COMPILE_OPTION(option, opt, instructions_unification);
862 SET_COMPILE_OPTION(option, opt, debug_frozen_string_literal);
863 SET_COMPILE_OPTION(option, opt, coverage_enabled);
864 SET_COMPILE_OPTION_NUM(option, opt, debug_level);
866#undef SET_COMPILE_OPTION
867#undef SET_COMPILE_OPTION_NUM
868 VALUE frozen_string_literal = option->frozen_string_literal == -1 ?
Qnil : RBOOL(option->frozen_string_literal);
869 rb_hash_aset(opt,
ID2SYM(rb_intern(
"frozen_string_literal")), frozen_string_literal);
877 return rb_iseq_new_with_opt(ast_value, name, path, realpath, 0, parent,
878 0,
type, &COMPILE_OPTION_DEFAULT,
883ast_line_count(
const VALUE ast_value)
885 rb_ast_t *ast = rb_ruby_ast_data_get(ast_value);
886 return ast->body.line_count;
890iseq_setup_coverage(
VALUE coverages,
VALUE path,
int line_count)
892 if (line_count >= 0) {
893 int len = (rb_get_coverage_mode() & COVERAGE_TARGET_ONESHOT_LINES) ? 0 : line_count;
895 VALUE coverage = rb_default_coverage(
len);
896 rb_hash_aset(coverages, path, coverage);
905iseq_new_setup_coverage(
VALUE path,
int line_count)
907 VALUE coverages = rb_get_coverages();
909 if (
RTEST(coverages)) {
910 iseq_setup_coverage(coverages, path, line_count);
917 iseq_new_setup_coverage(path, ast_line_count(ast_value));
919 return rb_iseq_new_with_opt(ast_value, name, path, realpath, 0, parent, 0,
920 ISEQ_TYPE_TOP, &COMPILE_OPTION_DEFAULT,
932 return pm_iseq_new_with_opt(node, name, path, realpath, 0, parent, 0,
933 ISEQ_TYPE_TOP, &COMPILE_OPTION_DEFAULT, error_state);
939 iseq_new_setup_coverage(path, ast_line_count(ast_value));
941 return rb_iseq_new_with_opt(ast_value, rb_fstring_lit(
"<main>"),
943 parent, 0, ISEQ_TYPE_MAIN, opt ? &COMPILE_OPTION_DEFAULT : &COMPILE_OPTION_FALSE,
956 return pm_iseq_new_with_opt(node, rb_fstring_lit(
"<main>"),
958 parent, 0, ISEQ_TYPE_MAIN, opt ? &COMPILE_OPTION_DEFAULT : &COMPILE_OPTION_FALSE, error_state);
962rb_iseq_new_eval(
const VALUE ast_value,
VALUE name,
VALUE path,
VALUE realpath,
int first_lineno,
const rb_iseq_t *parent,
int isolated_depth)
964 if (rb_get_coverage_mode() & COVERAGE_TARGET_EVAL) {
965 VALUE coverages = rb_get_coverages();
966 if (
RTEST(coverages) &&
RTEST(path) && !
RTEST(rb_hash_has_key(coverages, path))) {
967 iseq_setup_coverage(coverages, path, ast_line_count(ast_value) + first_lineno - 1);
971 return rb_iseq_new_with_opt(ast_value, name, path, realpath, first_lineno,
972 parent, isolated_depth, ISEQ_TYPE_EVAL, &COMPILE_OPTION_DEFAULT,
978 int first_lineno,
const rb_iseq_t *parent,
int isolated_depth,
int *error_state)
980 if (rb_get_coverage_mode() & COVERAGE_TARGET_EVAL) {
981 VALUE coverages = rb_get_coverages();
982 if (
RTEST(coverages) &&
RTEST(path) && !
RTEST(rb_hash_has_key(coverages, path))) {
983 iseq_setup_coverage(coverages, path, ((
int) (node->parser->
newline_list.
size - 1)) + first_lineno - 1);
987 return pm_iseq_new_with_opt(node, name, path, realpath, first_lineno,
988 parent, isolated_depth, ISEQ_TYPE_EVAL, &COMPILE_OPTION_DEFAULT, error_state);
995 VALUE v1 = iseqw_new(iseq);
997 if (v1 != v2 &&
CLASS_OF(v2) == rb_cISeq) {
1007 int first_lineno,
const rb_iseq_t *parent,
int isolated_depth,
1011 rb_ast_t *ast = rb_ruby_ast_data_get(ast_value);
1013 const NODE *node = body ? body->root : 0;
1018 if (!option) option = &COMPILE_OPTION_DEFAULT;
1021 option = set_compile_option_from_ast(&new_opt, body);
1024 if (!
NIL_P(script_lines)) {
1027 else if (body && body->script_lines) {
1028 script_lines = rb_parser_build_script_lines_from(body->script_lines);
1031 script_lines = ISEQ_BODY(parent)->variable.script_lines;
1034 prepare_iseq_build(iseq, name, path, realpath, first_lineno, node ? &node->nd_loc : NULL, node ? nd_node_id(node) : -1,
1035 parent, isolated_depth,
type, script_lines, option);
1037 rb_iseq_compile_node(iseq, node);
1038 finish_iseq_build(iseq);
1041 return iseq_translate(iseq);
1050pm_iseq_new_with_opt_try(
VALUE d)
1055 pm_iseq_compile_node(data->iseq, data->node);
1058 finish_iseq_build(data->iseq);
1077 int first_lineno,
const rb_iseq_t *parent,
int isolated_depth,
1081 ISEQ_BODY(iseq)->prism =
true;
1084 if (!option) option = &COMPILE_OPTION_DEFAULT;
1086 next_option = *option;
1087 next_option.coverage_enabled = node->coverage_enabled < 0 ? 0 : node->coverage_enabled > 0;
1088 option = &next_option;
1091 int32_t start_line = node->parser->
start_line;
1097 .beg_pos = { .lineno = (int) start.
line, .column = (
int) start.
column },
1098 .end_pos = { .lineno = (int) end.
line, .column = (
int) end.
column }
1101 prepare_iseq_build(iseq, name, path, realpath, first_lineno, &code_location, node->ast_node->
node_id,
1102 parent, isolated_depth,
type, node->
script_lines == NULL ?
Qnil : *node->script_lines, option);
1108 rb_protect(pm_iseq_new_with_opt_try, (
VALUE)&data, error_state);
1110 if (*error_state)
return NULL;
1112 return iseq_translate(iseq);
1116rb_iseq_new_with_callback(
1119 int first_lineno,
const rb_iseq_t *parent,
1125 if (!option) option = &COMPILE_OPTION_DEFAULT;
1126 prepare_iseq_build(iseq, name, path, realpath, first_lineno, NULL, -1, parent, 0,
type,
Qnil, option);
1128 rb_iseq_compile_callback(iseq, ifunc);
1129 finish_iseq_build(iseq);
1135rb_iseq_load_iseq(
VALUE fname)
1140 return iseqw_check(iseqv);
1146#define CHECK_ARRAY(v) rb_to_array_type(v)
1147#define CHECK_HASH(v) rb_to_hash_type(v)
1148#define CHECK_STRING(v) rb_str_to_str(v)
1149#define CHECK_SYMBOL(v) rb_to_symbol_type(v)
1152static enum rb_iseq_type
1155 const ID id_top = rb_intern(
"top");
1156 const ID id_method = rb_intern(
"method");
1157 const ID id_block = rb_intern(
"block");
1158 const ID id_class = rb_intern(
"class");
1159 const ID id_rescue = rb_intern(
"rescue");
1160 const ID id_ensure = rb_intern(
"ensure");
1161 const ID id_eval = rb_intern(
"eval");
1162 const ID id_main = rb_intern(
"main");
1163 const ID id_plain = rb_intern(
"plain");
1167 if (
typeid == id_top)
return ISEQ_TYPE_TOP;
1168 if (
typeid == id_method)
return ISEQ_TYPE_METHOD;
1169 if (
typeid == id_block)
return ISEQ_TYPE_BLOCK;
1170 if (
typeid == id_class)
return ISEQ_TYPE_CLASS;
1171 if (
typeid == id_rescue)
return ISEQ_TYPE_RESCUE;
1172 if (
typeid == id_ensure)
return ISEQ_TYPE_ENSURE;
1173 if (
typeid == id_eval)
return ISEQ_TYPE_EVAL;
1174 if (
typeid == id_main)
return ISEQ_TYPE_MAIN;
1175 if (
typeid == id_plain)
return ISEQ_TYPE_PLAIN;
1176 return (
enum rb_iseq_type)-1;
1184 VALUE magic, version1, version2, format_type, misc;
1185 VALUE name, path, realpath, code_location, node_id;
1186 VALUE type, body, locals, params, exception;
1188 st_data_t iseq_type;
1198 data = CHECK_ARRAY(data);
1205 ((void)magic, (
void)version1, (void)version2, (
void)format_type);
1210 realpath =
NIL_P(realpath) ?
Qnil : CHECK_STRING(realpath);
1219 ISEQ_BODY(iseq)->local_iseq = iseq;
1221 iseq_type = iseq_type_from_sym(
type);
1222 if (iseq_type == (
enum rb_iseq_type)-1) {
1226 node_id = rb_hash_aref(misc,
ID2SYM(rb_intern(
"node_id")));
1228 code_location = rb_hash_aref(misc,
ID2SYM(rb_intern(
"code_location")));
1236 if (
SYM2ID(rb_hash_aref(misc,
ID2SYM(rb_intern(
"parser")))) == rb_intern(
"prism")) {
1237 ISEQ_BODY(iseq)->prism =
true;
1240 make_compile_option(&option, opt);
1241 option.peephole_optimization = FALSE;
1242 prepare_iseq_build(iseq, name, path, realpath, first_lineno, &tmp_loc,
NUM2INT(node_id),
1243 parent, 0, (
enum rb_iseq_type)iseq_type,
Qnil, &option);
1245 rb_iseq_build_from_ary(iseq, misc, locals, params, exception, body);
1247 finish_iseq_build(iseq);
1249 return iseqw_new(iseq);
1256iseq_s_load(
int argc,
VALUE *argv,
VALUE self)
1260 return iseq_load(data, NULL, opt);
1266 return iseq_load(data,
RTEST(parent) ? (
rb_iseq_t *)parent : NULL, opt);
1274#if !defined(__GNUC__) || (__GNUC__ == 4 && __GNUC_MINOR__ == 8)
1275# define INITIALIZED volatile
1281 VALUE INITIALIZED ast_value;
1283 VALUE name = rb_fstring_lit(
"<compiled>");
1286 make_compile_option(&option, opt);
1290 parse = rb_parser_compile_file_path;
1293 parse = rb_parser_compile_string_path;
1297 const VALUE parser = rb_parser_new();
1298 const rb_iseq_t *outer_scope = rb_iseq_new(
Qnil, name, name,
Qnil, 0, ISEQ_TYPE_TOP);
1300 rb_parser_set_context(parser, outer_scope, FALSE);
1301 if (ruby_vm_keep_script_lines) rb_parser_set_script_lines(parser);
1303 ast_value = (*parse)(parser, file, src, ln);
1306 ast = rb_ruby_ast_data_get(ast_value);
1308 if (!ast || !ast->body.root) {
1309 rb_ast_dispose(ast);
1313 iseq = rb_iseq_new_with_opt(ast_value, name, file, realpath, ln,
1314 NULL, 0, ISEQ_TYPE_TOP, &option,
1316 rb_ast_dispose(ast);
1328 VALUE name = rb_fstring_lit(
"<compiled>");
1331 make_compile_option(&option, opt);
1335 bool parse_file =
false;
1346 pm_options_scopes_init(&result.
options, 1);
1347 result.
node.coverage_enabled = 1;
1349 switch (option.frozen_string_literal) {
1350 case ISEQ_FROZEN_STRING_LITERAL_UNSET:
1352 case ISEQ_FROZEN_STRING_LITERAL_DISABLED:
1353 pm_options_frozen_string_literal_set(&result.
options,
false);
1355 case ISEQ_FROZEN_STRING_LITERAL_ENABLED:
1356 pm_options_frozen_string_literal_set(&result.
options,
true);
1359 rb_bug(
"pm_iseq_compile_with_option: invalid frozen_string_literal=%d", option.frozen_string_literal);
1367 error = pm_load_parse_file(&result, src, ruby_vm_keep_script_lines ? &script_lines : NULL);
1370 error = pm_parse_string(&result, src, file, ruby_vm_keep_script_lines ? &script_lines : NULL);
1375 if (error ==
Qnil) {
1377 iseq = pm_iseq_new_with_opt(&result.
node, name, file, realpath, ln, NULL, 0, ISEQ_TYPE_TOP, &option, &error_state);
1379 pm_parse_result_free(&result);
1383 rb_jump_tag(error_state);
1387 pm_parse_result_free(&result);
1397 return pathobj_path(ISEQ_BODY(iseq)->location.pathobj);
1403 return pathobj_realpath(ISEQ_BODY(iseq)->location.pathobj);
1407rb_iseq_absolute_path(
const rb_iseq_t *iseq)
1409 return rb_iseq_realpath(iseq);
1413rb_iseq_from_eval_p(
const rb_iseq_t *iseq)
1415 return NIL_P(rb_iseq_realpath(iseq));
1421 return ISEQ_BODY(iseq)->location.label;
1425rb_iseq_base_label(
const rb_iseq_t *iseq)
1427 return ISEQ_BODY(iseq)->location.base_label;
1431rb_iseq_first_lineno(
const rb_iseq_t *iseq)
1433 return RB_INT2NUM(ISEQ_BODY(iseq)->location.first_lineno);
1437rb_iseq_method_name(
const rb_iseq_t *iseq)
1441 if (body->type == ISEQ_TYPE_METHOD) {
1442 return body->location.base_label;
1450rb_iseq_code_location(
const rb_iseq_t *iseq,
int *beg_pos_lineno,
int *beg_pos_column,
int *end_pos_lineno,
int *end_pos_column)
1453 if (beg_pos_lineno) *beg_pos_lineno = loc->beg_pos.lineno;
1454 if (beg_pos_column) *beg_pos_column = loc->beg_pos.column;
1455 if (end_pos_lineno) *end_pos_lineno = loc->end_pos.lineno;
1456 if (end_pos_column) *end_pos_column = loc->end_pos.column;
1459static ID iseq_type_id(
enum rb_iseq_type
type);
1464 return ID2SYM(iseq_type_id(ISEQ_BODY(iseq)->
type));
1470 return ISEQ_COVERAGE(iseq);
1474remove_coverage_i(
void *vstart,
void *vend,
size_t stride,
void *data)
1477 for (; v != (
VALUE)vend; v += stride) {
1478 void *ptr = rb_asan_poisoned_object_p(v);
1479 rb_asan_unpoison_object(v,
false);
1481 if (rb_obj_is_iseq(v)) {
1483 ISEQ_COVERAGE_SET(iseq,
Qnil);
1486 asan_poison_object_if(ptr, v);
1492rb_iseq_remove_coverage_all(
void)
1494 rb_objspace_each_objects(remove_coverage_i, NULL);
1500iseqw_mark(
void *ptr)
1502 rb_gc_mark_movable(*(
VALUE *)ptr);
1506iseqw_memsize(
const void *ptr)
1508 return rb_iseq_memsize(*(
const rb_iseq_t **)ptr);
1512iseqw_ref_update(
void *ptr)
1515 *vptr = rb_gc_location(*vptr);
1526 0, 0, RUBY_TYPED_FREE_IMMEDIATELY|RUBY_TYPED_WB_PROTECTED
1532 if (iseq->wrapper) {
1534 rb_raise(
rb_eTypeError,
"wrong iseq wrapper: %" PRIsVALUE
" for %p",
1535 iseq->wrapper, (
void *)iseq);
1537 return iseq->wrapper;
1554 return iseqw_new(iseq);
1563iseqw_s_compile_parser(
int argc,
VALUE *argv,
VALUE self,
bool prism)
1569 if (i > 4+
NIL_P(opt)) rb_error_arity(argc, 1, 5);
1571 case 5: opt = argv[--i];
1572 case 4: line = argv[--i];
1573 case 3: path = argv[--i];
1574 case 2: file = argv[--i];
1577 if (
NIL_P(file)) file = rb_fstring_lit(
"<compiled>");
1578 if (
NIL_P(path)) path = file;
1586 iseq = pm_iseq_compile_with_option(src, file, path, line, opt);
1589 iseq = rb_iseq_compile_with_option(src, file, path, line, opt);
1592 return iseqw_new(iseq);
1633iseqw_s_compile(
int argc,
VALUE *argv,
VALUE self)
1635 return iseqw_s_compile_parser(argc, argv, self, rb_ruby_prism_p());
1675iseqw_s_compile_parsey(
int argc,
VALUE *argv,
VALUE self)
1677 return iseqw_s_compile_parser(argc, argv, self,
false);
1717iseqw_s_compile_prism(
int argc,
VALUE *argv,
VALUE self)
1719 return iseqw_s_compile_parser(argc, argv, self,
true);
1743iseqw_s_compile_file(
int argc,
VALUE *argv,
VALUE self)
1752 i =
rb_scan_args(argc, argv,
"1*:", &file, NULL, &opt);
1753 if (i > 1+
NIL_P(opt)) rb_error_arity(argc, 1, 2);
1755 case 2: opt = argv[--i];
1758 file = rb_fstring(file);
1763 VALUE v = rb_vm_push_frame_fname(ec, file);
1765 parser = rb_parser_new();
1766 rb_parser_set_context(parser, NULL, FALSE);
1767 ast_value = rb_parser_load_file(parser, file);
1768 ast = rb_ruby_ast_data_get(ast_value);
1769 if (!ast->body.root) exc = GET_EC()->errinfo;
1772 if (!ast->body.root) {
1773 rb_ast_dispose(ast);
1777 make_compile_option(&option, opt);
1779 ret = iseqw_new(rb_iseq_new_with_opt(ast_value, rb_fstring_lit(
"<main>"),
1781 rb_realpath_internal(
Qnil, file, 1),
1782 1, NULL, 0, ISEQ_TYPE_TOP, &option,
1784 rb_ast_dispose(ast);
1787 rb_vm_pop_frame(ec);
1814iseqw_s_compile_file_prism(
int argc,
VALUE *argv,
VALUE self)
1820 i =
rb_scan_args(argc, argv,
"1*:", &file, NULL, &opt);
1821 if (i > 1+
NIL_P(opt)) rb_error_arity(argc, 1, 2);
1823 case 2: opt = argv[--i];
1826 file = rb_fstring(file);
1829 VALUE v = rb_vm_push_frame_fname(ec, file);
1833 result.
node.coverage_enabled = 1;
1836 VALUE error = pm_load_parse_file(&result, file, ruby_vm_keep_script_lines ? &script_lines : NULL);
1838 if (error ==
Qnil) {
1839 make_compile_option(&option, opt);
1842 rb_iseq_t *iseq = pm_iseq_new_with_opt(&result.
node, rb_fstring_lit(
"<main>"),
1844 rb_realpath_internal(
Qnil, file, 1),
1845 1, NULL, 0, ISEQ_TYPE_TOP, &option, &error_state);
1847 pm_parse_result_free(&result);
1851 rb_jump_tag(error_state);
1854 ret = iseqw_new(iseq);
1855 rb_vm_pop_frame(ec);
1860 pm_parse_result_free(&result);
1861 rb_vm_pop_frame(ec);
1898iseqw_s_compile_option_set(
VALUE self,
VALUE opt)
1901 make_compile_option(&option, opt);
1902 COMPILE_OPTION_DEFAULT = option;
1915iseqw_s_compile_option_get(
VALUE self)
1917 return make_compile_option_value(&COMPILE_OPTION_DEFAULT);
1921iseqw_check(
VALUE iseqw)
1927 if (!ISEQ_BODY(iseq)) {
1928 rb_ibf_load_iseq_complete(iseq);
1931 if (!ISEQ_BODY(iseq)->location.label) {
1932 rb_raise(
rb_eTypeError,
"uninitialized InstructionSequence");
1938rb_iseqw_to_iseq(
VALUE iseqw)
1940 return iseqw_check(iseqw);
1952iseqw_eval(
VALUE self)
1954 const rb_iseq_t *iseq = iseqw_check(self);
1955 if (0 == ISEQ_BODY(iseq)->iseq_size) {
1956 rb_raise(
rb_eTypeError,
"attempt to evaluate dummy InstructionSequence");
1958 return rb_iseq_eval(iseq);
1966iseqw_inspect(
VALUE self)
1968 const rb_iseq_t *iseq = iseqw_check(self);
1972 if (!body->location.label) {
1973 return rb_sprintf(
"#<%"PRIsVALUE
": uninitialized>", klass);
1976 return rb_sprintf(
"<%"PRIsVALUE
":%"PRIsVALUE
"@%"PRIsVALUE
":%d>",
1978 body->location.label, rb_iseq_path(iseq),
1979 FIX2INT(rb_iseq_first_lineno(iseq)));
2007iseqw_path(
VALUE self)
2009 return rb_iseq_path(iseqw_check(self));
2029iseqw_absolute_path(
VALUE self)
2031 return rb_iseq_realpath(iseqw_check(self));
2058iseqw_label(
VALUE self)
2060 return rb_iseq_label(iseqw_check(self));
2084iseqw_base_label(
VALUE self)
2086 return rb_iseq_base_label(iseqw_check(self));
2100iseqw_first_lineno(
VALUE self)
2102 return rb_iseq_first_lineno(iseqw_check(self));
2189iseqw_to_a(
VALUE self)
2191 const rb_iseq_t *iseq = iseqw_check(self);
2192 return iseq_data_to_ary(iseq);
2195#if VM_INSN_INFO_TABLE_IMPL == 1
2197get_insn_info_binary_search(
const rb_iseq_t *iseq,
size_t pos)
2200 size_t size = body->insns_info.size;
2202 const unsigned int *positions = body->insns_info.positions;
2203 const int debug = 0;
2206 printf(
"size: %"PRIuSIZE
"\n", size);
2207 printf(
"insns_info[%"PRIuSIZE
"]: position: %d, line: %d, pos: %"PRIuSIZE
"\n",
2208 (
size_t)0, positions[0], insns_info[0].line_no, pos);
2214 else if (size == 1) {
2215 return &insns_info[0];
2218 size_t l = 1, r = size - 1;
2220 size_t m = l + (r - l) / 2;
2221 if (positions[m] == pos) {
2222 return &insns_info[m];
2224 if (positions[m] < pos) {
2232 return &insns_info[size-1];
2234 if (positions[l] > pos) {
2235 return &insns_info[l-1];
2237 return &insns_info[l];
2242get_insn_info(
const rb_iseq_t *iseq,
size_t pos)
2244 return get_insn_info_binary_search(iseq, pos);
2248#if VM_INSN_INFO_TABLE_IMPL == 2
2250get_insn_info_succinct_bitvector(
const rb_iseq_t *iseq,
size_t pos)
2253 size_t size = body->insns_info.size;
2255 const int debug = 0;
2258#if VM_CHECK_MODE > 0
2259 const unsigned int *positions = body->insns_info.positions;
2260 printf(
"size: %"PRIuSIZE
"\n", size);
2261 printf(
"insns_info[%"PRIuSIZE
"]: position: %d, line: %d, pos: %"PRIuSIZE
"\n",
2262 (
size_t)0, positions[0], insns_info[0].line_no, pos);
2264 printf(
"size: %"PRIuSIZE
"\n", size);
2265 printf(
"insns_info[%"PRIuSIZE
"]: line: %d, pos: %"PRIuSIZE
"\n",
2266 (
size_t)0, insns_info[0].line_no, pos);
2273 else if (size == 1) {
2274 return &insns_info[0];
2278 VM_ASSERT(body->insns_info.succ_index_table != NULL);
2279 index = succ_index_lookup(body->insns_info.succ_index_table, (
int)pos);
2280 return &insns_info[index-1];
2285get_insn_info(
const rb_iseq_t *iseq,
size_t pos)
2287 return get_insn_info_succinct_bitvector(iseq, pos);
2291#if VM_CHECK_MODE > 0 || VM_INSN_INFO_TABLE_IMPL == 0
2293get_insn_info_linear_search(
const rb_iseq_t *iseq,
size_t pos)
2296 size_t i = 0, size = body->insns_info.size;
2298 const unsigned int *positions = body->insns_info.positions;
2299 const int debug = 0;
2302 printf(
"size: %"PRIuSIZE
"\n", size);
2303 printf(
"insns_info[%"PRIuSIZE
"]: position: %d, line: %d, pos: %"PRIuSIZE
"\n",
2304 i, positions[i], insns_info[i].line_no, pos);
2310 else if (size == 1) {
2311 return &insns_info[0];
2314 for (i=1; i<size; i++) {
2315 if (debug) printf(
"insns_info[%"PRIuSIZE
"]: position: %d, line: %d, pos: %"PRIuSIZE
"\n",
2316 i, positions[i], insns_info[i].line_no, pos);
2318 if (positions[i] == pos) {
2319 return &insns_info[i];
2321 if (positions[i] > pos) {
2322 return &insns_info[i-1];
2326 return &insns_info[i-1];
2330#if VM_INSN_INFO_TABLE_IMPL == 0
2332get_insn_info(
const rb_iseq_t *iseq,
size_t pos)
2334 return get_insn_info_linear_search(iseq, pos);
2338#if VM_CHECK_MODE > 0 && VM_INSN_INFO_TABLE_IMPL > 0
2340validate_get_insn_info(
const rb_iseq_t *iseq)
2344 for (i = 0; i < body->iseq_size; i++) {
2345 if (get_insn_info_linear_search(iseq, i) != get_insn_info(iseq, i)) {
2346 rb_bug(
"validate_get_insn_info: get_insn_info_linear_search(iseq, %"PRIuSIZE
") != get_insn_info(iseq, %"PRIuSIZE
")", i, i);
2353rb_iseq_line_no(
const rb_iseq_t *iseq,
size_t pos)
2358 return entry->line_no;
2365#ifdef USE_ISEQ_NODE_ID
2367rb_iseq_node_id(
const rb_iseq_t *iseq,
size_t pos)
2372 return entry->node_id;
2381rb_iseq_event_flags(
const rb_iseq_t *iseq,
size_t pos)
2385 return entry->events;
2399 entry->events &= ~reset;
2400 if (!(entry->events & iseq->aux.exec.global_trace_events)) {
2401 void rb_iseq_trace_flag_cleared(
const rb_iseq_t *iseq,
size_t pos);
2402 rb_iseq_trace_flag_cleared(iseq, pos);
2415 for (i = 0; i < level; i++) {
2416 diseq = ISEQ_BODY(diseq)->parent_iseq;
2418 idx = ISEQ_BODY(diseq)->local_table_size - (int)op - 1;
2419 lid = ISEQ_BODY(diseq)->local_table[idx];
2420 name = rb_id2str(lid);
2430 rb_str_catf(name,
"@%d", idx);
2434int rb_insn_unified_local_var_level(
VALUE);
2438rb_insn_operand_intern(
const rb_iseq_t *iseq,
2442 const char *types = insn_op_types(insn);
2443 char type = types[op_no];
2448 ret = rb_sprintf(
"%"PRIdVALUE, (
VALUE)(pos +
len + op));
2452 if (insn == BIN(defined) && op_no == 0) {
2453 enum defined_type deftype = (
enum defined_type)op;
2456 ret = rb_fstring_lit(
"func");
2459 ret = rb_fstring_lit(
"ref");
2461 case DEFINED_CONST_FROM:
2462 ret = rb_fstring_lit(
"constant-from");
2465 ret = rb_iseq_defined_string(deftype);
2470 else if (insn == BIN(checktype) && op_no == 0) {
2476 ret = rb_sprintf(
"%"PRIuVALUE, op);
2481 if (types[op_no+1] == TS_NUM && pnop) {
2482 ret = local_var_name(iseq, *pnop, op - VM_ENV_DATA_SIZE);
2484 else if ((level = rb_insn_unified_local_var_level(insn)) >= 0) {
2485 ret = local_var_name(iseq, (
VALUE)level, op - VM_ENV_DATA_SIZE);
2497 op = obj_resurrect(op);
2498 if (insn == BIN(defined) && op_no == 1 &&
FIXNUM_P(op)) {
2503 ret = rb_sprintf(
":$%c", (
type >> 1));
2506 ret = rb_sprintf(
":$%d", (
type >> 1));
2511 ret = rb_dump_literal(op);
2523 ret = ISEQ_BODY(iseq)->location.label;
2537 const ID *segments = ((
IC)op)->segments;
2540 rb_str_catf(ret,
"::%s", rb_id2name(*segments++));
2556 ID mid = vm_ci_mid(ci);
2559 rb_ary_push(ary, rb_sprintf(
"mid:%"PRIsVALUE, rb_id2str(mid)));
2562 rb_ary_push(ary, rb_sprintf(
"argc:%d", vm_ci_argc(ci)));
2564 if (vm_ci_flag(ci) & VM_CALL_KWARG) {
2570 if (vm_ci_flag(ci)) {
2572# define CALL_FLAG(n) if (vm_ci_flag(ci) & VM_CALL_##n) rb_ary_push(flags, rb_str_new2(#n))
2573 CALL_FLAG(ARGS_SPLAT);
2574 CALL_FLAG(ARGS_SPLAT_MUT);
2575 CALL_FLAG(ARGS_BLOCKARG);
2578 CALL_FLAG(ARGS_SIMPLE);
2579 CALL_FLAG(TAILCALL);
2583 CALL_FLAG(KW_SPLAT);
2584 CALL_FLAG(KW_SPLAT_MUT);
2585 CALL_FLAG(FORWARDING);
2586 CALL_FLAG(OPT_SEND);
2602 if (dladdr((
void *)op, &info) && info.dli_sname) {
2614 ret = rb_sprintf(
"<builtin!%s/%d>",
2615 bf->name, bf->argc);
2620 rb_bug(
"unknown operand type: %c",
type);
2626right_strip(
VALUE str)
2628 const char *beg = RSTRING_PTR(str), *end =
RSTRING_END(str);
2629 while (end-- > beg && *end ==
' ');
2639rb_iseq_disasm_insn(
VALUE ret,
const VALUE *code,
size_t pos,
2642 VALUE insn = code[pos];
2643 int len = insn_len(insn);
2645 const char *types = insn_op_types(insn);
2647 const char *insn_name_buff;
2649 insn_name_buff = insn_name(insn);
2651 extern const int rb_vm_max_insn_name_size;
2652 rb_str_catf(str,
"%04"PRIuSIZE
" %-*s ", pos, rb_vm_max_insn_name_size, insn_name_buff);
2655 rb_str_catf(str,
"%04"PRIuSIZE
" %-28.*s ", pos,
2656 (
int)strcspn(insn_name_buff,
"_"), insn_name_buff);
2659 for (j = 0; types[j]; j++) {
2660 VALUE opstr = rb_insn_operand_intern(iseq, insn, j, code[pos + j + 1],
2661 len, pos, &code[pos + j + 2],
2671 unsigned int line_no = rb_iseq_line_no(iseq, pos);
2672 unsigned int prev = pos == 0 ? 0 : rb_iseq_line_no(iseq, pos - 1);
2673 if (line_no && line_no != prev) {
2674 long slen = RSTRING_LEN(str);
2675 slen = (slen > 70) ? 0 : (70 - slen);
2676 str = rb_str_catf(str,
"%*s(%4d)", (
int)slen,
"", line_no);
2683 str = rb_str_catf(str,
"[%s%s%s%s%s%s%s%s%s%s%s%s]",
2694 events & RUBY_EVENT_COVERAGE_LINE ?
"Cli" :
"",
2695 events & RUBY_EVENT_COVERAGE_BRANCH ?
"Cbr" :
"");
2705 printf(
"%.*s\n", (
int)RSTRING_LEN(str), RSTRING_PTR(str));
2714 case CATCH_TYPE_RESCUE:
2716 case CATCH_TYPE_ENSURE:
2718 case CATCH_TYPE_RETRY:
2720 case CATCH_TYPE_BREAK:
2722 case CATCH_TYPE_REDO:
2724 case CATCH_TYPE_NEXT:
2727 rb_bug(
"unknown catch type: %d",
type);
2736 if (!body->location.label) {
2737 return rb_sprintf(
"#<ISeq: uninitialized>");
2741 return rb_sprintf(
"#<ISeq:%"PRIsVALUE
"@%"PRIsVALUE
":%d (%d,%d)-(%d,%d)>",
2742 body->location.label, rb_iseq_path(iseq),
2743 loc->beg_pos.lineno,
2744 loc->beg_pos.lineno,
2745 loc->beg_pos.column,
2746 loc->end_pos.lineno,
2747 loc->end_pos.column);
2753 {(void (*)(
void *))rb_mark_set, (void (*)(
void *))st_free_table, 0, 0,},
2754 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
2768 enum {header_minlen = 72};
2771 const char *indent_str;
2774 size = body->iseq_size;
2776 indent_len = RSTRING_LEN(indent);
2777 indent_str = RSTRING_PTR(indent);
2783 if ((l = RSTRING_LEN(str) - indent_len) < header_minlen) {
2787 if (iseq->body->builtin_attrs) {
2788#define disasm_builtin_attr(str, iseq, attr) \
2789 if (iseq->body->builtin_attrs & BUILTIN_ATTR_ ## attr) { \
2790 rb_str_cat2(str, " " #attr); \
2792 disasm_builtin_attr(str, iseq, LEAF);
2793 disasm_builtin_attr(str, iseq, SINGLE_NOARG_LEAF);
2794 disasm_builtin_attr(str, iseq, INLINE_BLOCK);
2795 disasm_builtin_attr(str, iseq, C_TRACE);
2800 if (body->catch_table) {
2804 if (body->catch_table) {
2806 indent_str = RSTRING_PTR(indent);
2807 for (i = 0; i < body->catch_table->size; i++) {
2809 UNALIGNED_MEMBER_PTR(body->catch_table, entries[i]);
2812 "| catch type: %-6s st: %04d ed: %04d sp: %04d cont: %04d\n",
2813 catch_type((
int)entry->type), (
int)entry->start,
2814 (
int)entry->end, (
int)entry->sp, (
int)entry->cont);
2815 if (entry->iseq && !(done_iseq && st_is_member(done_iseq, (st_data_t)entry->iseq))) {
2816 rb_str_concat(str, rb_iseq_disasm_recursive(rb_iseq_check(entry->iseq), indent));
2818 done_iseq = st_init_numtable();
2821 st_insert(done_iseq, (st_data_t)entry->iseq, (st_data_t)0);
2822 indent_str = RSTRING_PTR(indent);
2825 rb_str_resize(indent, indent_len);
2826 indent_str = RSTRING_PTR(indent);
2828 if (body->catch_table) {
2830 rb_str_cat2(str,
"|-------------------------------------"
2831 "-----------------------------------\n");
2835 if (body->local_table) {
2836 const struct rb_iseq_param_keyword *
const keyword = body->
param.keyword;
2839 "local table (size: %d, argc: %d "
2840 "[opts: %d, rest: %d, post: %d, block: %d, kw: %d@%d, kwrest: %d])\n",
2841 body->local_table_size,
2842 body->
param.lead_num,
2843 body->
param.opt_num,
2844 body->
param.flags.has_rest ? body->
param.rest_start : -1,
2845 body->param.post_num,
2846 body->param.flags.has_block ? body->param.block_start : -1,
2847 body->param.flags.has_kw ? keyword->num : -1,
2848 body->param.flags.has_kw ? keyword->required_num : -1,
2849 body->param.flags.has_kwrest ? keyword->rest_start : -1);
2851 for (i = body->local_table_size; i > 0;) {
2852 int li = body->local_table_size - --i - 1;
2854 VALUE name = local_var_name(iseq, 0, i);
2859 if (body->
param.flags.has_opt) {
2860 int argc = body->
param.lead_num;
2861 int opts = body->
param.opt_num;
2862 if (li >= argc && li < argc + opts) {
2863 snprintf(opti,
sizeof(opti),
"Opt=%"PRIdVALUE,
2864 body->
param.opt_table[li - argc]);
2868 snprintf(argi,
sizeof(argi),
"%s%s%s%s%s%s",
2869 (body->
param.lead_num > li) ? (body->
param.flags.ambiguous_param0 ?
"AmbiguousArg" :
"Arg") :
"",
2871 (body->param.flags.has_rest && body->param.rest_start == li) ? (body->param.flags.anon_rest ?
"AnonRest" :
"Rest") :
"",
2872 (body->param.flags.has_post && body->param.post_start <= li && li < body->param.post_start + body->param.post_num) ?
"Post" :
"",
2873 (body->param.flags.has_kwrest && keyword->rest_start == li) ? (body->param.flags.anon_kwrest ?
"AnonKwrest" :
"Kwrest") :
"",
2874 (body->param.flags.has_block && body->param.block_start == li) ?
"Block" :
"");
2877 rb_str_catf(str,
"[%2d] ", i + 1);
2878 width = RSTRING_LEN(str) + 11;
2880 if (*argi) rb_str_catf(str,
"<%s>", argi);
2881 if ((width -= RSTRING_LEN(str)) > 0) rb_str_catf(str,
"%*s", (
int)width,
"");
2887 code = rb_iseq_original_iseq(iseq);
2888 for (n = 0; n < size;) {
2890 n += rb_iseq_disasm_insn(str, code, n, iseq, child);
2895 if (done_iseq && st_is_member(done_iseq, (st_data_t)isv))
continue;
2898 indent_str = RSTRING_PTR(indent);
2909 rb_str_resize(str, RSTRING_LEN(str));
2919rb_estimate_iv_count(
VALUE klass,
const rb_iseq_t * initialize_iseq)
2921 struct rb_id_table * iv_names = rb_id_table_create(0);
2923 for (
unsigned int i = 0; i < ISEQ_BODY(initialize_iseq)->ivc_size; i++) {
2924 IVC cache = (
IVC)&ISEQ_BODY(initialize_iseq)->is_entries[i];
2926 if (cache->iv_set_name) {
2927 rb_id_table_insert(iv_names, cache->iv_set_name,
Qtrue);
2931 attr_index_t count = (attr_index_t)rb_id_table_size(iv_names);
2934 count += RCLASS_MAX_IV_COUNT(superclass);
2936 rb_id_table_free(iv_names);
2960iseqw_disasm(
VALUE self)
2962 return rb_iseq_disasm(iseqw_check(self));
2966iseq_iterate_children(
const rb_iseq_t *iseq,
void (*iter_func)(
const rb_iseq_t *child_iseq,
void *data),
void *data)
2969 VALUE *code = rb_iseq_original_iseq(iseq);
2974 if (body->catch_table) {
2975 for (i = 0; i < body->catch_table->size; i++) {
2977 UNALIGNED_MEMBER_PTR(body->catch_table, entries[i]);
2978 child = entry->iseq;
2980 if (
NIL_P(rb_hash_aref(all_children, (
VALUE)child))) {
2981 rb_hash_aset(all_children, (
VALUE)child,
Qtrue);
2982 (*iter_func)(child, data);
2988 for (i=0; i<body->iseq_size;) {
2989 VALUE insn = code[i];
2990 int len = insn_len(insn);
2991 const char *types = insn_op_types(insn);
2994 for (j=0; types[j]; j++) {
2999 if (
NIL_P(rb_hash_aref(all_children, (
VALUE)child))) {
3000 rb_hash_aset(all_children, (
VALUE)child,
Qtrue);
3001 (*iter_func)(child, data);
3016yield_each_children(
const rb_iseq_t *child_iseq,
void *data)
3030iseqw_each_child(
VALUE self)
3032 const rb_iseq_t *iseq = iseqw_check(self);
3033 iseq_iterate_children(iseq, yield_each_children, NULL);
3040#define C(ev, cstr, l) if (events & ev) rb_ary_push(ary, rb_ary_new_from_args(2, l, ID2SYM(rb_intern(cstr))));
3060iseqw_trace_points(
VALUE self)
3062 const rb_iseq_t *iseq = iseqw_check(self);
3067 for (i=0; i<body->insns_info.size; i++) {
3069 if (entry->events) {
3070 push_event_info(iseq, entry->events, entry->line_no, ary);
3116 if (rb_frame_info_p(body)) {
3117 iseq = rb_get_iseq_from_frame_info(body);
3120 iseq = vm_proc_iseq(body);
3122 if (!rb_obj_is_iseq((
VALUE)iseq)) {
3127 iseq = rb_method_iseq(body);
3129 else if (rb_typeddata_is_instance_of(body, &iseqw_data_type)) {
3133 return iseq ? iseqw_new(iseq) :
Qnil;
3191 VALUE iseqw = iseqw_s_of(klass, body);
3192 return NIL_P(iseqw) ?
Qnil : rb_iseq_disasm(iseqw_check(iseqw));
3196register_label(
struct st_table *table,
unsigned long idx)
3199 st_insert(table, idx, sym);
3208 case CATCH_TYPE_RESCUE:
CONST_ID(
id,
"rescue");
break;
3209 case CATCH_TYPE_ENSURE:
CONST_ID(
id,
"ensure");
break;
3210 case CATCH_TYPE_RETRY:
CONST_ID(
id,
"retry");
break;
3211 case CATCH_TYPE_BREAK:
CONST_ID(
id,
"break");
break;
3212 case CATCH_TYPE_REDO:
CONST_ID(
id,
"redo");
break;
3213 case CATCH_TYPE_NEXT:
CONST_ID(
id,
"next");
break;
3215 rb_bug(
"unknown exception type: %d", (
int)
type);
3230 {(void (*)(
void *))rb_mark_tbl, (void (*)(
void *))st_free_table, 0, 0,},
3231 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
3234#define DECL_ID(name) \
3237#define INIT_ID(name) \
3238 id_##name = rb_intern(#name)
3241iseq_type_id(
enum rb_iseq_type
type)
3266 case ISEQ_TYPE_TOP:
return id_top;
3267 case ISEQ_TYPE_METHOD:
return id_method;
3268 case ISEQ_TYPE_BLOCK:
return id_block;
3269 case ISEQ_TYPE_CLASS:
return id_class;
3270 case ISEQ_TYPE_RESCUE:
return id_rescue;
3271 case ISEQ_TYPE_ENSURE:
return id_ensure;
3272 case ISEQ_TYPE_EVAL:
return id_eval;
3273 case ISEQ_TYPE_MAIN:
return id_main;
3274 case ISEQ_TYPE_PLAIN:
return id_plain;
3277 rb_bug(
"unsupported iseq type: %d", (
int)
type);
3289 VALUE *seq, *iseq_original;
3294 VALUE params = rb_hash_new();
3298 VALUE misc = rb_hash_new();
3300 static ID insn_syms[VM_BARE_INSTRUCTION_SIZE];
3301 struct st_table *labels_table = st_init_numtable();
3304 if (insn_syms[0] == 0) {
3306 for (i=0; i<numberof(insn_syms); i++) {
3307 insn_syms[i] = rb_intern(insn_name(i));
3312 type = iseq_type_id(iseq_body->type);
3315 for (i=0; i<iseq_body->local_table_size; i++) {
3316 ID lid = iseq_body->local_table[i];
3318 if (rb_id2str(lid)) {
3332 const struct rb_iseq_param_keyword *
const keyword = iseq_body->
param.keyword;
3335 if (iseq_body->
param.flags.has_opt) {
3336 int len = iseq_body->
param.opt_num + 1;
3339 for (j = 0; j <
len; j++) {
3340 VALUE l = register_label(labels_table, iseq_body->
param.opt_table[j]);
3343 rb_hash_aset(params,
ID2SYM(rb_intern(
"opt")), arg_opt_labels);
3347 if (iseq_body->
param.flags.has_lead) rb_hash_aset(params,
ID2SYM(rb_intern(
"lead_num")),
INT2FIX(iseq_body->
param.lead_num));
3348 if (iseq_body->
param.flags.has_post) rb_hash_aset(params,
ID2SYM(rb_intern(
"post_num")),
INT2FIX(iseq_body->
param.post_num));
3349 if (iseq_body->
param.flags.has_post) rb_hash_aset(params,
ID2SYM(rb_intern(
"post_start")),
INT2FIX(iseq_body->
param.post_start));
3350 if (iseq_body->
param.flags.has_rest) rb_hash_aset(params,
ID2SYM(rb_intern(
"rest_start")),
INT2FIX(iseq_body->
param.rest_start));
3351 if (iseq_body->
param.flags.has_block) rb_hash_aset(params,
ID2SYM(rb_intern(
"block_start")),
INT2FIX(iseq_body->
param.block_start));
3352 if (iseq_body->
param.flags.has_kw) {
3355 for (i=0; i<keyword->required_num; i++) {
3358 for (j=0; i<keyword->num; i++, j++) {
3359 VALUE key = rb_ary_new_from_args(1,
ID2SYM(keyword->table[i]));
3360 if (!UNDEF_P(keyword->default_values[j])) {
3366 rb_hash_aset(params,
ID2SYM(rb_intern(
"kwbits")),
3367 INT2FIX(keyword->bits_start));
3368 rb_hash_aset(params,
ID2SYM(rb_intern(
"keyword")), keywords);
3370 if (iseq_body->
param.flags.has_kwrest) rb_hash_aset(params,
ID2SYM(rb_intern(
"kwrest")),
INT2FIX(keyword->rest_start));
3371 if (iseq_body->
param.flags.ambiguous_param0) rb_hash_aset(params,
ID2SYM(rb_intern(
"ambiguous_param0")),
Qtrue);
3372 if (iseq_body->
param.flags.use_block) rb_hash_aset(params,
ID2SYM(rb_intern(
"use_block")),
Qtrue);
3376 iseq_original = rb_iseq_original_iseq((
rb_iseq_t *)iseq);
3378 for (seq = iseq_original; seq < iseq_original + iseq_body->iseq_size; ) {
3379 VALUE insn = *seq++;
3380 int j,
len = insn_len(insn);
3385 for (j=0; j<
len-1; j++, seq++) {
3386 enum ruby_insn_type_chars op_type = insn_op_type(insn, j);
3390 unsigned long idx = nseq - iseq_original + *seq;
3391 rb_ary_push(ary, register_label(labels_table, idx));
3405 VALUE val = iseq_data_to_ary(rb_iseq_check(iseq));
3416 const ID *ids = ((
IC)*seq)->segments;
3435 VALUE e = rb_hash_new();
3436 int argc = vm_ci_argc(ci);
3438 ID mid = vm_ci_mid(ci);
3440 rb_hash_aset(e,
ID2SYM(rb_intern(
"flag")),
UINT2NUM(vm_ci_flag(ci)));
3442 if (vm_ci_flag(ci) & VM_CALL_KWARG) {
3447 argc -= kwarg->keyword_len;
3448 for (i = 0; i < kwarg->keyword_len; i++) {
3451 rb_hash_aset(e,
ID2SYM(rb_intern(
"kw_arg")), kw);
3454 rb_hash_aset(e,
ID2SYM(rb_intern(
"orig_argc")),
3472 unsigned long idx = nseq - iseq_original + pos;
3475 register_label(labels_table, idx));
3482#if SIZEOF_VALUE <= SIZEOF_LONG
3492 VALUE val = rb_hash_new();
3493#if SIZEOF_VALUE <= SIZEOF_LONG
3498 rb_hash_aset(val,
ID2SYM(rb_intern(
"func_ptr")), func_ptr);
3506 rb_bug(
"unknown operand: %c", insn_op_type(insn, j));
3515 if (iseq_body->catch_table)
for (i=0; i<iseq_body->catch_table->size; i++) {
3518 UNALIGNED_MEMBER_PTR(iseq_body->catch_table, entries[i]);
3519 rb_ary_push(ary, exception_type2symbol(entry->type));
3521 rb_ary_push(ary, iseq_data_to_ary(rb_iseq_check(entry->iseq)));
3526 rb_ary_push(ary, register_label(labels_table, entry->start));
3527 rb_ary_push(ary, register_label(labels_table, entry->end));
3528 rb_ary_push(ary, register_label(labels_table, entry->cont));
3535 prev_insn_info = NULL;
3536#ifdef USE_ISEQ_NODE_ID
3545 if (st_lookup(labels_table, pos, &label)) {
3549 info = get_insn_info(iseq, pos);
3550#ifdef USE_ISEQ_NODE_ID
3554 if (prev_insn_info != info) {
3555 int line = info->line_no;
3558 if (line > 0 && last_line != line) {
3562#define CHECK_EVENT(ev) if (events & ev) rb_ary_push(body, ID2SYM(rb_intern(#ev)));
3572 prev_insn_info = info;
3582 rb_hash_aset(misc,
ID2SYM(rb_intern(
"local_size")),
INT2FIX(iseq_body->local_table_size));
3583 rb_hash_aset(misc,
ID2SYM(rb_intern(
"stack_max")),
INT2FIX(iseq_body->stack_max));
3584 rb_hash_aset(misc,
ID2SYM(rb_intern(
"node_id")),
INT2FIX(iseq_body->location.node_id));
3585 rb_hash_aset(misc,
ID2SYM(rb_intern(
"code_location")),
3586 rb_ary_new_from_args(4,
3587 INT2FIX(iseq_body->location.code_location.beg_pos.lineno),
3588 INT2FIX(iseq_body->location.code_location.beg_pos.column),
3589 INT2FIX(iseq_body->location.code_location.end_pos.lineno),
3590 INT2FIX(iseq_body->location.code_location.end_pos.column)));
3591#ifdef USE_ISEQ_NODE_ID
3592 rb_hash_aset(misc,
ID2SYM(rb_intern(
"node_ids")), node_ids);
3594 rb_hash_aset(misc,
ID2SYM(rb_intern(
"parser")), iseq_body->prism ?
ID2SYM(rb_intern(
"prism")) :
ID2SYM(rb_intern(
"parse.y")));
3619rb_iseq_parameters(
const rb_iseq_t *iseq,
int is_proc)
3623 const struct rb_iseq_param_keyword *
const keyword = body->
param.keyword;
3625 ID req, opt, rest, block, key, keyrest;
3626#define PARAM_TYPE(type) rb_ary_push(a = rb_ary_new2(2), ID2SYM(type))
3627#define PARAM_ID(i) body->local_table[(i)]
3628#define PARAM(i, type) ( \
3630 rb_id2str(PARAM_ID(i)) ? \
3631 rb_ary_push(a, ID2SYM(PARAM_ID(i))) : \
3637 if (body->
param.flags.forwardable) {
3648 for (i = 0; i < body->
param.lead_num; i++) {
3650 if (rb_id2str(PARAM_ID(i))) {
3657 for (i = 0; i < body->
param.lead_num; i++) {
3661 r = body->
param.lead_num + body->
param.opt_num;
3662 for (; i < r; i++) {
3664 if (rb_id2str(PARAM_ID(i))) {
3669 if (body->
param.flags.has_rest) {
3673 r = body->
param.post_start + body->
param.post_num;
3675 for (i = body->
param.post_start; i < r; i++) {
3677 if (rb_id2str(PARAM_ID(i))) {
3684 for (i = body->
param.post_start; i < r; i++) {
3688 if (body->
param.flags.accepts_no_kwarg) {
3694 if (body->
param.flags.has_kw) {
3696 if (keyword->required_num > 0) {
3699 for (; i < keyword->required_num; i++) {
3701 if (rb_id2str(keyword->table[i])) {
3708 for (; i < keyword->num; i++) {
3710 if (rb_id2str(keyword->table[i])) {
3716 if (body->
param.flags.has_kwrest || body->
param.flags.ruby2_keywords) {
3719 PARAM_TYPE(keyrest);
3720 if (body->
param.flags.has_kwrest &&
3721 rb_id2str(param = PARAM_ID(keyword->rest_start))) {
3724 else if (body->
param.flags.ruby2_keywords) {
3729 if (body->
param.flags.has_block) {
3737rb_iseq_defined_string(
enum defined_type
type)
3739 static const char expr_names[][18] = {
3741 "instance-variable",
3757 if ((
unsigned)(
type - 1) >= (
unsigned)numberof(expr_names)) rb_bug(
"unknown defined type %d",
type);
3758 estr = expr_names[
type - 1];
3759 return rb_fstring_cstr(estr);
3769 void *notrace_encoded_insn;
3770 void *trace_encoded_insn;
3773 void *zjit_encoded_insn;
3776static insn_data_t insn_data[VM_BARE_INSTRUCTION_SIZE];
3779rb_free_encoded_insn_data(
void)
3781 st_free_table(encoded_insn_data);
3787rb_vm_encoded_insn_data_table_init(
void)
3789#if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE
3790 const void *
const *table = rb_vm_get_insns_address_table();
3791#define INSN_CODE(insn) ((VALUE)table[insn])
3793#define INSN_CODE(insn) ((VALUE)(insn))
3795 encoded_insn_data = st_init_numtable_with_size(VM_BARE_INSTRUCTION_SIZE);
3797 for (
int insn = 0; insn < VM_BARE_INSTRUCTION_SIZE; insn++) {
3798 insn_data[insn].insn = insn;
3799 insn_data[insn].insn_len = insn_len(insn);
3804 int notrace_insn = (insn != BIN(opt_invokebuiltin_delegate_leave)) ? insn : BIN(opt_invokebuiltin_delegate);
3805 insn_data[insn].notrace_encoded_insn = (
void *)INSN_CODE(notrace_insn);
3806 insn_data[insn].trace_encoded_insn = (
void *)INSN_CODE(notrace_insn + VM_BARE_INSTRUCTION_SIZE);
3808 st_data_t key1 = (st_data_t)INSN_CODE(insn);
3809 st_data_t key2 = (st_data_t)INSN_CODE(insn + VM_BARE_INSTRUCTION_SIZE);
3810 st_add_direct(encoded_insn_data, key1, (st_data_t)&insn_data[insn]);
3811 st_add_direct(encoded_insn_data, key2, (st_data_t)&insn_data[insn]);
3814 int zjit_insn = vm_bare_insn_to_zjit_insn(insn);
3815 insn_data[insn].zjit_insn = zjit_insn;
3816 insn_data[insn].zjit_encoded_insn = (insn != zjit_insn) ? (
void *)INSN_CODE(zjit_insn) : 0;
3818 if (insn != zjit_insn) {
3819 st_data_t key3 = (st_data_t)INSN_CODE(zjit_insn);
3820 st_add_direct(encoded_insn_data, key3, (st_data_t)&insn_data[insn]);
3830rb_vm_insn_addr2insn(
const void *addr)
3832 st_data_t key = (st_data_t)addr;
3835 if (st_lookup(encoded_insn_data, key, &val)) {
3837 return (
int)e->insn;
3840 rb_bug(
"rb_vm_insn_addr2insn: invalid insn address: %p", addr);
3846rb_vm_insn_addr2opcode(
const void *addr)
3848 st_data_t key = (st_data_t)addr;
3851 if (st_lookup(encoded_insn_data, key, &val)) {
3853 int opcode = e->insn;
3854 if (addr == e->trace_encoded_insn) {
3855 opcode += VM_BARE_INSTRUCTION_SIZE;
3858 else if (addr == e->zjit_encoded_insn) {
3859 opcode = e->zjit_insn;
3865 rb_bug(
"rb_vm_insn_addr2opcode: invalid insn address: %p", addr);
3872rb_vm_insn_decode(
const VALUE encoded)
3874#if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE
3875 int insn = rb_vm_insn_addr2insn((
void *)encoded);
3877 int insn = (int)encoded;
3884encoded_iseq_trace_instrument(
VALUE *iseq_encoded_insn,
rb_event_flag_t turnon,
bool remain_current_trace)
3886 st_data_t key = (st_data_t)*iseq_encoded_insn;
3889 if (st_lookup(encoded_insn_data, key, &val)) {
3891 if (remain_current_trace && key == (st_data_t)e->trace_encoded_insn) {
3894 *iseq_encoded_insn = (
VALUE) (turnon ? e->trace_encoded_insn : e->notrace_encoded_insn);
3898 rb_bug(
"trace_instrument: invalid insn address: %p", (
void *)*iseq_encoded_insn);
3903rb_iseq_trace_flag_cleared(
const rb_iseq_t *iseq,
size_t pos)
3906 VALUE *iseq_encoded = (
VALUE *)body->iseq_encoded;
3907 encoded_iseq_trace_instrument(&iseq_encoded[pos], 0,
false);
3933 VALUE *iseq_encoded = (
VALUE *)body->iseq_encoded;
3935 VM_ASSERT(ISEQ_EXECUTABLE_P(iseq));
3937 for (pc=0; pc<body->iseq_size;) {
3941 unsigned int line = (int)entry->line_no;
3943 if (target_line == 0 || target_line == line) {
3947 target_events &= ~RUBY_EVENT_LINE;
3950 if (pc_events & target_events) {
3953 pc += encoded_iseq_trace_instrument(&iseq_encoded[pc], pc_events & (target_events | iseq->aux.exec.global_trace_events),
true);
3957 if (iseq->aux.exec.local_hooks == NULL) {
3959 iseq->aux.exec.local_hooks->is_local =
true;
3961 rb_hook_list_connect_tracepoint((
VALUE)iseq, iseq->aux.exec.local_hooks, tpval, target_line);
3970 unsigned int target_line;
3975iseq_add_local_tracepoint_i(
const rb_iseq_t *iseq,
void *p)
3978 data->n += iseq_add_local_tracepoint(iseq, data->turnon_events, data->tpval, data->target_line);
3979 iseq_iterate_children(iseq, iseq_add_local_tracepoint_i, p);
3983rb_iseq_add_local_tracepoint_recursively(
const rb_iseq_t *iseq,
rb_event_flag_t turnon_events,
VALUE tpval,
unsigned int target_line,
bool target_bmethod)
3986 if (target_bmethod) {
3987 turnon_events = add_bmethod_events(turnon_events);
3989 data.turnon_events = turnon_events;
3991 data.target_line = target_line;
3994 iseq_add_local_tracepoint_i(iseq, (
void *)&data);
3995 if (0)
rb_funcall(
Qnil, rb_intern(
"puts"), 1, rb_iseq_disasm(iseq));
4004 if (iseq->aux.exec.local_hooks) {
4007 VALUE *iseq_encoded = (
VALUE *)body->iseq_encoded;
4010 rb_hook_list_remove_tracepoint(iseq->aux.exec.local_hooks, tpval);
4011 local_events = iseq->aux.exec.local_hooks->events;
4013 if (local_events == 0) {
4014 rb_hook_list_free(iseq->aux.exec.local_hooks);
4015 ((
rb_iseq_t *)iseq)->aux.exec.local_hooks = NULL;
4018 local_events = add_bmethod_events(local_events);
4019 for (pc = 0; pc<body->iseq_size;) {
4021 pc += encoded_iseq_trace_instrument(&iseq_encoded[pc], pc_events & (local_events | iseq->aux.exec.global_trace_events),
false);
4033iseq_remove_local_tracepoint_i(
const rb_iseq_t *iseq,
void *p)
4036 data->n += iseq_remove_local_tracepoint(iseq, data->tpval);
4037 iseq_iterate_children(iseq, iseq_remove_local_tracepoint_i, p);
4041rb_iseq_remove_local_tracepoint_recursively(
const rb_iseq_t *iseq,
VALUE tpval)
4047 iseq_remove_local_tracepoint_i(iseq, (
void *)&data);
4054 if (iseq->aux.exec.global_trace_events == turnon_events) {
4058 if (!ISEQ_EXECUTABLE_P(iseq)) {
4065 VALUE *iseq_encoded = (
VALUE *)body->iseq_encoded;
4067 rb_event_flag_t local_events = iseq->aux.exec.local_hooks ? iseq->aux.exec.local_hooks->events : 0;
4068 ((
rb_iseq_t *)iseq)->aux.exec.global_trace_events = turnon_events;
4069 enabled_events = add_bmethod_events(turnon_events | local_events);
4071 for (pc=0; pc<body->iseq_size;) {
4073 pc += encoded_iseq_trace_instrument(&iseq_encoded[pc], pc_events & enabled_events,
true);
4081clear_attr_cc(
VALUE v)
4083 if (imemo_type_p(v, imemo_callcache) && vm_cc_ivar_p((
const struct rb_callcache *)v)) {
4095 if (imemo_type_p(v, imemo_callcache) && vm_cc_bf_p((
const struct rb_callcache *)v)) {
4105clear_attr_ccs_i(
void *vstart,
void *vend,
size_t stride,
void *data)
4108 for (; v != (
VALUE)vend; v += stride) {
4109 void *ptr = rb_asan_poisoned_object_p(v);
4110 rb_asan_unpoison_object(v,
false);
4112 asan_poison_object_if(ptr, v);
4118rb_clear_attr_ccs(
void)
4120 rb_objspace_each_objects(clear_attr_ccs_i, NULL);
4124clear_bf_ccs_i(
void *vstart,
void *vend,
size_t stride,
void *data)
4127 for (; v != (
VALUE)vend; v += stride) {
4128 void *ptr = rb_asan_poisoned_object_p(v);
4129 rb_asan_unpoison_object(v,
false);
4131 asan_poison_object_if(ptr, v);
4137rb_clear_bf_ccs(
void)
4139 rb_objspace_each_objects(clear_bf_ccs_i, NULL);
4143trace_set_i(
void *vstart,
void *vend,
size_t stride,
void *data)
4148 for (; v != (
VALUE)vend; v += stride) {
4149 void *ptr = rb_asan_poisoned_object_p(v);
4150 rb_asan_unpoison_object(v,
false);
4152 if (rb_obj_is_iseq(v)) {
4153 rb_iseq_trace_set(rb_iseq_check((
rb_iseq_t *)v), turnon_events);
4155 else if (clear_attr_cc(v)) {
4157 else if (clear_bf_cc(v)) {
4160 asan_poison_object_if(ptr, v);
4168 rb_objspace_each_objects(trace_set_i, &turnon_events);
4172rb_iseqw_local_variables(
VALUE iseqval)
4174 return rb_iseq_local_variables(iseqw_check(iseqval));
4195iseqw_to_binary(
int argc,
VALUE *argv,
VALUE self)
4198 return rb_iseq_ibf_dump(iseqw_check(self), opt);
4215iseqw_s_load_from_binary(
VALUE self,
VALUE str)
4217 return iseqw_new(rb_iseq_ibf_load(str));
4227iseqw_s_load_from_binary_extra_data(
VALUE self,
VALUE str)
4229 return rb_iseq_ibf_load_extra_data(str);
4232#if VM_INSN_INFO_TABLE_IMPL == 2
4265#define IMMEDIATE_TABLE_SIZE 54
4267struct succ_index_table {
4268 uint64_t imm_part[IMMEDIATE_TABLE_SIZE / 9];
4269 struct succ_dict_block {
4271 uint64_t small_block_ranks;
4272 uint64_t bits[512/64];
4273 } succ_part[FLEX_ARY_LEN];
4276#define imm_block_rank_set(v, i, r) (v) |= (uint64_t)(r) << (7 * (i))
4277#define imm_block_rank_get(v, i) (((int)((v) >> ((i) * 7))) & 0x7f)
4278#define small_block_rank_set(v, i, r) (v) |= (uint64_t)(r) << (9 * ((i) - 1))
4279#define small_block_rank_get(v, i) ((i) == 0 ? 0 : (((int)((v) >> (((i) - 1) * 9))) & 0x1ff))
4281static struct succ_index_table *
4282succ_index_table_create(
int max_pos,
int *data,
int size)
4284 const int imm_size = (max_pos < IMMEDIATE_TABLE_SIZE ? max_pos + 8 : IMMEDIATE_TABLE_SIZE) / 9;
4285 const int succ_size = (max_pos < IMMEDIATE_TABLE_SIZE ? 0 : (max_pos - IMMEDIATE_TABLE_SIZE + 511)) / 512;
4286 struct succ_index_table *sd =
4287 rb_xcalloc_mul_add_mul(
4288 imm_size,
sizeof(uint64_t),
4289 succ_size,
sizeof(
struct succ_dict_block));
4293 for (j = 0; j < imm_size; j++) {
4294 for (i = 0; i < 9; i++) {
4295 if (r < size && data[r] == j * 9 + i) r++;
4296 imm_block_rank_set(sd->imm_part[j], i, r);
4299 for (k = 0; k < succ_size; k++) {
4300 struct succ_dict_block *sd_block = &sd->succ_part[k];
4303 for (j = 0; j < 8; j++) {
4305 if (j) small_block_rank_set(sd_block->small_block_ranks, j, small_rank);
4306 for (i = 0; i < 64; i++) {
4307 if (r < size && data[r] == k * 512 + j * 64 + i + IMMEDIATE_TABLE_SIZE) {
4308 bits |= ((uint64_t)1) << i;
4312 sd_block->bits[j] = bits;
4313 small_rank += rb_popcount64(bits);
4319static unsigned int *
4320succ_index_table_invert(
int max_pos,
struct succ_index_table *sd,
int size)
4322 const int imm_size = (max_pos < IMMEDIATE_TABLE_SIZE ? max_pos + 8 : IMMEDIATE_TABLE_SIZE) / 9;
4323 const int succ_size = (max_pos < IMMEDIATE_TABLE_SIZE ? 0 : (max_pos - IMMEDIATE_TABLE_SIZE + 511)) / 512;
4324 unsigned int *positions =
ALLOC_N(
unsigned int, size), *p;
4325 int i, j, k, r = -1;
4327 for (j = 0; j < imm_size; j++) {
4328 for (i = 0; i < 9; i++) {
4329 int nr = imm_block_rank_get(sd->imm_part[j], i);
4330 if (r != nr) *p++ = j * 9 + i;
4334 for (k = 0; k < succ_size; k++) {
4335 for (j = 0; j < 8; j++) {
4336 for (i = 0; i < 64; i++) {
4337 if (sd->succ_part[k].bits[j] & (((uint64_t)1) << i)) {
4338 *p++ = k * 512 + j * 64 + i + IMMEDIATE_TABLE_SIZE;
4347succ_index_lookup(
const struct succ_index_table *sd,
int x)
4349 if (x < IMMEDIATE_TABLE_SIZE) {
4350 const int i = x / 9;
4351 const int j = x % 9;
4352 return imm_block_rank_get(sd->imm_part[i], j);
4355 const int block_index = (x - IMMEDIATE_TABLE_SIZE) / 512;
4356 const struct succ_dict_block *block = &sd->succ_part[block_index];
4357 const int block_bit_index = (x - IMMEDIATE_TABLE_SIZE) % 512;
4358 const int small_block_index = block_bit_index / 64;
4359 const int small_block_popcount = small_block_rank_get(block->small_block_ranks, small_block_index);
4360 const int popcnt = rb_popcount64(block->bits[small_block_index] << (63 - block_bit_index % 64));
4362 return block->rank + small_block_popcount + popcnt;
4381iseqw_script_lines(
VALUE self)
4383 const rb_iseq_t *iseq = iseqw_check(self);
4384 return ISEQ_BODY(iseq)->variable.script_lines;
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
#define rb_define_method(klass, mid, func, arity)
Defines klass#mid.
#define rb_define_singleton_method(klass, mid, func, arity)
Defines klass.mid.
#define rb_define_private_method(klass, mid, func, arity)
Defines klass#mid and makes it private.
#define RUBY_EVENT_END
Encountered an end of a class clause.
#define RUBY_EVENT_C_CALL
A method, written in C, is called.
#define RUBY_EVENT_B_RETURN
Encountered a next statement.
#define RUBY_EVENT_CLASS
Encountered a new class.
#define RUBY_EVENT_LINE
Encountered a new line.
#define RUBY_EVENT_RETURN
Encountered a return statement.
#define RUBY_EVENT_C_RETURN
Return from a method, written in C.
#define RUBY_EVENT_B_CALL
Encountered an yield statement.
uint32_t rb_event_flag_t
Represents event(s).
#define RUBY_EVENT_CALL
A method, written in Ruby, is called.
#define RUBY_EVENT_RESCUE
Encountered a rescue statement.
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
void rb_undef_method(VALUE klass, const char *name)
Defines an undef of a method.
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Retrieves argument from argc and argv to given VALUE references according to the format string.
#define rb_str_new2
Old name of rb_str_new_cstr.
#define T_FILE
Old name of RUBY_T_FILE.
#define T_STRING
Old name of RUBY_T_STRING.
#define Qundef
Old name of RUBY_Qundef.
#define INT2FIX
Old name of RB_INT2FIX.
#define rb_str_cat2
Old name of rb_str_cat_cstr.
#define ID2SYM
Old name of RB_ID2SYM.
#define SPECIAL_CONST_P
Old name of RB_SPECIAL_CONST_P.
#define ULONG2NUM
Old name of RB_ULONG2NUM.
#define SYM2ID
Old name of RB_SYM2ID.
#define ZALLOC
Old name of RB_ZALLOC.
#define LL2NUM
Old name of RB_LL2NUM.
#define CLASS_OF
Old name of rb_class_of.
#define T_NONE
Old name of RUBY_T_NONE.
#define FIX2INT
Old name of RB_FIX2INT.
#define T_HASH
Old name of RUBY_T_HASH.
#define ALLOC_N
Old name of RB_ALLOC_N.
#define FL_TEST_RAW
Old name of RB_FL_TEST_RAW.
#define LONG2NUM
Old name of RB_LONG2NUM.
#define Qtrue
Old name of RUBY_Qtrue.
#define NUM2INT
Old name of RB_NUM2INT.
#define INT2NUM
Old name of RB_INT2NUM.
#define Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
#define T_ARRAY
Old name of RUBY_T_ARRAY.
#define NIL_P
Old name of RB_NIL_P.
#define BUILTIN_TYPE
Old name of RB_BUILTIN_TYPE.
#define NUM2LONG
Old name of RB_NUM2LONG.
#define UINT2NUM
Old name of RB_UINT2NUM.
#define FIXNUM_P
Old name of RB_FIXNUM_P.
#define CONST_ID
Old name of RUBY_CONST_ID.
#define rb_ary_new2
Old name of rb_ary_new_capa.
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
VALUE rb_eTypeError
TypeError exception.
void * rb_check_typeddata(VALUE obj, const rb_data_type_t *data_type)
Identical to rb_typeddata_is_kind_of(), except it raises exceptions instead of returning false.
VALUE rb_eSyntaxError
SyntaxError exception.
VALUE rb_class_superclass(VALUE klass)
Queries the parent of the given class.
VALUE rb_obj_hide(VALUE obj)
Make the object invisible from Ruby code.
VALUE rb_obj_class(VALUE obj)
Queries the class of an object.
VALUE rb_inspect(VALUE obj)
Generates a human-readable textual representation of the given object.
#define RB_OBJ_WRITE(old, slot, young)
Declaration of a "back" pointer.
VALUE rb_funcall(VALUE recv, ID mid, int n,...)
Calls a method.
Defines RBIMPL_HAS_BUILTIN.
VALUE rb_ary_new_from_values(long n, const VALUE *elts)
Identical to rb_ary_new_from_args(), except how objects are passed.
VALUE rb_ary_resurrect(VALUE ary)
I guess there is no use case of this function in extension libraries, but this is a routine identical...
VALUE rb_ary_new(void)
Allocates a new, empty array.
VALUE rb_ary_hidden_new(long capa)
Allocates a hidden (no class) empty array.
VALUE rb_ary_push(VALUE ary, VALUE elem)
Special case of rb_ary_cat() that it adds only one element.
VALUE rb_ary_freeze(VALUE obj)
Freeze an array, preventing further modifications.
VALUE rb_ary_entry(VALUE ary, long off)
Queries an element of an array.
VALUE rb_ary_join(VALUE ary, VALUE sep)
Recursively stringises the elements of the passed array, flattens that result, then joins the sequenc...
void rb_ary_store(VALUE ary, long key, VALUE val)
Destructively stores the passed value to the passed array's passed index.
static int rb_check_arity(int argc, int min, int max)
Ensures that the passed integer is in the passed range.
VALUE rb_file_open_str(VALUE fname, const char *fmode)
Identical to rb_file_open(), except it takes the pathname as a Ruby's string instead of C's.
VALUE rb_io_close(VALUE io)
Closes the IO.
int rb_is_local_id(ID id)
Classifies the given ID, then sees if it is a local variable.
VALUE rb_obj_is_method(VALUE recv)
Queries if the given object is a method.
VALUE rb_obj_is_proc(VALUE recv)
Queries if the given object is a proc.
VALUE rb_str_append(VALUE dst, VALUE src)
Identical to rb_str_buf_append(), except it converts the right hand side before concatenating.
#define rb_str_new(str, len)
Allocates an instance of rb_cString.
#define rb_exc_new_cstr(exc, str)
Identical to rb_exc_new(), except it assumes the passed pointer is a pointer to a C string.
VALUE rb_str_dup(VALUE str)
Duplicates a string.
VALUE rb_str_cat(VALUE dst, const char *src, long srclen)
Destructively appends the passed contents to the string.
VALUE rb_str_resurrect(VALUE str)
I guess there is no use case of this function in extension libraries, but this is a routine identical...
void rb_str_set_len(VALUE str, long len)
Overwrites the length of the string.
VALUE rb_str_inspect(VALUE str)
Generates a "readable" version of the receiver.
int rb_str_cmp(VALUE lhs, VALUE rhs)
Compares two strings, as in strcmp(3).
VALUE rb_str_concat(VALUE dst, VALUE src)
Identical to rb_str_append(), except it also accepts an integer as a codepoint.
#define rb_str_cat_cstr(buf, str)
Identical to rb_str_cat(), except it assumes the passed pointer is a pointer to a C string.
void rb_str_modify_expand(VALUE str, long capa)
Identical to rb_str_modify(), except it additionally expands the capacity of the receiver.
#define rb_str_new_cstr(str)
Identical to rb_str_new, except it assumes the passed pointer is a pointer to a C string.
VALUE rb_str_intern(VALUE str)
Identical to rb_to_symbol(), except it assumes the receiver being an instance of RString.
VALUE rb_class_name(VALUE obj)
Queries the name of the given object's class.
int rb_respond_to(VALUE obj, ID mid)
Queries if the object responds to the method.
void rb_undef_alloc_func(VALUE klass)
Deletes the allocator function of a class.
VALUE rb_check_funcall(VALUE recv, ID mid, int argc, const VALUE *argv)
Identical to rb_funcallv(), except it returns RUBY_Qundef instead of raising rb_eNoMethodError.
ID rb_check_id(volatile VALUE *namep)
Detects if the given name is already interned or not.
VALUE rb_sym2str(VALUE symbol)
Obtain a frozen string representation of a symbol (not including the leading colon).
VALUE rb_io_path(VALUE io)
Returns the path for the given IO.
int len
Length of the buffer.
VALUE rb_ractor_make_shareable(VALUE obj)
Destructively transforms the passed object so that multiple Ractors can share it.
#define RB_NUM2INT
Just another name of rb_num2int_inline.
#define RB_INT2NUM
Just another name of rb_int2num_inline.
VALUE rb_yield(VALUE val)
Yields the block.
#define RB_GC_GUARD(v)
Prevents premature destruction of local objects.
#define RB_ZALLOC(type)
Shorthand of RB_ZALLOC_N with n=1.
VALUE type(ANYARGS)
ANYARGS-ed function type.
void rb_hash_foreach(VALUE q, int_type *w, VALUE e)
Iteration over the given hash.
#define RARRAY_LEN
Just another name of rb_array_len.
static int RARRAY_LENINT(VALUE ary)
Identical to rb_array_len(), except it differs for the return type.
#define RARRAY_AREF(a, i)
static VALUE RBASIC_CLASS(VALUE obj)
Queries the class of an object.
#define RHASH_SIZE(h)
Queries the size of the hash.
#define StringValue(v)
Ensures that the parameter object is a String.
static char * RSTRING_END(VALUE str)
Queries the end of the contents pointer of the string.
#define StringValueCStr(v)
Identical to StringValuePtr, except it additionally checks for the contents for viability as a C stri...
#define RUBY_TYPED_DEFAULT_FREE
This is a value you can set to rb_data_type_struct::dfree.
#define TypedData_Get_Struct(obj, type, data_type, sval)
Obtains a C struct from inside of a wrapper Ruby object.
#define TypedData_Wrap_Struct(klass, data_type, sval)
Converts sval, a pointer to your struct, into a Ruby object.
#define TypedData_Make_Struct(klass, type, data_type, sval)
Identical to TypedData_Wrap_Struct, except it allocates a new data region internally instead of takin...
#define FilePathValue(v)
Ensures that the parameter object is a path.
#define RTEST
This is an old name of RB_TEST.
const ID * segments
A null-terminated list of ids, used to represent a constant's path idNULL is used to represent the ::...
A line and column in a string.
uint32_t column
The column number.
int32_t line
The line number.
This represents a range of bytes in the source string to which a node or token corresponds.
const uint8_t * start
A pointer to the start location of the range in the source.
const uint8_t * end
A pointer to the end location of the range in the source.
size_t size
The number of offsets in the list.
uint32_t node_id
The unique identifier for this node, which is deterministic based on the source.
pm_location_t location
This is the location of the node in the source.
int32_t line
The line within the file that the parse starts on.
pm_scope_node_t node
The resulting scope node that will hold the generated AST.
pm_options_t options
The options that will be passed to the parser.
int32_t start_line
The line number at the start of the parse.
pm_newline_list_t newline_list
This is the list of newline offsets in the source file.
VALUE * script_lines
This is a pointer to the list of script lines for the ISEQs that will be associated with this scope n...
This is the struct that holds necessary info for a struct.
struct rb_iseq_constant_body::@154 param
parameter information
intptr_t SIGNED_VALUE
A signed integer type that has the same width with VALUE.
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
uintptr_t VALUE
Type that represents a Ruby object.
static void Check_Type(VALUE v, enum ruby_value_type t)
Identical to RB_TYPE_P(), except it raises exceptions on predication failure.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.
ruby_value_type
C-level type of an object.