(linenum→info "unix/slp.c:2238")

ruby/1.9.0/insnhelper.h

    1: /**********************************************************************
    2: 
    3:   insnhelper.h - helper macros to implement each instructions
    4: 
    5:   $Author: ko1 $
    6:   $Date: 2007-11-14 07:13:04 +0900 (Wed, 14 Nov 2007) $
    7:   created at: 04/01/01 15:50:34 JST
    8: 
    9:   Copyright (C) 2004-2007 Koichi Sasada
   10: 
   11: **********************************************************************/
   12: 
   13: #ifndef _INSNHELPER_H_INCLUDED_
   14: #define _INSNHELPER_H_INCLUDED_
   15: 
   16: #include "ruby/ruby.h"
   17: #include "ruby/node.h"
   18: #include "eval_intern.h"
   19: #include "vm_core.h"
   20: #include "vm.h"
   21: 
   22: /**********************************************************/
   23: /* deal with stack                                        */
   24: /**********************************************************/
   25: 
   26: #define PUSH(x) (SET_SV(x), INC_SP(1))
   27: #define TOPN(n) (*(GET_SP()-(n)-1))
   28: #define POPN(n) (DEC_SP(n))
   29: #define POP()   (DEC_SP(1))
   30: #define STACK_ADDR_FROM_TOP(n) (GET_SP()-(n))
   31: 
   32: #define GET_TOS()  (tos)        /* dummy */
   33: 
   34: /**********************************************************/
   35: /* deal with registers                                    */
   36: /**********************************************************/
   37: 
   38: #define REG_CFP (reg_cfp)
   39: #define REG_PC  (REG_CFP->pc)
   40: #define REG_SP  (REG_CFP->sp)
   41: #define REG_LFP (REG_CFP->lfp)
   42: #define REG_DFP (REG_CFP->dfp)
   43: 
   44: #define RESTORE_REGS() do { \
   45:   REG_CFP = th->cfp; \
   46: } while (0)
   47: 
   48: #define REG_A   reg_a
   49: #define REG_B   reg_b
   50: 
   51: #ifdef COLLECT_USAGE_ANALYSIS
   52: #define USAGE_ANALYSIS_REGISTER_HELPER(a, b, v) \
   53:   (USAGE_ANALYSIS_REGISTER(a, b), (v))
   54: #else
   55: #define USAGE_ANALYSIS_REGISTER_HELPER(a, b, v) (v)
   56: #endif
   57: 
   58: /* PC */
   59: #define GET_PC()           (USAGE_ANALYSIS_REGISTER_HELPER(0, 0, REG_PC))
   60: #define SET_PC(x)          (REG_PC = (USAGE_ANALYSIS_REGISTER_HELPER(0, 1, x)))
   61: #define GET_CURRENT_INSN() (*GET_PC())
   62: #define GET_OPERAND(n)     (GET_PC()[(n)])
   63: #define ADD_PC(n)          (SET_PC(REG_PC + (n)))
   64: 
   65: #define GET_PC_COUNT()     (REG_PC - GET_ISEQ()->iseq_encoded)
   66: #define JUMP(dst)          (REG_PC += (dst))
   67: 
   68: /* FP */
   69: #define GET_CFP()  (USAGE_ANALYSIS_REGISTER_HELPER(2, 0, REG_CFP))
   70: #define GET_LFP()  (USAGE_ANALYSIS_REGISTER_HELPER(3, 0, REG_LFP))
   71: #define SET_LFP(x) (REG_LFP = (USAGE_ANALYSIS_REGISTER_HELPER(3, 1, (x))))
   72: #define GET_DFP()  (USAGE_ANALYSIS_REGISTER_HELPER(4, 0, REG_DFP))
   73: #define SET_DFP(x) (REG_DFP = (USAGE_ANALYSIS_REGISTER_HELPER(4, 1, (x))))
   74: 
   75: /* SP */
   76: #define GET_SP()   (USAGE_ANALYSIS_REGISTER_HELPER(1, 0, REG_SP))
   77: #define SET_SP(x)  (REG_SP  = (USAGE_ANALYSIS_REGISTER_HELPER(1, 1, (x))))
   78: #define INC_SP(x)  (REG_SP += (USAGE_ANALYSIS_REGISTER_HELPER(1, 1, (x))))
   79: #define DEC_SP(x)  (REG_SP -= (USAGE_ANALYSIS_REGISTER_HELPER(1, 1, (x))))
   80: #define SET_SV(x)  (*GET_SP() = (x))
   81:   /* set current stack value as x */
   82: 
   83: #define GET_SP_COUNT() (REG_SP - th->stack)
   84: 
   85: /* instruction sequence C struct */
   86: #define GET_ISEQ() (GET_CFP()->iseq)
   87: 
   88: /**********************************************************/
   89: /* deal with variables                                    */
   90: /**********************************************************/
   91: 
   92: #define GET_PREV_DFP(dfp)                ((VALUE *)((dfp)[0] & ~0x03))
   93: 
   94: #define GET_GLOBAL(entry)       rb_gvar_get((struct global_entry*)entry)
   95: #define SET_GLOBAL(entry, val)  rb_gvar_set((struct global_entry*)entry, val)
   96: 
   97: #define GET_CONST_INLINE_CACHE(dst) ((IC) * (GET_PC() + (dst) + 1))
   98: 
   99: /**********************************************************/
  100: /* deal with values                                       */
  101: /**********************************************************/
  102: 
  103: #define GET_SELF() (USAGE_ANALYSIS_REGISTER_HELPER(5, 0, GET_CFP()->self))
  104: 
  105: /**********************************************************/
  106: /* deal with control flow 2: method/iterator              */
  107: /**********************************************************/
  108: 
  109: #define COPY_CREF(c1, c2) do {  \
  110:   NODE *__tmp_c2 = (c2); \
  111:   c1->nd_clss = __tmp_c2->nd_clss; \
  112:   c1->nd_visi = __tmp_c2->nd_visi; \
  113:   c1->nd_next = __tmp_c2->nd_next; \
  114: } while (0)
  115: 
  116: #define CALL_METHOD(num, blockptr, flag, id, mn, recv, klass) do { \
  117:     VALUE v = vm_call_method(th, GET_CFP(), num, blockptr, flag, id, mn, recv, klass); \
  118:     if (v == Qundef) { \
  119:         RESTORE_REGS(); \
  120:         NEXT_INSN(); \
  121:     } \
  122:     else { \
  123:         val = v; \
  124:     } \
  125: } while (0)
  126: 
  127: #define GET_BLOCK_PTR() \
  128:   ((rb_block_t *)(GC_GUARDED_PTR_REF(GET_LFP()[0])))
  129: 
  130: /**********************************************************/
  131: /* deal with control flow 3: exception                    */
  132: /**********************************************************/
  133: 
  134: 
  135: /**********************************************************/
  136: /* others                                                 */
  137: /**********************************************************/
  138: 
  139: /* optimize insn */
  140: #define FIXNUM_2_P(a, b) ((a) & (b) & 1)
  141: #define BASIC_OP_UNREDEFINED_P(op) ((ruby_vm_redefined_flag & (op)) == 0)
  142: #define HEAP_CLASS_OF(obj) RBASIC(obj)->klass
  143: 
  144: #define CALL_SIMPLE_METHOD(num, id, recv) do { \
  145:     VALUE klass = CLASS_OF(recv); \
  146:     CALL_METHOD(num, 0, 0, id, rb_method_node(klass, id), recv, CLASS_OF(recv)); \
  147: } while (0)
  148: 
  149: #endif /* _INSNHELPER_H_INCLUDED_ */
Syntax (Markdown)