00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef RUBY_INSNHELPER_H
00013 #define RUBY_INSNHELPER_H
00014
00028 #ifndef VMDEBUG
00029 #define VMDEBUG 0
00030 #endif
00031
00032 #if 0
00033 #undef VMDEBUG
00034 #define VMDEBUG 3
00035 #endif
00036
00037 enum {
00038 BOP_PLUS,
00039 BOP_MINUS,
00040 BOP_MULT,
00041 BOP_DIV,
00042 BOP_MOD,
00043 BOP_EQ,
00044 BOP_EQQ,
00045 BOP_LT,
00046 BOP_LE,
00047 BOP_LTLT,
00048 BOP_AREF,
00049 BOP_ASET,
00050 BOP_LENGTH,
00051 BOP_SIZE,
00052 BOP_SUCC,
00053 BOP_GT,
00054 BOP_GE,
00055 BOP_NOT,
00056 BOP_NEQ,
00057
00058 BOP_LAST_
00059 };
00060
00061 extern char ruby_vm_redefined_flag[BOP_LAST_];
00062 extern VALUE ruby_vm_const_missing_count;
00063
00064
00065
00066
00067
00068
00069 #define PUSH(x) (SET_SV(x), INC_SP(1))
00070 #define TOPN(n) (*(GET_SP()-(n)-1))
00071 #define POPN(n) (DEC_SP(n))
00072 #define POP() (DEC_SP(1))
00073 #define STACK_ADDR_FROM_TOP(n) (GET_SP()-(n))
00074
00075 #define GET_TOS() (tos)
00076
00077
00078
00079
00080
00081 #define REG_CFP (reg_cfp)
00082 #define REG_PC (REG_CFP->pc)
00083 #define REG_SP (REG_CFP->sp)
00084 #define REG_LFP (REG_CFP->lfp)
00085 #define REG_DFP (REG_CFP->dfp)
00086
00087 #define RESTORE_REGS() do { \
00088 REG_CFP = th->cfp; \
00089 } while (0)
00090
00091 #define REG_A reg_a
00092 #define REG_B reg_b
00093
00094 #ifdef COLLECT_USAGE_ANALYSIS
00095 #define USAGE_ANALYSIS_REGISTER_HELPER(a, b, v) \
00096 (USAGE_ANALYSIS_REGISTER(a, b), (v))
00097 #else
00098 #define USAGE_ANALYSIS_REGISTER_HELPER(a, b, v) (v)
00099 #endif
00100
00101
00102 #define GET_PC() (USAGE_ANALYSIS_REGISTER_HELPER(0, 0, REG_PC))
00103 #define SET_PC(x) (REG_PC = (USAGE_ANALYSIS_REGISTER_HELPER(0, 1, x)))
00104 #define GET_CURRENT_INSN() (*GET_PC())
00105 #define GET_OPERAND(n) (GET_PC()[(n)])
00106 #define ADD_PC(n) (SET_PC(REG_PC + (n)))
00107
00108 #define GET_PC_COUNT() (REG_PC - GET_ISEQ()->iseq_encoded)
00109 #define JUMP(dst) (REG_PC += (dst))
00110
00111
00112 #define GET_CFP() (USAGE_ANALYSIS_REGISTER_HELPER(2, 0, REG_CFP))
00113 #define GET_LFP() (USAGE_ANALYSIS_REGISTER_HELPER(3, 0, REG_LFP))
00114 #define SET_LFP(x) (REG_LFP = (USAGE_ANALYSIS_REGISTER_HELPER(3, 1, (x))))
00115 #define GET_DFP() (USAGE_ANALYSIS_REGISTER_HELPER(4, 0, REG_DFP))
00116 #define SET_DFP(x) (REG_DFP = (USAGE_ANALYSIS_REGISTER_HELPER(4, 1, (x))))
00117
00118
00119 #define GET_SP() (USAGE_ANALYSIS_REGISTER_HELPER(1, 0, REG_SP))
00120 #define SET_SP(x) (REG_SP = (USAGE_ANALYSIS_REGISTER_HELPER(1, 1, (x))))
00121 #define INC_SP(x) (REG_SP += (USAGE_ANALYSIS_REGISTER_HELPER(1, 1, (x))))
00122 #define DEC_SP(x) (REG_SP -= (USAGE_ANALYSIS_REGISTER_HELPER(1, 1, (x))))
00123 #define SET_SV(x) (*GET_SP() = (x))
00124
00125
00126 #define GET_SP_COUNT() (REG_SP - th->stack)
00127
00128
00129 #define GET_ISEQ() (GET_CFP()->iseq)
00130
00131
00132
00133
00134
00135 #define GET_PREV_DFP(dfp) ((VALUE *)((dfp)[0] & ~0x03))
00136
00137 #define GET_GLOBAL(entry) rb_gvar_get((struct rb_global_entry*)entry)
00138 #define SET_GLOBAL(entry, val) rb_gvar_set((struct rb_global_entry*)entry, val)
00139
00140 #define GET_CONST_INLINE_CACHE(dst) ((IC) * (GET_PC() + (dst) + 2))
00141
00142
00143
00144
00145
00146 #define GET_SELF() (USAGE_ANALYSIS_REGISTER_HELPER(5, 0, GET_CFP()->self))
00147
00148
00149
00150
00151
00152 #define COPY_CREF(c1, c2) do { \
00153 NODE *__tmp_c2 = (c2); \
00154 c1->nd_clss = __tmp_c2->nd_clss; \
00155 c1->nd_visi = __tmp_c2->nd_visi;\
00156 c1->nd_next = __tmp_c2->nd_next; \
00157 } while (0)
00158
00159 #define CALL_METHOD(num, blockptr, flag, id, me, recv) do { \
00160 VALUE v = vm_call_method(th, GET_CFP(), num, blockptr, flag, id, me, recv); \
00161 if (v == Qundef) { \
00162 RESTORE_REGS(); \
00163 NEXT_INSN(); \
00164 } \
00165 else { \
00166 val = v; \
00167 } \
00168 } while (0)
00169
00170 #define GET_BLOCK_PTR() \
00171 ((rb_block_t *)(GC_GUARDED_PTR_REF(GET_LFP()[0] & \
00172 ((GET_LFP()[0] & 0x02) - 0x02))))
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184 #define FIXNUM_2_P(a, b) ((a) & (b) & 1)
00185 #define BASIC_OP_UNREDEFINED_P(op) (LIKELY(ruby_vm_redefined_flag[op] == 0))
00186 #define HEAP_CLASS_OF(obj) RBASIC(obj)->klass
00187
00188 #ifndef USE_IC_FOR_SPECIALIZED_METHOD
00189 #define USE_IC_FOR_SPECIALIZED_METHOD 1
00190 #endif
00191
00192 #if USE_IC_FOR_SPECIALIZED_METHOD
00193
00194 #define CALL_SIMPLE_METHOD(num, id, recv) do { \
00195 VALUE klass = CLASS_OF(recv); \
00196 CALL_METHOD(num, 0, 0, id, vm_method_search(id, klass, ic), recv); \
00197 } while (0)
00198
00199 #else
00200
00201 #define CALL_SIMPLE_METHOD(num, id, recv) do { \
00202 VALUE klass = CLASS_OF(recv); \
00203 CALL_METHOD(num, 0, 0, id, rb_method_entry(klass, id), recv); \
00204 } while (0)
00205
00206 #endif
00207
00208 #endif
00209