Ruby: internal/vm.h File Reference

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

Macros | Typedefs | Enumerations | Functions
vm.h File Reference

Internal header for RubyVM. More...

`#include "ruby/internal/stdbool.h"`
`#include "internal/serial.h"`
`#include "internal/static_assert.h"`
`#include "ruby/ruby.h"`
`#include "ruby/st.h"`

Go to the source code of this file.

## Macros
#define | RUBY_DTRACE_CREATE_HOOK(name, arg) RUBY_DTRACE_HOOK(name##_CREATE, arg)
#define | RUBY_DTRACE_HOOK(name, arg)

## Typedefs
typedef void | rb_check_funcall_hook(int, VALUE, ID, int, const VALUE *, VALUE)

## Enumerations
enum | method_missing_reason { MISSING_NOENTRY = 0x00 , MISSING_PRIVATE = 0x01 , MISSING_PROTECTED = 0x02 , MISSING_FCALL = 0x04 , MISSING_VCALL = 0x08 , MISSING_SUPER = 0x10 , MISSING_MISSING = 0x20 , MISSING_NONE = 0x40 }

## Functions
rb_serial_t | rb_next_class_serial (void)
VALUE | rb_obj_is_thread (VALUE obj)
void | rb_vm_mark (void *ptr)
void | rb_vm_each_stack_value (void *ptr, void(*cb)(VALUE, void *), void *ctx)
VALUE | rb_vm_top_self (void)
void | rb_vm_inc_const_missing_count (void)
const void ** | rb_vm_get_insns_address_table (void)
VALUE | rb_source_location (int *pline)
const char * | rb_source_location_cstr (int *pline)
void | rb_vm_pop_cfunc_frame (void)
int | rb_vm_add_root_module (VALUE module)
void | rb_vm_check_redefinition_by_prepend (VALUE klass)
int | rb_vm_check_optimizable_mid (VALUE mid)
VALUE | rb_yield_refine_block (VALUE refinement, VALUE refinements)
VALUE | ruby_vm_special_exception_copy (VALUE)
st_table * | rb_vm_fstring_table (void)
VALUE | vm_exec (struct rb_execution_context_struct *, bool)
VALUE | rb_current_realfilepath (void)
VALUE | rb_check_block_call (VALUE, ID, int, const VALUE *, rb_block_call_func_t, VALUE)
VALUE | rb_check_funcall_with_hook (VALUE recv, ID mid, int argc, const VALUE *argv, rb_check_funcall_hook *hook, VALUE arg)
VALUE | rb_check_funcall_with_hook_kw (VALUE recv, ID mid, int argc, const VALUE *argv, rb_check_funcall_hook *hook, VALUE arg, int kw_splat)
const char * | rb_type_str (enum ruby_value_type type)
VALUE | rb_check_funcall_default (VALUE, ID, int, const VALUE *, VALUE)
VALUE | rb_check_funcall_basic_kw (VALUE, ID, VALUE, int, const VALUE *, int)
| Calls a method only if it is the basic method of `ancestor` otherwise returns Qundef;. More...
VALUE | rb_yield_1 (VALUE val)
VALUE | rb_yield_force_blockarg (VALUE values)
VALUE | rb_lambda_call (VALUE obj, ID mid, int argc, const VALUE *argv, rb_block_call_func_t bl_proc, int min_argc, int max_argc, VALUE data2)
void | rb_check_stack_overflow (void)
VALUE | rb_equal_opt (VALUE obj1, VALUE obj2)
VALUE | rb_eql_opt (VALUE obj1, VALUE obj2)
const struct rb_callcache * | rb_vm_search_method_slowpath (const struct rb_callinfo *ci, VALUE klass)
int | rb_ec_obj_respond_to (struct rb_execution_context_struct *ec, VALUE obj, ID id, int priv)
void | rb_print_backtrace (void)
VALUE | rb_vm_thread_backtrace (int argc, const VALUE *argv, VALUE thval)
VALUE | rb_vm_thread_backtrace_locations (int argc, const VALUE *argv, VALUE thval)
VALUE | rb_vm_backtrace (int argc, const VALUE *argv, struct rb_execution_context_struct *ec)
VALUE | rb_vm_backtrace_locations (int argc, const VALUE *argv, struct rb_execution_context_struct *ec)
VALUE | rb_make_backtrace (void)
void | rb_backtrace_print_as_bugreport (void)
int | rb_backtrace_p (VALUE obj)
VALUE | rb_backtrace_to_str_ary (VALUE obj)
VALUE | rb_backtrace_to_location_ary (VALUE obj)
void | rb_backtrace_each (VALUE(*iter)(VALUE recv, VALUE str), VALUE output)
VALUE | rb_ec_backtrace_object (const struct rb_execution_context_struct *ec)
void | rb_backtrace_use_iseq_first_lineno_for_last_location (VALUE self)

