Граф коммитов

460 Коммитов

Автор SHA1 Сообщение Дата
ko1 731c9288da * vm_core.h: remove rb_call_info_t::aux.opt_pc.
* vm_insnhelper.c: introduce shortcut functions for opt_pc == 0
  because opt_pc is always 0 on shortcut function.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51827 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-11 18:25:54 +00:00
nobu 9c7bf9494b vm_insnhelper.c: use update argc
* vm_insnhelper.c (vm_invoke_block): use ci->argc updated by
  CALLER_SETUP_ARG().  [Bug #11451]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51655 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-08-21 15:31:39 +00:00
ko1 416aa45918 * vm_insnhelper.c (vm_invoke_block): we should not expect ci->argc is
stable after invoking a block. [Bug #11451]
* test/ruby/test_yield.rb: add a test. This test script is given by
  Alex Dowad.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-08-21 08:37:46 +00:00
nobu 288f6e1b89 vm_insnhelper.c: suppress a warning
* vm_insnhelper.c (vm_setivar): cast to long both side of a
  conditional expression to suppress a sign-compare warning.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51391 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-26 06:24:18 +00:00
ko1 22be6d06ab * vm_core.h: size should be unsigned.
* rb_call_info_t::index
  * rb_iseq_constant_body::stack_max
  * rb_iseq_constant_body::local_size
  * rb_iseq_constant_body::param::size
  * rb_iseq_constant_body::local_table_size
  * rb_iseq_constant_body::is_size
  * rb_iseq_constant_body::callinfo_size
* iseq.h: same for iseq_catch_table::size.
* compile.c: catch up these fix.
* iseq.c: ditto.
* proc.c: ditto.
* vm.c: ditto.
* vm_args.c: ditto.
* vm_eval.c: ditto.
* vm_insnhelper.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51369 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-24 21:44:14 +00:00
ko1 e4198a73d4 * make rb_iseq_t T_IMEMO object (type is imemo_iseq).
All contents of previous rb_iseq_t is in rb_iseq_t::body.
  Remove rb_iseq_t::self because rb_iseq_t is an object.
  RubyVM::InstructionSequence is wrapper object points T_IMEMO/iseq.
  So RubyVM::ISeq.of(something) method returns different wrapper
  objects but they point the same T_IMEMO/iseq object.
  This patch is big, but most of difference is replacement of
  iseq->xxx to iseq->body->xxx.
  (previous) rb_iseq_t::compile_data is also located to
  rb_iseq_t::compile_data.
  It was moved from rb_iseq_body::compile_data.
  Now rb_iseq_t has empty two pointers.
  I will split rb_iseq_body data into static data and dynamic data.
* compile.c: rename some functions/macros.
  Now, we don't need to separate iseq and iseqval (only VALUE).
* eval.c (ruby_exec_internal): `n' is rb_iseq_t (T_IMEMO/iseq).
* ext/objspace/objspace.c (count_imemo_objects): count T_IMEMO/iseq.
* gc.c: check T_IMEMO/iseq.
* internal.h: add imemo_type::imemo_iseq.
* iseq.c: define RubyVM::InstructionSequnce as T_OBJECT.
  Methods are implemented by functions named iseqw_....
* load.c (rb_load_internal0): rb_iseq_new_top() returns
  rb_iseq_t (T_IMEMO/iesq).
* method.h (rb_add_method_iseq): accept rb_iseq_t (T_IMEMO/iseq).
* vm_core.h (GetISeqPtr): removed because it is not T_DATA now.
* vm_core.h (struct rb_iseq_body): remove padding for
  [Bug #10037][ruby-core:63721].



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51327 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-21 22:52:59 +00:00
ko1 948bd807c3 * vm_core.h: constify rb_call_info_t::blockiseq and rb_iseq_t::iseq.
* vm.c, vm_insnhelper.c: catch up this fix.
* iseq.c (iseq_data_to_ary): constify the first iseq parameter.
* vm_insnhelper.c (vm_make_proc_with_iseq): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51323 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-21 21:28:43 +00:00
ko1 c5618920ed * method.h: constify rb_method_iseq_t::iseqptr.
* proc.c (rb_method_entry_min_max_arity): catch up this fix.
* vm_insnhelper.c (def_iseq_ptr): constify.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51322 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-21 21:19:02 +00:00
nobu 1b8ff4f799 ruby_vm_throw_flags
* vm_core.h (ruby_vm_throw_flags): constants for throw.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51300 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-20 00:08:23 +00:00
ko1 c3e8cca950 * vm_core.h: constify rb_iseq_t::parent_iseq.
rb_iseq_t::local_iseq is not constant data because
  local_iseq::flip_cnt can be modified (commentted).
* compile.c: catch up this fix.
* iseq.c: ditto.
* vm_insnhelper.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51269 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-16 13:13:50 +00:00
ko1 f23adf7459 * vm_insnhelper.c (vm_search_super_method): use CI_SET_FASTPATH().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51201 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-09 04:04:30 +00:00
ko1 d53e1a7937 * vm_core.h: remove rb_call_info_t::klass because
rb_callable_method_entry_t has information about defined class.
* vm_insnhelper.c (vm_search_method): don't set ci->klass because
  it is removed.
* vm_insnhelper.c (rb_equal_opt): ditto.
* vm_insnhelper.c (vm_search_superclass): removed because it is too
  simple to write code directly.
* vm_insnhelper.c (vm_defined): don't use vm_search_superclass().
  This fix avoid searching current callable `me' twice.
* vm_insnhelper.c (vm_search_super_method): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51200 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-09 02:10:51 +00:00
ko1 02d5868962 * vm_core.h: remove rb_iseq_t::klass to reduce dynamic data.
* internal.h, iseq.c (rb_iseq_klass): remove it because
  rb_iseq_t::klass is removed.
* vm_insnhelper.c (vm_super_outside): do not see cfp->iseq, but
  check callable method entry on a frame.
  This fix simplify the logic to search super class.
* test/ruby/test_method.rb: support super() from Proc.
  Now, [Bug #4881] and [Bug #3136] was solved.
* proc.c (rb_mod_define_method): catch up this change.
* vm.c (vm_define_method): ditto.
* vm_backtrace.c (rb_profile_frames): now, each `frame' objects
  are rb_callable_method_entry_t data or iseq VALUEs.
  This fix introduce minor compatibility issue that
  rb_profile_frame_label() always returns
  rb_profile_frame_base_label().
* test/-ext-/debug/test_profile_frames.rb: catch up this change.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-06 18:44:54 +00:00
ko1 c8854d2ca4 * vm_insnhelper.c (vm_search_super_method): do not skip calling
same methods in super.
  [Bug #3351]
* test/ruby/test_super.rb: fix a test.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51161 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-06 09:02:34 +00:00
ko1 5e8a147480 * method.h: introduce rb_callable_method_entry_t to remove
rb_control_frame_t::klass.
  [Bug #11278], [Bug #11279]
  rb_method_entry_t data belong to modules/classes.
  rb_method_entry_t::owner points defined module or class.
    module M
      def foo; end
    end
  In this case, owner is M.
  rb_callable_method_entry_t data belong to only classes.
  For modules, MRI creates corresponding T_ICLASS internally.
  rb_callable_method_entry_t can also belong to T_ICLASS.
  rb_callable_method_entry_t::defined_class points T_CLASS or
  T_ICLASS.
  rb_method_entry_t data for classes (not for modules) are also
  rb_callable_method_entry_t data because it is completely same data.
  In this case, rb_method_entry_t::owner == rb_method_entry_t::defined_class.
  For example, there are classes C and D, and incldues M,
    class C; include M; end
    class D; include M; end
  then, two T_ICLASS objects for C's super class and D's super class
  will be created.
  When C.new.foo is called, then M#foo is searcheed and
  rb_callable_method_t data is used by VM to invoke M#foo.
  rb_method_entry_t data is only one for M#foo.
  However, rb_callable_method_entry_t data are two (and can be more).
  It is proportional to the number of including (and prepending)
  classes (the number of T_ICLASS which point to the module).
  Now, created rb_callable_method_entry_t are collected when
  the original module M was modified. We can think it is a cache.
  We need to select what kind of method entry data is needed.
  To operate definition, then you need to use rb_method_entry_t.
  You can access them by the following functions.
  * rb_method_entry(VALUE klass, ID id);
  * rb_method_entry_with_refinements(VALUE klass, ID id);
  * rb_method_entry_without_refinements(VALUE klass, ID id);
  * rb_resolve_refined_method(VALUE refinements, const rb_method_entry_t *me);
  To invoke methods, then you need to use rb_callable_method_entry_t
  which you can get by the following APIs corresponding to the
  above listed functions.
  * rb_callable_method_entry(VALUE klass, ID id);
  * rb_callable_method_entry_with_refinements(VALUE klass, ID id);
  * rb_callable_method_entry_without_refinements(VALUE klass, ID id);
  * rb_resolve_refined_method_callable(VALUE refinements, const rb_callable_method_entry_t *me);
  VM pushes rb_callable_method_entry_t, so that rb_vm_frame_method_entry()
  returns rb_callable_method_entry_t.
  You can check a super class of current method by
  rb_callable_method_entry_t::defined_class.
* method.h: renamed from rb_method_entry_t::klass to
  rb_method_entry_t::owner.
* internal.h: add rb_classext_struct::callable_m_tbl to cache
  rb_callable_method_entry_t data.
  We need to consider abotu this field again because it is only
  active for T_ICLASS.
* class.c (method_entry_i): ditto.
* class.c (rb_define_attr): rb_method_entry() does not takes
  defiend_class_ptr.
* gc.c (mark_method_entry): mark RCLASS_CALLABLE_M_TBL() for T_ICLASS.
* cont.c (fiber_init): rb_control_frame_t::klass is removed.
* proc.c: fix `struct METHOD' data structure because
  rb_callable_method_t has all information.
* vm_core.h: remove several fields.
  * rb_control_frame_t::klass.
  * rb_block_t::klass.
  And catch up changes.
* eval.c: catch up changes.
* gc.c: ditto.
* insns.def: ditto.
* vm.c: ditto.
* vm_args.c: ditto.
* vm_backtrace.c: ditto.
* vm_dump.c: ditto.
* vm_eval.c: ditto.
* vm_insnhelper.c: ditto.
* vm_method.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-03 11:24:50 +00:00
ko1 c7edd997e8 * vm.c: use VM_ASSERT instead of assert().
* vm_args.c: ditto.
* vm_insnhelper.c: ditto.
* vm_method.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50822 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-10 23:42:01 +00:00
ko1 85647d9f2b * vm_core.h: define VM_ASSERT() for assertion
enabled only when (VM_CHECK_MODE > 0).
* vm_insnhelper.c: move definition VM_CHECK_MODE
  from vm_insnhelper.c to vm_core.h.
* vm.c: remove <assert.h>



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50821 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-10 23:25:30 +00:00
ko1 62a81ad98c * vm_insnhelper.c (check_frame): check type of cref_or_me first.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50820 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-10 21:56:23 +00:00
ko1 c19d373750 * method.h: back to share rb_method_definition_t by
rb_method_entry_t.
  r50728 changed sharing `def's to isolating `def's
  on alias and so on. However, this change conflicts
  future improvement plan. So I change back to sharing approach.
* method.h: move rb_method_definition_t::flags to
  rb_method_entry_t::attr::flags.
  rb_method_entry_t::attr is union with VALUE because this field
  should have same size of VALUE. rb_method_entry_t is T_IMEMO).
  And also add the following access macros to it's fileds.
  * METHOD_ENTRY_VISI(me)
  * METHOD_ENTRY_BASIC(me)
  * METHOD_ENTRY_SAFE(me)
* vm_method.c (rb_method_definition_addref): added instead of
  rb_method_definition_clone().
  Do not create new definition, but increment alias_count.
* class.c (clone_method): catch up this fix.
* class.c (method_entry_i): ditto.
* proc.c (mnew_internal): ditto.
* proc.c (mnew_missing): ditto.
* vm_eval.c: ditto.
* vm_insnhelper.c: ditto.
* vm_method.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50792 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-06 10:19:48 +00:00
ko1 b6b76e3a85 * internal.h: move definition of rb_cref_t to method.h.
* eval_intern.h: move definition of rb_scope_visibility_t
  to method.h.
* method.h: change rb_cref_t::scope_visi from VALUE to
  rb_scope_visibility_t.
  [Bug #11219]
* vm.c (vm_cref_new): accept rb_method_visibility_t directly.
* vm_insnhelper.c (rb_vm_rewrite_cref): don't use 0,
  but METHOD_VISI_UNDEF.
* vm_method.c (rb_scope_visibility_set): don't need to use cast.
* vm_method.c (rb_scope_module_func_set): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50782 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-05 11:42:34 +00:00
ko1 63e1601049 * vm_insnhelper.c (vm_defined): no need to use cast.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50774 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-04 16:17:53 +00:00
ko1 54a9ac7655 * vm_insnhelper.c (vm_defined): show additional messages on rb_bug().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50773 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-04 16:15:13 +00:00
ko1 3619a8b52d * method.h: constify rb_method_refined_t::orig_me.
Also constify the following functions.
  * rb_resolve_refined_method()
  * rb_method_entry_with_refinements()
  * rb_method_entry_without_refinements()
  * rb_method_entry_copy()'s parameter.
* class.c: catch up this fix.
* vm_insnhelper.c: ditto.
* vm_method.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50770 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-04 16:02:01 +00:00
ko1 9e73d45e0f * method.h: introduce rb_method_refined_t for refined method entry.
* class.c (move_refined_method): catch up this fix.
* gc.c (mark_method_entry): ditto.
* vm_eval.c (vm_call0_body): ditto.
* vm_insnhelper.c (vm_call_method): ditto.
* vm_method.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50761 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-03 22:27:51 +00:00
ko1 4ef6a68235 add a fix to last commit
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50757 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-03 20:26:55 +00:00
ko1 bd1e9d638e * vm_insnhelper.c (def_iseq_ptr): `iseqval' is not available any more.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50756 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-03 20:15:24 +00:00
ko1 4e870d302b * vm_core.h (rb_vm_rewrite_cref_stack): rename to rb_vm_rewrite_cref().
* class.c (clone_method): use renamed name.
* vm_insnhelper.c (rb_vm_rewrite_cref): do not use `node' in variable
  names.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50752 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-03 19:12:26 +00:00
ko1 5ac1972c1a * vm_core.h: rename enum missing_reason to enum method_missing_reason.
* vm_core.h: use enum method_missing_reason for
  rb_thread_t::method_missing_reason.
* vm_eval.c: catch up this fix.
* vm_insnhelper.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50747 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-03 10:42:18 +00:00
ko1 b5cd6ba214 * method.h: change fileds order to gather frequent acces fields.
* vm_insnhelper.c (vm_call_method): add LIKELY().



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50745 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-03 02:48:43 +00:00
ko1 18bbd05709 * method.h: split rb_method_definition_t::flag to several flags.
`flag' contains several categories of attributes and it makes us
  confusion (at least, I had confused).
  * rb_method_visibility_t (flags::visi)
    * NOEX_UNDEF     -> METHOD_VISI_UNDEF     = 0
    * NOEX_PUBLIC    -> METHOD_VISI_PUBLIC    = 1
    * NOEX_PRIVATE   -> METHOD_VISI_PRIVATE   = 2
    * NOEX_PROTECTED -> METHOD_VISI_PROTECTED = 3
  * NOEX_SAFE(flag)) -> safe (flags::safe, 2 bits)
  * NOEX_BASIC       -> basic (flags::basic, 1 bit)
  * NOEX_MODFUNC     -> rb_scope_visibility_t in CREF
  * NOEX_SUPER       -> MISSING_SUPER (enum missing_reason)
  * NOEX_VCALL       -> MISSING_VCALL (enum missing_reason)
  * NOEX_RESPONDS    -> BOUND_RESPONDS (macro)
  Now, NOEX_NOREDEF is not supported (I'm not sure it is needed).
  Background:
    I did not know what "NOEX" stands for.
    I asked Matz (who made this name) and his answer was "Nothing".
    "At first, it meant NO EXport (private), but the original
    meaning was gone."
    This is why I remove the mysterious word "NOEX" from MRI.
* vm_core.h: introduce `enum missing_reason' to represent
  method_missing (NoMethodError) reason.
* eval_intern.h: introduce rb_scope_visibility_t to represent
  scope visibility.
  It has 3 method visibilities (public/private/protected)
  and `module_function`.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50743 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-03 01:39:16 +00:00
nagachika 4fc87d4cb5 * vm_insnhelper.c: fix a typo. [ci skip]
check_resopnd_to_missing -> check_respond_to_missing

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50740 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-02 20:03:54 +00:00
ko1 a54da1c050 * vm_insnhelper.c (vm_defined): check respond_to_missing?
at defined?(func()).
* test/ruby/test_defined.rb: add a test for this fix.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50738 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-02 19:49:22 +00:00
ko1 5bcae57c6f * vm_insnhelper.c (vm_defined): skip respond_to_missing? when
a method is available.
  [Bug #11211]
* test/ruby/test_defined.rb: add a test for this fix.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50737 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-02 19:36:43 +00:00
ko1 15164bf33c * 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
2015-06-02 19:15:29 +00:00
ko1 57b817f4c5 * method.h: make rb_method_entry_t a VALUE.
Motivation and new data structure are described in [Bug #11203].
  This patch also solve the following issues.
  * [Bug #11200] Memory leak of method entries
  * [Bug #11046] __callee__ returns incorrect method name in orphan
                 proc
* test/ruby/test_method.rb: add a test for [Bug #11046].
* vm_core.h: remvoe rb_control_frame_t::me. me is located at value
  stack.
* vm_core.h, gc.c, vm_method.c: remove unlinked_method... codes
  because method entries are simple VALUEs.
* method.h:  Now, all method entries has own independent method
  definititons. Strictly speaking, this change is not essential,
  but for future changes.
  * rb_method_entry_t::flag is move to rb_method_definition_t::flag.
  * rb_method_definition_t::alias_count is now
    rb_method_definition_t::alias_count_ptr, a pointer to the counter.
* vm_core.h, vm_insnhelper.c (rb_vm_frame_method_entry) added to
  search the current method entry from value stack.
* vm_insnhelper.c (VM_CHECK_MODE): introduced to enable/disable
  assertions.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50728 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-02 04:20:30 +00:00
kazu abe5b048bd fix typo
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50721 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-01 15:00:17 +00:00
ko1 f1d4e8b3b3 * method.h: add VM_METHOD_TYPE_ALIAS rb_method_definition_t::type
to fix [Bug #11173].
  Now, inter class/method alias creates new method entry
  VM_METHOD_TYPE_ALIAS, which has an original method entry.
* vm_insnhelper.c (find_defiend_class_by_owner): added.
  Search corresponding defined_class from owner class/module.
* vm_method.c (rb_method_entry_get_without_cache): return me->klass
  directly for defined_class.
  Now, no need to check me->klass any more.
* vm_method.c (method_entry_set0): separated from method_entry_set().
* vm_method.c (rb_alias): make method entry has VM_METHOD_TYPE_ALIAS.
* vm_method.c (release_method_definition): support VM_METHOD_TYPE_ALIAS.
* vm_method.c (rb_hash_method_definition): ditto.
* vm_method.c (rb_method_definition_eq): ditto.
* vm_method.c (release_method_definition): ditto.
* vm_insnhelper.c (vm_call_method): ditto.
* vm_insnhelper.c (vm_method_cfunc_entry): ditto.
* vm_eval.c (vm_call0_body): ditto.
* gc.c (mark_method_entry): ditto.
* proc.c (method_def_iseq): ditto.
* proc.c (method_cref): ditto.
* proc.c (rb_method_entry_min_max_arity): ditto.
* test/ruby/test_alias.rb: add tests.
* test/ruby/test_module.rb: fix a test to catch up current behavior.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50691 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-30 18:45:28 +00:00
nobu ca61b4c4e0 vm.c: vm_invoke_bmethod
* vm.c (vm_invoke_bmethod): bmethod does not need EXEC_TAG as it
  does not set safe level.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-20 22:03:06 +00:00
nobu c0bf2c5efe vm_core.h: update for OPT_CALL_CFUNC_WITHOUT_FRAME
* vm_eval.c (vm_call0_cfunc): update invoker arguments.
* vm_insnhelper.c (vm_call_cfunc_latter): ditto.
* vm_insnhelper.c (rb_vm_call_cfunc_push_frame): ditto, and prefix
  with rb_.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50154 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-03 02:43:20 +00:00
ko1 7790f37efd * node.h: remove NODE_IFUNC, NEW_IFUNC.
* internal.h: use T_IMEMO for IFUNC.
  rename `struct IFUNC' to `struct vm_ifunc' and move the definition
  from vm_insnhelper.h. Add imemo_ifunc.
* gc.c (gc_mark_children): mark imemo_ifunc type T_IMEMO object.
* compile.c: catch up these changes.
* proc.c: ditto.
* vm_core.h (RUBY_VM_IFUNC_P): ditto.
* vm_eval.c (rb_iterate): ditto.
* vm_insnhelper.c: ditto.
* ext/objspace/objspace.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49938 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-11 13:31:11 +00:00
ko1 ce179b3d04 * vm_insnhelper.h: use T_IMEMO to create THROW_DATA.
Add THROW_DATA_NEW().
* internal.h: move defnition of `struct THROW_DATA'
  from vm_insnhelper.h to internal.h.
  Rename `THROW_DATA' to `vm_throw_data'.
* eval_intern.h (THROW_DATA_P): move to internal.h.
  THROW_DATA is no longer T_NODE, so check T_IMEMO.
* gc.c (gc_mark_children): mark THROW_DATA.
* vm.c: catch up these changes.
* vm_eval.c: ditto.
* vm_insnhelper.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49936 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-11 12:49:27 +00:00
ko1 ac28b985bd * vm_insnhelper.c: use T_IMEMO to create SVAR.
* internal.h, vm_insnhelper.h: move definition `struct SVAR'
  from vm_insnhelper.h to internal.h. And rename it to strcut vm_svar.
  new imemo_type imemo_svar is added.
* gc.c (gc_mark_children): mark imemo_svar.
* node.c (rb_gc_mark_node): remove useless marking.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49935 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-11 12:27:34 +00:00
ko1 0952b43b9b * include/ruby/ruby.h: introduce new type T_IMEMO.
T_IMEMO is Internal Memo type, internal use only.
  T_IMEMO has same purpose of NODE_MEMO.
  To insert T_IMEMO, type numbers are modified a little.
* internal.h: define struct RIMemo. Each RIMemo objects
  has imemo_type. We can observe it by the imemo_type() function.
* gc.c (rb_imemo_new): added.
* node.h: remove NODE_CREF and NEW_CREF().
* node.c (rb_gc_mark_node): ditto.
* vm.c (vm_cref_new): use rb_imem_new().
* vm_eval.c: ditto.
* vm_eval.c (eval_string_with_cref):
* vm_eval.c (rb_type_str):
* vm_insnhelper.c: use RIMemo objects for CREF.
* ext/objspace/objspace.c: support T_IMEMO.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49932 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-11 10:36:17 +00:00
ko1 b8fa8865ee * vm_insnhelper.h: define struct IFUNC.
* vm_eval.c (rb_iterate): use it.
* vm_insnhelper.c (vm_yield_with_cfunc): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49925 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-10 19:57:30 +00:00
ko1 ed130faf28 * proc.c: use RUBY_VM_IFUNC_P() to recognize IFUNC or not.
* vm.c: ditto.
* vm_dump.c: ditto.
* vm_insnhelper.c: ditto.
* vm_core.h: use RB_TYPE_P() instead of BUILTIN_TYPE().



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49922 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-10 18:50:15 +00:00
ko1 46cdb8f187 * vm_insnhelper.h: define struct THROW_DATA to represent
throwing data. Also define accessor functions.
* eval_intern.h: move related changes into vm_insnhelper.h.
  Now these MACROs (functions) are only used in vm*.c.
  There is only THROW_DATA_P(err) to check this data type or not.
* vm.c: catch up these changes.
* vm_eval.c: ditto.
* vm_insnhelper.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49921 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-10 18:39:46 +00:00
ko1 c5c5e96643 * vm_insnhelper.c (ep_cref): rename to lep_cref() because it should be
local ep.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49906 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-09 12:43:00 +00:00
ko1 5856347f16 * vm_insnhelper.h: define struct SVAR for SVAR.
This data type is also same layout of NODE (NODE_IF).
* vm_insnhelper.c: catch up this change.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49899 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-08 21:53:05 +00:00
ko1 2262aba6a2 * vm_insnhelper.c (lep_svar_set): add WBs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49898 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-08 21:44:00 +00:00
ko1 8dced4d2c0 * internal.h: define rb_cref_t and change to use it.
rb_cref_t is data type of CREF. Now, the body is still NODE.
  It is easy to understand what is CREF and what is pure NODE.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-08 21:22:43 +00:00
ko1 ae166317a4 * internal.h: define CREF accessor macros.
* CREF_CLASS(cref)
  * CREF_NEXT(cref)
  * CREF_VISI(cref)
  * CREF_VISI_SET(cref, v)
  * CREF_REFINEMENTS(cref)
  * CREF_PUSHED_BY_EVAL(cref)
  * CREF_PUSHED_BY_EVAL_SET(cref)
  * CREF_OMOD_SHARED(cref)
  * CREF_OMOD_SHARED_SET(cref)
  * CREF_OMOD_SHARED_UNSET(cref)
  This is process to change CREF data type from NODE.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49894 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-08 19:50:37 +00:00
ko1 d84f9b1694 * fix namespace issue on singleton class expressions. [Bug #10943]
* vm_core.h, method.h: remove rb_iseq_t::cref_stack. CREF is stored
  to rb_method_definition_t::body.iseq_body.cref.
* vm_insnhelper.c: modify SVAR usage.
  When calling ISEQ type method, push CREF information onto method
  frame, SVAR located place. Before this fix, SVAR is simply nil.
  After this patch, CREF (or NULL == Qfalse for not iseq methods)
  is stored at the method invocation.
  When SVAR is requierd, then put NODE_IF onto SVAR location,
  and NDOE_IF::nd_reserved points CREF itself.
* vm.c (vm_cref_new, vm_cref_dump, vm_cref_new_toplevel): added.
* vm_insnhelper.c (vm_push_frame): accept CREF.
* method.h, vm_method.c (rb_add_method_iseq): added. This function
  accepts iseq and CREF.
* class.c (clone_method): use rb_add_method_iseq().
* gc.c (mark_method_entry): mark method_entry::body.iseq_body.cref.
* iseq.c: remove CREF related codes.
* insns.def (getinlinecache/setinlinecache): CREF should be cache key
  because a different CREF has a different namespace.
* node.c (rb_gc_mark_node): mark NODE_IF::nd_reserved for SVAR.
* proc.c: catch up changes.
* struct.c: ditto.
* insns.def: ditto.
* vm_args.c (raise_argument_error): ditto.
* vm_eval.c: ditto.
* test/ruby/test_class.rb: add a test.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49874 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-06 12:24:58 +00:00
ko1 ca6b174078 * vm_core.h: define vm_svar_index.
* vm_insnhelper.c, vm.c, compile.c: use vm_svar_index names.
* iseq.h: remove DEFAULT_SPECIAL_VAR_COUNT.
  use VM_SVAR_FLIPFLOP_START instead.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49772 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-27 08:10:04 +00:00
ko1 fbc8841a8f * vm_insnhelper.c (lep_svar_place, lep_svar_get): do not create
additional T_NODE object (svars holder) when only getting
  svars.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49721 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-24 10:11:14 +00:00
ktsj e660f776c0 * vm_insnhelper.c (rb_vm_rewrite_cref_stack): copy nd_refinements
of orignal crefs. It fixes segmentation fault when calling
  refined method in duplicate module. [ruby-dev:48878] [Bug #10885]

* vm_core.h, class.c: change accordingly.

* test/ruby/test_refinement.rb: add a test for above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49685 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-22 07:05:14 +00:00
shugo 53053bcac6 * vm_insnhelper.c (vm_call_method): stop method search when a method
is not found in a refinement, to support undef in refinements.
  [ruby-core:66741] [Bug #10578]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49554 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-10 02:40:21 +00:00
nobu 738ce30f99 convert method name to a Symbol
* vm_eval.c (send_internal), vm_insnhelper.c (vm_call_opt_send):
  convert String method name into a Symbol, as method_missing
  method expects its first argument to be a Symbol.  [Bug #10828]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49506 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-05 04:41:05 +00:00
nobu 73645c1c51 vm_insnhelper.c: fix missing reason
* vm_insnhelper.c (ci_missing_reason): return the reason of method
  missing in call info.
* vm_insnhelper.c (vm_call_opt_send): re-apply r49500 with the
  proper missing reason.  [Bug #10828]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49505 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-05 03:31:07 +00:00
marcandre 1fd6ab5bab * vm_insnhelper.c: Revert r49500 (6ae6a8c7bc)
Creates a regression in test_drb. Above my rubyfu. [#10828]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49502 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-04 19:45:16 +00:00
marcandre 6ae6a8c7bc * vm_insnhelper.c: Fix symbol leak with +send+ and method_missing [#10828]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49500 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-04 19:03:20 +00:00
marcandre 454f89e2ea * vm_insnhelper.c: Fix one type of symbol leak with +send+
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49499 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-04 19:03:04 +00:00
nobu 26d0a2a3d6 vm_insnhelper.c: break from nested rescue
* vm_insnhelper.c (vm_throw_start): search the target to break
  from a block with nested rescue, from the nested blocks.
  [ruby-core:67765] [Bug #10775] [Fix GH-820]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49390 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-23 14:57:08 +00:00
ktsj e62a99b924 * eval_intern.h, vm.c, vm_eval.c, vm_insnhelper.c:
change throw mechanism (not save target ep, but save target cfp).
  It fixes `unexpected break' bug that occurs when
  TracePoint#binding is called.
  [ruby-dev:48797] [Bug #10689]

* test/ruby/test_settracefunc.rb: add a test.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49266 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-16 02:54:22 +00:00
nobu fd639a4c3b vm.c: constify
* vm.c (rb_vm_get_binding_creatable_next_cfp): constify arguments.
  (rb_vm_get_ruby_level_next_cfp): ditto.
  (vm_get_ruby_level_caller_cfp): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48875 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-17 03:08:20 +00:00
nobu e4717eaa4c iseq.c: struct accessors
* iseq.c (rb_method_for_self_aref, rb_method_for_self_aset): call
  accessor functions directly, not to be affected by [] and []=
  methods.  [ruby-core:66846] [Bug #10601]
* struct.c (define_aref_method, define_aset_method): ditto.
* vm_insnhelper.c (rb_vm_opt_struct_aref, rb_vm_opt_struct_aset):
  direct accessors of Struct.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48864 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-16 06:18:25 +00:00
ko1 6115f65d7d * vm_args.c: fix backtrace location for keyword related exceptions.
For example, the following program
    def foo(k1: 1); end # line 1
            foo(k2: 2)          # line 2
  causes "unknown keyword: k2 (ArgumentError)".
  Before this patch, the backtrace location is only line 2.
  However, error should be located at line 1 (over line 2 in
  stack trace). This patch fix this problem.
* class.c (rb_keyword_error_new): separate exception creation logic
  from rb_keyword_error(), to use in vm_args.c.
* vm_insnhelper.c (rb_arg_error_new): rename to rb_arity_error_new().
* vm_args.c (argument_arity_error): rename to argument_arity_error().
* vm_args.c (arugment_kw_error): added to fix backtrace.
* test/ruby/test_keyword.rb: add tests.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48608 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-27 10:15:47 +00:00
nobu 5d4aad2b1b vm_eval.c: preserve encoding
* vm_eval.c (rb_method_call_status): preserve encoding of called method
  name in error messages.

* vm_insnhelper.c (vm_call_method): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48572 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-25 18:44:07 +00:00
nobu 26ae645501 vm.c: super in bmethod
* vm_eval.c (vm_call_super): allow bound proc method to call super
  method.
* vm_insnhelper.c (vm_yield_with_cfunc): push defined class and
  bound proc method entry to the control frame.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48348 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-09 14:25:52 +00:00
ko1 831e33c780 * vm_core.h: change iseq parameter data structure.
https://bugs.ruby-lang.org/issues/10440#change-49694
  * change terminology `arg' to `param'.
  * move rb_iseq_t::arg_* to rb_iseq_t::param.
  * move rb_iseq_t::arg_size to rb_iseq_t::param::size.
  * move rb_iseq_t::argc to rb_iseq_t::param::lead_num.
  * move rb_iseq_t::arg_opts to rb_iseq_t::param::opt_num.
  * move rb_iseq_t::arg_rest to rb_iseq_t::param::rest_start.
  * move rb_iseq_t::arg_post_num to rb_iseq_t::param::post_num.
  * move rb_iseq_t::arg_post_start to rb_iseq_t::param::post_start.
  * move rb_iseq_t::arg_block to rb_iseq_t::param::block_start.
  * move rb_iseq_t::arg_keyword* to rb_iseq_t::param::keyword.
    rb_iseq_t::param::keyword is allocated only when keyword
    parameters are available.
  * introduce rb_iseq_t::param::flags to represent parameter
    availability. For example, rb_iseq_t::param:🎏:has_kw
    represents that this iseq has keyword parameters and
    rb_iseq_t::param::keyword is allocated.
    We don't need to compare with -1 to check availability.
  * remove rb_iseq_t::arg_simple.
* compile.c: catch up this change.
* iseq.c: ditto.
* proc.c: ditto.
* vm.c, vm_args.c, vm_dump.c, vm_insnhelper.c: ditto.
* iseq.c (iseq_data_to_ary): support keyword argument.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48242 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-02 23:14:21 +00:00
ko1 fbebd502f9 * rewrite method/block parameter fitting logic to optimize
keyword arguments/parameters and a splat argument.
  [Feature #10440] (Details are described in this ticket)
  Most of complex part is moved to vm_args.c.
  Now, ISeq#to_a does not catch up new instruction format.
* vm_core.h: change iseq data structures.
  * introduce rb_call_info_kw_arg_t to represent keyword arguments.
  * add rb_call_info_t::kw_arg.
  * rename rb_iseq_t::arg_post_len to rb_iseq_t::arg_post_num.
  * rename rb_iseq_t::arg_keywords to arg_keyword_num.
  * rename rb_iseq_t::arg_keyword to rb_iseq_t::arg_keyword_bits.
    to represent keyword bitmap parameter index.
    This bitmap parameter shows that which keyword parameters are given
    or not given (0 for given).
    It is refered by `checkkeyword' instruction described bellow.
  * rename rb_iseq_t::arg_keyword_check to rb_iseq_t::arg_keyword_rest
    to represent keyword rest parameter index.
  * add rb_iseq_t::arg_keyword_default_values to represent default
    keyword values.
  * rename VM_CALL_ARGS_SKIP_SETUP to VM_CALL_ARGS_SIMPLE
    to represent
      (ci->flag & (SPLAT|BLOCKARG)) &&
      ci->blockiseq == NULL &&
      ci->kw_arg == NULL.
* vm_insnhelper.c, vm_args.c: rewrite with refactoring.
  * rewrite splat argument code.
  * rewrite keyword arguments/parameters code.
  * merge method and block parameter fitting code into one code base.
* vm.c, vm_eval.c: catch up these changes.
* compile.c (new_callinfo): callinfo requires kw_arg parameter.
* compile.c (compile_array_): check the last argument Hash object or
  not. If Hash object and all keys are Symbol literals, they are
  compiled to keyword arguments.
* insns.def (checkkeyword): add new instruction.
  This instruction check the availability of corresponding keyword.
  For example, a method "def foo k1: 'v1'; end" is cimpiled to the
  following instructions.
    0000 checkkeyword     2, 0  # check k1 is given.
    0003 branchif         9     # if given, jump to address #9
    0005 putstring        "v1"
    0007 setlocal_OP__WC__0 3   # k1 = 'v1'
    0009 trace            8
    0011 putnil
    0012 trace            16
    0014 leave
* insns.def (opt_send_simple): removed and add new instruction
  "opt_send_without_block".
* parse.y (new_args_tail_gen): reorder variables.
  Before this patch, a method "def foo(k1: 1, kr1:, k2: 2, **krest, &b)"
  has parameter variables "k1, kr1, k2, &b, internal_id, krest",
  but this patch reorders to "kr1, k1, k2, internal_id, krest, &b".
  (locate a block variable at last)
* parse.y (vtable_pop): added.
  This function remove latest `n' variables from vtable.
* iseq.c: catch up iseq data changes.
* proc.c: ditto.
* class.c (keyword_error): export as rb_keyword_error().
* common.mk: depend vm_args.c for vm.o.
* hash.c (rb_hash_has_key): export.
* internal.h: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-02 18:02:55 +00:00
nobu e95e524782 vm_insnhelper.c: allow to_ary
* vm_insnhelper.c (vm_callee_setup_arg{_complex,}): try conversion
  by to_ary for a lambda, as well as a proc.
  [ruby-core:65887] [Bug #9605]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48193 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-10-30 02:16:15 +00:00
nobu bd2d094aab vm_insnhelper.c: preserve encoding
* vm_insnhelper.c (vm_getivar): preserve variable name encoding in
  warning message.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48047 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-10-20 05:20:39 +00:00
nobu 6e21b611aa variable.c, vm_insnhelper.c: improve performance
* variable.c (rb_ivar_get), vm_insnhelper.c (vm_getivar): improve
  instance variable retrieval performance by checking ruby_verbose
  before call of rb_warning and evaluation of its argument.
  [ruby-core:65786] [Feature #10396]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48035 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-10-19 17:23:31 +00:00
nobu 963f1bd990 vm_insnhelper.c: refactoring
* vm_insnhelper.c (vm_getivar): move common expressions.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48033 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-10-19 16:58:58 +00:00
nobu ddf6eb40c7 variable.c: check index overflow
* variable.c (rb_ivar_set), vm_insnhelper.c (vm_setivar): check
  instance variable index overflow.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47512 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 08:05:12 +00:00
normal b3a4367ce4 rb_call_info_t: shrink to 96 bytes from 104 bytes on 64-bit
This keeps ci->flag and ci->aux.index consistent across 32-bit
and 64-bit platforms.

ci->flag: VM_CALL_* flags only use 9 bits, currently
ci->aux.index: 2 billion ivars per class should be enough for anybody

This saves around 50K allocations on "valgrind ruby -e exit" on x86-64
before:
  total heap usage: 48,122 allocs, 19,253 frees, 8,099,197 bytes allocated
after:
  total heap usage: 48,069 allocs, 19,214 frees, 8,047,266 bytes allocated

* vm_core.h (rb_call_info_t): ci->flag becomes 32-bit unsigned int
  ci->index becomes a 32-bit signed int (from signed long).
  Reorder for better packing on 64-bit, giving an 8 byte reduction
  from 104 to 96 bytes for each ci.

* compile.c (new_callinfo, setup_args, iseq_compile_each,
  iseq_build_from_ary_body): adjust for type changes

* vm_insnhelper.c (vm_getivar): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 06:32:44 +00:00
normal 4938045735 variable: cleanup to use rb_const_lookup
* variable.c: cleanup to use rb_const_lookup
* vm_insnshelper.c: ditto

This reduces casting and long lines.  This should make it easier to
switch to alternatives to st for constant storage.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47059 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-08-04 01:12:53 +00:00
nobu a6d34e7501 vm_insnhelper.c: fix unusable super class
* vm_insnhelper.c (vm_call_method): unusable super class should cause
  method missing when BasicObject is refined but not been using.
  [ruby-core:64166] [Bug #10106]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47037 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-08-03 01:43:10 +00:00
ngoto e54e53f355 * vm_core.h (struct rb_iseq_struct): stack_max is changed to int
because all calculations related to stack_max in compile.c
  (iseq_set_sequence) and vm_insnhelper.c (vm_push_frame) are
  conducted by using int. This partly reverts r23945.
* vm_insnhelper.c (vm_push_frame): ditto. This reverts r42401.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46839 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-16 11:46:06 +00:00
normal e91ae784bc vm_core.h (struct rb_iseq_struct): reduce to 296 bytes on 64-bit
Most iseq do not have a catch_table, so avoid needlessly adding
4-8 bytes to the struct for the common case.

Changes from v2:
- iseq_catch_table_size removed, use if (...) for (;...;)

Changes from v1:
- renamed iseq->_catch_table to iseq->catch_table
- iseq_catch_table_bytes: made a static inline function
- iseq_catch_table_size: new function replaces the
  iseq_catch_table_each iterator macro

* iseq.h (struct iseq_catch_table): new flexible array struct
         (iseq_catch_table_bytes): allocated size function
* vm_core.h (struct rb_iseq_struct): uupdate catch_table member
* compile.c (iseq_set_exception_table): update for struct changes
* iseq.c (iseq_free): ditto
* iseq.c (iseq_memsize): ditto
* iseq.c (rb_iseq_disasm): ditto
* iseq.c (iseq_data_to_ary): ditto
* iseq.c (rb_iseq_build_for_ruby2cext): ditto (untested)
* vm.c (vm_exec): ditto
* vm_core.h (struct rb_iseq_struct): ditto
* vm_insnhelper.c (vm_throw): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46811 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-14 07:06:26 +00:00
nobu 813ad48975 vm_insnhelper.c: fix implicit splat keyword argument
* vm_insnhelper.c (vm_callee_setup_keyword_arg): adjust VM stack
  pointer to get rid of overwriting splat arguments by arguments
  for `to_hash` conversion.  [ruby-core:63593] [Bug #10016]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46775 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-10 06:02:54 +00:00
nobu 3ff85b795a eval.c: no method calls at stack overflow
* eval.c (setup_exception): get rid of method calls before raising
  stack overflow, not to cause stack overflow again.
* defs/id.def: add IDs for backtraces.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46593 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-28 04:58:25 +00:00
nobu 053759edfc Backtrace for SystemStackError
* eval.c (setup_exception): set backtrace in system stack error
  other than the pre-allocated sysstack_error.  [Feature #6216]
* proc.c (Init_Proc): freeze the pre-allocated sysstack_error.
* vm_insnhelper.c (vm_stackoverflow): raise new instance for each
  times without calling any methods to keep the backtrace with no
  further stack overflow.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46502 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-23 02:35:18 +00:00
nobu 7d9b37cc53 insns.def: avoid type-punned pointer cast
* insns.def (once), vm_insnhelper.c (vm_once_exec): turn the
  parameter into a VALUE to get rid of type-punned pointer cast.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46478 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-20 06:59:28 +00:00
ko1 370212a8ae * vm.c (invoke_block_from_c): move call/return event timing for
bmethod. It can invoke inconsistent call event if this call raises
  argument error.
  [Bug #9959]
* vm_insnhelper.c (vm_call_bmethod_body): ditto.
* test/ruby/test_settracefunc.rb: add a test.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46464 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-19 10:49:46 +00:00
ko1 ba6b0acdb6 * vm.c (invoke_block_from_c): add VM_FRAME_FLAG_BMETHOD to record
it is bmethod frame.
* vm.c (vm_exec): invoke RUBY_EVENT_RETURN event if rollbacked frame
  is VM_FRAME_FLAG_BMETHOD.
  [Bug #9759]
* test/ruby/test_settracefunc.rb: add a test for TracePoint/set_trace_func.
* vm_core.h: renmae rb_thread_t::passed_me to
  rb_thread_t::passed_bmethod_me to clarify the usage.
* vm_insnhelper.c (vm_call_bmethod_body): use renamed member.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45758 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-30 09:08:10 +00:00
nobu 46f578d806 proc.c: fix super in bound UnboundMethod
* proc.c (rb_method_call_with_block, umethod_bind): call with
  IClass including the module for a module instance method.
  [ruby-core:61936] [Bug #9721]
* vm_insnhelper.c (vm_search_super_method): allow bound
  UnboundMethod case.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45565 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-11 06:05:28 +00:00
nobu 2329a1a88d vm_insnhelper.c: preserve encodings
* vm_insnhelper.c (vm_search_super_method): preserve encodings of
  classes in message.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45564 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-11 05:40:52 +00:00
nobu 163f9abe4f vm_insnhelper.c: relax arity check
* vm.c (invoke_block_from_c): add splattable argument.
* vm.c (vm_invoke_proc): disallow to splat when directly invoked.
* vm_insnhelper.c (vm_callee_setup_arg_complex, vm_callee_setup_arg):
  relax arity check of yielded lambda.  [ruby-core:61340] [Bug #9605]
* test/ruby/test_yield.rb (TestRubyYieldGen#emu_bind_params): no
  longer raise ArgumentError when splatting to lambda.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45327 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-13 16:18:45 +00:00
nobu c28b5723f6 vm_insnhelper.c: disable fastpath if splat
* vm_insnhelper.c (vm_callee_setup_arg): disable fastpath if splat
  argument, since argc may differ for each calls.
  [ruby-core:61422] [Bug #9622]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45321 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-12 02:19:13 +00:00
nobu ab9e4d11a3 vm_insnhelper.c: inline function
* vm_insnhelper.c (vm_callee_setup_arg): turn a macro into an
  inline function.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45320 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-12 02:18:50 +00:00
shugo 4d33c0e965 * vm_insnhelper.c (vm_call_method): should check ci->me->flag of
a refining method in case the method is private.
  [ruby-core:60111] [Bug #9452]

* vm_method.c (make_method_entry_refined): set me->flag of a refined
  method entry to NOEX_PUBLIC in case the original method is private
  and it is refined as a public method.  The original flag is stored
  in me->def->body.orig_me, so it's OK to make a refined method
  entry public.  [ruby-core:60111] [Bug #9452]

* test/ruby/test_refinement.rb: related tests.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44931 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-13 14:44:41 +00:00
nobu c7652dec6f vm_insnhelper.c: adjust indent
* vm_insnhelper.c (check_match): adjust indent.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44888 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-08 09:20:33 +00:00
nobu aee9f2879d vm_insnhelper.c: boudn method transplanting
* vm_insnhelper.c (vm_search_super_method): allow bound method from a
  module, yet another method transplanting.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44553 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-10 09:01:44 +00:00
nobu 5c0d17c9a2 vm_insnhelper.c: revive r44455 for bound module method
* vm_insnhelper.c (vm_search_super_method): when super called in a
  bound UnboundMethod generated from a module, no superclass is
  found since the current defined class is the module, then call
  method_missing in that case.  [ruby-core:59619] [Bug #9377]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44527 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-08 13:53:18 +00:00
nobu a69f01fa52 proc.c: fix inherited method owner
* proc.c (mnew_from_me): keep iclass as-is, to make inheritance
  chain consistent.  [ruby-core:59358] [Bug #9315]

* proc.c (method_owner): return the original defined_class from
  prepended iclass, instead.

* vm_insnhelper.c (vm_search_super_method): revert r44455, no
  longer defined_class becomes a module.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44458 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-29 03:11:17 +00:00
nobu 24c3331bdf vm_insnhelper.c: missing super in method module
* vm_insnhelper.c (vm_search_super_method): direct superclass of a
  module is found when super called in a Method object generated a
  method defined in a module, call method_missing in that case.
  [ruby-core:59358] [Bug #9315]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44455 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-28 23:21:14 +00:00
ko1 485e6ebed8 * vm_insnhelper.c (argument_error): insert dummy frame to make
a backtrace object intead of modify backtrace string array.
  [Bug #9295]
* test/ruby/test_backtrace.rb: add a test for this patch.
  fix test to compare a result of Exception#backtrace with
  a result of Exception#backtrace_locations.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44411 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-25 09:35:03 +00:00
ko1 c702005a7b * include/ruby/ruby.h: rename OBJ_WRITE and OBJ_WRITTEN into
RB_OBJ_WRITE and RB_OBJ_WRITTEN.
* array.c, class.c, compile.c, hash.c, internal.h, iseq.c,
  proc.c, process.c, re.c, string.c, variable.c, vm.c,
  vm_eval.c, vm_insnhelper.c, vm_insnhelper.h,
  vm_method.c: catch up this change.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-20 08:07:47 +00:00
tmm1 4cd675ea9e vm_insnhelper.c: optimize for loop
* vm_insnhelper.c (vm_call_iseq_setup_normal): simple for loop
  condition optimization. this area shows up as a hotspot in VM
  profiles.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-19 02:27:36 +00:00