diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-06-02 19:15:29 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-06-02 19:15:29 +0000 |
commit | 15164bf33cf27f38cd5657e2b58acfd9a312f2ed (patch) | |
tree | f939e6fdde282f61ea440b773a3d2dc841611767 | |
parent | 86bafab212c2d73f02386a5e8440f9a72a86ae31 (diff) | |
download | ruby-15164bf33cf27f38cd5657e2b58acfd9a312f2ed.tar.gz |
* insns.def (defined), vm_insnhelper.c (vm_defined):
move instruction body to the vm_defined() function.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50736 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | insns.def | 101 | ||||
-rw-r--r-- | vm_insnhelper.c | 108 |
3 files changed, 114 insertions, 100 deletions
@@ -1,3 +1,8 @@ +Wed Jun 3 04:14:13 2015 Koichi Sasada <ko1@atdot.net> + + * 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@gmail.com> * test/ruby/test_module.rb: Do not assume class variable order. @@ -715,106 +715,7 @@ defined (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); } /** diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 7f9905eda7..4601f80dc9 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -2406,3 +2406,111 @@ FUNC_FASTCALL(rb_vm_opt_struct_aset)(rb_thread_t *th, rb_control_frame_t *reg_cf 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; + } +} |