Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)
iseq.h
Go to the documentation of this file.
1#ifndef RUBY_ISEQ_H
2#define RUBY_ISEQ_H 1
3/**********************************************************************
4
5 iseq.h -
6
7 $Author$
8 created at: 04/01/01 23:36:57 JST
9
10 Copyright (C) 2004-2008 Koichi Sasada
11
12**********************************************************************/
13#include "internal/gc.h"
14#include "vm_core.h"
15
17#define ISEQ_MAJOR_VERSION ((unsigned int)ruby_api_version[0])
18#define ISEQ_MINOR_VERSION ((unsigned int)ruby_api_version[1])
19
20#ifndef rb_iseq_t
21typedef struct rb_iseq_struct rb_iseq_t;
22#define rb_iseq_t rb_iseq_t
23#endif
24
25extern const ID rb_iseq_shared_exc_local_tbl[];
26
27#define ISEQ_COVERAGE(iseq) iseq->body->variable.coverage
28#define ISEQ_COVERAGE_SET(iseq, cov) RB_OBJ_WRITE(iseq, &iseq->body->variable.coverage, cov)
29#define ISEQ_LINE_COVERAGE(iseq) RARRAY_AREF(ISEQ_COVERAGE(iseq), COVERAGE_INDEX_LINES)
30#define ISEQ_BRANCH_COVERAGE(iseq) RARRAY_AREF(ISEQ_COVERAGE(iseq), COVERAGE_INDEX_BRANCHES)
31
32#define ISEQ_PC2BRANCHINDEX(iseq) iseq->body->variable.pc2branchindex
33#define ISEQ_PC2BRANCHINDEX_SET(iseq, h) RB_OBJ_WRITE(iseq, &iseq->body->variable.pc2branchindex, h)
34
35#define ISEQ_FLIP_CNT(iseq) (iseq)->body->variable.flip_count
36
37static inline rb_snum_t
38ISEQ_FLIP_CNT_INCREMENT(const rb_iseq_t *iseq)
39{
41 iseq->body->variable.flip_count += 1;
42 return cnt;
43}
44
45static inline VALUE *
46ISEQ_ORIGINAL_ISEQ(const rb_iseq_t *iseq)
47{
48 return iseq->body->variable.original_iseq;
49}
50
51static inline void
52ISEQ_ORIGINAL_ISEQ_CLEAR(const rb_iseq_t *iseq)
53{
54 void *ptr = iseq->body->variable.original_iseq;
56 if (ptr) {
58 }
59}
60
61static inline VALUE *
62ISEQ_ORIGINAL_ISEQ_ALLOC(const rb_iseq_t *iseq, long size)
63{
64 return iseq->body->variable.original_iseq =
66}
67
68#define ISEQ_TRACE_EVENTS (RUBY_EVENT_LINE | \
69 RUBY_EVENT_CLASS | \
70 RUBY_EVENT_END | \
71 RUBY_EVENT_CALL | \
72 RUBY_EVENT_RETURN| \
73 RUBY_EVENT_B_CALL| \
74 RUBY_EVENT_B_RETURN| \
75 RUBY_EVENT_COVERAGE_LINE| \
76 RUBY_EVENT_COVERAGE_BRANCH)
77
78#define ISEQ_NOT_LOADED_YET IMEMO_FL_USER1
79#define ISEQ_USE_COMPILE_DATA IMEMO_FL_USER2
80#define ISEQ_TRANSLATED IMEMO_FL_USER3
81#define ISEQ_MARKABLE_ISEQ IMEMO_FL_USER4
82
83#define ISEQ_EXECUTABLE_P(iseq) (FL_TEST_RAW(((VALUE)iseq), ISEQ_NOT_LOADED_YET | ISEQ_USE_COMPILE_DATA) == 0)
84
86 /* GC is needed */
88 const VALUE catch_table_ary; /* Array */
89
90 /* GC is not needed */
96 struct {
100 struct {
101 struct iseq_compile_data_storage *storage_head;
102 struct iseq_compile_data_storage *storage_current;
104 int loopval_popped; /* used by NODE_BREAK */
109 unsigned int ci_index;
113#if OPT_SUPPORT_JOKE
114 st_table *labels_table;
115#endif
116};
117
118static inline struct iseq_compile_data *
119ISEQ_COMPILE_DATA(const rb_iseq_t *iseq)
120{
121 if (iseq->flags & ISEQ_USE_COMPILE_DATA) {
122 return iseq->aux.compile_data;
123 }
124 else {
125 return NULL;
126 }
127}
128
129static inline void
130ISEQ_COMPILE_DATA_ALLOC(rb_iseq_t *iseq)
131{
134}
135
136static inline void
137ISEQ_COMPILE_DATA_CLEAR(rb_iseq_t *iseq)
138{
139 iseq->flags &= ~ISEQ_USE_COMPILE_DATA;
140 iseq->aux.compile_data = NULL;
141}
142
143static inline rb_iseq_t *
144iseq_imemo_alloc(void)
145{
146 return (rb_iseq_t *)rb_imemo_new(imemo_iseq, 0, 0, 0, 0);
147}
148
149VALUE rb_iseq_ibf_dump(const rb_iseq_t *iseq, VALUE opt);
152const rb_iseq_t *rb_iseq_ibf_load_bytes(const char *cstr, size_t);
154void rb_iseq_init_trace(rb_iseq_t *iseq);
155int rb_iseq_add_local_tracepoint_recursively(const rb_iseq_t *iseq, rb_event_flag_t turnon_events, VALUE tpval, unsigned int target_line);
157const rb_iseq_t *rb_iseq_load_iseq(VALUE fname);
158
159#if VM_INSN_INFO_TABLE_IMPL == 2
160unsigned int *rb_iseq_insns_info_decode_positions(const struct rb_iseq_constant_body *body);
161#endif
162
163RUBY_SYMBOL_EXPORT_BEGIN
164
165/* compile.c */
169void rb_iseq_build_from_ary(rb_iseq_t *iseq, VALUE misc,
170 VALUE locals, VALUE args,
171 VALUE exception, VALUE body);
173
174/* iseq.c */
175VALUE rb_iseq_load(VALUE data, VALUE parent, VALUE opt);
176VALUE rb_iseq_parameters(const rb_iseq_t *iseq, int is_proc);
177unsigned int rb_iseq_line_no(const rb_iseq_t *iseq, size_t pos);
178void rb_iseq_trace_set(const rb_iseq_t *iseq, rb_event_flag_t turnon_events);
179void rb_iseq_trace_set_all(rb_event_flag_t turnon_events);
181
183VALUE rb_iseqw_new(const rb_iseq_t *iseq);
184const rb_iseq_t *rb_iseqw_to_iseq(VALUE iseqw);
185
186VALUE rb_iseq_absolute_path(const rb_iseq_t *iseq); /* obsolete */
187VALUE rb_iseq_label(const rb_iseq_t *iseq);
191void rb_iseq_code_location(const rb_iseq_t *iseq, int *first_lineno, int *first_column, int *last_lineno, int *last_column);
192
194
195/* proc.c */
196const rb_iseq_t *rb_method_iseq(VALUE body);
197const rb_iseq_t *rb_proc_get_iseq(VALUE proc, int *is_proc);
198
200 unsigned int inline_const_cache: 1;
201 unsigned int peephole_optimization: 1;
202 unsigned int tailcall_optimization: 1;
203 unsigned int specialized_instruction: 1;
204 unsigned int operands_unification: 1;
206 unsigned int stack_caching: 1;
207 unsigned int frozen_string_literal: 1;
209 unsigned int coverage_enabled: 1;
211};
212
216};
217
227
228 /*
229 * iseq type:
230 * CATCH_TYPE_RESCUE, CATCH_TYPE_ENSURE:
231 * use iseq as continuation.
232 *
233 * CATCH_TYPE_BREAK (iter):
234 * use iseq as key.
235 *
236 * CATCH_TYPE_BREAK (while), CATCH_TYPE_RETRY,
237 * CATCH_TYPE_REDO, CATCH_TYPE_NEXT:
238 * NULL.
239 */
241
242 unsigned int start;
243 unsigned int end;
244 unsigned int cont;
245 unsigned int sp;
246};
247
248PACKED_STRUCT_UNALIGNED(struct iseq_catch_table {
249 unsigned int size;
250 struct iseq_catch_table_entry entries[FLEX_ARY_LEN];
251});
252
253static inline int
254iseq_catch_table_bytes(int n)
255{
256 enum {
257 catch_table_entry_size = sizeof(struct iseq_catch_table_entry),
258 catch_table_entries_max = (INT_MAX - offsetof(struct iseq_catch_table, entries)) / catch_table_entry_size
259 };
260 if (n > catch_table_entries_max) rb_fatal("too large iseq_catch_table - %d", n);
261 return (int)(offsetof(struct iseq_catch_table, entries) +
262 n * catch_table_entry_size);
263}
264
265#define INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE (512)
266
269 unsigned int pos;
270 unsigned int size;
272};
273
274/* defined? */
275
297
299
300/* vm.c */
302
303RUBY_SYMBOL_EXPORT_END
304
305#endif /* RUBY_ISEQ_H */
#define offsetof(p_type, field)
Definition: addrinfo.h:186
#define PACKED_STRUCT_UNALIGNED(x)
Definition: attributes.h:163
#define FLEX_ARY_LEN
Definition: compilers.h:88
struct RIMemo * ptr
Definition: debug.c:88
#define RUBY_EXTERN
Definition: dllexport.h:36
char str[HTML_ESCAPE_MAX_LEN+1]
Definition: escape.c:18
uint32_t rb_event_flag_t
Definition: event.h:66
void ruby_xfree(void *x)
Deallocates a storage instance.
Definition: gc.c:10914
VALUE rb_imemo_new(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0)
Definition: gc.c:2412
void rb_fatal(const char *fmt,...)
Definition: error.c:2968
VALUE rb_iseqw_new(const rb_iseq_t *iseq)
Definition: iseq.c:1217
@ imemo_iseq
Definition: imemo.h:42
voidpf void uLong size
Definition: ioapi.h:138
void rb_iseq_remove_coverage_all(void)
Definition: iseq.c:1170
void rb_iseq_init_trace(rb_iseq_t *iseq)
Definition: iseq.c:675
void rb_iseq_insns_info_encode_positions(const rb_iseq_t *iseq)
Definition: iseq.c:646
const ID rb_iseq_shared_exc_local_tbl[]
Definition: compile.c:125
void rb_ibf_load_iseq_complete(rb_iseq_t *iseq)
Definition: compile.c:11971
unsigned int rb_iseq_line_no(const rb_iseq_t *iseq, size_t pos)
Definition: iseq.c:1821
const int ruby_api_version[]
Definition: version.c:26
void rb_iseq_build_from_ary(rb_iseq_t *iseq, VALUE misc, VALUE locals, VALUE args, VALUE exception, VALUE body)
Definition: compile.c:9665
VALUE rb_iseq_parameters(const rb_iseq_t *iseq, int is_proc)
Definition: iseq.c:2993
const rb_iseq_t * rb_proc_get_iseq(VALUE proc, int *is_proc)
Definition: proc.c:1242
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:1136
VALUE rb_iseq_label(const rb_iseq_t *iseq)
Definition: iseq.c:1105
VALUE rb_iseq_ibf_dump(const rb_iseq_t *iseq, VALUE opt)
Definition: compile.c:11913
VALUE rb_iseq_base_label(const rb_iseq_t *iseq)
Definition: iseq.c:1111
const rb_iseq_t * rb_iseq_ibf_load_bytes(const char *cstr, size_t)
Definition: compile.c:12150
VALUE rb_iseq_ibf_load_extra_data(VALUE str)
Definition: compile.c:12164
VALUE rb_iseq_defined_string(enum defined_type type)
Definition: iseq.c:3087
#define ISEQ_USE_COMPILE_DATA
Definition: iseq.h:79
defined_type
Definition: iseq.h:276
@ DEFINED_METHOD
Definition: iseq.h:284
@ DEFINED_CONST
Definition: iseq.h:283
@ DEFINED_GVAR
Definition: iseq.h:281
@ DEFINED_IVAR
Definition: iseq.h:279
@ DEFINED_ASGN
Definition: iseq.h:290
@ DEFINED_REF
Definition: iseq.h:293
@ DEFINED_FALSE
Definition: iseq.h:289
@ DEFINED_NIL
Definition: iseq.h:278
@ DEFINED_LVAR
Definition: iseq.h:280
@ DEFINED_IVAR2
Definition: iseq.h:292
@ DEFINED_NOT_DEFINED
Definition: iseq.h:277
@ DEFINED_FUNC
Definition: iseq.h:294
@ DEFINED_EXPR
Definition: iseq.h:291
@ DEFINED_TRUE
Definition: iseq.h:288
@ DEFINED_SELF
Definition: iseq.h:287
@ DEFINED_YIELD
Definition: iseq.h:285
@ DEFINED_ZSUPER
Definition: iseq.h:286
@ DEFINED_CVAR
Definition: iseq.h:282
@ DEFINED_CONST_FROM
Definition: iseq.h:295
const rb_iseq_t * rb_iseqw_to_iseq(VALUE iseqw)
Definition: iseq.c:1410
VALUE rb_iseq_compile_node(rb_iseq_t *iseq, const NODE *node)
Definition: compile.c:729
void rb_iseq_trace_set_all(rb_event_flag_t turnon_events)
Definition: iseq.c:3379
VALUE rb_iseq_local_variables(const rb_iseq_t *iseq)
Definition: vm.c:885
const rb_iseq_t * rb_iseq_ibf_load(VALUE str)
Definition: compile.c:12136
VALUE rb_iseq_absolute_path(const rb_iseq_t *iseq)
Definition: iseq.c:1099
void rb_iseq_mark_insn_storage(struct iseq_compile_data_storage *arena)
Definition: compile.c:9611
void rb_iseq_trace_set(const rb_iseq_t *iseq, rb_event_flag_t turnon_events)
Definition: iseq.c:3333
VALUE rb_iseq_first_lineno(const rb_iseq_t *iseq)
Definition: iseq.c:1117
const rb_iseq_t * rb_iseq_load_iseq(VALUE fname)
Definition: iseq.c:907
VALUE rb_iseq_compile_callback(rb_iseq_t *iseq, const struct rb_iseq_new_with_callback_callback_func *ifunc)
Definition: compile.c:715
struct rb_iseq_constant_body * rb_iseq_constant_body_alloc(void)
Definition: iseq.c:486
const rb_iseq_t * rb_method_iseq(VALUE body)
Definition: proc.c:2835
VALUE rb_iseq_method_name(const rb_iseq_t *iseq)
Definition: iseq.c:1123
VALUE rb_iseq_load(VALUE data, VALUE parent, VALUE opt)
Definition: iseq.c:1032
VALUE * rb_iseq_original_iseq(const rb_iseq_t *iseq)
Definition: compile.c:863
int rb_iseq_remove_local_tracepoint_recursively(const rb_iseq_t *iseq, VALUE tpval)
Definition: iseq.c:3322
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:3266
#define INT2FIX
Definition: long.h:48
#define ALLOC_N
Definition: memory.h:133
VALUE type(ANYARGS)
ANYARGS-ed function type.
Definition: cxxanyargs.hpp:56
#define NULL
Definition: regenc.h:69
rb_atomic_t cnt[RUBY_NSIG]
Definition: signal.c:508
Definition: node.h:149
Definition: iseq.h:218
catch_type
Definition: iseq.h:219
@ CATCH_TYPE_RETRY
Definition: iseq.h:222
@ CATCH_TYPE_NEXT
Definition: iseq.h:225
@ CATCH_TYPE_REDO
Definition: iseq.h:224
@ CATCH_TYPE_RESCUE
Definition: iseq.h:220
@ CATCH_TYPE_BREAK
Definition: iseq.h:223
@ CATCH_TYPE_ENSURE
Definition: iseq.h:221
rb_iseq_t * iseq
Definition: iseq.h:240
unsigned int cont
Definition: iseq.h:244
enum iseq_catch_table_entry::catch_type type
unsigned int start
Definition: iseq.h:242
unsigned int end
Definition: iseq.h:243
unsigned int sp
Definition: iseq.h:245
unsigned int pos
Definition: iseq.h:269
unsigned int size
Definition: iseq.h:270
struct iseq_compile_data_storage * next
Definition: iseq.h:268
char buff[FLEX_ARY_LEN]
Definition: iseq.h:271
struct iseq_label_data * start_label
Definition: iseq.h:91
const rb_iseq_t * current_block
Definition: iseq.h:94
struct iseq_label_data * redo_label
Definition: iseq.h:93
const rb_compile_option_t * option
Definition: iseq.h:110
struct iseq_compile_data_ensure_node_stack * ensure_node_stack
Definition: iseq.h:95
struct iseq_compile_data::@122 insn
struct rb_id_table * ivar_cache_table
Definition: iseq.h:111
struct iseq_compile_data_storage * storage_current
Definition: iseq.h:98
int loopval_popped
Definition: iseq.h:104
struct iseq_compile_data_storage * storage_head
Definition: iseq.h:97
struct iseq_compile_data::@121 node
struct iseq_label_data * end_label
Definition: iseq.h:92
int isolated_depth
Definition: iseq.h:108
const VALUE err_info
Definition: iseq.h:87
const struct rb_builtin_function * builtin_function_table
Definition: iseq.h:112
unsigned int ci_index
Definition: iseq.h:109
const VALUE catch_table_ary
Definition: iseq.h:88
int node_level
Definition: iseq.h:107
Definition: iseq.h:213
int line_no
Definition: iseq.h:214
rb_event_flag_t events
Definition: iseq.h:215
unsigned int debug_frozen_string_literal
Definition: iseq.h:208
unsigned int operands_unification
Definition: iseq.h:204
unsigned int tailcall_optimization
Definition: iseq.h:202
unsigned int coverage_enabled
Definition: iseq.h:209
unsigned int peephole_optimization
Definition: iseq.h:201
unsigned int specialized_instruction
Definition: iseq.h:203
unsigned int stack_caching
Definition: iseq.h:206
unsigned int frozen_string_literal
Definition: iseq.h:207
unsigned int instructions_unification
Definition: iseq.h:205
unsigned int inline_const_cache
Definition: iseq.h:200
rb_snum_t flip_count
Definition: vm_core.h:418
VALUE * original_iseq
Definition: vm_core.h:421
struct rb_iseq_constant_body::@189 variable
struct rb_iseq_constant_body * body
Definition: vm_core.h:448
struct iseq_compile_data * compile_data
Definition: vm_core.h:451
union rb_iseq_struct::@191 aux
VALUE flags
Definition: vm_core.h:445
Definition: st.h:79
unsigned long VALUE
Definition: value.h:38
unsigned long ID
Definition: value.h:39
signed long rb_snum_t
Definition: vm_core.h:183
#define ZALLOC(strm, items, size)
Definition: zutil.h:266