Ruby  2.5.0dev(2017-10-22revision60238)
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 
15 #define ISEQ_MAJOR_VERSION 2
16 #define ISEQ_MINOR_VERSION 3
17 
18 #ifndef rb_iseq_t
19 typedef struct rb_iseq_struct rb_iseq_t;
20 #define rb_iseq_t rb_iseq_t
21 #endif
22 
23 static inline size_t
24 rb_call_info_kw_arg_bytes(int keyword_len)
25 {
26  return sizeof(struct rb_call_info_kw_arg) + sizeof(VALUE) * (keyword_len - 1);
27 }
28 
34 };
35 
36 static inline VALUE
37 iseq_mark_ary_create(int flip_cnt)
38 {
40  rb_ary_push(ary, Qnil); /* ISEQ_MARK_ARY_COVERAGE */
41  rb_ary_push(ary, INT2FIX(flip_cnt)); /* ISEQ_MARK_ARY_FLIP_CNT */
42  rb_ary_push(ary, Qnil); /* ISEQ_MARK_ARY_ORIGINAL_ISEQ */
43  return ary;
44 }
45 
46 #define ISEQ_MARK_ARY(iseq) (iseq)->body->mark_ary
47 
48 #define ISEQ_COVERAGE(iseq) RARRAY_AREF(ISEQ_MARK_ARY(iseq), ISEQ_MARK_ARY_COVERAGE)
49 #define ISEQ_COVERAGE_SET(iseq, cov) RARRAY_ASET(ISEQ_MARK_ARY(iseq), ISEQ_MARK_ARY_COVERAGE, cov)
50 #define ISEQ_LINE_COVERAGE(iseq) RARRAY_AREF(ISEQ_COVERAGE(iseq), COVERAGE_INDEX_LINES)
51 #define ISEQ_BRANCH_COVERAGE(iseq) RARRAY_AREF(ISEQ_COVERAGE(iseq), COVERAGE_INDEX_BRANCHES)
52 #define ISEQ_METHOD_COVERAGE(iseq) RARRAY_AREF(ISEQ_COVERAGE(iseq), COVERAGE_INDEX_METHODS)
53 
54 #define ISEQ_FLIP_CNT(iseq) FIX2INT(RARRAY_AREF(ISEQ_MARK_ARY(iseq), ISEQ_MARK_ARY_FLIP_CNT))
55 
56 static inline int
57 ISEQ_FLIP_CNT_INCREMENT(const rb_iseq_t *iseq)
58 {
59  int cnt = ISEQ_FLIP_CNT(iseq);
61  return cnt;
62 }
63 
64 static inline VALUE *
65 ISEQ_ORIGINAL_ISEQ(const rb_iseq_t *iseq)
66 {
68  if (RTEST(str)) return (VALUE *)RSTRING_PTR(str);
69  return NULL;
70 }
71 
72 static inline VALUE *
73 ISEQ_ORIGINAL_ISEQ_ALLOC(const rb_iseq_t *iseq, long size)
74 {
75  VALUE str = rb_str_tmp_new(size * sizeof(VALUE));
77  return (VALUE *)RSTRING_PTR(str);
78 }
79 
80 #define ISEQ_COMPILE_DATA(iseq) (iseq)->aux.compile_data
81 
82 static inline rb_iseq_t *
83 iseq_imemo_alloc(void)
84 {
85  return (rb_iseq_t *)rb_imemo_new(imemo_iseq, 0, 0, 0, 0);
86 }
87 
88 #define ISEQ_NOT_LOADED_YET IMEMO_FL_USER1
89 
90 VALUE iseq_ibf_dump(const rb_iseq_t *iseq, VALUE opt);
92 const rb_iseq_t *iseq_ibf_load(VALUE str);
94 
96 
97 /* compile.c */
101 void rb_iseq_build_from_ary(rb_iseq_t *iseq, VALUE misc,
102  VALUE locals, VALUE args,
103  VALUE exception, VALUE body);
104 
105 /* iseq.c */
106 void rb_iseq_add_mark_object(const rb_iseq_t *iseq, VALUE obj);
107 VALUE rb_iseq_load(VALUE data, VALUE parent, VALUE opt);
108 VALUE rb_iseq_parameters(const rb_iseq_t *iseq, int is_proc);
109 struct st_table *ruby_insn_make_insn_table(void);
110 unsigned int rb_iseq_line_no(const rb_iseq_t *iseq, size_t pos);
111 
112 int rb_iseqw_line_trace_each(VALUE iseqval, int (*func)(int line, rb_event_flag_t *events_ptr, void *d), void *data);
115 VALUE rb_iseqw_new(const rb_iseq_t *iseq);
116 const rb_iseq_t *rb_iseqw_to_iseq(VALUE iseqw);
117 
118 VALUE rb_iseq_absolute_path(const rb_iseq_t *iseq); /* obsolete */
119 VALUE rb_iseq_label(const rb_iseq_t *iseq);
120 VALUE rb_iseq_base_label(const rb_iseq_t *iseq);
122 VALUE rb_iseq_method_name(const rb_iseq_t *iseq);
123 
124 /* proc.c */
125 const rb_iseq_t *rb_method_iseq(VALUE body);
126 const rb_iseq_t *rb_proc_get_iseq(VALUE proc, int *is_proc);
127 
129  unsigned int inline_const_cache: 1;
130  unsigned int peephole_optimization: 1;
131  unsigned int tailcall_optimization: 1;
132  unsigned int specialized_instruction: 1;
133  unsigned int operands_unification: 1;
134  unsigned int instructions_unification: 1;
135  unsigned int stack_caching: 1;
136  unsigned int trace_instruction: 1;
137  unsigned int frozen_string_literal: 1;
139  unsigned int coverage_enabled: 1;
141 };
142 
144  unsigned int position;
145  unsigned int line_no;
146 };
147 
149  enum catch_type {
150  CATCH_TYPE_RESCUE = INT2FIX(1),
151  CATCH_TYPE_ENSURE = INT2FIX(2),
152  CATCH_TYPE_RETRY = INT2FIX(3),
153  CATCH_TYPE_BREAK = INT2FIX(4),
154  CATCH_TYPE_REDO = INT2FIX(5),
155  CATCH_TYPE_NEXT = INT2FIX(6)
156  } type;
157 
158  /*
159  * iseq type:
160  * CATCH_TYPE_RESCUE, CATCH_TYPE_ENSURE:
161  * use iseq as continuation.
162  *
163  * CATCH_TYPE_BREAK (iter):
164  * use iseq as key.
165  *
166  * CATCH_TYPE_BREAK (while), CATCH_TYPE_RETRY,
167  * CATCH_TYPE_REDO, CATCH_TYPE_NEXT:
168  * NULL.
169  */
170  const rb_iseq_t *iseq;
171 
172  unsigned int start;
173  unsigned int end;
174  unsigned int cont;
175  unsigned int sp;
176 };
177 
178 PACKED_STRUCT_UNALIGNED(struct iseq_catch_table {
179  unsigned int size;
180  struct iseq_catch_table_entry entries[1]; /* flexible array */
181 });
182 
183 static inline int
184 iseq_catch_table_bytes(int n)
185 {
186  enum {
187  catch_table_entries_max = (INT_MAX - sizeof(struct iseq_catch_table)) / sizeof(struct iseq_catch_table_entry)
188  };
189  if (n > catch_table_entries_max) rb_fatal("too large iseq_catch_table - %d", n);
190  return (int)(sizeof(struct iseq_catch_table) +
191  (n - 1) * sizeof(struct iseq_catch_table_entry));
192 }
193 
194 #define INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE (512)
195 
198  unsigned int pos;
199  unsigned int size;
200  char buff[1]; /* flexible array */
201 };
202 
203 /* account for flexible array */
204 #define SIZEOF_ISEQ_COMPILE_DATA_STORAGE \
205  (sizeof(struct iseq_compile_data_storage) - 1)
206 
208  /* GC is needed */
211  const VALUE catch_table_ary; /* Array */
212 
213  /* GC is not needed */
221  int loopval_popped; /* used by NODE_BREAK */
227  int label_no;
229  unsigned int ci_index;
230  unsigned int ci_kw_index;
233 #if SUPPORT_JOKE
234  st_table *labels_table;
235 #endif
236 };
237 
238 /* defined? */
239 
258 };
259 
262 
263 /* vm.c */
265 
267 
268 #endif /* RUBY_ISEQ_H */
void rb_fatal(const char *fmt,...)
Definition: error.c:2338
const rb_iseq_t * iseq
Definition: iseq.h:170
PACKED_STRUCT_UNALIGNED(struct iseq_catch_table { unsigned int size;struct iseq_catch_table_entry entries[1];})
VALUE rb_iseqw_line_trace_all(VALUE iseqval)
Definition: iseq.c:2307
void rb_iseq_build_from_ary(rb_iseq_t *iseq, VALUE misc, VALUE locals, VALUE args, VALUE exception, VALUE body)
Definition: compile.c:7385
catch_type
Definition: iseq.h:149
const rb_iseq_t * rb_method_iseq(VALUE body)
Definition: proc.c:2460
Definition: st.h:79
unsigned int rb_iseq_line_no(const rb_iseq_t *iseq, size_t pos)
Definition: iseq.c:1263
const rb_iseq_t * rb_proc_get_iseq(VALUE proc, int *is_proc)
Definition: proc.c:1086
VALUE rb_imemo_new(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0)
Definition: gc.c:2020
struct iseq_compile_data_storage * storage_head
Definition: iseq.h:223
unsigned int end
Definition: iseq.h:173
unsigned int operands_unification
Definition: iseq.h:133
struct st_table * ruby_insn_make_insn_table(void)
const rb_iseq_t * iseq_ibf_load(VALUE str)
Definition: compile.c:9112
VALUE rb_ary_push(VALUE ary, VALUE item)
Definition: array.c:924
const rb_iseq_t * current_block
Definition: iseq.h:217
VALUE rb_iseq_local_variables(const rb_iseq_t *iseq)
Definition: vm.c:794
VALUE rb_ary_tmp_new(long capa)
Definition: array.c:544
struct iseq_label_data * start_label
Definition: iseq.h:214
struct iseq_compile_data_storage * next
Definition: iseq.h:197
VALUE rb_iseq_base_label(const rb_iseq_t *iseq)
Definition: iseq.c:716
struct iseq_compile_data_ensure_node_stack * ensure_node_stack
Definition: iseq.h:220
VALUE rb_str_tmp_new(long)
Definition: string.c:1310
unsigned int cont
Definition: iseq.h:174
VALUE rb_iseq_first_lineno(const rb_iseq_t *iseq)
Definition: iseq.c:722
VALUE rb_iseq_method_name(const rb_iseq_t *iseq)
Definition: iseq.c:728
const rb_compile_option_t * option
Definition: iseq.h:231
VALUE iseq_ibf_dump(const rb_iseq_t *iseq, VALUE opt)
Definition: compile.c:8936
const VALUE catch_table_ary
Definition: iseq.h:211
Definition: node.h:233
struct rb_id_table * ivar_cache_table
Definition: iseq.h:232
VALUE rb_iseqw_new(const rb_iseq_t *iseq)
Definition: iseq.c:782
unsigned int trace_instruction
Definition: iseq.h:136
VALUE rb_iseq_parameters(const rb_iseq_t *iseq, int is_proc)
Definition: iseq.c:2125
unsigned int specialized_instruction
Definition: iseq.h:132
void rb_iseq_make_compile_option(struct rb_compile_option_struct *option, VALUE opt)
Definition: iseq.c:401
VALUE rb_iseqw_line_trace_specify(VALUE iseqval, VALUE pos, VALUE set)
Definition: iseq.c:2354
VALUE mark_ary
Definition: iseq.h:210
VALUE rb_iseq_defined_string(enum defined_type type)
Definition: iseq.c:2211
const VALUE err_info
Definition: iseq.h:209
rb_atomic_t cnt[RUBY_NSIG]
Definition: signal.c:525
unsigned int tailcall_optimization
Definition: iseq.h:131
unsigned int frozen_string_literal
Definition: iseq.h:137
void ibf_load_iseq_complete(rb_iseq_t *iseq)
Definition: compile.c:8995
unsigned int ci_kw_index
Definition: iseq.h:230
VALUE rb_iseq_load(VALUE data, VALUE parent, VALUE opt)
Definition: iseq.c:626
unsigned int instructions_unification
Definition: iseq.h:134
unsigned int size
Definition: iseq.h:199
defined_type
Definition: iseq.h:240
unsigned int coverage_enabled
Definition: iseq.h:139
iseq_mark_ary_index
Definition: iseq.h:29
const rb_iseq_t * rb_iseqw_to_iseq(VALUE iseqw)
Definition: iseq.c:958
#define RUBY_SYMBOL_EXPORT_END
Definition: missing.h:49
VALUE rb_iseq_absolute_path(const rb_iseq_t *iseq)
Definition: iseq.c:704
struct iseq_label_data * redo_label
Definition: iseq.h:216
unsigned int peephole_optimization
Definition: iseq.h:130
#define Qnil
Definition: ruby.h:438
unsigned long VALUE
Definition: ruby.h:85
Definition: iseq.h:148
void rb_iseq_add_mark_object(const rb_iseq_t *iseq, VALUE obj)
Definition: iseq.c:280
#define RUBY_SYMBOL_EXPORT_BEGIN
Definition: missing.h:48
VALUE * rb_iseq_original_iseq(const rb_iseq_t *iseq)
Definition: compile.c:753
unsigned int pos
Definition: iseq.h:198
#define RSTRING_PTR(str)
Definition: ruby.h:975
#define RARRAY_ASET(a, i, v)
Definition: ruby.h:1034
int size
Definition: encoding.c:57
#define INT2FIX(i)
Definition: ruby.h:232
unsigned int start
Definition: iseq.h:172
unsigned int position
Definition: iseq.h:144
#define RARRAY_AREF(a, i)
Definition: ruby.h:1033
VALUE ensure_node
Definition: iseq.h:218
int cached_const
Definition: iseq.h:222
VALUE for_iseq
Definition: iseq.h:219
struct iseq_compile_data_storage * storage_current
Definition: iseq.h:224
#define ISEQ_FLIP_CNT(iseq)
Definition: iseq.h:54
RUBY_SYMBOL_EXPORT_BEGIN VALUE rb_iseq_compile_node(rb_iseq_t *iseq, NODE *node)
Definition: compile.c:611
#define RTEST(v)
Definition: ruby.h:450
unsigned int ci_index
Definition: iseq.h:229
VALUE rb_iseq_label(const rb_iseq_t *iseq)
Definition: iseq.c:710
unsigned int inline_const_cache
Definition: iseq.h:129
int last_coverable_line
Definition: iseq.h:226
unsigned int stack_caching
Definition: iseq.h:135
int rb_iseq_translate_threaded_code(rb_iseq_t *iseq)
Definition: compile.c:719
struct iseq_label_data * end_label
Definition: iseq.h:215
int loopval_popped
Definition: iseq.h:221
uint32_t rb_event_flag_t
Definition: ruby.h:2116
Definition: iseq.h:143
unsigned int debug_frozen_string_literal
Definition: iseq.h:138
int node_level
Definition: iseq.h:228
#define ISEQ_MARK_ARY(iseq)
Definition: iseq.h:46
#define NULL
Definition: _sdbm.c:102
unsigned int line_no
Definition: iseq.h:145
unsigned int sp
Definition: iseq.h:175
VALUE iseq_ibf_load_extra_data(VALUE str)
Definition: compile.c:9126
int rb_iseqw_line_trace_each(VALUE iseqval, int(*func)(int line, rb_event_flag_t *events_ptr, void *d), void *data)
Definition: iseq.c:2255