Ruby 2.0.0p353(2013-11-22revision43784)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

vm_insnhelper.h
Go to the documentation of this file.
1 /**********************************************************************
2
3 insnhelper.h - helper macros to implement each instructions
4
5 $Author: naruse $
6 created at: 04/01/01 15:50:34 JST
7
8 Copyright (C) 2004-2007 Koichi Sasada
9
10 **********************************************************************/
11
12 #ifndef RUBY_INSNHELPER_H
13 #define RUBY_INSNHELPER_H
14
28 #ifndef VMDEBUG
29 #define VMDEBUG 0
30 #endif
31
32 #if 0
33 #undef VMDEBUG
34 #define VMDEBUG 3
35 #endif
36
37 enum {
38 BOP_PLUS,
39 BOP_MINUS,
40 BOP_MULT,
41 BOP_DIV,
42 BOP_MOD,
43 BOP_EQ,
44 BOP_EQQ,
45 BOP_LT,
46 BOP_LE,
47 BOP_LTLT,
48 BOP_AREF,
49 BOP_ASET,
50 BOP_LENGTH,
51 BOP_SIZE,
52 BOP_EMPTY_P,
53 BOP_SUCC,
54 BOP_GT,
55 BOP_GE,
56 BOP_NOT,
57 BOP_NEQ,
58
59 BOP_LAST_
60 };
61
62 extern char ruby_vm_redefined_flag[BOP_LAST_];
63 extern VALUE ruby_vm_const_missing_count;
64
65 #if VM_COLLECT_USAGE_DETAILS
66 #define COLLECT_USAGE_INSN(insn) vm_collect_usage_insn(insn)
67 #define COLLECT_USAGE_OPERAND(insn, n, op) vm_collect_usage_operand((insn), (n), ((VALUE)(op)))
68
69 #define COLLECT_USAGE_REGISTER(reg, s) vm_collect_usage_register((reg), (s))
70 #else
71 #define COLLECT_USAGE_INSN(insn) /* none */
72 #define COLLECT_USAGE_OPERAND(insn, n, op) /* none */
73 #define COLLECT_USAGE_REGISTER(reg, s) /* none */
74 #endif
75
76 /**********************************************************/
77 /* deal with stack */
78 /**********************************************************/
79
80 #define PUSH(x) (SET_SV(x), INC_SP(1))
81 #define TOPN(n) (*(GET_SP()-(n)-1))
82 #define POPN(n) (DEC_SP(n))
83 #define POP() (DEC_SP(1))
84 #define STACK_ADDR_FROM_TOP(n) (GET_SP()-(n))
85
86 #define GET_TOS() (tos) /* dummy */
87
88 /**********************************************************/
89 /* deal with registers */
90 /**********************************************************/
91
92 #define REG_CFP (reg_cfp)
93 #define REG_PC (REG_CFP->pc)
94 #define REG_SP (REG_CFP->sp)
95 #define REG_EP (REG_CFP->ep)
96
97 #define RESTORE_REGS() do { \
98 REG_CFP = th->cfp; \
99 } while (0)
100
101 #define REG_A reg_a
102 #define REG_B reg_b
103
104 enum vm_regan_regtype {
105 VM_REGAN_PC = 0,
106 VM_REGAN_SP = 1,
107 VM_REGAN_EP = 2,
108 VM_REGAN_CFP = 3,
109 VM_REGAN_SELF = 4,
110 VM_REGAN_ISEQ = 5,
111 };
112 enum vm_regan_acttype {
113 VM_REGAN_ACT_GET = 0,
114 VM_REGAN_ACT_SET = 1,
115 };
116
117 #if VM_COLLECT_USAGE_DETAILS
118 #define COLLECT_USAGE_REGISTER_HELPER(a, b, v) \
119 (COLLECT_USAGE_REGISTER((VM_REGAN_##a), (VM_REGAN_ACT_##b)), (v))
120 #else
121 #define COLLECT_USAGE_REGISTER_HELPER(a, b, v) (v)
122 #endif
123
124 /* PC */
125 #define GET_PC() (COLLECT_USAGE_REGISTER_HELPER(PC, GET, REG_PC))
126 #define SET_PC(x) (REG_PC = (COLLECT_USAGE_REGISTER_HELPER(PC, SET, (x))))
127 #define GET_CURRENT_INSN() (*GET_PC())
128 #define GET_OPERAND(n) (GET_PC()[(n)])
129 #define ADD_PC(n) (SET_PC(REG_PC + (n)))
130
131 #define GET_PC_COUNT() (REG_PC - GET_ISEQ()->iseq_encoded)
132 #define JUMP(dst) (REG_PC += (dst))
133
134 /* frame pointer, environment pointer */
135 #define GET_CFP() (COLLECT_USAGE_REGISTER_HELPER(CFP, GET, REG_CFP))
136 #define GET_EP() (COLLECT_USAGE_REGISTER_HELPER(EP, GET, REG_EP))
137 #define SET_EP(x) (REG_EP = (COLLECT_USAGE_REGISTER_HELPER(EP, SET, (x))))
138 #define GET_LEP() (VM_EP_LEP(GET_EP()))
139
140 /* SP */
141 #define GET_SP() (COLLECT_USAGE_REGISTER_HELPER(SP, GET, REG_SP))
142 #define SET_SP(x) (REG_SP = (COLLECT_USAGE_REGISTER_HELPER(SP, SET, (x))))
143 #define INC_SP(x) (REG_SP += (COLLECT_USAGE_REGISTER_HELPER(SP, SET, (x))))
144 #define DEC_SP(x) (REG_SP -= (COLLECT_USAGE_REGISTER_HELPER(SP, SET, (x))))
145 #define SET_SV(x) (*GET_SP() = (x))
146 /* set current stack value as x */
147
148 #define GET_SP_COUNT() (REG_SP - th->stack)
149
150 /* instruction sequence C struct */
151 #define GET_ISEQ() (GET_CFP()->iseq)
152
153 /**********************************************************/
154 /* deal with variables */
155 /**********************************************************/
156
157 #define GET_PREV_EP(ep) ((VALUE *)((ep)[0] & ~0x03))
158
159 #define GET_GLOBAL(entry) rb_gvar_get((struct rb_global_entry*)(entry))
160 #define SET_GLOBAL(entry, val) rb_gvar_set((struct rb_global_entry*)(entry), (val))
161
162 #define GET_CONST_INLINE_CACHE(dst) ((IC) * (GET_PC() + (dst) + 2))
163
164 /**********************************************************/
165 /* deal with values */
166 /**********************************************************/
167
168 #define GET_SELF() (COLLECT_USAGE_REGISTER_HELPER(SELF, GET, GET_CFP()->self))
169
170 /**********************************************************/
171 /* deal with control flow 2: method/iterator */
172 /**********************************************************/
173
174 #define COPY_CREF_OMOD(c1, c2) do { \
175 (c1)->nd_refinements = (c2)->nd_refinements; \
176 if (!NIL_P((c2)->nd_refinements)) { \
177 (c1)->flags |= NODE_FL_CREF_OMOD_SHARED; \
178 (c2)->flags |= NODE_FL_CREF_OMOD_SHARED; \
179 } \
180 } while (0)
181
182 #define COPY_CREF(c1, c2) do { \
183 NODE *__tmp_c2 = (c2); \
184 COPY_CREF_OMOD(c1, __tmp_c2); \
185 (c1)->nd_clss = __tmp_c2->nd_clss; \
186 (c1)->nd_visi = __tmp_c2->nd_visi;\
187 (c1)->nd_next = __tmp_c2->nd_next; \
188 if (__tmp_c2->flags & NODE_FL_CREF_PUSHED_BY_EVAL) { \
189 (c1)->flags |= NODE_FL_CREF_PUSHED_BY_EVAL; \
190 } \
191 } while (0)
192
193 #define CALL_METHOD(ci) do { \
194 VALUE v = (*(ci)->call)(th, GET_CFP(), (ci)); \
195 if (v == Qundef) { \
196 RESTORE_REGS(); \
197 NEXT_INSN(); \
198 } \
199 else { \
200 val = v; \
201 } \
202 } while (0)
203
204 /* set fastpath when cached method is *NOT* protected
205 * because inline method cache does not care about receiver.
206 */
207
208 #ifndef OPT_CALL_FASTPATH
209 #define OPT_CALL_FASTPATH 1
210 #endif
211
212 #if OPT_CALL_FASTPATH
213 #define CI_SET_FASTPATH(ci, func, enabled) do { \
214 if (LIKELY(enabled)) ((ci)->call = (func)); \
215 } while (0)
216 #else
217 #define CI_SET_FASTPATH(ci, func, enabled) /* do nothing */
218 #endif
219
220 #define GET_BLOCK_PTR() ((rb_block_t *)(GC_GUARDED_PTR_REF(GET_LEP()[0])))
221
222 /**********************************************************/
223 /* deal with control flow 3: exception */
224 /**********************************************************/
225
226
227 /**********************************************************/
228 /* others */
229 /**********************************************************/
230
231 /* optimize insn */
232 #define FIXNUM_REDEFINED_OP_FLAG (1 << 0)
233 #define FLOAT_REDEFINED_OP_FLAG (1 << 1)
234 #define STRING_REDEFINED_OP_FLAG (1 << 2)
235 #define ARRAY_REDEFINED_OP_FLAG (1 << 3)
236 #define HASH_REDEFINED_OP_FLAG (1 << 4)
237 #define BIGNUM_REDEFINED_OP_FLAG (1 << 5)
238 #define SYMBOL_REDEFINED_OP_FLAG (1 << 6)
239 #define TIME_REDEFINED_OP_FLAG (1 << 7)
240
241 #define BASIC_OP_UNREDEFINED_P(op, klass) (LIKELY((ruby_vm_redefined_flag[(op)]&(klass)) == 0))
242
243 #define FIXNUM_2_P(a, b) ((a) & (b) & 1)
244 #if USE_FLONUM
245 #define FLONUM_2_P(a, b) (((((a)^2) | ((b)^2)) & 3) == 0) /* (FLONUM_P(a) && FLONUM_P(b)) */
246 #else
247 #define FLONUM_2_P(a, b) 0
248 #endif
249 #define HEAP_CLASS_OF(obj) (RBASIC(obj)->klass)
250
251 #ifndef USE_IC_FOR_SPECIALIZED_METHOD
252 #define USE_IC_FOR_SPECIALIZED_METHOD 1
253 #endif
254
255 #define CALL_SIMPLE_METHOD(recv) do { \
256 ci->blockptr = 0; ci->argc = ci->orig_argc; \
257 vm_search_method(ci, ci->recv = (recv)); \
258 CALL_METHOD(ci); \
259 } while (0)
260
261 static VALUE ruby_vm_global_state_version = 1;
262
263 #define GET_VM_STATE_VERSION() (ruby_vm_global_state_version)
264 #define INC_VM_STATE_VERSION() do { \
265 ruby_vm_global_state_version = (ruby_vm_global_state_version + 1); \
266 if (ruby_vm_global_state_version == 0) vm_clear_all_cache(); \
267 } while (0)
268 static void vm_clear_all_cache(void);
269
270 static VALUE make_no_method_exception(VALUE exc, const char *format,
271 VALUE obj, int argc, const VALUE *argv);
272
273
274 #endif /* RUBY_INSNHELPER_H */
VM_REGAN_ACT_SET
Definition: vm_insnhelper.h:114
vm_regan_regtype
vm_regan_regtype
Definition: vm_insnhelper.h:104
ruby_vm_const_missing_count
VALUE ruby_vm_const_missing_count
Definition: vm.c:94
ruby_vm_redefined_flag
char ruby_vm_redefined_flag[BOP_LAST_]
Definition: vm.c:95
ruby_vm_global_state_version
static VALUE ruby_vm_global_state_version
Definition: vm_insnhelper.h:261
BOP_ASET
Definition: vm_insnhelper.h:49
BOP_AREF
Definition: vm_insnhelper.h:48
BOP_NOT
Definition: vm_insnhelper.h:56
exc
VALUE exc
Definition: tcltklib.c:3096
BOP_LTLT
Definition: vm_insnhelper.h:47
BOP_LAST_
Definition: vm_insnhelper.h:59
BOP_LT
Definition: vm_insnhelper.h:45
BOP_MINUS
Definition: vm_insnhelper.h:39
VM_REGAN_SP
Definition: vm_insnhelper.h:106
BOP_EMPTY_P
Definition: vm_insnhelper.h:52
BOP_LE
Definition: vm_insnhelper.h:46
obj
static VALUE VALUE obj
Definition: tcltklib.c:3158
BOP_LENGTH
Definition: vm_insnhelper.h:50
VM_REGAN_SELF
Definition: vm_insnhelper.h:109
argv
VALUE * argv
Definition: tcltklib.c:1971
BOP_EQ
Definition: vm_insnhelper.h:43
VM_REGAN_CFP
Definition: vm_insnhelper.h:108
argc
int argc
Definition: tcltklib.c:1970
BOP_GE
Definition: vm_insnhelper.h:55
BOP_EQQ
Definition: vm_insnhelper.h:44
vm_clear_all_cache
static void vm_clear_all_cache(void)
VM_REGAN_ISEQ
Definition: vm_insnhelper.h:110
BOP_PLUS
Definition: vm_insnhelper.h:38
make_no_method_exception
static VALUE make_no_method_exception(VALUE exc, const char *format, VALUE obj, int argc, const VALUE *argv)
BOP_NEQ
Definition: vm_insnhelper.h:57
VM_REGAN_EP
Definition: vm_insnhelper.h:107
BOP_MOD
Definition: vm_insnhelper.h:42
BOP_GT
Definition: vm_insnhelper.h:54
BOP_MULT
Definition: vm_insnhelper.h:40
vm_regan_acttype
vm_regan_acttype
Definition: vm_insnhelper.h:112
VM_REGAN_PC
Definition: vm_insnhelper.h:105
VALUE
unsigned long VALUE
Definition: ripper.y:104
VM_REGAN_ACT_GET
Definition: vm_insnhelper.h:113
BOP_SIZE
Definition: vm_insnhelper.h:51
BOP_SUCC
Definition: vm_insnhelper.h:53
BOP_DIV
Definition: vm_insnhelper.h:41