Ruby 2.7.6p219 (2022-04-12 revision c9c2245c0a25176072e02db9254f0e0c84c805cd)
iseq.h
Go to the documentation of this file.
1/**********************************************************************
2
3 iseq.h -
4
5 $Author$
6 created at: 04/01/01 23:36:57 JST
7
8 Copyright (C) 2004-2008 Koichi Sasada
9
10**********************************************************************/
11
12#ifndef RUBY_ISEQ_H
13#define RUBY_ISEQ_H 1
14
16#define ISEQ_MAJOR_VERSION ((unsigned int)ruby_api_version[0])
17#define ISEQ_MINOR_VERSION ((unsigned int)ruby_api_version[1])
18
19#ifndef rb_iseq_t
21#define rb_iseq_t rb_iseq_t
22#endif
23
24extern const ID rb_iseq_shared_exc_local_tbl[];
25
26static inline size_t
27rb_call_info_kw_arg_bytes(int keyword_len)
28{
30 keyword_len - 1, sizeof(VALUE), sizeof(struct rb_call_info_kw_arg),
32}
33
34#define ISEQ_COVERAGE(iseq) iseq->body->variable.coverage
35#define ISEQ_COVERAGE_SET(iseq, cov) RB_OBJ_WRITE(iseq, &iseq->body->variable.coverage, cov)
36#define ISEQ_LINE_COVERAGE(iseq) RARRAY_AREF(ISEQ_COVERAGE(iseq), COVERAGE_INDEX_LINES)
37#define ISEQ_BRANCH_COVERAGE(iseq) RARRAY_AREF(ISEQ_COVERAGE(iseq), COVERAGE_INDEX_BRANCHES)
38
39#define ISEQ_PC2BRANCHINDEX(iseq) iseq->body->variable.pc2branchindex
40#define ISEQ_PC2BRANCHINDEX_SET(iseq, h) RB_OBJ_WRITE(iseq, &iseq->body->variable.pc2branchindex, h)
41
42#define ISEQ_FLIP_CNT(iseq) (iseq)->body->variable.flip_count
43
44static inline rb_snum_t
45ISEQ_FLIP_CNT_INCREMENT(const rb_iseq_t *iseq)
46{
49 return cnt;
50}
51
52static inline VALUE *
53ISEQ_ORIGINAL_ISEQ(const rb_iseq_t *iseq)
54{
56}
57
58static inline void
59ISEQ_ORIGINAL_ISEQ_CLEAR(const rb_iseq_t *iseq)
60{
63 if (ptr) {
65 }
66}
67
68static inline VALUE *
69ISEQ_ORIGINAL_ISEQ_ALLOC(const rb_iseq_t *iseq, long size)
70{
73}
74
75#define ISEQ_TRACE_EVENTS (RUBY_EVENT_LINE | \
76 RUBY_EVENT_CLASS | \
77 RUBY_EVENT_END | \
78 RUBY_EVENT_CALL | \
79 RUBY_EVENT_RETURN| \
80 RUBY_EVENT_B_CALL| \
81 RUBY_EVENT_B_RETURN| \
82 RUBY_EVENT_COVERAGE_LINE| \
83 RUBY_EVENT_COVERAGE_BRANCH)
84
85#define ISEQ_NOT_LOADED_YET IMEMO_FL_USER1
86#define ISEQ_USE_COMPILE_DATA IMEMO_FL_USER2
87#define ISEQ_TRANSLATED IMEMO_FL_USER3
88#define ISEQ_MARKABLE_ISEQ IMEMO_FL_USER4
89
90#define ISEQ_EXECUTABLE_P(iseq) (FL_TEST_RAW((iseq), ISEQ_NOT_LOADED_YET | ISEQ_USE_COMPILE_DATA) == 0)
91
92struct iseq_compile_data {
93 /* GC is needed */
94 const VALUE err_info;
95 const VALUE catch_table_ary; /* Array */
96
97 /* GC is not needed */
103 struct {
107 struct {
111 int loopval_popped; /* used by NODE_BREAK */
112 int last_line;
113 int label_no;
114 int node_level;
115 unsigned int ci_index;
116 unsigned int ci_kw_index;
120#if OPT_SUPPORT_JOKE
121 st_table *labels_table;
122#endif
123};
124
125static inline struct iseq_compile_data *
126ISEQ_COMPILE_DATA(const rb_iseq_t *iseq)
127{
129 return iseq->aux.compile_data;
130 }
131 else {
132 return NULL;
133 }
134}
135
136static inline void
137ISEQ_COMPILE_DATA_ALLOC(rb_iseq_t *iseq)
138{
141}
142
143static inline void
144ISEQ_COMPILE_DATA_CLEAR(rb_iseq_t *iseq)
145{
146 iseq->flags &= ~ISEQ_USE_COMPILE_DATA;
148}
149
150static inline rb_iseq_t *
151iseq_imemo_alloc(void)
152{
153 return (rb_iseq_t *)rb_imemo_new(imemo_iseq, 0, 0, 0, 0);
154}
155
159const rb_iseq_t *rb_iseq_ibf_load_bytes(const char *cstr, size_t);
162int rb_iseq_add_local_tracepoint_recursively(const rb_iseq_t *iseq, rb_event_flag_t turnon_events, VALUE tpval, unsigned int target_line);
164const rb_iseq_t *rb_iseq_load_iseq(VALUE fname);
165
166#if VM_INSN_INFO_TABLE_IMPL == 2
167unsigned int *rb_iseq_insns_info_decode_positions(const struct rb_iseq_constant_body *body);
168#endif
169
171
172/* compile.c */
177 VALUE locals, VALUE args,
178 VALUE exception, VALUE body);
180
181/* iseq.c */
182VALUE rb_iseq_load(VALUE data, VALUE parent, VALUE opt);
183VALUE rb_iseq_parameters(const rb_iseq_t *iseq, int is_proc);
184unsigned int rb_iseq_line_no(const rb_iseq_t *iseq, size_t pos);
185void rb_iseq_trace_set(const rb_iseq_t *iseq, rb_event_flag_t turnon_events);
186void rb_iseq_trace_set_all(rb_event_flag_t turnon_events);
188
191const rb_iseq_t *rb_iseqw_to_iseq(VALUE iseqw);
192
193VALUE rb_iseq_absolute_path(const rb_iseq_t *iseq); /* obsolete */
198void rb_iseq_code_location(const rb_iseq_t *iseq, int *first_lineno, int *first_column, int *last_lineno, int *last_column);
199
201
202/* proc.c */
203const rb_iseq_t *rb_method_iseq(VALUE body);
204const rb_iseq_t *rb_proc_get_iseq(VALUE proc, int *is_proc);
205
207 unsigned int inline_const_cache: 1;
208 unsigned int peephole_optimization: 1;
209 unsigned int tailcall_optimization: 1;
210 unsigned int specialized_instruction: 1;
211 unsigned int operands_unification: 1;
212 unsigned int instructions_unification: 1;
213 unsigned int stack_caching: 1;
214 unsigned int frozen_string_literal: 1;
215 unsigned int debug_frozen_string_literal: 1;
216 unsigned int coverage_enabled: 1;
217 int debug_level;
218};
219
221 int line_no;
223};
224
233 } type;
234
235 /*
236 * iseq type:
237 * CATCH_TYPE_RESCUE, CATCH_TYPE_ENSURE:
238 * use iseq as continuation.
239 *
240 * CATCH_TYPE_BREAK (iter):
241 * use iseq as key.
242 *
243 * CATCH_TYPE_BREAK (while), CATCH_TYPE_RETRY,
244 * CATCH_TYPE_REDO, CATCH_TYPE_NEXT:
245 * NULL.
246 */
248
249 unsigned int start;
250 unsigned int end;
251 unsigned int cont;
252 unsigned int sp;
253};
254
256 unsigned int size;
258});
259
260static inline int
261iseq_catch_table_bytes(int n)
262{
263 enum {
264 catch_table_entry_size = sizeof(struct iseq_catch_table_entry),
265 catch_table_entries_max = (INT_MAX - offsetof(struct iseq_catch_table, entries)) / catch_table_entry_size
266 };
267 if (n > catch_table_entries_max) rb_fatal("too large iseq_catch_table - %d", n);
268 return (int)(offsetof(struct iseq_catch_table, entries) +
269 n * catch_table_entry_size);
270}
271
272#define INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE (512)
273
276 unsigned int pos;
277 unsigned int size;
278 char buff[FLEX_ARY_LEN];
279};
280
281/* defined? */
282
304
306
307/* vm.c */
309
311
312#endif /* RUBY_ISEQ_H */
struct RIMemo * ptr
Definition: debug.c:65
char str[HTML_ESCAPE_MAX_LEN+1]
Definition: escape.c:18
void rb_fatal(const char *fmt,...)
Definition: error.c:2722
VALUE rb_eRuntimeError
Definition: error.c:922
VALUE rb_iseqw_new(const rb_iseq_t *iseq)
Definition: iseq.c:1157
void rb_iseq_remove_coverage_all(void)
Definition: iseq.c:1110
RUBY_SYMBOL_EXPORT_BEGIN VALUE rb_iseq_compile_node(rb_iseq_t *iseq, const NODE *node)
Definition: compile.c:644
void rb_iseq_init_trace(rb_iseq_t *iseq)
Definition: iseq.c:623
void rb_iseq_insns_info_encode_positions(const rb_iseq_t *iseq)
Definition: iseq.c:595
const ID rb_iseq_shared_exc_local_tbl[]
Definition: compile.c:110
void rb_ibf_load_iseq_complete(rb_iseq_t *iseq)
Definition: compile.c:11434
unsigned int rb_iseq_line_no(const rb_iseq_t *iseq, size_t pos)
Definition: iseq.c:1761
void rb_iseq_build_from_ary(rb_iseq_t *iseq, VALUE misc, VALUE locals, VALUE args, VALUE exception, VALUE body)
Definition: compile.c:9248
VALUE rb_iseq_parameters(const rb_iseq_t *iseq, int is_proc)
Definition: iseq.c:2939
const rb_iseq_t * rb_proc_get_iseq(VALUE proc, int *is_proc)
Definition: proc.c:1194
void rb_iseq_code_location(const rb_iseq_t *iseq, int *first_lineno, int *first_column, int *last_lineno, int *last_column)
Definition: iseq.c:1076
VALUE rb_iseq_label(const rb_iseq_t *iseq)
Definition: iseq.c:1045
VALUE rb_iseq_ibf_dump(const rb_iseq_t *iseq, VALUE opt)
Definition: compile.c:11376
VALUE rb_iseq_base_label(const rb_iseq_t *iseq)
Definition: iseq.c:1051
const rb_iseq_t * rb_iseq_ibf_load_bytes(const char *cstr, size_t)
Definition: compile.c:11614
VALUE rb_iseq_ibf_load_extra_data(VALUE str)
Definition: compile.c:11628
VALUE rb_iseq_defined_string(enum defined_type type)
Definition: iseq.c:3033
#define ISEQ_USE_COMPILE_DATA
Definition: iseq.h:86
@ DEFINED_METHOD
Definition: iseq.h:291
@ DEFINED_CONST
Definition: iseq.h:290
@ DEFINED_GVAR
Definition: iseq.h:288
@ DEFINED_IVAR
Definition: iseq.h:286
@ DEFINED_ASGN
Definition: iseq.h:297
@ DEFINED_REF
Definition: iseq.h:300
@ DEFINED_FALSE
Definition: iseq.h:296
@ DEFINED_NIL
Definition: iseq.h:285
@ DEFINED_LVAR
Definition: iseq.h:287
@ DEFINED_IVAR2
Definition: iseq.h:299
@ DEFINED_NOT_DEFINED
Definition: iseq.h:284
@ DEFINED_FUNC
Definition: iseq.h:301
@ DEFINED_EXPR
Definition: iseq.h:298
@ DEFINED_TRUE
Definition: iseq.h:295
@ DEFINED_SELF
Definition: iseq.h:294
@ DEFINED_YIELD
Definition: iseq.h:292
@ DEFINED_ZSUPER
Definition: iseq.h:293
@ DEFINED_CVAR
Definition: iseq.h:289
@ DEFINED_CONST_FROM
Definition: iseq.h:302
const rb_iseq_t * rb_iseqw_to_iseq(VALUE iseqw)
Definition: iseq.c:1350
PACKED_STRUCT_UNALIGNED(struct iseq_catch_table { unsigned int size;struct iseq_catch_table_entry entries[FLEX_ARY_LEN];})
void rb_iseq_trace_set_all(rb_event_flag_t turnon_events)
Definition: iseq.c:3319
VALUE rb_iseq_local_variables(const rb_iseq_t *iseq)
Definition: vm.c:849
const rb_iseq_t * rb_iseq_ibf_load(VALUE str)
Definition: compile.c:11600
VALUE rb_iseq_absolute_path(const rb_iseq_t *iseq)
Definition: iseq.c:1039
void rb_iseq_mark_insn_storage(struct iseq_compile_data_storage *arena)
Definition: compile.c:9196
void rb_iseq_trace_set(const rb_iseq_t *iseq, rb_event_flag_t turnon_events)
Definition: iseq.c:3273
VALUE rb_iseq_first_lineno(const rb_iseq_t *iseq)
Definition: iseq.c:1057
const rb_iseq_t * rb_iseq_load_iseq(VALUE fname)
Definition: iseq.c:847
VALUE rb_iseq_compile_callback(rb_iseq_t *iseq, const struct rb_iseq_new_with_callback_callback_func *ifunc)
Definition: compile.c:630
struct rb_iseq_constant_body * rb_iseq_constant_body_alloc(void)
Definition: iseq.c:433
const rb_iseq_t * rb_method_iseq(VALUE body)
Definition: proc.c:2691
VALUE rb_iseq_method_name(const rb_iseq_t *iseq)
Definition: iseq.c:1063
VALUE rb_iseq_load(VALUE data, VALUE parent, VALUE opt)
Definition: iseq.c:972
VALUE * rb_iseq_original_iseq(const rb_iseq_t *iseq)
Definition: compile.c:778
RUBY_EXTERN const int ruby_api_version[]
Definition: iseq.h:15
int rb_iseq_remove_local_tracepoint_recursively(const rb_iseq_t *iseq, VALUE tpval)
Definition: iseq.c:3262
int rb_iseq_add_local_tracepoint_recursively(const rb_iseq_t *iseq, rb_event_flag_t turnon_events, VALUE tpval, unsigned int target_line)
Definition: iseq.c:3206
VALUE type(ANYARGS)
ANYARGS-ed function type.
Definition: cxxanyargs.hpp:39
#define NULL
#define offsetof(TYPE, MEMBER)
const char size_t n
#define RUBY_SYMBOL_EXPORT_BEGIN
unsigned long VALUE
signed long rb_snum_t
#define ALLOC_N(type, n)
#define ZALLOC(type)
#define RUBY_SYMBOL_EXPORT_END
#define INT_MAX
const rb_iseq_t * iseq
unsigned int size
#define FLEX_ARY_LEN
unsigned int * rb_iseq_insns_info_decode_positions(const struct rb_iseq_constant_body *body)
Definition: iseq.c:613
VALUE rb_imemo_new(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0)
Definition: gc.c:2321
#define INT2FIX(i)
void void ruby_xfree(void *)
Definition: gc.c:10183
uint32_t rb_event_flag_t
size_t rb_size_mul_add_or_raise(size_t, size_t, size_t, VALUE)
Definition: gc.c:219
#define RUBY_EXTERN
unsigned long ID
struct iseq_catch_table_entry entries[]
rb_atomic_t cnt[RUBY_NSIG]
Definition: signal.c:503
catch_type
@ CATCH_TYPE_RETRY
@ CATCH_TYPE_ENSURE
@ CATCH_TYPE_NEXT
@ CATCH_TYPE_REDO
@ CATCH_TYPE_BREAK
@ CATCH_TYPE_RESCUE
rb_iseq_t * iseq
unsigned int cont
enum iseq_catch_table_entry::catch_type type
unsigned int start
unsigned int end
unsigned int sp
struct iseq_compile_data_storage * next
struct iseq_compile_data_ensure_node_stack * ensure_node_stack
const struct rb_builtin_function * builtin_function_table
const rb_compile_option_t * option
struct iseq_compile_data_storage * storage_current
const rb_iseq_t * current_block
struct iseq_compile_data::@61 insn
struct iseq_compile_data::@60 node
struct iseq_compile_data_storage * storage_head
struct rb_id_table * ivar_cache_table
struct iseq_label_data * start_label
struct iseq_label_data * end_label
struct iseq_label_data * redo_label
int line_no
rb_event_flag_t events
struct rb_iseq_constant_body::@46 variable
struct rb_iseq_constant_body * body
struct iseq_compile_data * compile_data
union rb_iseq_struct::@48 aux