12#define RUBY_VM_INSNS_INFO 1
15#include "ruby/internal/config.h"
21#include "eval_intern.h"
25#include "internal/bits.h"
26#include "internal/class.h"
27#include "internal/compile.h"
28#include "internal/error.h"
29#include "internal/file.h"
30#include "internal/gc.h"
31#include "internal/hash.h"
32#include "internal/io.h"
33#include "internal/ruby_parser.h"
34#include "internal/sanitizers.h"
35#include "internal/set_table.h"
36#include "internal/symbol.h"
37#include "internal/thread.h"
38#include "internal/variable.h"
42#include "ractor_core.h"
43#include "vm_callinfo.h"
48#include "insns_info.inc"
55#if VM_INSN_INFO_TABLE_IMPL == 2
56static struct succ_index_table *succ_index_table_create(
int max_pos,
int *data,
int size);
57static unsigned int *succ_index_table_invert(
int max_pos,
struct succ_index_table *sd,
int size);
58static int succ_index_lookup(
const struct succ_index_table *sd,
int x);
61#define hidden_obj_p(obj) (!SPECIAL_CONST_P(obj) && !RBASIC(obj)->klass)
64obj_resurrect(
VALUE obj)
66 if (hidden_obj_p(obj)) {
75 obj = rb_hash_resurrect(obj);
100 free_arena(compile_data->node.storage_head);
101 free_arena(compile_data->insn.storage_head);
102 if (compile_data->ivar_cache_table) {
103 rb_id_table_free(compile_data->ivar_cache_table);
105 SIZED_FREE(compile_data);
110remove_from_constant_cache(
ID id,
IC ic)
114 st_data_t ic_data = (st_data_t)ic;
116 if (rb_id_table_lookup(&vm->constant_cache,
id, &lookup_result)) {
118 set_table_delete(ics, &ic_data);
120 if (ics->num_entries == 0 &&
122 id != vm->inserting_constant_cache_id) {
123 rb_id_table_delete(&vm->constant_cache,
id);
133iseq_clear_ic_references(
const rb_iseq_t *iseq)
139 if (!ISEQ_BODY(iseq)->is_entries) {
143 for (
unsigned int ic_idx = 0; ic_idx < ISEQ_BODY(iseq)->ic_size; ic_idx++) {
144 IC ic = &ISEQ_IS_IC_ENTRY(ISEQ_BODY(iseq), ic_idx);
152 if (segments == NULL)
156 for (i = 0; segments[i]; i++) {
158 if (
id == idNULL)
continue;
159 remove_from_constant_cache(
id, ic);
162 SIZED_FREE_N(segments, i + 1);
172 if (st_lookup(rb_ractor_targeted_hooks(r), (st_data_t)iseq, &val)) {
174 RUBY_ASSERT(hook_list->type == hook_list_type_targeted_iseq);
178 hook_list->type = hook_list_type_targeted_iseq;
179 st_insert(rb_ractor_targeted_hooks(r), (st_data_t)iseq, (st_data_t)hook_list);
187 RUBY_FREE_ENTER(
"iseq");
189 if (iseq && ISEQ_BODY(iseq)) {
190 iseq_clear_ic_references(iseq);
193 rb_yjit_iseq_free(iseq);
196 rb_yjit_live_iseq_count--;
200 rb_zjit_iseq_free(iseq);
202 SIZED_FREE_N(body->iseq_encoded, body->iseq_size);
203 SIZED_FREE_N(body->insns_info.body, body->insns_info.size);
204 SIZED_FREE_N(body->insns_info.positions, body->insns_info.size);
205#if VM_INSN_INFO_TABLE_IMPL == 2
206 ruby_xfree(body->insns_info.succ_index_table);
208 SIZED_FREE_N(body->is_entries, ISEQ_IS_SIZE(body));
209 SIZED_FREE_N(body->call_data, body->ci_size);
210 if (body->catch_table) {
211 ruby_xfree_sized(body->catch_table, iseq_catch_table_bytes(body->catch_table->size));
213 SIZED_FREE_N(body->param.opt_table, body->param.opt_num + 1);
214 if (ISEQ_MBITS_BUFLEN(body->iseq_size) > 1 && body->mark_bits.list) {
215 SIZED_FREE_N(body->mark_bits.list, ISEQ_MBITS_BUFLEN(body->iseq_size));
218 ISEQ_ORIGINAL_ISEQ_CLEAR(iseq);
220 struct rb_iseq_param_keyword *pkw = (
struct rb_iseq_param_keyword *)body->param.keyword;
222 if (pkw->table != &body->local_table[pkw->bits_start - pkw->num])
223 SIZED_FREE_N(pkw->table, pkw->required_num);
224 if (pkw->default_values) {
225 SIZED_FREE_N(pkw->default_values, pkw->num - pkw->required_num);
229 if (LIKELY(body->local_table != rb_iseq_shared_exc_local_tbl)) {
230 SIZED_FREE_N(body->local_table, body->local_table_size);
232 SIZED_FREE_N(body->lvar_states, body->local_table_size);
234 compile_data_free(ISEQ_COMPILE_DATA(iseq));
235 if (body->outer_variables) rb_id_table_free(body->outer_variables);
239 RUBY_FREE_LEAVE(
"iseq");
242typedef VALUE iseq_value_itr_t(
void *ctx,
VALUE obj);
245iseq_scan_bits(
unsigned int page, iseq_bits_t bits,
VALUE *code,
VALUE *original_iseq)
248 unsigned int page_offset = (page * ISEQ_MBITS_BITLENGTH);
251 offset = ntz_intptr(bits);
252 VALUE op = code[page_offset + offset];
253 rb_gc_mark_and_move(&code[page_offset + offset]);
254 VALUE newop = code[page_offset + offset];
255 if (original_iseq && newop != op) {
256 original_iseq[page_offset + offset] = newop;
263rb_iseq_mark_and_move_each_compile_data_value(
const rb_iseq_t *iseq,
VALUE *original_iseq)
269 size = compile_data->iseq_size;
270 code = compile_data->iseq_encoded;
273 if (compile_data->mark_bits.list) {
274 if(compile_data->is_single_mark_bit) {
275 iseq_scan_bits(0, compile_data->mark_bits.single, code, original_iseq);
278 for (
unsigned int i = 0; i < ISEQ_MBITS_BUFLEN(size); i++) {
279 iseq_bits_t bits = compile_data->mark_bits.list[i];
280 iseq_scan_bits(i, bits, code, original_iseq);
286rb_iseq_mark_and_move_each_body_value(
const rb_iseq_t *iseq,
VALUE *original_iseq)
292 size = body->iseq_size;
293 code = body->iseq_encoded;
297 if (body->is_entries) {
299 is_entries += body->ivc_size;
302 for (
unsigned int i = 0; i < body->icvarc_size; i++, is_entries++) {
307 rb_gc_mark_and_move(&icvarc->entry->class_value);
312 for (
unsigned int i = 0; i < body->ise_size; i++, is_entries++) {
314 if (is->once.value) {
315 rb_gc_mark_and_move(&is->once.value);
320 for (
unsigned int i = 0; i < body->ic_size; i++, is_entries++) {
321 IC ic = (
IC)is_entries;
323 rb_gc_mark_and_move_ptr(&ic->entry);
329 if (body->mark_bits.list) {
330 if (ISEQ_MBITS_BUFLEN(size) == 1) {
331 iseq_scan_bits(0, body->mark_bits.single, code, original_iseq);
334 for (
unsigned int i = 0; i < ISEQ_MBITS_BUFLEN(size); i++) {
335 iseq_bits_t bits = body->mark_bits.list[i];
336 iseq_scan_bits(i, bits, code, original_iseq);
343cc_is_active(
const struct rb_callcache *cc,
bool reference_updating)
346 if (cc == rb_vm_empty_cc() || rb_vm_empty_cc_for_super()) {
350 if (reference_updating) {
354 if (vm_cc_markable(cc) && vm_cc_valid(cc)) {
356 if (reference_updating) {
359 if (!METHOD_ENTRY_INVALIDATED(cme)) {
368rb_iseq_mark_and_move(
rb_iseq_t *iseq,
bool reference_updating)
370 RUBY_MARK_ENTER(
"iseq");
372 rb_gc_mark_and_move(&iseq->wrapper);
374 if (ISEQ_BODY(iseq)) {
377 rb_iseq_mark_and_move_each_body_value(iseq, reference_updating ? ISEQ_ORIGINAL_ISEQ(iseq) : NULL);
379 rb_gc_mark_and_move(&body->variable.script_lines);
380 rb_gc_mark_and_move(&body->location.label);
381 rb_gc_mark_and_move(&body->location.base_label);
382 rb_gc_mark_and_move(&body->location.pathobj);
383 if (body->local_iseq) rb_gc_mark_and_move_ptr(&body->local_iseq);
384 if (body->parent_iseq) rb_gc_mark_and_move_ptr(&body->parent_iseq);
385 if (body->mandatory_only_iseq) rb_gc_mark_and_move_ptr(&body->mandatory_only_iseq);
387 if (body->call_data) {
388 for (
unsigned int i = 0; i < body->ci_size; i++) {
391 if (cds[i].ci) rb_gc_mark_and_move_ptr(&cds[i].ci);
393 if (cc_is_active(cds[i].cc, reference_updating)) {
394 rb_gc_mark_and_move_ptr(&cds[i].cc);
396 else if (cds[i].cc != rb_vm_empty_cc()) {
397 cds[i].cc = rb_vm_empty_cc();
402 if (body->param.flags.has_kw && body->param.keyword != NULL) {
403 const struct rb_iseq_param_keyword *
const keyword = body->param.keyword;
405 if (keyword->default_values != NULL) {
406 for (
int j = 0, i = keyword->required_num; i < keyword->num; i++, j++) {
407 rb_gc_mark_and_move(&keyword->default_values[j]);
412 if (body->catch_table) {
415 for (
unsigned int i = 0; i < table->size; i++) {
417 entry = UNALIGNED_MEMBER_PTR(table, entries[i]);
419 rb_gc_mark_and_move_ptr(&entry->iseq);
424 if (reference_updating) {
426 rb_yjit_iseq_update_references(iseq);
429 rb_zjit_iseq_update_references(body->zjit_payload);
434 if (!rb_gc_checking_shareable()) {
436 rb_yjit_iseq_mark(body->yjit_payload);
439 rb_zjit_iseq_mark(body->zjit_payload);
445 if (!rb_gc_checking_shareable()) {
446 rb_gc_mark_and_move(&body->variable.coverage);
447 rb_gc_mark_and_move(&body->variable.pc2branchindex);
452 if (!rb_gc_checking_shareable()) {
453 rb_gc_mark_and_move(&iseq->aux.loader.obj);
457 if (!rb_gc_checking_shareable()) {
460 rb_iseq_mark_and_move_insn_storage(compile_data->insn.storage_head);
461 rb_iseq_mark_and_move_each_compile_data_value(iseq, reference_updating ? ISEQ_ORIGINAL_ISEQ(iseq) : NULL);
463 rb_gc_mark_and_move((
VALUE *)&compile_data->err_info);
464 rb_gc_mark_and_move((
VALUE *)&compile_data->catch_table_ary);
469 VM_ASSERT(ISEQ_EXECUTABLE_P(iseq));
472 RUBY_MARK_LEAVE(
"iseq");
476param_keyword_size(
const struct rb_iseq_param_keyword *pkw)
480 if (!pkw)
return size;
482 size +=
sizeof(
struct rb_iseq_param_keyword);
483 size +=
sizeof(
VALUE) * (pkw->num - pkw->required_num);
497 if (ISEQ_EXECUTABLE_P(iseq) && body) {
499 size += body->iseq_size *
sizeof(
VALUE);
501 size += body->local_table_size *
sizeof(
ID);
502 size += ISEQ_MBITS_BUFLEN(body->iseq_size) * ISEQ_MBITS_SIZE;
503 if (body->catch_table) {
504 size += iseq_catch_table_bytes(body->catch_table->size);
506 size += (body->param.opt_num + 1) *
sizeof(
VALUE);
507 size += param_keyword_size(body->param.keyword);
512 if (ISEQ_BODY(iseq)->is_entries) {
514 for (
unsigned int ic_idx = 0; ic_idx < body->ic_size; ic_idx++) {
515 IC ic = &ISEQ_IS_IC_ENTRY(body, ic_idx);
530 compile_data = ISEQ_COMPILE_DATA(iseq);
536 cur = compile_data->node.storage_head;
547rb_iseq_constant_body_alloc(
void)
558 ISEQ_BODY(iseq) = rb_iseq_constant_body_alloc();
563rb_iseq_pathobj_new(
VALUE path,
VALUE realpath)
569 if (path == realpath ||
571 pathobj = rb_fstring(path);
574 if (!
NIL_P(realpath)) {
575 realpath = rb_fstring(realpath);
577 VALUE fpath = rb_fstring(path);
579 pathobj = rb_ary_new_from_args(2, fpath, realpath);
581 RB_OBJ_SET_SHAREABLE(pathobj);
590 rb_iseq_pathobj_new(path, realpath));
595rb_iseq_alloc_with_dummy_path(
VALUE fname)
599 ISEQ_BODY(dummy_iseq)->type = ISEQ_TYPE_TOP;
602 RB_OBJ_SET_FROZEN_SHAREABLE(fname);
605 RB_OBJ_WRITE(dummy_iseq, &ISEQ_BODY(dummy_iseq)->location.pathobj, fname);
606 RB_OBJ_WRITE(dummy_iseq, &ISEQ_BODY(dummy_iseq)->location.label, fname);
616 rb_iseq_pathobj_set(iseq, path, realpath);
619 loc->first_lineno = first_lineno;
621 if (ISEQ_BODY(iseq)->local_iseq == iseq && strcmp(RSTRING_PTR(name),
"initialize") == 0) {
622 ISEQ_BODY(iseq)->param.flags.use_block = 1;
626 loc->node_id = node_id;
627 loc->code_location = *code_location;
630 loc->code_location.beg_pos.lineno = 0;
631 loc->code_location.beg_pos.column = 0;
632 loc->code_location.end_pos.lineno = -1;
633 loc->code_location.end_pos.column = -1;
646 if (
type == ISEQ_TYPE_TOP) {
647 body->local_iseq = iseq;
649 else if (
type == ISEQ_TYPE_METHOD ||
type == ISEQ_TYPE_CLASS) {
650 body->local_iseq = iseq;
653 RB_OBJ_WRITE(iseq, &body->local_iseq, ISEQ_BODY(piseq)->local_iseq);
660 if (
type == ISEQ_TYPE_MAIN) {
661 body->local_iseq = iseq;
670 ALLOC_N(
char, INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE +
675 new_arena->size = INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE;
681prepare_node_id(
const NODE *node)
683 if (!node)
return -1;
685 if (nd_type(node) == NODE_SCOPE && RNODE_SCOPE(node)->nd_parent) {
686 return nd_node_id(RNODE_SCOPE(node)->nd_parent);
689 return nd_node_id(node);
695 const rb_iseq_t *parent,
int isolated_depth,
enum rb_iseq_type
type,
702 if (parent && (
type == ISEQ_TYPE_MAIN ||
type == ISEQ_TYPE_TOP))
706 set_relation(iseq, parent);
708 name = rb_fstring(name);
709 iseq_location_setup(iseq, name, path, realpath, first_lineno, code_location, node_id);
710 if (iseq != body->local_iseq) {
711 RB_OBJ_WRITE(iseq, &body->location.base_label, ISEQ_BODY(body->local_iseq)->location.label);
713 ISEQ_COVERAGE_SET(iseq,
Qnil);
714 ISEQ_ORIGINAL_ISEQ_CLEAR(iseq);
715 body->variable.flip_count = 0;
717 if (
NIL_P(script_lines)) {
724 ISEQ_COMPILE_DATA_ALLOC(iseq);
725 RB_OBJ_WRITE(iseq, &ISEQ_COMPILE_DATA(iseq)->err_info, err_info);
728 ISEQ_COMPILE_DATA(iseq)->node.storage_head = ISEQ_COMPILE_DATA(iseq)->node.storage_current = new_arena();
729 ISEQ_COMPILE_DATA(iseq)->insn.storage_head = ISEQ_COMPILE_DATA(iseq)->insn.storage_current = new_arena();
730 ISEQ_COMPILE_DATA(iseq)->isolated_depth = isolated_depth;
731 ISEQ_COMPILE_DATA(iseq)->option = option;
732 ISEQ_COMPILE_DATA(iseq)->ivar_cache_table = NULL;
733 ISEQ_COMPILE_DATA(iseq)->builtin_function_table = GET_VM()->builtin_function_table;
735 if (option->coverage_enabled) {
736 VALUE coverages = rb_get_coverages();
737 if (
RTEST(coverages)) {
738 coverage = rb_hash_lookup(coverages, rb_iseq_path(iseq));
742 ISEQ_COVERAGE_SET(iseq, coverage);
743 if (coverage && ISEQ_BRANCH_COVERAGE(iseq))
749#if VM_CHECK_MODE > 0 && VM_INSN_INFO_TABLE_IMPL > 0
750static void validate_get_insn_info(
const rb_iseq_t *iseq);
754rb_iseq_insns_info_encode_positions(
const rb_iseq_t *iseq)
756#if VM_INSN_INFO_TABLE_IMPL == 2
759 int size = body->insns_info.size;
760 int max_pos = body->iseq_size;
761 int *data = (
int *)body->insns_info.positions;
762 if (body->insns_info.succ_index_table) ruby_xfree(body->insns_info.succ_index_table);
763 body->insns_info.succ_index_table = succ_index_table_create(max_pos, data, size);
764#if VM_CHECK_MODE == 0
765 SIZED_FREE_N(body->insns_info.positions, body->insns_info.size);
766 body->insns_info.positions = NULL;
771#if VM_INSN_INFO_TABLE_IMPL == 2
775 int size = body->insns_info.size;
776 int max_pos = body->iseq_size;
777 struct succ_index_table *sd = body->insns_info.succ_index_table;
778 return succ_index_table_invert(max_pos, sd, size);
785 iseq->aux.exec.global_trace_events = 0;
786 if (ruby_vm_event_enabled_global_flags & ISEQ_TRACE_EVENTS) {
787 rb_iseq_trace_set(iseq, ruby_vm_event_enabled_global_flags & ISEQ_TRACE_EVENTS);
796 VALUE err = data->err_info;
797 ISEQ_COMPILE_DATA_CLEAR(iseq);
798 compile_data_free(data);
800#if VM_CHECK_MODE > 0 && VM_INSN_INFO_TABLE_IMPL > 0
801 validate_get_insn_info(iseq);
805 VALUE path = pathobj_path(body->location.pathobj);
807 rb_funcallv(err, rb_intern(
"set_backtrace"), 1, &path);
811 RB_DEBUG_COUNTER_INC(iseq_num);
812 RB_DEBUG_COUNTER_ADD(iseq_cd_num, ISEQ_BODY(iseq)->ci_size);
814 rb_iseq_init_trace(iseq);
819 .inline_const_cache = OPT_INLINE_CONST_CACHE,
820 .peephole_optimization = OPT_PEEPHOLE_OPTIMIZATION,
821 .tailcall_optimization = OPT_TAILCALL_OPTIMIZATION,
822 .specialized_instruction = OPT_SPECIALISED_INSTRUCTION,
823 .operands_unification = OPT_OPERANDS_UNIFICATION,
824 .instructions_unification = OPT_INSTRUCTIONS_UNIFICATION,
825 .frozen_string_literal = OPT_FROZEN_STRING_LITERAL,
826 .debug_frozen_string_literal = OPT_DEBUG_FROZEN_STRING_LITERAL,
827 .coverage_enabled = TRUE,
831 .frozen_string_literal = -1,
835rb_iseq_opt_frozen_string_literal(
void)
837 return COMPILE_OPTION_DEFAULT.frozen_string_literal;
843#define SET_COMPILE_OPTION(o, h, mem) \
844 { VALUE flag = rb_hash_aref((h), ID2SYM(rb_intern(#mem))); \
845 if (flag == Qtrue) { (o)->mem = 1; } \
846 else if (flag == Qfalse) { (o)->mem = 0; } \
848#define SET_COMPILE_OPTION_NUM(o, h, mem) \
849 { VALUE num = rb_hash_aref((h), ID2SYM(rb_intern(#mem))); \
850 if (!NIL_P(num)) (o)->mem = NUM2INT(num); \
852 SET_COMPILE_OPTION(option, opt, inline_const_cache);
853 SET_COMPILE_OPTION(option, opt, peephole_optimization);
854 SET_COMPILE_OPTION(option, opt, tailcall_optimization);
855 SET_COMPILE_OPTION(option, opt, specialized_instruction);
856 SET_COMPILE_OPTION(option, opt, operands_unification);
857 SET_COMPILE_OPTION(option, opt, instructions_unification);
858 SET_COMPILE_OPTION(option, opt, frozen_string_literal);
859 SET_COMPILE_OPTION(option, opt, debug_frozen_string_literal);
860 SET_COMPILE_OPTION(option, opt, coverage_enabled);
861 SET_COMPILE_OPTION_NUM(option, opt, debug_level);
862#undef SET_COMPILE_OPTION
863#undef SET_COMPILE_OPTION_NUM
869#define SET_COMPILE_OPTION(o, a, mem) \
870 ((a)->mem < 0 ? 0 : ((o)->mem = (a)->mem > 0))
871 SET_COMPILE_OPTION(option, ast, coverage_enabled);
872#undef SET_COMPILE_OPTION
873 if (ast->frozen_string_literal >= 0) {
874 option->frozen_string_literal = ast->frozen_string_literal;
883 *option = COMPILE_OPTION_DEFAULT;
886 *option = COMPILE_OPTION_FALSE;
888 else if (opt ==
Qtrue) {
891 ((
int *)option)[i] = 1;
894 *option = COMPILE_OPTION_DEFAULT;
895 set_compile_option_from_hash(option, opt);
898 rb_raise(
rb_eTypeError,
"Compile option must be Hash/true/false/nil");
905 VALUE opt = rb_hash_new_with_size(11);
906#define SET_COMPILE_OPTION(o, h, mem) \
907 rb_hash_aset((h), ID2SYM(rb_intern(#mem)), RBOOL((o)->mem))
908#define SET_COMPILE_OPTION_NUM(o, h, mem) \
909 rb_hash_aset((h), ID2SYM(rb_intern(#mem)), INT2NUM((o)->mem))
911 SET_COMPILE_OPTION(option, opt, inline_const_cache);
912 SET_COMPILE_OPTION(option, opt, peephole_optimization);
913 SET_COMPILE_OPTION(option, opt, tailcall_optimization);
914 SET_COMPILE_OPTION(option, opt, specialized_instruction);
915 SET_COMPILE_OPTION(option, opt, operands_unification);
916 SET_COMPILE_OPTION(option, opt, instructions_unification);
917 SET_COMPILE_OPTION(option, opt, debug_frozen_string_literal);
918 SET_COMPILE_OPTION(option, opt, coverage_enabled);
919 SET_COMPILE_OPTION_NUM(option, opt, debug_level);
921#undef SET_COMPILE_OPTION
922#undef SET_COMPILE_OPTION_NUM
923 VALUE frozen_string_literal = option->frozen_string_literal == -1 ?
Qnil : RBOOL(option->frozen_string_literal);
924 rb_hash_aset(opt,
ID2SYM(rb_intern(
"frozen_string_literal")), frozen_string_literal);
932 return rb_iseq_new_with_opt(ast_value, name, path, realpath, 0, parent,
933 0,
type, &COMPILE_OPTION_DEFAULT,
938ast_line_count(
const VALUE ast_value)
940 rb_ast_t *ast = rb_ruby_ast_data_get(ast_value);
941 return ast->body.line_count;
945iseq_setup_coverage(
VALUE coverages,
VALUE path,
int line_count)
947 if (line_count >= 0) {
948 int len = (rb_get_coverage_mode() & COVERAGE_TARGET_ONESHOT_LINES) ? 0 : line_count;
950 VALUE coverage = rb_default_coverage(
len);
951 rb_hash_aset(coverages, path, coverage);
960iseq_new_setup_coverage(
VALUE path,
int line_count)
962 VALUE coverages = rb_get_coverages();
964 if (
RTEST(coverages)) {
965 iseq_setup_coverage(coverages, path, line_count);
972 iseq_new_setup_coverage(path, ast_line_count(ast_value));
974 return rb_iseq_new_with_opt(ast_value, name, path, realpath, 0, parent, 0,
975 ISEQ_TYPE_TOP, &COMPILE_OPTION_DEFAULT,
985 iseq_new_setup_coverage(path, (
int) (pm_parser_line_offsets(node->parser)->
size - 1));
987 return pm_iseq_new_with_opt(node, name, path, realpath, 0, parent, 0,
988 ISEQ_TYPE_TOP, &COMPILE_OPTION_DEFAULT, error_state);
994 iseq_new_setup_coverage(path, ast_line_count(ast_value));
996 return rb_iseq_new_with_opt(ast_value, rb_fstring_lit(
"<main>"),
998 parent, 0, ISEQ_TYPE_MAIN, opt ? &COMPILE_OPTION_DEFAULT : &COMPILE_OPTION_FALSE,
1009 iseq_new_setup_coverage(path, (
int) (pm_parser_line_offsets(node->parser)->
size - 1));
1011 return pm_iseq_new_with_opt(node, rb_fstring_lit(
"<main>"),
1013 parent, 0, ISEQ_TYPE_MAIN, opt ? &COMPILE_OPTION_DEFAULT : &COMPILE_OPTION_FALSE, error_state);
1017rb_iseq_new_eval(
const VALUE ast_value,
VALUE name,
VALUE path,
VALUE realpath,
int first_lineno,
const rb_iseq_t *parent,
int isolated_depth)
1019 if (rb_get_coverage_mode() & COVERAGE_TARGET_EVAL) {
1020 VALUE coverages = rb_get_coverages();
1021 if (
RTEST(coverages) &&
RTEST(path) && !
RTEST(rb_hash_has_key(coverages, path))) {
1022 iseq_setup_coverage(coverages, path, ast_line_count(ast_value) + first_lineno - 1);
1026 return rb_iseq_new_with_opt(ast_value, name, path, realpath, first_lineno,
1027 parent, isolated_depth, ISEQ_TYPE_EVAL, &COMPILE_OPTION_DEFAULT,
1033 int first_lineno,
const rb_iseq_t *parent,
int isolated_depth,
int *error_state)
1035 if (rb_get_coverage_mode() & COVERAGE_TARGET_EVAL) {
1036 VALUE coverages = rb_get_coverages();
1037 if (
RTEST(coverages) &&
RTEST(path) && !
RTEST(rb_hash_has_key(coverages, path))) {
1038 iseq_setup_coverage(coverages, path, ((
int) (pm_parser_line_offsets(node->parser)->
size - 1)) + first_lineno - 1);
1042 return pm_iseq_new_with_opt(node, name, path, realpath, first_lineno,
1043 parent, isolated_depth, ISEQ_TYPE_EVAL, &COMPILE_OPTION_DEFAULT, error_state);
1050 VALUE v1 = iseqw_new(iseq);
1052 if (v1 != v2 &&
CLASS_OF(v2) == rb_cISeq) {
1062 int first_lineno,
const rb_iseq_t *parent,
int isolated_depth,
1066 rb_ast_t *ast = rb_ruby_ast_data_get(ast_value);
1068 const NODE *node = body ? body->root : 0;
1073 if (!option) option = &COMPILE_OPTION_DEFAULT;
1076 option = set_compile_option_from_ast(&new_opt, body);
1079 if (!
NIL_P(script_lines)) {
1082 else if (body && body->script_lines) {
1083 script_lines = rb_parser_build_script_lines_from(body->script_lines);
1086 script_lines = ISEQ_BODY(parent)->variable.script_lines;
1089 prepare_iseq_build(iseq, name, path, realpath, first_lineno, node ? &node->nd_loc : NULL, prepare_node_id(node),
1090 parent, isolated_depth,
type, script_lines, option);
1092 rb_iseq_compile_node(iseq, node);
1093 finish_iseq_build(iseq);
1096 return iseq_translate(iseq);
1106 int first_lineno,
const rb_iseq_t *parent,
int isolated_depth,
1110 ISEQ_BODY(iseq)->prism =
true;
1113 if (!option) option = &COMPILE_OPTION_DEFAULT;
1115 next_option = *option;
1116 next_option.coverage_enabled = node->coverage_enabled < 0 ? 0 : node->coverage_enabled > 0;
1117 option = &next_option;
1120 int32_t start_line = pm_parser_start_line(node->parser);
1123 pm_line_column_t start = pm_line_offset_list_line_column(line_offsets, location->
start, start_line);
1127 .beg_pos = { .lineno = (int) start.
line, .column = (
int) start.
column },
1128 .end_pos = { .lineno = (int) end.
line, .column = (
int) end.
column }
1131 prepare_iseq_build(iseq, name, path, realpath, first_lineno, &code_location, node->ast_node->
node_id,
1132 parent, isolated_depth,
type, node->
script_lines == NULL ?
Qnil : *node->script_lines, option);
1134 pm_iseq_compile_node(iseq, node);
1135 finish_iseq_build(iseq);
1137 return iseq_translate(iseq);
1143 VALUE name, path, realpath;
1144 int first_lineno, isolated_depth;
1146 enum rb_iseq_type
type;
1151pm_iseq_new_with_opt_try(
VALUE d)
1154 data->iseq = pm_iseq_build(data->node, data->name, data->path, data->realpath,
1155 data->first_lineno, data->parent, data->isolated_depth,
1156 data->type, data->option);
1174 int first_lineno,
const rb_iseq_t *parent,
int isolated_depth,
1178 .node = node, .name = name, .path = path, .realpath = realpath,
1179 .first_lineno = first_lineno, .parent = parent,
1180 .isolated_depth = isolated_depth, .type =
type, .option = option
1182 rb_protect(pm_iseq_new_with_opt_try, (
VALUE)&data, error_state);
1184 if (*error_state)
return NULL;
1190rb_iseq_new_with_callback(
1193 int first_lineno,
const rb_iseq_t *parent,
1199 if (!option) option = &COMPILE_OPTION_DEFAULT;
1200 prepare_iseq_build(iseq, name, path, realpath, first_lineno, NULL, -1, parent, 0,
type,
Qnil, option);
1202 rb_iseq_compile_callback(iseq, ifunc);
1203 finish_iseq_build(iseq);
1209rb_iseq_load_iseq(
VALUE fname)
1214 return iseqw_check(iseqv);
1229 return iseqw_check(iseqv);
1235#define CHECK_ARRAY(v) rb_to_array_type(v)
1236#define CHECK_HASH(v) rb_to_hash_type(v)
1237#define CHECK_STRING(v) rb_str_to_str(v)
1238#define CHECK_SYMBOL(v) rb_to_symbol_type(v)
1241static enum rb_iseq_type
1244 const ID id_top = rb_intern(
"top");
1245 const ID id_method = rb_intern(
"method");
1246 const ID id_block = rb_intern(
"block");
1247 const ID id_class = rb_intern(
"class");
1248 const ID id_rescue = rb_intern(
"rescue");
1249 const ID id_ensure = rb_intern(
"ensure");
1250 const ID id_eval = rb_intern(
"eval");
1251 const ID id_main = rb_intern(
"main");
1252 const ID id_plain = rb_intern(
"plain");
1256 if (
typeid == id_top)
return ISEQ_TYPE_TOP;
1257 if (
typeid == id_method)
return ISEQ_TYPE_METHOD;
1258 if (
typeid == id_block)
return ISEQ_TYPE_BLOCK;
1259 if (
typeid == id_class)
return ISEQ_TYPE_CLASS;
1260 if (
typeid == id_rescue)
return ISEQ_TYPE_RESCUE;
1261 if (
typeid == id_ensure)
return ISEQ_TYPE_ENSURE;
1262 if (
typeid == id_eval)
return ISEQ_TYPE_EVAL;
1263 if (
typeid == id_main)
return ISEQ_TYPE_MAIN;
1264 if (
typeid == id_plain)
return ISEQ_TYPE_PLAIN;
1265 return (
enum rb_iseq_type)-1;
1273 VALUE magic, version1, version2, format_type, misc;
1274 VALUE name, path, realpath, code_location, node_id;
1275 VALUE type, body, locals, params, exception;
1277 st_data_t iseq_type;
1287 data = CHECK_ARRAY(data);
1294 ((void)magic, (
void)version1, (void)version2, (
void)format_type);
1299 realpath =
NIL_P(realpath) ?
Qnil : CHECK_STRING(realpath);
1308 ISEQ_BODY(iseq)->local_iseq = iseq;
1310 iseq_type = iseq_type_from_sym(
type);
1311 if (iseq_type == (
enum rb_iseq_type)-1) {
1315 node_id = rb_hash_aref(misc,
ID2SYM(rb_intern(
"node_id")));
1317 code_location = rb_hash_aref(misc,
ID2SYM(rb_intern(
"code_location")));
1325 if (
SYM2ID(rb_hash_aref(misc,
ID2SYM(rb_intern(
"parser")))) == rb_intern(
"prism")) {
1326 ISEQ_BODY(iseq)->prism =
true;
1329 make_compile_option(&option, opt);
1330 option.peephole_optimization = FALSE;
1331 prepare_iseq_build(iseq, name, path, realpath, first_lineno, &tmp_loc,
NUM2INT(node_id),
1332 parent, 0, (
enum rb_iseq_type)iseq_type,
Qnil, &option);
1334 rb_iseq_build_from_ary(iseq, misc, locals, params, exception, body);
1336 finish_iseq_build(iseq);
1338 return iseqw_new(iseq);
1345iseq_s_load(
int argc,
VALUE *argv,
VALUE self)
1349 return iseq_load(data, NULL, opt);
1355 return iseq_load(data,
RTEST(parent) ? (
rb_iseq_t *)parent : NULL, opt);
1363#if !defined(__GNUC__) || (__GNUC__ == 4 && __GNUC_MINOR__ == 8)
1364# define INITIALIZED volatile
1370 VALUE INITIALIZED ast_value;
1372 VALUE name = rb_fstring_lit(
"<compiled>");
1375 make_compile_option(&option, opt);
1379 parse = rb_parser_compile_file_path;
1382 parse = rb_parser_compile_string_path;
1386 const VALUE parser = rb_parser_new();
1387 const rb_iseq_t *outer_scope = rb_iseq_new(
Qnil, name, name,
Qnil, 0, ISEQ_TYPE_TOP);
1389 rb_parser_set_context(parser, outer_scope, FALSE);
1390 if (ruby_vm_keep_script_lines) rb_parser_set_script_lines(parser);
1392 ast_value = (*parse)(parser, file, src, ln);
1395 ast = rb_ruby_ast_data_get(ast_value);
1397 if (!ast || !ast->body.root) {
1398 rb_ast_dispose(ast);
1402 iseq = rb_iseq_new_with_opt(ast_value, name, file, realpath, ln,
1403 NULL, 0, ISEQ_TYPE_TOP, &option,
1405 rb_ast_dispose(ast);
1417 VALUE name = rb_fstring_lit(
"<compiled>");
1420 make_compile_option(&option, opt);
1424 bool parse_file =
false;
1434 pm_parse_result_init(&result);
1436 pm_options_scopes_init(result.
options, 1);
1437 result.
node.coverage_enabled = 1;
1439 switch (option.frozen_string_literal) {
1440 case ISEQ_FROZEN_STRING_LITERAL_UNSET:
1442 case ISEQ_FROZEN_STRING_LITERAL_DISABLED:
1443 pm_options_frozen_string_literal_set(result.
options,
false);
1445 case ISEQ_FROZEN_STRING_LITERAL_ENABLED:
1446 pm_options_frozen_string_literal_set(result.
options,
true);
1449 rb_bug(
"pm_iseq_compile_with_option: invalid frozen_string_literal=%d", option.frozen_string_literal);
1457 error = pm_load_parse_file(&result, src, ruby_vm_keep_script_lines ? &script_lines : NULL);
1460 error = pm_parse_string(&result, src, file, ruby_vm_keep_script_lines ? &script_lines : NULL);
1465 if (error ==
Qnil) {
1467 iseq = pm_iseq_new_with_opt(&result.
node, name, file, realpath, ln, NULL, 0, ISEQ_TYPE_TOP, &option, &error_state);
1469 pm_parse_result_free(&result);
1473 rb_jump_tag(error_state);
1477 pm_parse_result_free(&result);
1487 return pathobj_path(ISEQ_BODY(iseq)->location.pathobj);
1493 return pathobj_realpath(ISEQ_BODY(iseq)->location.pathobj);
1497rb_iseq_absolute_path(
const rb_iseq_t *iseq)
1499 return rb_iseq_realpath(iseq);
1503rb_iseq_from_eval_p(
const rb_iseq_t *iseq)
1505 return NIL_P(rb_iseq_realpath(iseq));
1511 return ISEQ_BODY(iseq)->location.label;
1515rb_iseq_base_label(
const rb_iseq_t *iseq)
1517 return ISEQ_BODY(iseq)->location.base_label;
1521rb_iseq_first_lineno(
const rb_iseq_t *iseq)
1523 return RB_INT2NUM(ISEQ_BODY(iseq)->location.first_lineno);
1527rb_iseq_method_name(
const rb_iseq_t *iseq)
1531 if (body->type == ISEQ_TYPE_METHOD) {
1532 return body->location.base_label;
1540rb_iseq_code_location(
const rb_iseq_t *iseq,
int *beg_pos_lineno,
int *beg_pos_column,
int *end_pos_lineno,
int *end_pos_column)
1543 if (beg_pos_lineno) *beg_pos_lineno = loc->beg_pos.lineno;
1544 if (beg_pos_column) *beg_pos_column = loc->beg_pos.column;
1545 if (end_pos_lineno) *end_pos_lineno = loc->end_pos.lineno;
1546 if (end_pos_column) *end_pos_column = loc->end_pos.column;
1549static ID iseq_type_id(
enum rb_iseq_type
type);
1554 return ID2SYM(iseq_type_id(ISEQ_BODY(iseq)->
type));
1560 return ISEQ_COVERAGE(iseq);
1564remove_coverage_i(
void *vstart,
void *vend,
size_t stride,
void *data)
1567 for (; v != (
VALUE)vend; v += stride) {
1568 void *ptr = rb_asan_poisoned_object_p(v);
1569 rb_asan_unpoison_object(v,
false);
1571 if (rb_obj_is_iseq(v)) {
1573 ISEQ_COVERAGE_SET(iseq,
Qnil);
1576 asan_poison_object_if(ptr, v);
1582rb_iseq_remove_coverage_all(
void)
1584 rb_objspace_each_objects(remove_coverage_i, NULL);
1590iseqw_mark_and_move(
void *ptr)
1592 rb_gc_mark_and_move((
VALUE *)ptr);
1596iseqw_memsize(
const void *ptr)
1598 return rb_iseq_memsize(*(
const rb_iseq_t **)ptr);
1604 iseqw_mark_and_move,
1607 iseqw_mark_and_move,
1615 if (iseq->wrapper) {
1617 rb_raise(
rb_eTypeError,
"wrong iseq wrapper: %" PRIsVALUE
" for %p",
1618 iseq->wrapper, (
void *)iseq);
1620 return iseq->wrapper;
1628 RB_OBJ_SET_FROZEN_SHAREABLE((
VALUE)obj);
1638 return iseqw_new(iseq);
1647iseqw_s_compile_parser(
int argc,
VALUE *argv,
VALUE self,
bool prism)
1653 if (i > 4+
NIL_P(opt)) rb_error_arity(argc, 1, 5);
1655 case 5: opt = argv[--i];
1656 case 4: line = argv[--i];
1657 case 3: path = argv[--i];
1658 case 2: file = argv[--i];
1661 if (
NIL_P(file)) file = rb_fstring_lit(
"<compiled>");
1662 if (
NIL_P(path)) path = file;
1670 iseq = pm_iseq_compile_with_option(src, file, path, line, opt);
1673 iseq = rb_iseq_compile_with_option(src, file, path, line, opt);
1676 return iseqw_new(iseq);
1717iseqw_s_compile(
int argc,
VALUE *argv,
VALUE self)
1719 return iseqw_s_compile_parser(argc, argv, self, rb_ruby_prism_p());
1759iseqw_s_compile_parsey(
int argc,
VALUE *argv,
VALUE self)
1761 return iseqw_s_compile_parser(argc, argv, self,
false);
1801iseqw_s_compile_prism(
int argc,
VALUE *argv,
VALUE self)
1803 return iseqw_s_compile_parser(argc, argv, self,
true);
1806static VALUE iseqw_s_compile_file_prism(
int argc,
VALUE *argv,
VALUE self);
1829iseqw_s_compile_file(
int argc,
VALUE *argv,
VALUE self)
1831 if (rb_ruby_prism_p()) {
1832 return iseqw_s_compile_file_prism(argc, argv, self);
1842 i =
rb_scan_args(argc, argv,
"1*:", &file, NULL, &opt);
1843 if (i > 1+
NIL_P(opt)) rb_error_arity(argc, 1, 2);
1845 case 2: opt = argv[--i];
1848 file = rb_fstring(file);
1853 VALUE v = rb_vm_push_frame_fname(ec, file);
1855 parser = rb_parser_new();
1856 rb_parser_set_context(parser, NULL, FALSE);
1857 ast_value = rb_parser_load_file(parser, file);
1858 ast = rb_ruby_ast_data_get(ast_value);
1859 if (!ast->body.root) exc = GET_EC()->errinfo;
1862 if (!ast->body.root) {
1863 rb_ast_dispose(ast);
1867 make_compile_option(&option, opt);
1869 ret = iseqw_new(rb_iseq_new_with_opt(ast_value, rb_fstring_lit(
"<main>"),
1871 rb_realpath_internal(
Qnil, file, 1),
1872 1, NULL, 0, ISEQ_TYPE_TOP, &option,
1874 rb_ast_dispose(ast);
1877 rb_vm_pop_frame(ec);
1904iseqw_s_compile_file_prism(
int argc,
VALUE *argv,
VALUE self)
1910 i =
rb_scan_args(argc, argv,
"1*:", &file, NULL, &opt);
1911 if (i > 1+
NIL_P(opt)) rb_error_arity(argc, 1, 2);
1913 case 2: opt = argv[--i];
1916 file = rb_fstring(file);
1919 VALUE v = rb_vm_push_frame_fname(ec, file);
1922 pm_parse_result_init(&result);
1923 result.
node.coverage_enabled = 1;
1926 VALUE error = pm_load_parse_file(&result, file, ruby_vm_keep_script_lines ? &script_lines : NULL);
1928 if (error ==
Qnil) {
1929 make_compile_option(&option, opt);
1932 rb_iseq_t *iseq = pm_iseq_new_with_opt(&result.
node, rb_fstring_lit(
"<main>"),
1934 rb_realpath_internal(
Qnil, file, 1),
1935 1, NULL, 0, ISEQ_TYPE_TOP, &option, &error_state);
1937 pm_parse_result_free(&result);
1941 rb_jump_tag(error_state);
1944 ret = iseqw_new(iseq);
1945 rb_vm_pop_frame(ec);
1950 pm_parse_result_free(&result);
1951 rb_vm_pop_frame(ec);
1988iseqw_s_compile_option_set(
VALUE self,
VALUE opt)
1991 make_compile_option(&option, opt);
1992 COMPILE_OPTION_DEFAULT = option;
2005iseqw_s_compile_option_get(
VALUE self)
2007 return make_compile_option_value(&COMPILE_OPTION_DEFAULT);
2011iseqw_check(
VALUE iseqw)
2017 if (!ISEQ_BODY(iseq)) {
2018 rb_ibf_load_iseq_complete(iseq);
2021 if (!ISEQ_BODY(iseq)->location.label) {
2022 rb_raise(
rb_eTypeError,
"uninitialized InstructionSequence");
2028rb_iseqw_to_iseq(
VALUE iseqw)
2030 return iseqw_check(iseqw);
2042iseqw_eval(
VALUE self)
2044 const rb_iseq_t *iseq = iseqw_check(self);
2045 if (0 == ISEQ_BODY(iseq)->iseq_size) {
2046 rb_raise(
rb_eTypeError,
"attempt to evaluate dummy InstructionSequence");
2048 return rb_iseq_eval(iseq, rb_current_box());
2056iseqw_inspect(
VALUE self)
2058 const rb_iseq_t *iseq = iseqw_check(self);
2062 if (!body->location.label) {
2063 return rb_sprintf(
"#<%"PRIsVALUE
": uninitialized>", klass);
2066 return rb_sprintf(
"<%"PRIsVALUE
":%"PRIsVALUE
"@%"PRIsVALUE
":%d>",
2068 body->location.label, rb_iseq_path(iseq),
2069 FIX2INT(rb_iseq_first_lineno(iseq)));
2097iseqw_path(
VALUE self)
2099 return rb_iseq_path(iseqw_check(self));
2119iseqw_absolute_path(
VALUE self)
2121 return rb_iseq_realpath(iseqw_check(self));
2148iseqw_label(
VALUE self)
2150 return rb_iseq_label(iseqw_check(self));
2174iseqw_base_label(
VALUE self)
2176 return rb_iseq_base_label(iseqw_check(self));
2190iseqw_first_lineno(
VALUE self)
2192 return rb_iseq_first_lineno(iseqw_check(self));
2279iseqw_to_a(
VALUE self)
2281 const rb_iseq_t *iseq = iseqw_check(self);
2282 return iseq_data_to_ary(iseq);
2285#if VM_INSN_INFO_TABLE_IMPL == 1
2287get_insn_info_binary_search(
const rb_iseq_t *iseq,
size_t pos)
2290 size_t size = body->insns_info.size;
2292 const unsigned int *positions = body->insns_info.positions;
2293 const int debug = 0;
2296 printf(
"size: %"PRIuSIZE
"\n", size);
2297 printf(
"insns_info[%"PRIuSIZE
"]: position: %d, line: %d, pos: %"PRIuSIZE
"\n",
2298 (
size_t)0, positions[0], insns_info[0].line_no, pos);
2304 else if (size == 1) {
2305 return &insns_info[0];
2308 size_t l = 1, r = size - 1;
2310 size_t m = l + (r - l) / 2;
2311 if (positions[m] == pos) {
2312 return &insns_info[m];
2314 if (positions[m] < pos) {
2322 return &insns_info[size-1];
2324 if (positions[l] > pos) {
2325 return &insns_info[l-1];
2327 return &insns_info[l];
2332get_insn_info(
const rb_iseq_t *iseq,
size_t pos)
2334 return get_insn_info_binary_search(iseq, pos);
2338#if VM_INSN_INFO_TABLE_IMPL == 2
2340get_insn_info_succinct_bitvector(
const rb_iseq_t *iseq,
size_t pos)
2343 size_t size = body->insns_info.size;
2345 const int debug = 0;
2348#if VM_CHECK_MODE > 0
2349 const unsigned int *positions = body->insns_info.positions;
2350 printf(
"size: %"PRIuSIZE
"\n", size);
2351 printf(
"insns_info[%"PRIuSIZE
"]: position: %d, line: %d, pos: %"PRIuSIZE
"\n",
2352 (
size_t)0, positions[0], insns_info[0].line_no, pos);
2354 printf(
"size: %"PRIuSIZE
"\n", size);
2355 printf(
"insns_info[%"PRIuSIZE
"]: line: %d, pos: %"PRIuSIZE
"\n",
2356 (
size_t)0, insns_info[0].line_no, pos);
2363 else if (size == 1) {
2364 return &insns_info[0];
2368 VM_ASSERT(body->insns_info.succ_index_table != NULL);
2369 index = succ_index_lookup(body->insns_info.succ_index_table, (
int)pos);
2370 return &insns_info[index-1];
2375get_insn_info(
const rb_iseq_t *iseq,
size_t pos)
2377 return get_insn_info_succinct_bitvector(iseq, pos);
2381#if VM_CHECK_MODE > 0 || VM_INSN_INFO_TABLE_IMPL == 0
2383get_insn_info_linear_search(
const rb_iseq_t *iseq,
size_t pos)
2386 size_t i = 0, size = body->insns_info.size;
2388 const unsigned int *positions = body->insns_info.positions;
2389 const int debug = 0;
2392 printf(
"size: %"PRIuSIZE
"\n", size);
2393 printf(
"insns_info[%"PRIuSIZE
"]: position: %d, line: %d, pos: %"PRIuSIZE
"\n",
2394 i, positions[i], insns_info[i].line_no, pos);
2400 else if (size == 1) {
2401 return &insns_info[0];
2404 for (i=1; i<size; i++) {
2405 if (debug) printf(
"insns_info[%"PRIuSIZE
"]: position: %d, line: %d, pos: %"PRIuSIZE
"\n",
2406 i, positions[i], insns_info[i].line_no, pos);
2408 if (positions[i] == pos) {
2409 return &insns_info[i];
2411 if (positions[i] > pos) {
2412 return &insns_info[i-1];
2416 return &insns_info[i-1];
2420#if VM_INSN_INFO_TABLE_IMPL == 0
2422get_insn_info(
const rb_iseq_t *iseq,
size_t pos)
2424 return get_insn_info_linear_search(iseq, pos);
2428#if VM_CHECK_MODE > 0 && VM_INSN_INFO_TABLE_IMPL > 0
2430validate_get_insn_info(
const rb_iseq_t *iseq)
2434 for (i = 0; i < body->iseq_size; i++) {
2435 if (get_insn_info_linear_search(iseq, i) != get_insn_info(iseq, i)) {
2436 rb_bug(
"validate_get_insn_info: get_insn_info_linear_search(iseq, %"PRIuSIZE
") != get_insn_info(iseq, %"PRIuSIZE
")", i, i);
2443rb_iseq_line_no(
const rb_iseq_t *iseq,
size_t pos)
2448 return entry->line_no;
2455#ifdef USE_ISEQ_NODE_ID
2457rb_iseq_node_id(
const rb_iseq_t *iseq,
size_t pos)
2462 return entry->node_id;
2471rb_iseq_event_flags(
const rb_iseq_t *iseq,
size_t pos)
2475 return entry->events;
2482static void rb_iseq_trace_flag_cleared(
const rb_iseq_t *iseq,
size_t pos);
2494 entry->events &= ~reset;
2495 if (!(entry->events & iseq->aux.exec.global_trace_events)) {
2496 rb_iseq_trace_flag_cleared(iseq, pos);
2510 for (i = 0; i < level; i++) {
2511 diseq = ISEQ_BODY(diseq)->parent_iseq;
2513 idx = ISEQ_BODY(diseq)->local_table_size - (int)op - 1;
2514 lid = ISEQ_BODY(diseq)->local_table[idx];
2515 name = rb_id2str(lid);
2525 rb_str_catf(name,
"@%d", idx);
2529int rb_insn_unified_local_var_level(
VALUE);
2533rb_insn_operand_intern(
const rb_iseq_t *iseq,
2537 const char *types = insn_op_types(insn);
2538 char type = types[op_no];
2543 ret = rb_sprintf(
"%"PRIdVALUE, (
VALUE)(pos +
len + op));
2547 if (insn == BIN(defined) && op_no == 0) {
2548 enum defined_type deftype = (
enum defined_type)op;
2551 ret = rb_fstring_lit(
"func");
2554 ret = rb_fstring_lit(
"ref");
2556 case DEFINED_CONST_FROM:
2557 ret = rb_fstring_lit(
"constant-from");
2560 ret = rb_iseq_defined_string(deftype);
2565 else if (insn == BIN(checktype) && op_no == 0) {
2571 ret = rb_sprintf(
"%"PRIuVALUE, op);
2576 if (types[op_no+1] == TS_NUM && pnop) {
2577 ret = local_var_name(iseq, *pnop, op - VM_ENV_DATA_SIZE);
2579 else if ((level = rb_insn_unified_local_var_level(insn)) >= 0) {
2580 ret = local_var_name(iseq, (
VALUE)level, op - VM_ENV_DATA_SIZE);
2592 op = obj_resurrect(op);
2593 if (insn == BIN(defined) && op_no == 1 &&
FIXNUM_P(op)) {
2598 ret = rb_sprintf(
":$%c", (
type >> 1));
2601 ret = rb_sprintf(
":$%d", (
type >> 1));
2606 ret = rb_dump_literal(op);
2618 ret = ISEQ_BODY(iseq)->location.label;
2632 const ID *segments = ((
IC)op)->segments;
2635 rb_str_catf(ret,
"::%s", rb_id2name(*segments++));
2651 ID mid = vm_ci_mid(ci);
2654 rb_ary_push(ary, rb_sprintf(
"mid:%"PRIsVALUE, rb_id2str(mid)));
2657 rb_ary_push(ary, rb_sprintf(
"argc:%d", vm_ci_argc(ci)));
2659 if (vm_ci_flag(ci) & VM_CALL_KWARG) {
2665 if (vm_ci_flag(ci)) {
2667# define CALL_FLAG(n) if (vm_ci_flag(ci) & VM_CALL_##n) rb_ary_push(flags, rb_str_new2(#n))
2668 CALL_FLAG(ARGS_SPLAT);
2669 CALL_FLAG(ARGS_SPLAT_MUT);
2670 CALL_FLAG(ARGS_BLOCKARG);
2673 CALL_FLAG(ARGS_SIMPLE);
2674 CALL_FLAG(TAILCALL);
2678 CALL_FLAG(KW_SPLAT);
2679 CALL_FLAG(KW_SPLAT_MUT);
2680 CALL_FLAG(FORWARDING);
2681 CALL_FLAG(OPT_SEND);
2697 if (dladdr((
void *)op, &info) && info.dli_sname) {
2709 ret = rb_sprintf(
"<builtin!%s/%d>",
2710 bf->name, bf->argc);
2715 rb_bug(
"unknown operand type: %c",
type);
2721right_strip(
VALUE str)
2723 const char *beg = RSTRING_PTR(str), *end =
RSTRING_END(str);
2724 while (end-- > beg && *end ==
' ');
2734rb_iseq_disasm_insn(
VALUE ret,
const VALUE *code,
size_t pos,
2737 VALUE insn = code[pos];
2738 int len = insn_len(insn);
2740 const char *types = insn_op_types(insn);
2742 const char *insn_name_buff;
2744 insn_name_buff = insn_name(insn);
2746 extern const int rb_vm_max_insn_name_size;
2747 rb_str_catf(str,
"%04"PRIuSIZE
" %-*s ", pos, rb_vm_max_insn_name_size, insn_name_buff);
2750 rb_str_catf(str,
"%04"PRIuSIZE
" %-28.*s ", pos,
2751 (
int)strcspn(insn_name_buff,
"_"), insn_name_buff);
2754 for (j = 0; types[j]; j++) {
2755 VALUE opstr = rb_insn_operand_intern(iseq, insn, j, code[pos + j + 1],
2756 len, pos, &code[pos + j + 2],
2766 unsigned int line_no = rb_iseq_line_no(iseq, pos);
2767 unsigned int prev = pos == 0 ? 0 : rb_iseq_line_no(iseq, pos - 1);
2768 if (line_no && line_no != prev) {
2769 long slen = RSTRING_LEN(str);
2770 slen = (slen > 70) ? 0 : (70 - slen);
2771 str = rb_str_catf(str,
"%*s(%4d)", (
int)slen,
"", line_no);
2778 str = rb_str_catf(str,
"[%s%s%s%s%s%s%s%s%s%s%s%s]",
2789 events & RUBY_EVENT_COVERAGE_LINE ?
"Cli" :
"",
2790 events & RUBY_EVENT_COVERAGE_BRANCH ?
"Cbr" :
"");
2800 printf(
"%.*s\n", (
int)RSTRING_LEN(str), RSTRING_PTR(str));
2809 case CATCH_TYPE_RESCUE:
2811 case CATCH_TYPE_ENSURE:
2813 case CATCH_TYPE_RETRY:
2815 case CATCH_TYPE_BREAK:
2817 case CATCH_TYPE_REDO:
2819 case CATCH_TYPE_NEXT:
2822 rb_bug(
"unknown catch type: %d",
type);
2831 if (!body->location.label) {
2832 return rb_sprintf(
"#<ISeq: uninitialized>");
2836 return rb_sprintf(
"#<ISeq:%"PRIsVALUE
"@%"PRIsVALUE
":%d (%d,%d)-(%d,%d)>",
2837 body->location.label, rb_iseq_path(iseq),
2838 loc->beg_pos.lineno,
2839 loc->beg_pos.lineno,
2840 loc->beg_pos.column,
2841 loc->end_pos.lineno,
2842 loc->end_pos.column);
2848 {(void (*)(
void *))rb_mark_set, (void (*)(
void *))st_free_table, 0, 0,},
2863 enum {header_minlen = 72};
2866 const char *indent_str;
2869 size = body->iseq_size;
2871 indent_len = RSTRING_LEN(indent);
2872 indent_str = RSTRING_PTR(indent);
2878 if ((l = RSTRING_LEN(str) - indent_len) < header_minlen) {
2882 if (iseq->body->builtin_attrs) {
2883#define disasm_builtin_attr(str, iseq, attr) \
2884 if (iseq->body->builtin_attrs & BUILTIN_ATTR_ ## attr) { \
2885 rb_str_cat2(str, " " #attr); \
2887 disasm_builtin_attr(str, iseq, LEAF);
2888 disasm_builtin_attr(str, iseq, SINGLE_NOARG_LEAF);
2889 disasm_builtin_attr(str, iseq, INLINE_BLOCK);
2890 disasm_builtin_attr(str, iseq, C_TRACE);
2895 if (body->catch_table) {
2899 if (body->catch_table) {
2901 indent_str = RSTRING_PTR(indent);
2902 for (i = 0; i < body->catch_table->size; i++) {
2904 UNALIGNED_MEMBER_PTR(body->catch_table, entries[i]);
2907 "| catch type: %-6s st: %04d ed: %04d sp: %04d cont: %04d\n",
2908 catch_type((
int)entry->type), (
int)entry->start,
2909 (
int)entry->end, (
int)entry->sp, (
int)entry->cont);
2910 if (entry->iseq && !(done_iseq && st_is_member(done_iseq, (st_data_t)entry->iseq))) {
2911 rb_str_concat(str, rb_iseq_disasm_recursive(rb_iseq_check(entry->iseq), indent));
2913 done_iseq = st_init_numtable();
2916 st_insert(done_iseq, (st_data_t)entry->iseq, (st_data_t)0);
2917 indent_str = RSTRING_PTR(indent);
2920 rb_str_resize(indent, indent_len);
2921 indent_str = RSTRING_PTR(indent);
2923 if (body->catch_table) {
2925 rb_str_cat2(str,
"|-------------------------------------"
2926 "-----------------------------------\n");
2930 if (body->local_table) {
2931 const struct rb_iseq_param_keyword *
const keyword = body->param.keyword;
2934 "local table (size: %d, argc: %d "
2935 "[opts: %d, rest: %d, post: %d, block: %d, kw: %d@%d, kwrest: %d])\n",
2936 body->local_table_size,
2937 body->param.lead_num,
2938 body->param.opt_num,
2939 body->param.flags.has_rest ? body->param.rest_start : -1,
2940 body->param.post_num,
2941 body->param.flags.has_block ? body->param.block_start : -1,
2942 body->param.flags.has_kw ? keyword->num : -1,
2943 body->param.flags.has_kw ? keyword->required_num : -1,
2944 body->param.flags.has_kwrest ? keyword->rest_start : -1);
2946 for (i = body->local_table_size; i > 0;) {
2947 int li = body->local_table_size - --i - 1;
2949 VALUE name = local_var_name(iseq, 0, i);
2954 if (body->param.flags.has_opt) {
2955 int argc = body->param.lead_num;
2956 int opts = body->param.opt_num;
2957 if (li >= argc && li < argc + opts) {
2958 snprintf(opti,
sizeof(opti),
"Opt=%"PRIdVALUE,
2959 body->param.opt_table[li - argc]);
2963 snprintf(argi,
sizeof(argi),
"%s%s%s%s%s%s",
2964 (body->param.lead_num > li) ? (body->param.flags.ambiguous_param0 ?
"AmbiguousArg" :
"Arg") :
"",
2966 (body->param.flags.has_rest && body->param.rest_start == li) ? (body->param.flags.anon_rest ?
"AnonRest" :
"Rest") :
"",
2967 (body->param.flags.has_post && body->param.post_start <= li && li < body->param.post_start + body->param.post_num) ?
"Post" :
"",
2968 (body->param.flags.has_kwrest && keyword->rest_start == li) ? (body->param.flags.anon_kwrest ?
"AnonKwrest" :
"Kwrest") :
"",
2969 (body->param.flags.has_block && body->param.block_start == li) ?
"Block" :
"");
2972 rb_str_catf(str,
"[%2d] ", i + 1);
2973 width = RSTRING_LEN(str) + 11;
2975 if (*argi) rb_str_catf(str,
"<%s>", argi);
2976 if ((width -= RSTRING_LEN(str)) > 0) rb_str_catf(str,
"%*s", (
int)width,
"");
2982 code = rb_iseq_original_iseq(iseq);
2983 for (n = 0; n < size;) {
2985 n += rb_iseq_disasm_insn(str, code, n, iseq, child);
2990 if (done_iseq && st_is_member(done_iseq, (st_data_t)isv))
continue;
2993 indent_str = RSTRING_PTR(indent);
3004 rb_str_resize(str, RSTRING_LEN(str));
3014rb_estimate_iv_count(
VALUE klass,
const rb_iseq_t * initialize_iseq)
3017 set_init_embedded_numtable_with_size(&iv_names, 0);
3019 for (
unsigned int i = 0; i < ISEQ_BODY(initialize_iseq)->ivc_size; i++) {
3020 IVC cache = (
IVC)&ISEQ_BODY(initialize_iseq)->is_entries[i];
3022 if (cache->iv_set_name) {
3023 set_insert(&iv_names, cache->iv_set_name);
3027 attr_index_t count = (attr_index_t)iv_names.num_entries;
3030 if (!
NIL_P(superclass)) {
3031 count += RCLASS_MAX_IV_COUNT(superclass);
3034 set_free_embedded_table(&iv_names);
3058iseqw_disasm(
VALUE self)
3060 return rb_iseq_disasm(iseqw_check(self));
3064iseq_iterate_children(
const rb_iseq_t *iseq,
void (*iter_func)(
const rb_iseq_t *child_iseq,
void *data),
void *data)
3067 VALUE *code = rb_iseq_original_iseq(iseq);
3072 if (body->catch_table) {
3073 for (i = 0; i < body->catch_table->size; i++) {
3075 UNALIGNED_MEMBER_PTR(body->catch_table, entries[i]);
3076 child = entry->iseq;
3078 if (
NIL_P(rb_hash_aref(all_children, (
VALUE)child))) {
3079 rb_hash_aset(all_children, (
VALUE)child,
Qtrue);
3080 (*iter_func)(child, data);
3086 for (i=0; i<body->iseq_size;) {
3087 VALUE insn = code[i];
3088 int len = insn_len(insn);
3089 const char *types = insn_op_types(insn);
3092 for (j=0; types[j]; j++) {
3097 if (
NIL_P(rb_hash_aref(all_children, (
VALUE)child))) {
3098 rb_hash_aset(all_children, (
VALUE)child,
Qtrue);
3099 (*iter_func)(child, data);
3114yield_each_children(
const rb_iseq_t *child_iseq,
void *data)
3128iseqw_each_child(
VALUE self)
3130 const rb_iseq_t *iseq = iseqw_check(self);
3131 iseq_iterate_children(iseq, yield_each_children, NULL);
3138#define C(ev, cstr, l) if (events & ev) rb_ary_push(ary, rb_ary_new_from_args(2, l, ID2SYM(rb_intern(cstr))));
3158iseqw_trace_points(
VALUE self)
3160 const rb_iseq_t *iseq = iseqw_check(self);
3165 for (i=0; i<body->insns_info.size; i++) {
3167 if (entry->events) {
3168 push_event_info(iseq, entry->events, entry->line_no, ary);
3214 if (rb_frame_info_p(body)) {
3215 iseq = rb_get_iseq_from_frame_info(body);
3218 iseq = vm_proc_iseq(body);
3220 if (!rb_obj_is_iseq((
VALUE)iseq)) {
3225 iseq = rb_method_iseq(body);
3227 else if (rb_typeddata_is_instance_of(body, &iseqw_data_type)) {
3231 return iseq ? iseqw_new(iseq) :
Qnil;
3289 VALUE iseqw = iseqw_s_of(klass, body);
3290 return NIL_P(iseqw) ?
Qnil : rb_iseq_disasm(iseqw_check(iseqw));
3294register_label(
struct st_table *table,
unsigned long idx)
3297 st_insert(table, idx, sym);
3306 case CATCH_TYPE_RESCUE:
CONST_ID(
id,
"rescue");
break;
3307 case CATCH_TYPE_ENSURE:
CONST_ID(
id,
"ensure");
break;
3308 case CATCH_TYPE_RETRY:
CONST_ID(
id,
"retry");
break;
3309 case CATCH_TYPE_BREAK:
CONST_ID(
id,
"break");
break;
3310 case CATCH_TYPE_REDO:
CONST_ID(
id,
"redo");
break;
3311 case CATCH_TYPE_NEXT:
CONST_ID(
id,
"next");
break;
3313 rb_bug(
"unknown exception type: %d", (
int)
type);
3328 {(void (*)(
void *))rb_mark_tbl, (void (*)(
void *))st_free_table, 0, 0,},
3332#define DECL_ID(name) \
3335#define INIT_ID(name) \
3336 id_##name = rb_intern(#name)
3339iseq_type_id(
enum rb_iseq_type
type)
3364 case ISEQ_TYPE_TOP:
return id_top;
3365 case ISEQ_TYPE_METHOD:
return id_method;
3366 case ISEQ_TYPE_BLOCK:
return id_block;
3367 case ISEQ_TYPE_CLASS:
return id_class;
3368 case ISEQ_TYPE_RESCUE:
return id_rescue;
3369 case ISEQ_TYPE_ENSURE:
return id_ensure;
3370 case ISEQ_TYPE_EVAL:
return id_eval;
3371 case ISEQ_TYPE_MAIN:
return id_main;
3372 case ISEQ_TYPE_PLAIN:
return id_plain;
3375 rb_bug(
"unsupported iseq type: %d", (
int)
type);
3388 VALUE *seq, *iseq_original;
3393 VALUE params = rb_hash_new();
3397 VALUE misc = rb_hash_new();
3399 static ID insn_syms[VM_BARE_INSTRUCTION_SIZE];
3400 struct st_table *labels_table = st_init_numtable();
3403 if (insn_syms[0] == 0) {
3405 for (i=0; i<numberof(insn_syms); i++) {
3406 insn_syms[i] = rb_intern(insn_name(i));
3411 type = iseq_type_id(iseq_body->type);
3414 for (i=0; i<iseq_body->local_table_size; i++) {
3415 ID lid = iseq_body->local_table[i];
3417 if (lid != idItImplicit && rb_id2str(lid)) {
3431 const struct rb_iseq_param_keyword *
const keyword = iseq_body->param.keyword;
3434 if (iseq_body->param.flags.has_opt) {
3435 int len = iseq_body->param.opt_num + 1;
3438 for (j = 0; j <
len; j++) {
3439 VALUE l = register_label(labels_table, iseq_body->param.opt_table[j]);
3442 rb_hash_aset(params,
ID2SYM(rb_intern(
"opt")), arg_opt_labels);
3446 if (iseq_body->param.flags.has_lead) rb_hash_aset(params,
ID2SYM(rb_intern(
"lead_num")),
INT2FIX(iseq_body->param.lead_num));
3447 if (iseq_body->param.flags.has_post) rb_hash_aset(params,
ID2SYM(rb_intern(
"post_num")),
INT2FIX(iseq_body->param.post_num));
3448 if (iseq_body->param.flags.has_post) rb_hash_aset(params,
ID2SYM(rb_intern(
"post_start")),
INT2FIX(iseq_body->param.post_start));
3449 if (iseq_body->param.flags.has_rest) rb_hash_aset(params,
ID2SYM(rb_intern(
"rest_start")),
INT2FIX(iseq_body->param.rest_start));
3450 if (iseq_body->param.flags.has_block) rb_hash_aset(params,
ID2SYM(rb_intern(
"block_start")),
INT2FIX(iseq_body->param.block_start));
3451 if (iseq_body->param.flags.has_kw) {
3454 for (i=0; i<keyword->required_num; i++) {
3457 for (j=0; i<keyword->num; i++, j++) {
3458 VALUE key = rb_ary_new_from_args(1,
ID2SYM(keyword->table[i]));
3459 if (!UNDEF_P(keyword->default_values[j])) {
3465 rb_hash_aset(params,
ID2SYM(rb_intern(
"kwbits")),
3466 INT2FIX(keyword->bits_start));
3467 rb_hash_aset(params,
ID2SYM(rb_intern(
"keyword")), keywords);
3469 if (iseq_body->param.flags.has_kwrest) rb_hash_aset(params,
ID2SYM(rb_intern(
"kwrest")),
INT2FIX(keyword->rest_start));
3470 if (iseq_body->param.flags.ambiguous_param0) rb_hash_aset(params,
ID2SYM(rb_intern(
"ambiguous_param0")),
Qtrue);
3471 if (iseq_body->param.flags.use_block) rb_hash_aset(params,
ID2SYM(rb_intern(
"use_block")),
Qtrue);
3475 iseq_original = rb_iseq_original_iseq((
rb_iseq_t *)iseq);
3477 for (seq = iseq_original; seq < iseq_original + iseq_body->iseq_size; ) {
3478 VALUE insn = *seq++;
3479 int j,
len = insn_len(insn);
3484 for (j=0; j<
len-1; j++, seq++) {
3485 enum ruby_insn_type_chars op_type = insn_op_type(insn, j);
3489 unsigned long idx = nseq - iseq_original + *seq;
3490 rb_ary_push(ary, register_label(labels_table, idx));
3504 VALUE val = iseq_data_to_ary(rb_iseq_check(iseq));
3515 const ID *ids = ((
IC)*seq)->segments;
3534 VALUE e = rb_hash_new();
3535 int argc = vm_ci_argc(ci);
3537 ID mid = vm_ci_mid(ci);
3539 rb_hash_aset(e,
ID2SYM(rb_intern(
"flag")),
UINT2NUM(vm_ci_flag(ci)));
3541 if (vm_ci_flag(ci) & VM_CALL_KWARG) {
3546 argc -= kwarg->keyword_len;
3547 for (i = 0; i < kwarg->keyword_len; i++) {
3550 rb_hash_aset(e,
ID2SYM(rb_intern(
"kw_arg")), kw);
3553 rb_hash_aset(e,
ID2SYM(rb_intern(
"orig_argc")),
3571 unsigned long idx = nseq - iseq_original + pos;
3574 register_label(labels_table, idx));
3581#if SIZEOF_VALUE <= SIZEOF_LONG
3591 VALUE val = rb_hash_new();
3592#if SIZEOF_VALUE <= SIZEOF_LONG
3597 rb_hash_aset(val,
ID2SYM(rb_intern(
"func_ptr")), func_ptr);
3605 rb_bug(
"unknown operand: %c", insn_op_type(insn, j));
3614 if (iseq_body->catch_table)
for (i=0; i<iseq_body->catch_table->size; i++) {
3617 UNALIGNED_MEMBER_PTR(iseq_body->catch_table, entries[i]);
3618 rb_ary_push(ary, exception_type2symbol(entry->type));
3620 rb_ary_push(ary, iseq_data_to_ary(rb_iseq_check(entry->iseq)));
3625 rb_ary_push(ary, register_label(labels_table, entry->start));
3626 rb_ary_push(ary, register_label(labels_table, entry->end));
3627 rb_ary_push(ary, register_label(labels_table, entry->cont));
3634 prev_insn_info = NULL;
3635#ifdef USE_ISEQ_NODE_ID
3644 if (st_lookup(labels_table, pos, &label)) {
3648 info = get_insn_info(iseq, pos);
3649#ifdef USE_ISEQ_NODE_ID
3653 if (prev_insn_info != info) {
3654 int line = info->line_no;
3657 if (line > 0 && last_line != line) {
3661#define CHECK_EVENT(ev) if (events & ev) rb_ary_push(body, ID2SYM(rb_intern(#ev)));
3671 prev_insn_info = info;
3680 rb_hash_aset(misc,
ID2SYM(rb_intern(
"arg_size")),
INT2FIX(iseq_body->param.size));
3681 rb_hash_aset(misc,
ID2SYM(rb_intern(
"local_size")),
INT2FIX(iseq_body->local_table_size));
3682 rb_hash_aset(misc,
ID2SYM(rb_intern(
"stack_max")),
INT2FIX(iseq_body->stack_max));
3683 rb_hash_aset(misc,
ID2SYM(rb_intern(
"node_id")),
INT2FIX(iseq_body->location.node_id));
3684 rb_hash_aset(misc,
ID2SYM(rb_intern(
"code_location")),
3685 rb_ary_new_from_args(4,
3686 INT2FIX(iseq_body->location.code_location.beg_pos.lineno),
3687 INT2FIX(iseq_body->location.code_location.beg_pos.column),
3688 INT2FIX(iseq_body->location.code_location.end_pos.lineno),
3689 INT2FIX(iseq_body->location.code_location.end_pos.column)));
3690#ifdef USE_ISEQ_NODE_ID
3691 rb_hash_aset(misc,
ID2SYM(rb_intern(
"node_ids")), node_ids);
3693 rb_hash_aset(misc,
ID2SYM(rb_intern(
"parser")), iseq_body->prism ?
ID2SYM(rb_intern(
"prism")) :
ID2SYM(rb_intern(
"parse.y")));
3721rb_iseq_parameters(
const rb_iseq_t *iseq,
int is_proc)
3725 const struct rb_iseq_param_keyword *
const keyword = body->param.keyword;
3727 ID req, opt, rest, block, key, keyrest;
3728#define PARAM_TYPE(type) rb_ary_push(a = rb_ary_new2(2), ID2SYM(type))
3729#define PARAM_ID(i) body->local_table[(i)]
3730#define PARAM(i, type) ( \
3732 PARAM_ID(i) != idItImplicit && rb_id2str(PARAM_ID(i)) ? \
3733 rb_ary_push(a, ID2SYM(PARAM_ID(i))) : \
3739 if (body->param.flags.forwardable) {
3750 for (i = 0; i < body->param.lead_num; i++) {
3755 for (i = 0; i < body->param.lead_num; i++) {
3759 r = body->param.lead_num + body->param.opt_num;
3760 for (; i < r; i++) {
3763 if (body->param.flags.has_rest) {
3765 rb_ary_push(args, PARAM(body->param.rest_start, rest));
3767 r = body->param.post_start + body->param.post_num;
3769 for (i = body->param.post_start; i < r; i++) {
3774 for (i = body->param.post_start; i < r; i++) {
3778 if (body->param.flags.accepts_no_kwarg) {
3784 if (body->param.flags.has_kw) {
3786 if (keyword->required_num > 0) {
3789 for (; i < keyword->required_num; i++) {
3791 if (rb_id2str(keyword->table[i])) {
3798 for (; i < keyword->num; i++) {
3800 if (rb_id2str(keyword->table[i])) {
3806 if (body->param.flags.has_kwrest || body->param.flags.ruby2_keywords) {
3809 PARAM_TYPE(keyrest);
3810 if (body->param.flags.has_kwrest &&
3811 rb_id2str(param = PARAM_ID(keyword->rest_start))) {
3814 else if (body->param.flags.ruby2_keywords) {
3819 if (body->param.flags.accepts_no_block) {
3822 PARAM_TYPE(noblock);
3825 else if (body->param.flags.has_block) {
3827 rb_ary_push(args, PARAM(body->param.block_start, block));
3833rb_iseq_defined_string(
enum defined_type
type)
3835 static const char expr_names[][18] = {
3837 "instance-variable",
3853 if ((
unsigned)(
type - 1) >= (
unsigned)numberof(expr_names)) rb_bug(
"unknown defined type %d",
type);
3854 estr = expr_names[
type - 1];
3855 return rb_fstring_cstr(estr);
3865 void *notrace_encoded_insn;
3866 void *trace_encoded_insn;
3869 void *zjit_encoded_insn;
3872static insn_data_t insn_data[VM_BARE_INSTRUCTION_SIZE];
3875rb_free_encoded_insn_data(
void)
3877 st_free_table(encoded_insn_data);
3883rb_vm_encoded_insn_data_table_init(
void)
3885#if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE
3886 const void *
const *table = rb_vm_get_insns_address_table();
3887#define INSN_CODE(insn) ((VALUE)table[insn])
3889#define INSN_CODE(insn) ((VALUE)(insn))
3891 encoded_insn_data = st_init_numtable_with_size(VM_BARE_INSTRUCTION_SIZE);
3893 for (
int insn = 0; insn < VM_BARE_INSTRUCTION_SIZE; insn++) {
3894 insn_data[insn].insn = insn;
3895 insn_data[insn].insn_len = insn_len(insn);
3900 int notrace_insn = (insn != BIN(opt_invokebuiltin_delegate_leave)) ? insn : BIN(opt_invokebuiltin_delegate);
3901 insn_data[insn].notrace_encoded_insn = (
void *)INSN_CODE(notrace_insn);
3902 insn_data[insn].trace_encoded_insn = (
void *)INSN_CODE(notrace_insn + VM_BARE_INSTRUCTION_SIZE);
3904 st_data_t key1 = (st_data_t)INSN_CODE(insn);
3905 st_data_t key2 = (st_data_t)INSN_CODE(insn + VM_BARE_INSTRUCTION_SIZE);
3906 st_add_direct(encoded_insn_data, key1, (st_data_t)&insn_data[insn]);
3907 st_add_direct(encoded_insn_data, key2, (st_data_t)&insn_data[insn]);
3910 int zjit_insn = vm_bare_insn_to_zjit_insn(insn);
3911 insn_data[insn].zjit_insn = zjit_insn;
3912 insn_data[insn].zjit_encoded_insn = (insn != zjit_insn) ? (
void *)INSN_CODE(zjit_insn) : 0;
3914 if (insn != zjit_insn) {
3915 st_data_t key3 = (st_data_t)INSN_CODE(zjit_insn);
3916 st_add_direct(encoded_insn_data, key3, (st_data_t)&insn_data[insn]);
3926rb_vm_insn_addr2insn(
const void *addr)
3928 st_data_t key = (st_data_t)addr;
3931 if (st_lookup(encoded_insn_data, key, &val)) {
3933 return (
int)e->insn;
3936 rb_bug(
"rb_vm_insn_addr2insn: invalid insn address: %p", addr);
3942rb_vm_insn_addr2opcode(
const void *addr)
3944 st_data_t key = (st_data_t)addr;
3947 if (st_lookup(encoded_insn_data, key, &val)) {
3949 int opcode = e->insn;
3950 if (addr == e->trace_encoded_insn) {
3951 opcode += VM_BARE_INSTRUCTION_SIZE;
3954 else if (addr == e->zjit_encoded_insn) {
3955 opcode = e->zjit_insn;
3961 rb_bug(
"rb_vm_insn_addr2opcode: invalid insn address: %p", addr);
3968rb_vm_insn_decode(
const VALUE encoded)
3970#if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE
3971 int insn = rb_vm_insn_addr2insn((
void *)encoded);
3973 int insn = (int)encoded;
3980encoded_iseq_trace_instrument(
VALUE *iseq_encoded_insn,
rb_event_flag_t turnon,
bool remain_traced)
3982 st_data_t key = (st_data_t)*iseq_encoded_insn;
3985 if (st_lookup(encoded_insn_data, key, &val)) {
3987 if (remain_traced && key == (st_data_t)e->trace_encoded_insn) {
3990 *iseq_encoded_insn = (
VALUE) (turnon ? e->trace_encoded_insn : e->notrace_encoded_insn);
3994 rb_bug(
"trace_instrument: invalid insn address: %p", (
void *)*iseq_encoded_insn);
3999rb_iseq_trace_flag_cleared(
const rb_iseq_t *iseq,
size_t pos)
4002 VALUE *iseq_encoded = (
VALUE *)body->iseq_encoded;
4003 encoded_iseq_trace_instrument(&iseq_encoded[pos], 0,
false);
4029 VALUE *iseq_encoded = (
VALUE *)body->iseq_encoded;
4032 VM_ASSERT(ISEQ_EXECUTABLE_P(iseq));
4033 ASSERT_vm_locking_with_barrier();
4035 for (pc=0; pc<body->iseq_size;) {
4039 unsigned int line = (int)entry->line_no;
4041 if (target_line == 0 || target_line == line) {
4045 target_events &= ~RUBY_EVENT_LINE;
4048 if (pc_events & target_events) {
4051 pc += encoded_iseq_trace_instrument(&iseq_encoded[pc], pc_events & (target_events | iseq->aux.exec.global_trace_events),
true);
4056 rb_hook_list_connect_local_tracepoint(hook_list, tpval, target_line);
4057 iseq_mut->aux.exec.local_hooks_cnt++;
4066 unsigned int target_line;
4072iseq_add_local_tracepoint_i(
const rb_iseq_t *iseq,
void *p)
4075 data->n += iseq_add_local_tracepoint(iseq, data->turnon_events, data->tpval, data->target_line, data->r);
4076 iseq_iterate_children(iseq, iseq_add_local_tracepoint_i, p);
4080rb_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)
4082 ASSERT_vm_locking_with_barrier();
4084 if (target_bmethod) {
4085 turnon_events = add_bmethod_events(turnon_events);
4087 data.turnon_events = turnon_events;
4089 data.target_line = target_line;
4091 data.r = GET_RACTOR();
4093 iseq_add_local_tracepoint_i(iseq, (
void *)&data);
4094 if (0) fprintf(stderr,
"Iseq disasm:\n:%s", RSTRING_PTR(rb_iseq_disasm(iseq)));
4102 unsigned int num_hooks_left;
4107 VALUE *iseq_encoded;
4108 ASSERT_vm_locking_with_barrier();
4110 hook_list = rb_iseq_local_hooks(iseq, r,
false);
4116 if (rb_hook_list_remove_local_tracepoint(hook_list, tpval)) {
4118 iseq_mut->aux.exec.local_hooks_cnt--;
4119 local_events = hook_list->events;
4120 num_hooks_left = rb_hook_list_count(hook_list);
4121 if (local_events == 0 && prev_events != 0) {
4122 st_delete(rb_ractor_targeted_hooks(r), (st_data_t*)&iseq, NULL);
4123 rb_hook_list_free(hook_list);
4126 if (iseq->aux.exec.local_hooks_cnt == num_hooks_left) {
4127 body = ISEQ_BODY(iseq);
4128 iseq_encoded = (
VALUE *)body->iseq_encoded;
4129 local_events = add_bmethod_events(local_events);
4130 for (pc = 0; pc<body->iseq_size;) {
4132 pc += encoded_iseq_trace_instrument(&iseq_encoded[pc], pc_events & (local_events | iseq->aux.exec.global_trace_events),
false);
4149iseq_remove_local_tracepoint_i(
const rb_iseq_t *iseq,
void *p)
4152 data->n += iseq_remove_local_tracepoint(iseq, data->tpval, data->r);
4153 iseq_iterate_children(iseq, iseq_remove_local_tracepoint_i, p);
4160 ASSERT_vm_locking_with_barrier();
4165 iseq_remove_local_tracepoint_i(iseq, (
void *)&data);
4172 if (iseq->aux.exec.global_trace_events == turnon_events) {
4176 if (!ISEQ_EXECUTABLE_P(iseq)) {
4185 VALUE *iseq_encoded = (
VALUE *)body->iseq_encoded;
4187 rb_hook_list_t *local_hooks = rb_iseq_local_hooks(iseq, GET_RACTOR(),
false);
4189 ((
rb_iseq_t *)iseq)->aux.exec.global_trace_events = turnon_events;
4190 enabled_events = add_bmethod_events(turnon_events | local_events);
4192 for (pc=0; pc<body->iseq_size;) {
4194 pc += encoded_iseq_trace_instrument(&iseq_encoded[pc], pc_events & enabled_events,
true);
4202clear_attr_cc(
VALUE v)
4204 ASSERT_vm_locking_with_barrier();
4205 if (imemo_type_p(v, imemo_callcache) && vm_cc_ivar_p((
const struct rb_callcache *)v)) {
4217 ASSERT_vm_locking_with_barrier();
4218 if (imemo_type_p(v, imemo_callcache) && vm_cc_bf_p((
const struct rb_callcache *)v)) {
4228clear_attr_ccs_i(
void *vstart,
void *vend,
size_t stride,
void *data)
4231 for (; v != (
VALUE)vend; v += stride) {
4232 void *ptr = rb_asan_poisoned_object_p(v);
4233 rb_asan_unpoison_object(v,
false);
4235 asan_poison_object_if(ptr, v);
4241rb_clear_attr_ccs(
void)
4245 rb_objspace_each_objects(clear_attr_ccs_i, NULL);
4250clear_bf_ccs_i(
void *vstart,
void *vend,
size_t stride,
void *data)
4253 for (; v != (
VALUE)vend; v += stride) {
4254 void *ptr = rb_asan_poisoned_object_p(v);
4255 rb_asan_unpoison_object(v,
false);
4257 asan_poison_object_if(ptr, v);
4263rb_clear_bf_ccs(
void)
4265 ASSERT_vm_locking_with_barrier();
4266 rb_objspace_each_objects(clear_bf_ccs_i, NULL);
4270trace_set_i(
void *vstart,
void *vend,
size_t stride,
void *data)
4275 for (; v != (
VALUE)vend; v += stride) {
4276 void *ptr = rb_asan_poisoned_object_p(v);
4277 rb_asan_unpoison_object(v,
false);
4279 if (rb_obj_is_iseq(v)) {
4280 rb_iseq_trace_set(rb_iseq_check((
rb_iseq_t *)v), turnon_events);
4282 else if (clear_attr_cc(v)) {
4284 else if (clear_bf_cc(v)) {
4287 asan_poison_object_if(ptr, v);
4297 rb_objspace_each_objects(trace_set_i, &turnon_events);
4302rb_iseqw_local_variables(
VALUE iseqval)
4304 return rb_iseq_local_variables(iseqw_check(iseqval));
4325iseqw_to_binary(
int argc,
VALUE *argv,
VALUE self)
4328 return rb_iseq_ibf_dump(iseqw_check(self), opt);
4345iseqw_s_load_from_binary(
VALUE self,
VALUE str)
4347 return iseqw_new(rb_iseq_ibf_load(str));
4357iseqw_s_load_from_binary_extra_data(
VALUE self,
VALUE str)
4359 return rb_iseq_ibf_load_extra_data(str);
4362#if VM_INSN_INFO_TABLE_IMPL == 2
4395#define IMMEDIATE_TABLE_SIZE 54
4397struct succ_index_table {
4398 uint64_t imm_part[IMMEDIATE_TABLE_SIZE / 9];
4399 struct succ_dict_block {
4401 uint64_t small_block_ranks;
4402 uint64_t bits[512/64];
4403 } succ_part[FLEX_ARY_LEN];
4406#define imm_block_rank_set(v, i, r) (v) |= (uint64_t)(r) << (7 * (i))
4407#define imm_block_rank_get(v, i) (((int)((v) >> ((i) * 7))) & 0x7f)
4408#define small_block_rank_set(v, i, r) (v) |= (uint64_t)(r) << (9 * ((i) - 1))
4409#define small_block_rank_get(v, i) ((i) == 0 ? 0 : (((int)((v) >> (((i) - 1) * 9))) & 0x1ff))
4411static struct succ_index_table *
4412succ_index_table_create(
int max_pos,
int *data,
int size)
4414 const int imm_size = (max_pos < IMMEDIATE_TABLE_SIZE ? max_pos + 8 : IMMEDIATE_TABLE_SIZE) / 9;
4415 const int succ_size = (max_pos < IMMEDIATE_TABLE_SIZE ? 0 : (max_pos - IMMEDIATE_TABLE_SIZE + 511)) / 512;
4416 struct succ_index_table *sd =
4417 rb_xcalloc_mul_add_mul(
4418 imm_size,
sizeof(uint64_t),
4419 succ_size,
sizeof(
struct succ_dict_block));
4423 for (j = 0; j < imm_size; j++) {
4424 for (i = 0; i < 9; i++) {
4425 if (r < size && data[r] == j * 9 + i) r++;
4426 imm_block_rank_set(sd->imm_part[j], i, r);
4429 for (k = 0; k < succ_size; k++) {
4430 struct succ_dict_block *sd_block = &sd->succ_part[k];
4433 for (j = 0; j < 8; j++) {
4435 if (j) small_block_rank_set(sd_block->small_block_ranks, j, small_rank);
4436 for (i = 0; i < 64; i++) {
4437 if (r < size && data[r] == k * 512 + j * 64 + i + IMMEDIATE_TABLE_SIZE) {
4438 bits |= ((uint64_t)1) << i;
4442 sd_block->bits[j] = bits;
4443 small_rank += rb_popcount64(bits);
4449static unsigned int *
4450succ_index_table_invert(
int max_pos,
struct succ_index_table *sd,
int size)
4452 const int imm_size = (max_pos < IMMEDIATE_TABLE_SIZE ? max_pos + 8 : IMMEDIATE_TABLE_SIZE) / 9;
4453 const int succ_size = (max_pos < IMMEDIATE_TABLE_SIZE ? 0 : (max_pos - IMMEDIATE_TABLE_SIZE + 511)) / 512;
4454 unsigned int *positions =
ALLOC_N(
unsigned int, size), *p;
4455 int i, j, k, r = -1;
4457 for (j = 0; j < imm_size; j++) {
4458 for (i = 0; i < 9; i++) {
4459 int nr = imm_block_rank_get(sd->imm_part[j], i);
4460 if (r != nr) *p++ = j * 9 + i;
4464 for (k = 0; k < succ_size; k++) {
4465 for (j = 0; j < 8; j++) {
4466 for (i = 0; i < 64; i++) {
4467 if (sd->succ_part[k].bits[j] & (((uint64_t)1) << i)) {
4468 *p++ = k * 512 + j * 64 + i + IMMEDIATE_TABLE_SIZE;
4477succ_index_lookup(
const struct succ_index_table *sd,
int x)
4479 if (x < IMMEDIATE_TABLE_SIZE) {
4480 const int i = x / 9;
4481 const int j = x % 9;
4482 return imm_block_rank_get(sd->imm_part[i], j);
4485 const int block_index = (x - IMMEDIATE_TABLE_SIZE) / 512;
4486 const struct succ_dict_block *block = &sd->succ_part[block_index];
4487 const int block_bit_index = (x - IMMEDIATE_TABLE_SIZE) % 512;
4488 const int small_block_index = block_bit_index / 64;
4489 const int small_block_popcount = small_block_rank_get(block->small_block_ranks, small_block_index);
4490 const int popcnt = rb_popcount64(block->bits[small_block_index] << (63 - block_bit_index % 64));
4492 return block->rank + small_block_popcount + popcnt;
4511iseqw_script_lines(
VALUE self)
4513 const rb_iseq_t *iseq = iseqw_check(self);
4514 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_cObject
Object 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)
Like rb_str_dup(), but always create an instance of rb_cString regardless of the given object's class...
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.
#define RB_OBJ_SHAREABLE_P(obj)
Queries if the passed object has previously classified as shareable or not.
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 RUBY_TYPED_FREE_IMMEDIATELY
Macros to see if each corresponding flag is defined.
#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 in bytes.
int32_t line
The line number.
A list of offsets of the start of lines in a string.
size_t size
The number of offsets in the list.
This struct represents a slice in the source code, defined by an offset and a length.
uint32_t start
The offset of the location from the start of the source.
uint32_t length
The length of the location.
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.
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.
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.
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.