ruby-changes:38655
From: ko1 <ko1@a...>
Date: Wed, 3 Jun 2015 04:15:43 +0900 (JST)
Subject: [ruby-changes:38655] ko1:r50736 (trunk): * insns.def (defined), vm_insnhelper.c (vm_defined):
ko1 2015-06-03 04:15:29 +0900 (Wed, 03 Jun 2015) New Revision: 50736 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50736 Log: * insns.def (defined), vm_insnhelper.c (vm_defined): move instruction body to the vm_defined() function. Modified files: trunk/ChangeLog trunk/insns.def trunk/vm_insnhelper.c Index: insns.def =================================================================== --- insns.def (revision 50735) +++ insns.def (revision 50736) @@ -715,106 +715,7 @@ defined https://github.com/ruby/ruby/blob/trunk/insns.def#L715 (VALUE v) (VALUE val) { - VALUE klass; - enum defined_type expr_type = 0; - enum defined_type type = (enum defined_type)op_type; - - val = Qnil; - - switch (type) { - case DEFINED_IVAR: - if (rb_ivar_defined(GET_SELF(), SYM2ID(obj))) { - expr_type = DEFINED_IVAR; - } - break; - case DEFINED_IVAR2: - klass = vm_get_cbase(GET_EP()); - break; - case DEFINED_GVAR: - if (rb_gvar_defined(rb_global_entry(SYM2ID(obj)))) { - expr_type = DEFINED_GVAR; - } - break; - case DEFINED_CVAR: { - const rb_cref_t *cref = rb_vm_get_cref(GET_EP()); - klass = vm_get_cvar_base(cref, GET_CFP()); - if (rb_cvar_defined(klass, SYM2ID(obj))) { - expr_type = DEFINED_CVAR; - } - break; - } - case DEFINED_CONST: - klass = v; - if (vm_get_ev_const(th, klass, SYM2ID(obj), 1)) { - expr_type = DEFINED_CONST; - } - break; - case DEFINED_FUNC: - klass = CLASS_OF(v); - if (rb_method_boundp(klass, SYM2ID(obj), 0)) { - expr_type = DEFINED_METHOD; - } - break; - case DEFINED_METHOD:{ - VALUE klass = CLASS_OF(v); - const rb_method_entry_t *me = rb_method_entry(klass, SYM2ID(obj), 0); - - if (me) { - const rb_method_definition_t *def = me->def; - if (!(def->flag & NOEX_PRIVATE)) { - if (!((def->flag & NOEX_PROTECTED) && - !rb_obj_is_kind_of(GET_SELF(), - rb_class_real(klass)))) { - expr_type = DEFINED_METHOD; - } - } - } - { - VALUE args[2]; - VALUE r; - - args[0] = obj; args[1] = Qfalse; - r = rb_check_funcall(v, idRespond_to_missing, 2, args); - if (r != Qundef && RTEST(r)) - expr_type = DEFINED_METHOD; - } - break; - } - case DEFINED_YIELD: - if (GET_BLOCK_PTR()) { - expr_type = DEFINED_YIELD; - } - break; - case DEFINED_ZSUPER:{ - rb_call_info_t cit; - if (vm_search_superclass(GET_CFP(), GET_ISEQ(), Qnil, &cit) == 0) { - VALUE klass = cit.klass; - ID id = cit.mid; - if (rb_method_boundp(klass, id, 0)) { - expr_type = DEFINED_ZSUPER; - } - } - break; - } - case DEFINED_REF:{ - val = vm_getspecial(th, GET_LEP(), Qfalse, FIX2INT(obj)); - if (val != Qnil) { - expr_type = DEFINED_GVAR; - } - break; - } - default: - rb_bug("unimplemented defined? type (VM)"); - break; - } - if (expr_type != 0) { - if (needstr != Qfalse) { - val = rb_iseq_defined_string(expr_type); - } - else { - val = Qtrue; - } - } + val = vm_defined(th, GET_CFP(), op_type, obj, needstr, v); } /** Index: ChangeLog =================================================================== --- ChangeLog (revision 50735) +++ ChangeLog (revision 50736) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Jun 3 04:14:13 2015 Koichi Sasada <ko1@a...> + + * insns.def (defined), vm_insnhelper.c (vm_defined): + move instruction body to the vm_defined() function. + Wed Jun 3 02:29:25 2015 Benoit Daloze <eregontp@g...> * test/ruby/test_module.rb: Do not assume class variable order. Index: vm_insnhelper.c =================================================================== --- vm_insnhelper.c (revision 50735) +++ vm_insnhelper.c (revision 50736) @@ -2406,3 +2406,111 @@ FUNC_FASTCALL(rb_vm_opt_struct_aset)(rb_ https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L2406 rb_struct_aset(GET_SELF(), TOPN(0), TOPN(1)); return reg_cfp; } + +/* defined insn */ + +static VALUE +vm_defined(rb_thread_t *th, rb_control_frame_t *reg_cfp, rb_num_t op_type, VALUE obj, VALUE needstr, VALUE v) +{ + VALUE klass; + enum defined_type expr_type = 0; + 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; + } + break; + case DEFINED_IVAR2: + klass = vm_get_cbase(GET_EP()); + break; + case DEFINED_GVAR: + if (rb_gvar_defined(rb_global_entry(SYM2ID(obj)))) { + expr_type = DEFINED_GVAR; + } + break; + case DEFINED_CVAR: { + const rb_cref_t *cref = rb_vm_get_cref(GET_EP()); + klass = vm_get_cvar_base(cref, GET_CFP()); + if (rb_cvar_defined(klass, SYM2ID(obj))) { + expr_type = DEFINED_CVAR; + } + break; + } + case DEFINED_CONST: + klass = v; + if (vm_get_ev_const(th, klass, SYM2ID(obj), 1)) { + expr_type = DEFINED_CONST; + } + break; + case DEFINED_FUNC: + klass = CLASS_OF(v); + if (rb_method_boundp(klass, SYM2ID(obj), 0)) { + expr_type = DEFINED_METHOD; + } + break; + case DEFINED_METHOD:{ + VALUE klass = CLASS_OF(v); + const rb_method_entry_t *me = rb_method_entry(klass, SYM2ID(obj), 0); + + if (me) { + const rb_method_definition_t *def = me->def; + if (!(def->flag & NOEX_PRIVATE)) { + if (!((def->flag & NOEX_PROTECTED) && + !rb_obj_is_kind_of(GET_SELF(), + rb_class_real(klass)))) { + expr_type = DEFINED_METHOD; + } + } + } + { + VALUE args[2]; + VALUE r; + + args[0] = obj; args[1] = Qfalse; + r = rb_check_funcall(v, idRespond_to_missing, 2, args); + if (r != Qundef && RTEST(r)) + expr_type = DEFINED_METHOD; + } + break; + } + case DEFINED_YIELD: + if (GET_BLOCK_PTR()) { + expr_type = DEFINED_YIELD; + } + break; + case DEFINED_ZSUPER:{ + rb_call_info_t cit; + if (vm_search_superclass(GET_CFP(), GET_ISEQ(), Qnil, &cit) == 0) { + VALUE klass = cit.klass; + ID id = cit.mid; + if (rb_method_boundp(klass, id, 0)) { + expr_type = DEFINED_ZSUPER; + } + } + break; + } + case DEFINED_REF:{ + if (vm_getspecial(th, GET_LEP(), Qfalse, FIX2INT(obj)) != Qnil) { + expr_type = DEFINED_GVAR; + } + break; + } + default: + rb_bug("unimplemented defined? type (VM)"); + break; + } + + if (expr_type != 0) { + if (needstr != Qfalse) { + return rb_iseq_defined_string(expr_type); + } + else { + return Qtrue; + } + } + else { + return Qnil; + } +} -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/