12#ifndef RUBY_INSNHELPER_H
13#define RUBY_INSNHELPER_H
24#if VM_COLLECT_USAGE_DETAILS
25#define COLLECT_USAGE_INSN(insn) vm_collect_usage_insn(insn)
26#define COLLECT_USAGE_OPERAND(insn, n, op) vm_collect_usage_operand((insn), (n), ((VALUE)(op)))
28#define COLLECT_USAGE_REGISTER(reg, s) vm_collect_usage_register((reg), (s))
30#define COLLECT_USAGE_INSN(insn)
31#define COLLECT_USAGE_OPERAND(insn, n, op)
32#define COLLECT_USAGE_REGISTER(reg, s)
39#define PUSH(x) (SET_SV(x), INC_SP(1))
40#define TOPN(n) (*(GET_SP()-(n)-1))
41#define POPN(n) (DEC_SP(n))
42#define POP() (DEC_SP(1))
43#define STACK_ADDR_FROM_TOP(n) (GET_SP()-(n))
49#define VM_REG_CFP (reg_cfp)
50#define VM_REG_PC (VM_REG_CFP->pc)
51#define VM_REG_SP (VM_REG_CFP->sp)
52#define VM_REG_EP (VM_REG_CFP->ep)
54#define RESTORE_REGS() do { \
55 VM_REG_CFP = ec->cfp; \
58#if VM_COLLECT_USAGE_DETAILS
59enum vm_regan_regtype {
67enum vm_regan_acttype {
72#define COLLECT_USAGE_REGISTER_HELPER(a, b, v) \
73 (COLLECT_USAGE_REGISTER((VM_REGAN_##a), (VM_REGAN_ACT_##b)), (v))
75#define COLLECT_USAGE_REGISTER_HELPER(a, b, v) (v)
79#define GET_PC() (COLLECT_USAGE_REGISTER_HELPER(PC, GET, VM_REG_PC))
80#define SET_PC(x) (VM_REG_PC = (COLLECT_USAGE_REGISTER_HELPER(PC, SET, (x))))
81#define GET_CURRENT_INSN() (*GET_PC())
82#define GET_OPERAND(n) (GET_PC()[(n)])
83#define ADD_PC(n) (SET_PC(VM_REG_PC + (n)))
84#define JUMP(dst) (SET_PC(VM_REG_PC + (dst)))
87#define GET_CFP() (COLLECT_USAGE_REGISTER_HELPER(CFP, GET, VM_REG_CFP))
88#define GET_EP() (COLLECT_USAGE_REGISTER_HELPER(EP, GET, VM_REG_EP))
89#define SET_EP(x) (VM_REG_EP = (COLLECT_USAGE_REGISTER_HELPER(EP, SET, (x))))
90#define GET_LEP() (VM_EP_LEP(GET_EP()))
93#define GET_SP() (COLLECT_USAGE_REGISTER_HELPER(SP, GET, VM_REG_SP))
94#define SET_SP(x) (VM_REG_SP = (COLLECT_USAGE_REGISTER_HELPER(SP, SET, (x))))
95#define INC_SP(x) (VM_REG_SP += (COLLECT_USAGE_REGISTER_HELPER(SP, SET, (x))))
96#define DEC_SP(x) (VM_REG_SP -= (COLLECT_USAGE_REGISTER_HELPER(SP, SET, (x))))
97#define SET_SV(x) (*GET_SP() = (x))
101#define GET_ISEQ() (GET_CFP()->iseq)
107#define GET_PREV_EP(ep) ((VALUE *)((ep)[VM_ENV_DATA_INDEX_SPECVAL] & ~0x03))
113#define GET_SELF() (COLLECT_USAGE_REGISTER_HELPER(SELF, GET, GET_CFP()->self))
138#define GET_BLOCK_HANDLER() (GET_LEP()[VM_ENV_DATA_INDEX_SPECVAL])
150#define SETUP_CANARY() \
154 SET_SV(vm_stack_canary); \
159#define CHECK_CANARY() \
161 if (*canary == vm_stack_canary) { \
165 vm_canary_is_found_dead(INSN_ATTR(bin), *canary); \
169#define SETUP_CANARY()
170#define CHECK_CANARY()
178#define CALL_SIMPLE_METHOD() do { \
179 rb_snum_t x = leaf ? INSN_ATTR(width) : 0; \
180 rb_snum_t y = attr_width_opt_send_without_block(0); \
181 rb_snum_t z = x - y; \
183 DISPATCH_ORIGINAL_INSN(opt_send_without_block); \
187#define PREV_CLASS_SERIAL() (ruby_vm_class_serial)
188#define NEXT_CLASS_SERIAL() (++ruby_vm_class_serial)
189#define GET_GLOBAL_METHOD_STATE() (ruby_vm_global_method_state)
190#define INC_GLOBAL_METHOD_STATE() (++ruby_vm_global_method_state)
191#define GET_GLOBAL_CONSTANT_STATE() (ruby_vm_global_constant_state)
192#define INC_GLOBAL_CONSTANT_STATE() (++ruby_vm_global_constant_state)
198 obj->throw_state =
st;
206 return obj->throw_obj;
213 return obj->catch_frame;
220 return obj->throw_state;
241 obj->throw_state =
st;
253#define IS_ARGS_SPLAT(ci) ((ci)->flag & VM_CALL_ARGS_SPLAT)
254#define IS_ARGS_KEYWORD(ci) ((ci)->flag & VM_CALL_KWARG)
255#define IS_ARGS_KW_SPLAT(ci) ((ci)->flag & VM_CALL_KW_SPLAT)
256#define IS_ARGS_KW_OR_KW_SPLAT(ci) ((ci)->flag & (VM_CALL_KWARG | VM_CALL_KW_SPLAT))
const struct rb_callable_method_entry_struct * me
VALUE(* call)(struct rb_execution_context_struct *ec, struct rb_control_frame_struct *cfp, struct rb_calling_info *calling, struct rb_call_data *cd)
struct rb_method_definition_struct *const def
RUBY_SYMBOL_EXPORT_BEGIN RUBY_EXTERN VALUE ruby_vm_const_missing_count
#define IS_ARGS_SPLAT(ci)
RUBY_EXTERN rb_serial_t ruby_vm_global_method_state
#define IS_ARGS_KEYWORD(ci)
RUBY_EXTERN rb_serial_t ruby_vm_global_constant_state
RUBY_EXTERN rb_serial_t ruby_vm_class_serial