From: "きたざわけんいち" Date: 2011-03-06T22:33:01+09:00 Subject: [ruby-dev:43319] Re: iseq_compile_each()でのマジックナンバ きたざわです。 何度も何度も、すいません。 TAG_xxxをマジックナンバのままでした。 あと、やっぱり > - int state = (int)(throw_state & 0xff); > - int flag = (int)(throw_state & 0x8000); > - rb_num_t level = throw_state >> 16; のあたりをマクロにしました。 Index: vm_core.h =================================================================== --- vm_core.h (リビジョン 31028) +++ vm_core.h (作業コピー) @@ -583,6 +583,13 @@ #define RUBYVM_CFUNC_FRAME_P(cfp) \ (VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_CFUNC) +/* vm_throw state */ +#define VM_THROW_NO_DFP 0x8000 +#define VM_THROW_STATE_MASK 0xff +#define VM_THROW_LEVEL_SHIFT 16 +#define GET_VM_THROW_STATE(s) ((int)(s & VM_THROW_STATE_MASK)) +#define GET_VM_THROW_NO_DFP(s) ((int)(s & VM_THROW_NO_DFP)) +#define GET_VM_THROW_LEVEL(s) ((rb_num_t)(s >> VM_THROW_LEVEL_SHIFT)) /* inline cache */ typedef struct iseq_inline_cache_entry *IC; Index: compile.c =================================================================== --- compile.c (リビジョン 31028) +++ compile.c (作業コピー) @@ -14,6 +14,7 @@ #define USE_INSN_STACK_INCREASE 1 #include "vm_core.h" +#include "eval_intern.h" #include "iseq.h" #include "insns.inc" #include "insns_info.inc" @@ -3336,7 +3337,7 @@ break_by_insn: /* escape from block */ COMPILE(ret, "break val (block)", node->nd_stts); - ADD_INSN1(ret, nd_line(node), throw, INT2FIX(level | 0x02) /* TAG_BREAK */ ); + ADD_INSN1(ret, nd_line(node), throw, INT2FIX(level | TAG_BREAK) /* TAG_BREAK */ ); if (poped) { ADD_INSN(ret, nd_line(node), pop); } @@ -3355,11 +3356,7 @@ level++; if (ip->compile_data->redo_label != 0) { - level = 0x8000; - if (ip->compile_data->loopval_popped == 0) { - /* need value */ - level |= 0x4000; - } + level = VM_THROW_NO_DFP; goto break_by_insn; } else if (ip->type == ISEQ_TYPE_BLOCK) { @@ -3419,7 +3416,7 @@ break; } - level = 0x8000 | 0x4000; + level = VM_THROW_NO_DFP; if (ip->compile_data->redo_label != 0) { /* while loop */ break; @@ -3435,7 +3432,7 @@ } if (ip != 0) { COMPILE(ret, "next val", node->nd_stts); - ADD_INSN1(ret, nd_line(node), throw, INT2FIX(level | 0x03) /* TAG_NEXT */ ); + ADD_INSN1(ret, nd_line(node), throw, INT2FIX(level | TAG_NEXT) /* TAG_NEXT */ ); if (poped) { ADD_INSN(ret, nd_line(node), pop); @@ -3481,7 +3478,7 @@ else { rb_iseq_t *ip; unsigned long level; - level = 0x8000 | 0x4000; + level = VM_THROW_NO_DFP; ip = iseq; while (ip) { if (!ip->compile_data) { @@ -3503,7 +3500,7 @@ } if (ip != 0) { ADD_INSN(ret, nd_line(node), putnil); - ADD_INSN1(ret, nd_line(node), throw, INT2FIX(level | 0x05) /* TAG_REDO */ ); + ADD_INSN1(ret, nd_line(node), throw, INT2FIX(level | TAG_REDO) /* TAG_REDO */ ); if (poped) { ADD_INSN(ret, nd_line(node), pop); @@ -3518,7 +3515,7 @@ case NODE_RETRY:{ if (iseq->type == ISEQ_TYPE_RESCUE) { ADD_INSN(ret, nd_line(node), putnil); - ADD_INSN1(ret, nd_line(node), throw, INT2FIX(0x04) /* TAG_RETRY */ ); + ADD_INSN1(ret, nd_line(node), throw, INT2FIX(TAG_RETRY) /* TAG_RETRY */ ); if (poped) { ADD_INSN(ret, nd_line(node), pop); @@ -4316,7 +4313,7 @@ } } else { - ADD_INSN1(ret, nd_line(node), throw, INT2FIX(0x01) /* TAG_RETURN */ ); + ADD_INSN1(ret, nd_line(node), throw, INT2FIX(TAG_RETURN) /* TAG_RETURN */ ); if (poped) { ADD_INSN(ret, nd_line(node), pop); } Index: vm_insnhelper.c =================================================================== --- vm_insnhelper.c (リビジョン 31028) +++ vm_insnhelper.c (作業コピー) @@ -1432,9 +1432,9 @@ vm_throw(rb_thread_t *th, rb_control_frame_t *reg_cfp, rb_num_t throw_state, VALUE throwobj) { - int state = (int)(throw_state & 0xff); - int flag = (int)(throw_state & 0x8000); - rb_num_t level = throw_state >> 16; + int state = GET_VM_THROW_STATE(throw_state); + int flag = GET_VM_THROW_NO_DFP(throw_state); + rb_num_t level = GET_VM_THROW_LEVEL(throw_state); if (state != 0) { VALUE *pt = 0; -- --- ぺーさん(peisunstar@gmail.com)