1 /**********************************************************************
6 created at: 04/01/01 16:56:59 JST
8 Copyright (C) 2004-2007 Koichi Sasada
10 **********************************************************************/
16 typedef unsigned long rb_num_t
;
17 typedef unsigned long lindex_t
;
18 typedef unsigned long dindex_t
;
19 typedef rb_num_t GENTRY
;
20 typedef rb_iseq_t
*ISEQ
;
23 extern VALUE ruby_vm_global_state_version
;
24 extern VALUE ruby_vm_redefined_flag
;
32 * 1: show instruction name
33 * 2: show stack frame when control stack frame is changed
34 * 3: show stack status
50 #ifdef COLLECT_USAGE_ANALYSIS
51 #define USAGE_ANALYSIS_INSN(insn) vm_analysis_insn(insn)
52 #define USAGE_ANALYSIS_OPERAND(insn, n, op) vm_analysis_operand(insn, n, (VALUE)op)
53 #define USAGE_ANALYSIS_REGISTER(reg, s) vm_analysis_register(reg, s)
55 #define USAGE_ANALYSIS_INSN(insn) /* none */
56 #define USAGE_ANALYSIS_OPERAND(insn, n, op) /* none */
57 #define USAGE_ANALYSIS_REGISTER(reg, s) /* none */
61 /* TODO: machine dependent prefetch instruction */
69 #define DEBUG_ENTER_INSN(insn) \
70 debug_print_pre(th, GET_CFP());
73 #define SC_REGS() , reg_a, reg_b
78 #define DEBUG_END_INSN() \
79 debug_print_post(th, GET_CFP() SC_REGS());
84 #define DEBUG_ENTER_INSN(insn)
85 #define DEBUG_END_INSN()
88 #define throwdebug if(0)printf
89 /* #define throwdebug printf */
91 #define SDR2(cfp) vm_stack_dump_raw(GET_THREAD(), (cfp))
94 /************************************************/
97 /************************************************/
98 #elif OPT_CALL_THREADED_CODE
100 #define LABEL(x) insn_func_##x
102 #define LABEL_PTR(x) &LABEL(x)
104 #define INSN_ENTRY(insn) \
105 static rb_control_frame_t * \
106 FUNC_FASTCALL(LABEL(insn))(rb_thread_t *th, rb_control_frame_t *reg_cfp) {
108 #define END_INSN(insn) return reg_cfp;}
110 #define NEXT_INSN() return reg_cfp;
112 /************************************************/
113 #elif OPT_TOKEN_THREADED_CODE || OPT_DIRECT_THREADED_CODE
114 /* threaded code with gcc */
116 #define LABEL(x) INSN_LABEL_##x
117 #define ELABEL(x) INSN_ELABEL_##x
118 #define LABEL_PTR(x) &&LABEL(x)
120 #define INSN_ENTRY_SIG(insn)
123 #define INSN_DISPATCH_SIG(insn)
125 #define INSN_ENTRY(insn) \
127 INSN_ENTRY_SIG(insn); \
130 #if __GNUC__ && (__i386__ || __x86_64__) && __GNUC__ == 3
131 #define DISPATCH_ARCH_DEPEND_WAY(addr) \
132 asm volatile("jmp *%0;\t# -- inseted by vm.h\t[length = 2]" : : "r" (addr))
135 #define DISPATCH_ARCH_DEPEND_WAY(addr) \
141 /**********************************/
142 #if OPT_DIRECT_THREADED_CODE
145 #define TC_DISPATCH(insn) \
146 INSN_DISPATCH_SIG(insn); \
147 goto *GET_CURRENT_INSN(); \
151 /* token threade code */
153 #define TC_DISPATCH(insn) \
154 DISPATCH_ARCH_DEPEND_WAY(insns_address_table[GET_CURRENT_INSN()]); \
155 INSN_DISPATCH_SIG(insn); \
156 goto *insns_address_table[GET_CURRENT_INSN()]; \
160 #endif /* DISPATCH_DIRECT_THREADED_CODE */
162 #define END_INSN(insn) \
166 #define INSN_DISPATCH() \
167 TC_DISPATCH(__START__) \
170 #define END_INSNS_DISPATCH() \
171 rb_bug("unknown insn: %ld", GET_CURRENT_INSN()); \
172 } /* end of while loop */ \
174 #define NEXT_INSN() TC_DISPATCH(__NEXT_INSN__)
176 /************************************************/
177 #else /* no threaded code */
178 /* most common method */
180 #define INSN_ENTRY(insn) \
183 #define END_INSN(insn) \
188 #define INSN_DISPATCH() \
190 switch(GET_CURRENT_INSN()){
192 #define END_INSNS_DISPATCH() \
195 rb_bug("unknown insn: %ld", GET_CURRENT_INSN()); \
196 } /* end of switch */ \
197 } /* end of while loop */ \
199 #define NEXT_INSN() goto first
204 /************************************************/
205 /************************************************/
207 #define VM_CFP_CNT(th, cfp) \
208 ((rb_control_frame_t *)(th->stack + th->stack_size) - (rb_control_frame_t *)(cfp))
209 #define VM_SP_CNT(th, sp) ((sp) - (th)->stack)
213 env[0] // special (block or prev env)
215 env[2] // prev env val
219 #define ENV_IN_HEAP_P(th, env) \
220 (!((th)->stack < (env) && (env) < ((th)->stack + (th)->stack_size)))
221 #define ENV_VAL(env) ((env)[1])
223 #define FRAME_MAGIC_METHOD 0x11
224 #define FRAME_MAGIC_BLOCK 0x21
225 #define FRAME_MAGIC_CLASS 0x31
226 #define FRAME_MAGIC_TOP 0x41
227 #define FRAME_MAGIC_FINISH 0x51
228 #define FRAME_MAGIC_CFUNC 0x61
229 #define FRAME_MAGIC_PROC 0x71
230 #define FRAME_MAGIC_IFUNC 0x81
231 #define FRAME_MAGIC_EVAL 0x91
232 #define FRAME_MAGIC_LAMBDA 0xa1
233 #define FRAME_MAGIC_MASK_BITS 8
234 #define FRAME_MAGIC_MASK (~(~0<<FRAME_MAGIC_MASK_BITS))
236 #define VM_FRAME_FLAG(type) ((VALUE)((type) & FRAME_MAGIC_MASK))
238 #define VM_FRAME_TYPE(cfp) \
239 ((cfp)->flag & FRAME_MAGIC_MASK)
241 #define RUBYVM_CFUNC_FRAME_P(cfp) \
242 (VM_FRAME_TYPE(cfp) == FRAME_MAGIC_CFUNC)
244 #if OPT_CALL_THREADED_CODE
245 #define THROW_EXCEPTION(exc) do { \
246 th->errinfo = (VALUE)(exc); \
250 #define THROW_EXCEPTION(exc) return (VALUE)(exc)
253 #define SCREG(r) (reg_##r)
255 /* VM state version */
257 #define GET_VM_STATE_VERSION() (ruby_vm_global_state_version)
258 #define INC_VM_STATE_VERSION() \
259 (ruby_vm_global_state_version = (ruby_vm_global_state_version+1) & 0x8fffffff)
261 #define BOP_PLUS 0x01
262 #define BOP_MINUS 0x02
263 #define BOP_MULT 0x04
269 #define BOP_LTLT 0x100
270 #define BOP_AREF 0x200
271 #define BOP_ASET 0x400
272 #define BOP_LENGTH 0x800
273 #define BOP_SUCC 0x1000
274 #define BOP_GT 0x2000
275 #define BOP_GE 0x4000
276 #define BOP_NOT 0x8000
277 #define BOP_NEQ 0x10000
279 #endif /* RUBY_VM_H */