## Detailed Description

Internal header for RubyVM.

Author
  Ruby developers ruby-.nosp@m.core.nosp@m.@ruby.nosp@m.-lan.nosp@m.g.org

Copyright
  This file is a part of the programming language Ruby. Permission is hereby granted, to either redistribute and/or modify this file, provided that the conditions mentioned in the file COPYING are met. Consult the file for details.

Definition in file vm.h.

## Macro Definition Documentation

## ◆ RUBY_DTRACE_CREATE_HOOK

#define RUBY_DTRACE_CREATE_HOOK | ( |  | name,
|  |  | arg
| ) |  | RUBY_DTRACE_HOOK(name##_CREATE, arg)

Definition at line 120 of file vm.h.

## ◆ RUBY_DTRACE_HOOK

#define RUBY_DTRACE_HOOK | ( |  | name,
|  |  | arg
| ) |  |

Value:
do { \
if (UNLIKELY(RUBY_DTRACE_##name##_ENABLED())) { \
int dtrace_line; \
const char *dtrace_file = rb_source_location_cstr(&dtrace_line); \
if (!dtrace_file) dtrace_file = ""; \
RUBY_DTRACE_##name(arg, dtrace_file, dtrace_line); \
} \
} while (0)
UNLIKELY
#define UNLIKELY(x)
Definition: ffi_common.h:126
rb_source_location_cstr
const char * rb_source_location_cstr(int *pline)
Definition: vm.c:1616
name
const char * name
Definition: nkf.c:208

Definition at line 122 of file vm.h.

## Typedef Documentation

## ◆ rb_check_funcall_hook

typedef void rb_check_funcall_hook(int, VALUE, ID, int, const VALUE *, VALUE)

Definition at line 70 of file vm.h.

## Enumeration Type Documentation

## ◆ method_missing_reason

enum method_missing_reason

Enumerator
MISSING_NOENTRY |
MISSING_PRIVATE |
MISSING_PROTECTED |
MISSING_FCALL |
MISSING_VCALL |
MISSING_SUPER |
MISSING_MISSING |
MISSING_NONE |

Definition at line 32 of file vm.h.

## Function Documentation

## ◆ rb_backtrace_each()

void rb_backtrace_each | ( | VALUE(*)(VALUE recv, VALUE str) | iter,
|  | VALUE | output
| ) |  |

Definition at line 1039 of file vm_backtrace.c.

References ALL_BACKTRACE_LINES, BACKTRACE_START, oldbt_arg::data, oldbt_arg::func, print_to_arg::iter, NULL, and print_to_arg::output.

## ◆ rb_backtrace_p()

int rb_backtrace_p | ( | VALUE | obj | ) |

Definition at line 471 of file vm_backtrace.c.

References rb_typeddata_is_kind_of().

## ◆ rb_backtrace_print_as_bugreport()

void rb_backtrace_print_as_bugreport | ( | void |  | ) |

Definition at line 994 of file vm_backtrace.c.

References ALL_BACKTRACE_LINES, BACKTRACE_START, oldbt_arg::data, oldbt_arg::func, and NULL.

Referenced by rb_vm_bugreport().

## ◆ rb_backtrace_to_location_ary()

VALUE rb_backtrace_to_location_ary | ( | VALUE | obj | ) |

Definition at line 864 of file vm_backtrace.c.

References GetCoreDataFromValue, and rb_backtrace_struct::locary.

## ◆ rb_backtrace_to_str_ary()

VALUE rb_backtrace_to_str_ary | ( | VALUE | obj | ) |

Definition at line 809 of file vm_backtrace.c.

References bt_iter_arg::bt, GetCoreDataFromValue, and rb_backtrace_struct::strary.

## ◆ rb_backtrace_use_iseq_first_lineno_for_last_location()

void rb_backtrace_use_iseq_first_lineno_for_last_location | ( | VALUE | self | ) |

Definition at line 821 of file vm_backtrace.c.

References rb_backtrace_struct::backtrace, rb_backtrace_struct::backtrace_size, rb_backtrace_location_struct::body, rb_iseq_struct::body, bt_iter_arg::bt, rb_iseq_location_struct::first_lineno, FIX2INT, GetCoreDataFromValue, rb_backtrace_location_struct::iseq, rb_iseq_constant_body::location, rb_backtrace_location_struct::type, and VM_ASSERT.

## ◆ rb_check_block_call()

VALUE rb_check_block_call | ( | VALUE | obj,
|  | ID | mid,
|  | int | argc,
|  | const VALUE * | argv,
|  | rb_block_call_func_t | bl_proc,
|  | VALUE | data2
| ) |  |

Definition at line 1625 of file vm_eval.c.

References argc, iter_method_arg::argc, argv, iter_method_arg::argv, iter_method_arg::kw_splat, iter_method_arg::mid, iter_method_arg::obj, and rb_iterate().

## ◆ rb_check_funcall_basic_kw()

VALUE rb_check_funcall_basic_kw | ( | VALUE | recv,
|  | ID | mid,
|  | VALUE | ancestor,
|  | int | argc,
|  | const VALUE * | argv,
|  | int | kw_splat
| ) |  |

Calls a method only if it is the basic method of `ancestor` otherwise returns Qundef;.

Parameters

  recv | receiver of the method
  mid | an ID that represents the name of the method
  ancestor | the Class that defined the basic method
  argc | the number of arguments
  argv | pointer to an array of method arguments
  kw_splat | bool

Definition at line 1111 of file vm_eval.c.

References argc, argv, CLASS_OF, rb_callable_method_entry_struct::defined_class, rb_callcache::klass, METHOD_ENTRY_BASIC, Qundef, rb_callable_method_entry(), rb_vm_call0(), and RBASIC_CLASS.

Referenced by rb_hash().

## ◆ rb_check_funcall_default()

VALUE rb_check_funcall_default | ( | VALUE | recv,
|  | ID | mid,
|  | int | argc,
|  | const VALUE * | argv,
|  | VALUE | def
| ) |  |

Definition at line 647 of file vm_eval.c.

References argc, argv, def(), rescue_funcall_args::mid, RB_NO_KEYWORDS, and rescue_funcall_args::recv.

Referenced by rb_get_path_check_to_string(), and rb_time_zone_abbreviation().

## ◆ rb_check_funcall_with_hook()

VALUE rb_check_funcall_with_hook | ( | VALUE | recv,
|  | ID | mid,
|  | int | argc,
|  | const VALUE * | argv,
|  | rb_check_funcall_hook * | hook,
|  | VALUE | arg
| ) |  |

Definition at line 679 of file vm_eval.c.

References argc, argv, rescue_funcall_args::mid, rb_check_funcall_with_hook_kw(), RB_NO_KEYWORDS, and rescue_funcall_args::recv.

## ◆ rb_check_funcall_with_hook_kw()

VALUE rb_check_funcall_with_hook_kw | ( | VALUE | recv,
|  | ID | mid,
|  | int | argc,
|  | const VALUE * | argv,
|  | rb_check_funcall_hook * | hook,
|  | VALUE | arg,
|  | int | kw_splat
| ) |  |

Definition at line 653 of file vm_eval.c.

References argc, argv, CLASS_OF, rescue_funcall_args::ec, FALSE, rescue_funcall_args::kw_splat, rescue_funcall_args::mid, Qundef, rb_vm_call_kw(), rescue_funcall_args::recv, rescue_funcall_args::respond, stack_check, and TRUE.

Referenced by rb_check_funcall_with_hook(), and rb_obj_dig().

## ◆ rb_check_stack_overflow()

void rb_check_stack_overflow | ( | void |  | ) |

Definition at line 331 of file vm_eval.c.

References ruby_current_ec_key, and stack_check.

## ◆ rb_current_realfilepath()

VALUE rb_current_realfilepath | ( | void |  | ) |

Definition at line 2569 of file vm_eval.c.

References rb_execution_context_struct::cfp, rb_control_frame_struct::iseq, Qnil, rb_iseq_realpath(), and RUBY_VM_PREVIOUS_CONTROL_FRAME.

Referenced by rb_f_require_relative().

## ◆ rb_ec_backtrace_object()

VALUE rb_ec_backtrace_object | ( | const struct rb_execution_context_struct * | ec | ) |

## ◆ rb_ec_obj_respond_to()

int rb_ec_obj_respond_to | ( | struct rb_execution_context_struct * | ec,
|  | VALUE | obj,
|  | ID | id,
|  | int | priv
| ) |  |

Definition at line 2552 of file vm_method.c.

References CLASS_OF.

Referenced by rb_obj_respond_to().

## ◆ rb_eql_opt()

VALUE rb_eql_opt | ( | VALUE | obj1,
|  | VALUE | obj2
| ) |  |

Definition at line 2016 of file vm_insnhelper.c.

References idEqlP.

Referenced by rb_eql().

## ◆ rb_equal_opt()

VALUE rb_equal_opt | ( | VALUE | obj1,
|  | VALUE | obj2
| ) |  |

Definition at line 2010 of file vm_insnhelper.c.

References idEq.

Referenced by rb_equal().

## ◆ rb_lambda_call()

VALUE rb_lambda_call | ( | VALUE | obj,
|  | ID | mid,
|  | int | argc,
|  | const VALUE * | argv,
|  | rb_block_call_func_t | bl_proc,
|  | int | min_argc,
|  | int | max_argc,
|  | VALUE | data2
| ) |  |

Definition at line 1598 of file vm_eval.c.

References argc, iter_method_arg::argc, argv, iter_method_arg::argv, iter_method_arg::kw_splat, iter_method_arg::mid, iter_method_arg::obj, rb_eArgError, rb_raise(), and rb_vm_ifunc_new().

## ◆ rb_make_backtrace()

VALUE rb_make_backtrace | ( | void |  | ) |

Definition at line 1059 of file vm_backtrace.c.

## ◆ rb_next_class_serial()

rb_serial_t rb_next_class_serial | ( | void |  | ) |

Definition at line 366 of file vm.c.

References NEXT_CLASS_SERIAL.

## ◆ rb_obj_is_thread()

VALUE rb_obj_is_thread | ( | VALUE | obj | ) |

Definition at line 3003 of file vm.c.

References Qfalse, Qtrue, rb_typeddata_is_kind_of(), and thread_data_type.

Referenced by rb_objspace_call_finalizer().

## ◆ rb_print_backtrace()

void rb_print_backtrace | ( | void |  | ) |

Definition at line 753 of file vm_dump.c.

References free, and int().

Referenced by rb_fatal(), and rb_vm_bugreport().

## ◆ rb_source_location()

VALUE rb_source_location | ( | int * | pline | ) |

Definition at line 1600 of file vm.c.

References rb_execution_context_struct::cfp, rb_control_frame_struct::iseq, Qnil, rb_iseq_path(), rb_vm_get_ruby_level_next_cfp(), and rb_vm_get_sourceline().

Referenced by rb_source_location_cstr().

## ◆ rb_source_location_cstr()

const char * rb_source_location_cstr | ( | int * | pline | ) |

Definition at line 1616 of file vm.c.

References NIL_P, NULL, rb_source_location(), and RSTRING_PTR.

Referenced by rb_bug_for_fatal_signal(), rb_bug_without_die(), and rb_dtrace_setup().

## ◆ rb_type_str()

const char * rb_type_str | ( | enum ruby_value_type | type | ) |

Definition at line 686 of file vm_eval.c.

References NULL, T_ARRAY, T_BIGNUM, T_CLASS, T_COMPLEX, T_DATA, T_FALSE, T_FILE, T_FIXNUM, T_FLOAT, T_HASH, T_ICLASS, T_IMEMO, T_MASK, T_MATCH, T_MODULE, T_MOVED, T_NIL, T_NODE, T_NONE, T_OBJECT, T_RATIONAL, T_REGEXP, T_STRING, T_STRUCT, T_SYMBOL, T_TRUE, T_UNDEF, T_ZOMBIE, and type_case.

Referenced by rb_insn_operand_intern().

## ◆ rb_vm_add_root_module()

int rb_vm_add_root_module | ( | VALUE | module | ) |

Definition at line 2622 of file vm.c.

References rb_vm_struct::defined_module_hash, st_insert, and TRUE.

Referenced by rb_define_class(), rb_define_class_id_under(), and rb_define_module().

## ◆ rb_vm_backtrace()

VALUE rb_vm_backtrace | ( | int | argc,
|  | const VALUE * | argv,
|  | struct rb_execution_context_struct * | ec
| ) |  |

Definition at line 1162 of file vm_backtrace.c.

References argc, and argv.

## ◆ rb_vm_backtrace_locations()

VALUE rb_vm_backtrace_locations | ( | int | argc,
|  | const VALUE * | argv,
|  | struct rb_execution_context_struct * | ec
| ) |  |

Definition at line 1167 of file vm_backtrace.c.

References argc, and argv.

## ◆ rb_vm_check_optimizable_mid()

int rb_vm_check_optimizable_mid | ( | VALUE | mid | ) |

Definition at line 1823 of file vm.c.

References FALSE, NULL, and st_lookup.

## ◆ rb_vm_check_redefinition_by_prepend()

void rb_vm_check_redefinition_by_prepend | ( | VALUE | klass | ) |

Definition at line 1873 of file vm.c.

References rb_id_table_foreach(), RCLASS_M_TBL, and RCLASS_ORIGIN.

Referenced by rb_prepend_module().

## ◆ rb_vm_each_stack_value()

void rb_vm_each_stack_value | ( | void * | ptr,
|  | void(*)(VALUE, void *) | cb,
|  | void * | ctx
| ) |  |

Definition at line 2501 of file vm.c.

References rb_execution_context_struct::cfp, rb_ractor_struct::cnt, rb_thread_struct::ec, NULL, ptr, rb_vm_struct::ractor, rb_ractor_struct::set, rb_vm_struct::set, rb_control_frame_struct::sp, rb_ractor_struct::threads, VM_ASSERT, and rb_execution_context_struct::vm_stack.

## ◆ rb_vm_fstring_table()

st_table * rb_vm_fstring_table | ( | void |  | ) |

Definition at line 3787 of file vm.c.

Referenced by Init_String(), and rb_str_free().

## ◆ rb_vm_get_insns_address_table()

const void ** rb_vm_get_insns_address_table | ( | void |  | ) |

Definition at line 153 of file vm_exec.c.

Referenced by rb_vm_encoded_insn_data_table_init().

## ◆ rb_vm_inc_const_missing_count()

void rb_vm_inc_const_missing_count | ( | void |  | ) |

Definition at line 425 of file vm.c.

References ruby_vm_const_missing_count.

Referenced by rb_const_missing().

## ◆ rb_vm_mark()

void rb_vm_mark | ( | void * | ptr | ) |

Definition at line 2538 of file vm.c.

References rb_vm_struct::cmd, rb_vm_struct::coverages, rb_vm_struct::defined_module_hash, rb_vm_struct::expanded_load_path, rb_vm_struct::global_cc_cache_table, len, rb_vm_struct::load_path, rb_vm_struct::load_path_check_cache, rb_vm_struct::load_path_snapshot, rb_vm_struct::loaded_features, rb_vm_struct::loaded_features_snapshot, rb_vm_struct::loading_table, rb_vm_struct::mark_object_ary, rb_vm_struct::negative_cme_table, NULL, rb_vm_struct::orig_progname, ptr, rb_vm_struct::ractor, RARRAY_CONST_PTR, RARRAY_LEN, rb_gc_mark(), rb_gc_mark_movable(), rb_gc_mark_values(), rb_id_table_foreach_values(), rb_mark_tbl(), RUBY_GC_INFO, RUBY_MARK_ENTER, RUBY_MARK_LEAVE, RUBY_MARK_MOVABLE_UNLESS_NULL, RUBY_NSIG, rb_vm_struct::set, rb_vm_struct::top_self, rb_vm_struct::trap_list, VM_ASSERT, and VM_GLOBAL_CC_CACHE_TABLE_SIZE.

## ◆ rb_vm_pop_cfunc_frame()

void rb_vm_pop_cfunc_frame | ( | void |  | ) |

Definition at line 625 of file vm.c.

References rb_callable_method_entry_struct::called_id, rb_execution_context_struct::cfp, rb_callable_method_entry_struct::def, rb_control_frame_struct::ep, EXEC_EVENT_HOOK, rb_method_definition_struct::original_id, rb_callable_method_entry_struct::owner, Qnil, rb_vm_frame_method_entry(), RUBY_DTRACE_CMETHOD_RETURN_HOOK, RUBY_EVENT_C_RETURN, and rb_control_frame_struct::self.

Referenced by rb_mod_const_missing(), and rb_vm_rewind_cfp().

## ◆ rb_vm_search_method_slowpath()

const struct rb_callcache * rb_vm_search_method_slowpath | ( | const struct rb_callinfo * | ci,
|  | VALUE | klass
| ) |  |

Definition at line 1729 of file vm_insnhelper.c.

References imemo_callcache, IMEMO_TYPE_P, rb_callcache::klass, METHOD_ENTRY_INVALIDATED, RB_VM_LOCK_ENTER, RB_VM_LOCK_LEAVE, T_CLASS, T_ICLASS, VM_ASSERT, and vm_cc_empty.

## ◆ rb_vm_thread_backtrace()

VALUE rb_vm_thread_backtrace | ( | int | argc,
|  | const VALUE * | argv,
|  | VALUE | thval
| ) |  |

Definition at line 1151 of file vm_backtrace.c.

References argc, and argv.

## ◆ rb_vm_thread_backtrace_locations()

VALUE rb_vm_thread_backtrace_locations | ( | int | argc,
|  | const VALUE * | argv,
|  | VALUE | thval
| ) |  |

Definition at line 1157 of file vm_backtrace.c.

References argc, and argv.

## ◆ rb_vm_top_self()

VALUE rb_vm_top_self | ( | void |  | ) |

Definition at line 3752 of file vm.c.

Referenced by Init_eval(), Init_eval_method(), Init_Proc(), Init_top_self(), Init_VM(), rb_eval_cmd_kw(), rb_eval_string_wrap(), and ruby_eval_string_from_file().

## ◆ rb_yield_1()

VALUE rb_yield_1 | ( | VALUE | val | ) |

Definition at line 1335 of file vm_eval.c.

## ◆ rb_yield_force_blockarg()

VALUE rb_yield_force_blockarg | ( | VALUE | values | ) |

Definition at line 1413 of file vm_eval.c.

## ◆ rb_yield_refine_block()

VALUE rb_yield_refine_block | ( | VALUE | refinement,
|  | VALUE | refinements
| ) |  |

Definition at line 1980 of file vm_eval.c.

References block_handler_type_iseq, rb_execution_context_struct::cfp, rb_captured_block::ep, FALSE, NULL, rb_bug(), RB_NO_KEYWORDS, rb_captured_block::self, TRUE, and VM_ENV_DATA_INDEX_SPECVAL.

## ◆ ruby_vm_special_exception_copy()

VALUE ruby_vm_special_exception_copy | ( | VALUE | exc | ) |

Definition at line 48 of file vm_insnhelper.c.

References rb_class_real(), rb_obj_alloc(), rb_obj_copy_ivar(), and RBASIC_CLASS.

Referenced by rb_memerror(), and rb_threadptr_execute_interrupts().

## ◆ vm_exec()

VALUE vm_exec | ( | struct rb_execution_context_struct * | ec,
|  | bool | mjit_enable_p
| ) |  |

Definition at line 2151 of file vm.c.

References EC_EXEC_TAG, EC_POP_TAG, EC_PUSH_TAG, rb_execution_context_struct::errinfo, Qnil, Qundef, RAISED_STACKOVERFLOW, rb_ec_raised_reset, rb_execution_context_struct::tag, TAG_NONE, and VM_ASSERT.