Ruby  2.4.2p198(2017-09-14revision59899)
iseq.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  iseq.h -
4 
5  $Author: naruse $
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 
51 #define ISEQ_FLIP_CNT(iseq) FIX2INT(RARRAY_AREF(ISEQ_MARK_ARY(iseq), ISEQ_MARK_ARY_FLIP_CNT))
52 
53 static inline int
55 {
56  int cnt = ISEQ_FLIP_CNT(iseq);
58  return cnt;
59 }
60 
61 static inline VALUE *
63 {
65  if (RTEST(str)) return (VALUE *)RSTRING_PTR(str);
66  return NULL;
67 }
68 
69 static inline VALUE *
71 {
72  VALUE str = rb_str_tmp_new(size * sizeof(VALUE));
74  return (VALUE *)RSTRING_PTR(str);
75 }
76 
77 #define ISEQ_COMPILE_DATA(iseq) (iseq)->aux.compile_data
78 
79 static inline rb_iseq_t *
81 {
82  return (rb_iseq_t *)rb_imemo_new(imemo_iseq, 0, 0, 0, 0);
83 }
84 
85 #define ISEQ_NOT_LOADED_YET IMEMO_FL_USER1
86 
87 VALUE iseq_ibf_dump(const rb_iseq_t *iseq, VALUE opt);
89 const rb_iseq_t *iseq_ibf_load(VALUE str);
91 
93 
94 /* compile.c */
98 void rb_iseq_build_from_ary(rb_iseq_t *iseq, VALUE misc,
99  VALUE locals, VALUE args,
100  VALUE exception, VALUE body);
101 
102 /* iseq.c */
103 void rb_iseq_add_mark_object(const rb_iseq_t *iseq, VALUE obj);
104 VALUE rb_iseq_load(VALUE data, VALUE parent, VALUE opt);
105 VALUE rb_iseq_parameters(const rb_iseq_t *iseq, int is_proc);
106 struct st_table *ruby_insn_make_insn_table(void);
107 unsigned int rb_iseq_line_no(const rb_iseq_t *iseq, size_t pos);
108 
109 int rb_iseqw_line_trace_each(VALUE iseqval, int (*func)(int line, rb_event_flag_t *events_ptr, void *d), void *data);
112 VALUE rb_iseqw_new(const rb_iseq_t *iseq);
113 const rb_iseq_t *rb_iseqw_to_iseq(VALUE iseqw);
114 
115 VALUE rb_iseq_path(const rb_iseq_t *iseq);
117 VALUE rb_iseq_label(const rb_iseq_t *iseq);
118 VALUE rb_iseq_base_label(const rb_iseq_t *iseq);
120 VALUE rb_iseq_method_name(const rb_iseq_t *iseq);
121 
122 /* proc.c */
123 const rb_iseq_t *rb_method_iseq(VALUE body);
124 const rb_iseq_t *rb_proc_get_iseq(VALUE proc, int *is_proc);
125 
127  unsigned int inline_const_cache: 1;
128  unsigned int peephole_optimization: 1;
129  unsigned int tailcall_optimization: 1;
130  unsigned int specialized_instruction: 1;
131  unsigned int operands_unification: 1;
132  unsigned int instructions_unification: 1;
133  unsigned int stack_caching: 1;
134  unsigned int trace_instruction: 1;
135  unsigned int frozen_string_literal: 1;
137  unsigned int coverage_enabled: 1;
139 };
140 
142  unsigned int position;
143  unsigned int line_no;
144 };
145 
147  enum catch_type {
148  CATCH_TYPE_RESCUE = INT2FIX(1),
149  CATCH_TYPE_ENSURE = INT2FIX(2),
150  CATCH_TYPE_RETRY = INT2FIX(3),
151  CATCH_TYPE_BREAK = INT2FIX(4),
152  CATCH_TYPE_REDO = INT2FIX(5),
153  CATCH_TYPE_NEXT = INT2FIX(6)
154  } type;
155  const rb_iseq_t *iseq;
156  unsigned int start;
157  unsigned int end;
158  unsigned int cont;
159  unsigned int sp;
160 };
161 
162 PACKED_STRUCT_UNALIGNED(struct iseq_catch_table {
163  unsigned int size;
164  struct iseq_catch_table_entry entries[1]; /* flexible array */
165 });
166 
167 static inline int
169 {
170  enum {
171  catch_table_entries_max = (INT_MAX - sizeof(struct iseq_catch_table)) / sizeof(struct iseq_catch_table_entry)
172  };
173  if (n > catch_table_entries_max) rb_fatal("too large iseq_catch_table - %d", n);
174  return (int)(sizeof(struct iseq_catch_table) +
175  (n - 1) * sizeof(struct iseq_catch_table_entry));
176 }
177 
178 #define INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE (512)
179 
182  unsigned int pos;
183  unsigned int size;
184  char buff[1]; /* flexible array */
185 };
186 
187 /* account for flexible array */
188 #define SIZEOF_ISEQ_COMPILE_DATA_STORAGE \
189  (sizeof(struct iseq_compile_data_storage) - 1)
190 
192  /* GC is needed */
195  const VALUE catch_table_ary; /* Array */
196 
197  /* GC is not needed */
205  int loopval_popped; /* used by NODE_BREAK */
211  int label_no;
213  unsigned int ci_index;
214  unsigned int ci_kw_index;
216  struct rb_id_table *ivar_cache_table;
217 #if SUPPORT_JOKE
218  st_table *labels_table;
219 #endif
220 };
221 
222 /* defined? */
223 
242 };
243 
246 
247 /* vm.c */
249 
251 
252 #endif /* RUBY_ISEQ_H */
const rb_iseq_t * iseq
Definition: iseq.h:155
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:2279
void rb_iseq_build_from_ary(rb_iseq_t *iseq, VALUE misc, VALUE locals, VALUE args, VALUE exception, VALUE body)
Definition: compile.c:6921
VALUE rb_iseq_path(const rb_iseq_t *iseq)
Definition: iseq.c:670
catch_type
Definition: iseq.h:147
const rb_iseq_t * rb_method_iseq(VALUE body)
Definition: proc.c:2467
Definition: st.h:79
unsigned int rb_iseq_line_no(const rb_iseq_t *iseq, size_t pos)
Definition: iseq.c:1234
const rb_iseq_t * rb_proc_get_iseq(VALUE proc, int *is_proc)
Definition: proc.c:1091
VALUE rb_imemo_new(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0)
Definition: gc.c:1971
struct iseq_compile_data_storage * storage_head
Definition: iseq.h:207
unsigned int end
Definition: iseq.h:157
unsigned int operands_unification
Definition: iseq.h:131
struct st_table * ruby_insn_make_insn_table(void)
const rb_iseq_t * iseq_ibf_load(VALUE str)
Definition: compile.c:8630
static VALUE * ISEQ_ORIGINAL_ISEQ(const rb_iseq_t *iseq)
Definition: iseq.h:62
VALUE rb_ary_push(VALUE ary, VALUE item)
Definition: array.c:905
const rb_iseq_t * current_block
Definition: iseq.h:201
VALUE rb_iseq_local_variables(const rb_iseq_t *iseq)
Definition: vm.c:792
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:54
VALUE rb_ary_tmp_new(long capa)
Definition: array.c:532
struct iseq_label_data * start_label
Definition: iseq.h:198
struct iseq_compile_data_storage * next
Definition: iseq.h:181
VALUE rb_iseq_base_label(const rb_iseq_t *iseq)
Definition: iseq.c:688
struct iseq_compile_data_ensure_node_stack * ensure_node_stack
Definition: iseq.h:204
VALUE rb_str_tmp_new(long)
Definition: string.c:1275
unsigned int cont
Definition: iseq.h:158
VALUE rb_iseq_first_lineno(const rb_iseq_t *iseq)
Definition: iseq.c:694
VALUE rb_iseq_method_name(const rb_iseq_t *iseq)
Definition: iseq.c:700
const rb_compile_option_t * option
Definition: iseq.h:215
VALUE iseq_ibf_dump(const rb_iseq_t *iseq, VALUE opt)
Definition: compile.c:8450
const VALUE catch_table_ary
Definition: iseq.h:195
Definition: node.h:235
static size_t rb_call_info_kw_arg_bytes(int keyword_len)
Definition: iseq.h:24
struct rb_id_table * ivar_cache_table
Definition: iseq.h:216
static int ISEQ_FLIP_CNT_INCREMENT(const rb_iseq_t *iseq)
Definition: iseq.h:54
unsigned int trace_instruction
Definition: iseq.h:134
static VALUE * ISEQ_ORIGINAL_ISEQ_ALLOC(const rb_iseq_t *iseq, long size)
Definition: iseq.h:70
VALUE rb_iseq_parameters(const rb_iseq_t *iseq, int is_proc)
Definition: iseq.c:2097
unsigned int specialized_instruction
Definition: iseq.h:130
void rb_iseq_make_compile_option(struct rb_compile_option_struct *option, VALUE opt)
Definition: iseq.c:379
VALUE rb_iseqw_line_trace_specify(VALUE iseqval, VALUE pos, VALUE set)
Definition: iseq.c:2326
VALUE mark_ary
Definition: iseq.h:194
VALUE rb_iseq_defined_string(enum defined_type type)
Definition: iseq.c:2183
const VALUE err_info
Definition: iseq.h:193
rb_atomic_t cnt[RUBY_NSIG]
Definition: signal.c:525
unsigned int tailcall_optimization
Definition: iseq.h:129
unsigned int frozen_string_literal
Definition: iseq.h:135
void ibf_load_iseq_complete(rb_iseq_t *iseq)
Definition: compile.c:8509
unsigned int ci_kw_index
Definition: iseq.h:214
VALUE rb_iseq_load(VALUE data, VALUE parent, VALUE opt)
Definition: iseq.c:604
unsigned int instructions_unification
Definition: iseq.h:132
unsigned int size
Definition: iseq.h:183
defined_type
Definition: iseq.h:224
unsigned int coverage_enabled
Definition: iseq.h:137
iseq_mark_ary_index
Definition: iseq.h:29
const rb_iseq_t * rb_iseqw_to_iseq(VALUE iseqw)
Definition: iseq.c:930
void rb_fatal(const char *fmt,...)
Definition: error.c:2261
#define RUBY_SYMBOL_EXPORT_END
Definition: missing.h:49
VALUE rb_iseq_absolute_path(const rb_iseq_t *iseq)
Definition: iseq.c:676
struct iseq_label_data * redo_label
Definition: iseq.h:200
static int iseq_catch_table_bytes(int n)
Definition: iseq.h:168
unsigned int peephole_optimization
Definition: iseq.h:128
#define Qnil
Definition: ruby.h:438
unsigned long VALUE
Definition: ruby.h:85
Definition: iseq.h:146
void rb_iseq_add_mark_object(const rb_iseq_t *iseq, VALUE obj)
Definition: iseq.c:262
#define RUBY_SYMBOL_EXPORT_BEGIN
Definition: missing.h:48
VALUE * rb_iseq_original_iseq(const rb_iseq_t *iseq)
Definition: compile.c:716
unsigned int pos
Definition: iseq.h:182
#define RSTRING_PTR(str)
Definition: ruby.h:982
#define RARRAY_ASET(a, i, v)
Definition: ruby.h:1041
static VALUE iseq_mark_ary_create(int flip_cnt)
Definition: iseq.h:37
int size
Definition: encoding.c:57
#define INT2FIX(i)
Definition: ruby.h:232
unsigned int start
Definition: iseq.h:156
unsigned int position
Definition: iseq.h:142
#define RARRAY_AREF(a, i)
Definition: ruby.h:1040
VALUE ensure_node
Definition: iseq.h:202
static rb_iseq_t * iseq_imemo_alloc(void)
Definition: iseq.h:80
int cached_const
Definition: iseq.h:206
VALUE for_iseq
Definition: iseq.h:203
struct iseq_compile_data_storage * storage_current
Definition: iseq.h:208
#define ISEQ_FLIP_CNT(iseq)
Definition: iseq.h:51
RUBY_SYMBOL_EXPORT_BEGIN VALUE rb_iseq_compile_node(rb_iseq_t *iseq, NODE *node)
Definition: compile.c:576
#define RTEST(v)
Definition: ruby.h:450
unsigned int ci_index
Definition: iseq.h:213
VALUE rb_iseq_label(const rb_iseq_t *iseq)
Definition: iseq.c:682
unsigned int inline_const_cache
Definition: iseq.h:127
int last_coverable_line
Definition: iseq.h:210
unsigned int stack_caching
Definition: iseq.h:133
int rb_iseq_translate_threaded_code(rb_iseq_t *iseq)
Definition: compile.c:682
VALUE rb_iseqw_new(const rb_iseq_t *iseq)
Definition: iseq.c:754
struct iseq_label_data * end_label
Definition: iseq.h:199
int loopval_popped
Definition: iseq.h:205
uint32_t rb_event_flag_t
Definition: ruby.h:2095
Definition: iseq.h:141
unsigned int debug_frozen_string_literal
Definition: iseq.h:136
int node_level
Definition: iseq.h:212
#define ISEQ_MARK_ARY(iseq)
Definition: iseq.h:46
#define NULL
Definition: _sdbm.c:102
unsigned int line_no
Definition: iseq.h:143
unsigned int sp
Definition: iseq.h:159
VALUE iseq_ibf_load_extra_data(VALUE str)
Definition: compile.c:8644
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:2227