diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-04-05 08:15:11 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-04-05 08:15:11 +0000 |
commit | 2b5bb8a0875b75f18e628c8b2df22760536bdad9 (patch) | |
tree | ed4f1e080d81f7f5b47c8a10ce6c33285220bed5 /vm.c | |
parent | 7fe64d17d3cd455a3f014d6f756cb201320f7f9a (diff) |
add definemethod/definesmethod insn.
* insns.def: add definemethod and definesmethod (singleton method)
instructions. Old YARV contains these instructions, but it is moved
to methods of FrozenCore class because remove number of instructions
can improve performance for some techniques (static stack caching
and so on). However, we don't employ these technique and it is hard
to optimize/analysis definition sequence. So I decide to introduce
them (and remove definition methods). `putiseq` insn is also removed.
* vm_method.c (rb_scope_visibility_get): renamed to
`vm_scope_visibility_get()` and make it accept `ec`.
Same for `vm_scope_module_func_check()`.
These fixes are result of refactoring `vm_define_method`.
* vm_insnhelper.c (rb_vm_get_cref): renamed to `vm_get_cref`
because of consistency with other functions.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67442 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm.c')
-rw-r--r-- | vm.c | 57 |
1 files changed, 2 insertions, 55 deletions
@@ -1368,12 +1368,7 @@ rb_cref_t * rb_vm_cref(void) { const rb_execution_context_t *ec = GET_EC(); - const rb_control_frame_t *cfp = rb_vm_get_ruby_level_next_cfp(ec, ec->cfp); - - if (cfp == NULL) { - return NULL; - } - return rb_vm_get_cref(cfp->ep); + return vm_ec_cref(ec); } rb_cref_t * @@ -1393,7 +1388,7 @@ rb_vm_cref_in_context(VALUE self, VALUE cbase) const rb_cref_t *cref; if (cfp->self != self) return NULL; if (!vm_env_cref_by_cref(cfp->ep)) return NULL; - cref = rb_vm_get_cref(cfp->ep); + cref = vm_get_cref(cfp->ep); if (CREF_CLASS(cref) != cbase) return NULL; return cref; } @@ -2678,34 +2673,6 @@ rb_thread_alloc(VALUE klass) return self; } -static void -vm_define_method(VALUE obj, ID id, VALUE iseqval, int is_singleton) -{ - VALUE klass; - rb_method_visibility_t visi; - rb_cref_t *cref = rb_vm_cref(); - - if (!is_singleton) { - klass = CREF_CLASS(cref); - visi = rb_scope_visibility_get(); - } - else { /* singleton */ - klass = rb_singleton_class(obj); /* class and frozen checked in this API */ - visi = METHOD_VISI_PUBLIC; - } - - if (NIL_P(klass)) { - rb_raise(rb_eTypeError, "no class/module to add method"); - } - - rb_add_method_iseq(klass, id, (const rb_iseq_t *)iseqval, cref, visi); - - if (!is_singleton && rb_scope_module_func_check()) { - klass = rb_singleton_class(klass); - rb_add_method_iseq(klass, id, (const rb_iseq_t *)iseqval, cref, METHOD_VISI_PUBLIC); - } -} - #define REWIND_CFP(expr) do { \ rb_execution_context_t *ec__ = GET_EC(); \ VALUE *const curr_sp = (ec__->cfp++)->sp; \ @@ -2716,24 +2683,6 @@ vm_define_method(VALUE obj, ID id, VALUE iseqval, int is_singleton) } while (0) static VALUE -m_core_define_method(VALUE self, VALUE sym, VALUE iseqval) -{ - REWIND_CFP({ - vm_define_method(Qnil, SYM2ID(sym), iseqval, FALSE); - }); - return sym; -} - -static VALUE -m_core_define_singleton_method(VALUE self, VALUE cbase, VALUE sym, VALUE iseqval) -{ - REWIND_CFP({ - vm_define_method(cbase, SYM2ID(sym), iseqval, TRUE); - }); - return sym; -} - -static VALUE m_core_set_method_alias(VALUE self, VALUE cbase, VALUE sym1, VALUE sym2) { REWIND_CFP({ @@ -2931,8 +2880,6 @@ Init_VM(void) rb_define_method_id(klass, id_core_set_method_alias, m_core_set_method_alias, 3); rb_define_method_id(klass, id_core_set_variable_alias, m_core_set_variable_alias, 2); rb_define_method_id(klass, id_core_undef_method, m_core_undef_method, 2); - rb_define_method_id(klass, id_core_define_method, m_core_define_method, 2); - rb_define_method_id(klass, id_core_define_singleton_method, m_core_define_singleton_method, 3); rb_define_method_id(klass, id_core_set_postexe, m_core_set_postexe, 0); rb_define_method_id(klass, id_core_hash_merge_ptr, m_core_hash_merge_ptr, -1); rb_define_method_id(klass, id_core_hash_merge_kwd, m_core_hash_merge_kwd, 2); |