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