diff --git a/insns.def b/insns.def index ca56416d23..1dc0bb3365 100644 --- a/insns.def +++ b/insns.def @@ -667,12 +667,10 @@ defined (VALUE val) // attr bool leaf = leafness_of_defined(op_type); { + val = Qnil; if (vm_defined(ec, GET_CFP(), op_type, obj, v)) { val = needstr; } - else { - val = Qnil; - } } /* check `target' matches `pattern'. diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 81ac2eb273..f343de0be4 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -3969,7 +3969,7 @@ vm_once_clear(VALUE data) /* defined insn */ -static enum defined_type +static VALUE check_respond_to_missing(VALUE obj, VALUE v) { VALUE args[2]; @@ -3978,10 +3978,10 @@ check_respond_to_missing(VALUE obj, VALUE v) args[0] = obj; args[1] = Qfalse; r = rb_check_funcall(v, idRespond_to_missing, 2, args); if (r != Qundef && RTEST(r)) { - return DEFINED_METHOD; + return Qtrue; } else { - return DEFINED_NOT_DEFINED; + return Qfalse; } } @@ -3989,42 +3989,31 @@ static VALUE vm_defined(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, rb_num_t op_type, VALUE obj, VALUE v) { VALUE klass; - enum defined_type expr_type = DEFINED_NOT_DEFINED; enum defined_type type = (enum defined_type)op_type; switch (type) { case DEFINED_IVAR: - if (rb_ivar_defined(GET_SELF(), SYM2ID(obj))) { - expr_type = DEFINED_IVAR; - } + return rb_ivar_defined(GET_SELF(), SYM2ID(obj)); break; case DEFINED_GVAR: - if (rb_gvar_defined(SYM2ID(obj))) { - expr_type = DEFINED_GVAR; - } + return rb_gvar_defined(SYM2ID(obj)); break; case DEFINED_CVAR: { const rb_cref_t *cref = vm_get_cref(GET_EP()); klass = vm_get_cvar_base(cref, GET_CFP(), 0); - if (rb_cvar_defined(klass, SYM2ID(obj))) { - expr_type = DEFINED_CVAR; - } + return rb_cvar_defined(klass, SYM2ID(obj)); break; } case DEFINED_CONST: case DEFINED_CONST_FROM: { bool allow_nil = type == DEFINED_CONST; klass = v; - if (vm_get_ev_const(ec, klass, SYM2ID(obj), allow_nil, true)) { - expr_type = DEFINED_CONST; - } + return vm_get_ev_const(ec, klass, SYM2ID(obj), allow_nil, true); break; } case DEFINED_FUNC: klass = CLASS_OF(v); - if (rb_ec_obj_respond_to(ec, v, SYM2ID(obj), TRUE)) { - expr_type = DEFINED_METHOD; - } + return rb_ec_obj_respond_to(ec, v, SYM2ID(obj), TRUE); break; case DEFINED_METHOD:{ VALUE klass = CLASS_OF(v); @@ -4039,20 +4028,20 @@ vm_defined(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, rb_num_t op_ break; } case METHOD_VISI_PUBLIC: - expr_type = DEFINED_METHOD; + return Qtrue; break; default: rb_bug("vm_defined: unreachable: %u", (unsigned int)METHOD_ENTRY_VISI(me)); } } else { - expr_type = check_respond_to_missing(obj, v); + return check_respond_to_missing(obj, v); } break; } case DEFINED_YIELD: if (GET_BLOCK_HANDLER() != VM_BLOCK_HANDLER_NONE) { - expr_type = DEFINED_YIELD; + return Qtrue; } break; case DEFINED_ZSUPER: @@ -4063,16 +4052,12 @@ vm_defined(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, rb_num_t op_ VALUE klass = vm_search_normal_superclass(me->defined_class); ID id = me->def->original_id; - if (rb_method_boundp(klass, id, 0)) { - expr_type = DEFINED_ZSUPER; - } + return rb_method_boundp(klass, id, 0); } } break; case DEFINED_REF:{ - if (vm_getspecial(ec, GET_LEP(), Qfalse, FIX2INT(obj)) != Qnil) { - expr_type = DEFINED_GVAR; - } + return vm_getspecial(ec, GET_LEP(), Qfalse, FIX2INT(obj)) != Qnil; break; } default: @@ -4080,12 +4065,7 @@ vm_defined(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, rb_num_t op_ break; } - if (expr_type != 0) { - return Qtrue; - } - else { - return Qfalse; - } + return Qfalse; } static const VALUE *