diff --git a/compile.c b/compile.c index ba5fae336d..a61c5866af 100644 --- a/compile.c +++ b/compile.c @@ -3725,11 +3725,11 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) level++; if (ip->compile_data->redo_label != 0) { - level = 0x8000; + level = VM_THROW_NO_ESCAPE_FLAG; goto break_by_insn; } else if (ip->type == ISEQ_TYPE_BLOCK) { - level <<= 16; + level <<= VM_THROW_LEVEL_SHIFT; goto break_by_insn; } else if (ip->type == ISEQ_TYPE_EVAL) { @@ -3785,7 +3785,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) break; } - level = 0x8000; + level = VM_THROW_NO_ESCAPE_FLAG; if (ip->compile_data->redo_label != 0) { /* while loop */ break; @@ -3846,7 +3846,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) } else { const rb_iseq_t *ip = iseq; - unsigned long level = 0x8000; + const unsigned long level = VM_THROW_NO_ESCAPE_FLAG; while (ip) { if (!ip->compile_data) { diff --git a/vm_core.h b/vm_core.h index 7cb60aa2db..d032307269 100644 --- a/vm_core.h +++ b/vm_core.h @@ -145,6 +145,12 @@ enum ruby_tag_type { #define TAG_FATAL RUBY_TAG_FATAL #define TAG_MASK RUBY_TAG_MASK +enum ruby_vm_throw_flags { + VM_THROW_NO_ESCAPE_FLAG = 0x8000, + VM_THROW_LEVEL_SHIFT = 16, + VM_THROW_STATE_MASK = 0xff +}; + /* iseq data type */ struct iseq_compile_data_ensure_node_stack; diff --git a/vm_insnhelper.c b/vm_insnhelper.c index da4ea9db03..8e85174bed 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -830,7 +830,8 @@ vm_throw_continue(rb_thread_t *th, VALUE err) } static VALUE -vm_throw_start(rb_thread_t * const th, rb_control_frame_t * const reg_cfp, int state, const int flag, const rb_num_t level, const VALUE throwobj) +vm_throw_start(rb_thread_t *const th, rb_control_frame_t *const reg_cfp, enum ruby_tag_type state, + const int flag, const rb_num_t level, const VALUE throwobj) { rb_control_frame_t *escape_cfp = NULL; const rb_control_frame_t * const eocfp = RUBY_VM_END_CONTROL_FRAME(th); /* end of control frame pointer */ @@ -966,9 +967,9 @@ static VALUE vm_throw(rb_thread_t *th, rb_control_frame_t *reg_cfp, rb_num_t throw_state, VALUE throwobj) { - const int state = (int)(throw_state & 0xff); - const int flag = (int)(throw_state & 0x8000); - const rb_num_t level = throw_state >> 16; + const int state = (int)(throw_state & VM_THROW_STATE_MASK); + const int flag = (int)(throw_state & VM_THROW_NO_ESCAPE_FLAG); + const rb_num_t level = throw_state >> VM_THROW_LEVEL_SHIFT; if (state != 0) { return vm_throw_start(th, reg_cfp, state, flag, level, throwobj);