Ruby 4.1.0dev (2026-10-28 revision 130c9ec44bd35c7319cdc99c301419188510e3a9)
vm.h
1#ifndef INTERNAL_VM_H /*-*-C-*-vi:se ft=c:*/
2#define INTERNAL_VM_H
11#include "ruby/internal/stdbool.h" /* for bool */
12#include "internal/serial.h" /* for rb_serial_t */
13#include "internal/static_assert.h" /* for STATIC_ASSERT */
14#include "ruby/ruby.h" /* for ID */
15#include "ruby/st.h" /* for st_table */
16
17#ifdef rb_funcallv
18# undef rb_funcallv
19#endif
20
21#ifdef rb_method_basic_definition_p
22# undef rb_method_basic_definition_p
23#endif
24
25struct rb_callable_method_entry_struct; /* in method.h */
26struct rb_method_definition_struct; /* in method.h */
27struct rb_cref_struct; /* in method.h */
28struct rb_execution_context_struct; /* in vm_core.h */
29struct rb_control_frame_struct; /* in vm_core.h */
30struct rb_callinfo; /* in vm_core.h */
31struct rb_gc_mark_ctx; /* in internal/gc.h */
32
33enum method_missing_reason {
34 MISSING_NOENTRY = 0x00,
35 MISSING_PRIVATE = 0x01,
36 MISSING_PROTECTED = 0x02,
37 MISSING_FCALL = 0x04,
38 MISSING_VCALL = 0x08,
39 MISSING_SUPER = 0x10,
40 MISSING_MISSING = 0x20,
41 MISSING_NONE = 0x40
42};
43
44/* vm_insnhelper.h */
45VALUE rb_vm_push_frame_fname(struct rb_execution_context_struct *ec, VALUE fname);
46
47/* vm.c */
48VALUE rb_obj_is_thread(VALUE obj);
49void rb_vm_mark(void *ptr);
50void rb_vm_register_global_object(VALUE obj);
51void rb_vm_each_stack_value(void *ptr, void (*cb)(VALUE, void*), void *ctx);
52PUREFUNC(VALUE rb_vm_top_self(void));
53const void **rb_vm_get_insns_address_table(void);
54VALUE rb_source_location(int *pline);
55const char *rb_source_location_cstr(int *pline);
56void rb_vm_pop_cfunc_frame(void);
57void rb_vm_check_redefinition_by_prepend(VALUE klass);
58int rb_vm_check_optimizable_mid(VALUE mid);
59VALUE rb_yield_refine_block(VALUE refinement, VALUE refinements);
60struct rb_cref_struct *rb_vm_cref_dup(const struct rb_cref_struct *cref);
61VALUE ruby_vm_special_exception_copy(VALUE);
62
63void rb_lastline_set_up(VALUE val, unsigned int up);
64
65/* vm_eval.c */
66VALUE rb_current_realfilepath(void);
67VALUE rb_current_filepath(void);
68VALUE rb_check_block_call(VALUE, ID, int, const VALUE *, rb_block_call_func_t, VALUE);
69typedef void rb_check_funcall_hook(int, VALUE, ID, int, const VALUE *, VALUE);
70VALUE rb_check_funcall_with_hook_kw(VALUE recv, ID mid, int argc, const VALUE *argv,
71 rb_check_funcall_hook *hook, VALUE arg, int kw_splat);
72const char *rb_type_str(enum ruby_value_type type);
73VALUE rb_check_funcall_default(VALUE, ID, int, const VALUE *, VALUE);
74VALUE rb_check_funcall_basic_kw(VALUE, ID, VALUE, int, const VALUE*, int);
75VALUE rb_yield_1(VALUE val);
76VALUE rb_ec_yield(struct rb_execution_context_struct *ec, VALUE val);
77VALUE rb_yield_force_blockarg(VALUE values);
78VALUE rb_lambda_call(VALUE obj, ID mid, int argc, const VALUE *argv,
79 rb_block_call_func_t bl_proc, int min_argc, int max_argc,
80 VALUE data2);
81void rb_check_stack_overflow(void);
82#define RB_BLOCK_NO_USE_PACKED_ARGS 2
83VALUE rb_block_call2(VALUE obj, ID mid, int argc, const VALUE *argv, rb_block_call_func_t bl_proc, VALUE data2, long flags);
84struct vm_ifunc *rb_current_ifunc(void);
85VALUE rb_gccct_clear_table(void);
86VALUE rb_funcallv_uncached(VALUE recv, ID mid, int argc, const VALUE *argv);
87VALUE rb_eval_cmd_call_kw(VALUE cmd, int argc, const VALUE *argv, int kw_splat);
88
89#if USE_YJIT || USE_ZJIT
90/* vm_exec.c */
91extern uint64_t rb_vm_insn_count;
92#endif
93
94extern bool rb_free_at_exit;
95
96/* miniinit.c and builtin.c */
97void rb_free_loaded_builtin_table(void);
98
99/* vm_insnhelper.c */
100VALUE rb_equal_opt(VALUE obj1, VALUE obj2);
101VALUE rb_eql_opt(VALUE obj1, VALUE obj2);
102
103struct rb_iseq_struct;
104const struct rb_callcache *rb_vm_search_method_slowpath(const struct rb_callinfo *ci, VALUE klass);
105
106/* vm_method.c */
107int rb_ec_obj_respond_to(struct rb_execution_context_struct *ec, VALUE obj, ID id, int priv);
108
109/* vm_dump.c */
110void rb_print_backtrace(FILE *);
111
112/* vm_backtrace.c */
113VALUE rb_vm_thread_backtrace(int argc, const VALUE *argv, VALUE thval);
114VALUE rb_vm_thread_backtrace_locations(int argc, const VALUE *argv, VALUE thval);
115VALUE rb_vm_backtrace(int argc, const VALUE * argv, struct rb_execution_context_struct * ec);
116VALUE rb_vm_backtrace_locations(int argc, const VALUE * argv, struct rb_execution_context_struct * ec);
117VALUE rb_make_backtrace(void);
118void rb_backtrace_print_as_bugreport(FILE*);
119int rb_backtrace_p(VALUE obj);
120VALUE rb_backtrace_dup(VALUE btobj);
121void *rb_backtrace_blob_dump(VALUE btobj, int *size_out);
122VALUE rb_backtrace_blob_load(const void *blob, int size);
123void rb_backtrace_blob_mark_ctx(const struct rb_gc_mark_ctx *ctx, const void *blob, int size);
124VALUE rb_backtrace_to_str_ary(VALUE obj);
125VALUE rb_backtrace_to_location_ary(VALUE obj);
126VALUE rb_location_ary_to_backtrace(VALUE ary);
127void rb_backtrace_each(VALUE (*iter)(VALUE recv, VALUE str), VALUE output);
128int rb_frame_info_p(VALUE obj);
129int rb_get_node_id_from_frame_info(VALUE obj);
130const struct rb_iseq_struct *rb_get_iseq_from_frame_info(VALUE obj);
131
132VALUE rb_ec_backtrace_object(const struct rb_execution_context_struct *ec);
133
134#define RUBY_DTRACE_CREATE_HOOK(name, arg) \
135 RUBY_DTRACE_HOOK(name##_CREATE, arg)
136#define RUBY_DTRACE_HOOK(name, arg) \
137do { \
138 if (UNLIKELY(RUBY_DTRACE_##name##_ENABLED())) { \
139 int dtrace_line; \
140 const char *dtrace_file = rb_source_location_cstr(&dtrace_line); \
141 if (!dtrace_file) dtrace_file = ""; \
142 RUBY_DTRACE_##name(arg, dtrace_file, dtrace_line); \
143 } \
144} while (0)
145#endif /* INTERNAL_VM_H */
rb_block_call_func * rb_block_call_func_t
Shorthand type that represents an iterator-written-in-C function pointer.
Definition iterator.h:88
VALUE type(ANYARGS)
ANYARGS-ed function type.
C99 shim for <stdbool.h>
Definition method.h:63
CREF (Class REFerence)
Definition method.h:45
IFUNC (Internal FUNCtion)
Definition imemo.h:89
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
Definition value.h:52
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40
ruby_value_type
C-level type of an object.
Definition value_type.h:113