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

290 Коммитов

Автор SHA1 Сообщение Дата
ko1 eec17b718a * vm_core.h: remove rb_call_info_t::blockiseq.
* insns.def (send, invokesuper): pass blockiseq explicitly.
* compile.c: catch up this fix.
* iseq.c: ditto.
* vm_args.c: ditto.
* iseq.c (ISEQ_MINOR_VERSION): 2->3 because instruction spec was
  changed.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51794 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-08 08:21:07 +00:00
ko1 970399a9ae * iseq.c (iseq_memsize): functions for wrapper object should have
iseqw_ prefix.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51755 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-03 19:48:12 +00:00
ko1 7cf523c7db * vm_opts.h, iseq.c, iseq.h: add compile option to force frozen
string literals.
  [Feature #11473]
  This addition is not specification change, but to try frozen
  string literal world discussed on [Feature #11473].
  You can try frozen string literal world using this magical line:
    RubyVM::InstructionSequence.compile_option =
      {frozen_string_literal: true}
  Note that this is a global compilation option, so that you need to
  compile another script like that:
    p 'foo'.frozen? #=> false
    RubyVM::InstructionSequence.compile_option =
      {frozen_string_literal: true}
    p 'foo'.frozen? #=> false, because this line is already compiled.
    p eval("'foo'.frozen?") #=> true
  Details:
    * String literals are deduped by rb_fstring().
    * Dynamic string literals ("...#{xyz}...") is now only frozen,
      not deduped. Maybe you have other ideas.
  Now, please do not use this option on your productions :)
  Of course, current specification can be changed.
* compile.c: ditto.
* test/ruby/test_iseq.rb: add a test.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-08-21 20:47:53 +00:00
normal e7bb5d44e6 iseq.c (rb_iseq_mark): reduce NULL checks
iseq_location_setup always sets path, label and base_label fields,
and the only caller of iseq_location_setup (prepare_iseq_build) will
always pass non-nil `name' and `path' arguments.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51581 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-08-14 19:23:02 +00:00
normal 7630957eba iseq.c (iseq_memsize): reimplement for wrapper
* iseq.c (iseq_memsize): reimplement for wrapper
  (param_keyword_size): extracted from iseq_memsize
  (iseqw_mark): new mark function
  (iseqw_data_type): new data type
  (iseqw_new): wrap as iseqw_data_type
  (iseqw_check): adjust for wrapper
  (Init_ISeq): remove iseqw_iseq_key initialization
* test/objspace/test_objspace.rb: new test
  [ruby-core:70344] [Feature #11435]

v2 changes:
- added RUBY_TYPED_WB_PROTECTED and write barrier
- account for rb_call_info_kw_arg_t entries

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51547 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-08-12 12:18:51 +00:00
nobu 6e54a6df22 iseq.c: fix type
* iseq.c (rb_iseq_disasm, iseq_data_to_ary): fix loop counter type
  for array length.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51373 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-25 02:18:32 +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 14428f09b1 * vm_core.h: constify rb_iseq_constant_body::line_info_table.
* iseq.c: catch up this fix.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51368 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-24 21:01:09 +00:00
ko1 8fbf5dd9e5 * vm_core.h: constify rb_iseq_constant_body::catch_table.
* compile.c (iseq_set_exception_table): catch up this fix.
* iseq.c: ditto.
* vm.c (vm_exec): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51365 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-24 19:49:16 +00:00
ko1 eed613f4b1 * vm_core.h: constify rb_iseq_constant_body::local_table and
rb_iseq_param_keyword::table and
  rb_iseq_param_keyword::default_values.
* compile.c: catch up this fix.
* iseq.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51357 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-23 09:53:16 +00:00
ko1 18f6978625 * vm_core.h: constify rb_iseq_constant_body::iseq_encoded and
rb_control_frame_t::pc.
* compile.c (rb_iseq_translate_threaded_code): catch up this fix.
* iseq.c: ditto.
* vm_exec.c (vm_exec_core): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51356 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-23 09:34:31 +00:00
ko1 0d775f2a3c * vm_core.h: separate rb_iseq_body into rb_iseq_constant_body and
rb_iseq_variable_body (rb_iseq_t::variable_body).
  rb_iseq_variable_body can be modified after compilation.
* compile.c: use rb_iseq_t::variable_body.
* iseq.c: ditto.
* thread.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51339 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-22 10:55:02 +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 331fb4a2b3 * vm_core.h: constify rb_call_info_t::kw_arg,
rb_control_frame_t::iseq and rb_control_frame_t::block_iseq.
* iseq.c (iseq_free): catch up this fix.
* vm.c: ditto.
* vm_dump.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51325 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-21 21:41:04 +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 c0c20ccb51 * compile.c: constify the first parameter (iseq).
* iseq_add_mark_object()
  * iseq_add_mark_object_compile_time()
* iseq.c, iseq.h (rb_iseq_add_mark_object): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51311 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-21 10:47:45 +00:00
normal 4fd2443580 avoid redundant GET_THREAD() calls
This reduces binary size slightly on my 32-bit system:

   text    data     bss     dec     hex filename
2847705   12360   30632 2890697  2c1bc9 ruby.orig
2847641   12360   30632 2890633  2c1b89 ruby

* iseq.c (rb_iseq_compile_with_option): reuse result of previous
  GET_THREAD() call
* thread.c (thread_create_core): ditto
  (rb_mutex_trylock): ditto
  (rb_mutex_lock): ditto
* process.c (rb_waitpid): avoid multiple eval from RUBY_VM_CHECK_INTS
* thread.c (rb_thread_check_ints): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51273 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-16 20:42:43 +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 7b08338ab1 * iseq.c (rb_iseq_disasm): rename rb_iseq_t *iseqdat to iseq
and VALUE *iseq to code.
* iseq.c (rb_iseq_disasm_insn): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51267 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-16 12:50:25 +00:00
normal a0908cb413 remove redundant NULL check in mark functions
gc.c (gc_mark_children)only calls mark_func if the T_DATA ptr is
non-NULL, so avoid redundantly checking for that in each
mark function.

* iseq.c (iseq_mark): remove check for data pointer
* proc.c (binding_mark): ditto
* vm.c (rb_thread_mark): ditto
* vm_trace.c (tp_mark): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51252 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-15 08:29:22 +00:00
normal 011347e4d7 iseq.c (iseq_data_to_ary): dump kw_arg as symbol
Fix RubyVM::InstructionSequence#to_a after r49517
Keywords were made symbols to fix [Bug #10831] [ruby-core:68031],
so we should dump symbols as-is instead of attempting to convert
them from IDs

* iseq.c (iseq_data_to_ary): dump kw_arg as symbol
* test/-ext-/iseq_load/test_iseq_load.rb: test kw_arg roundtrip
  [ruby-core:69891] [Bug #11338]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-07 19:50:49 +00:00
ko1 f395c5be87 * vm_core.h: remove rb_iseq_t::orig because rb_iseq_clone()
no longer exists.
* iseq.c: don't use rb_iseq_t::orig.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51172 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-07 02:41:52 +00:00
ko1 16a68369d2 * iseq.c, internal.h (rb_iseq_clone): removed because we don't need to
clone iseq any more.
* class.c (clone_method): share iseq between cloned methods. All of
  method dependent information are able to refer from method entry.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51171 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-07 02:27:41 +00:00
ko1 5c4d7b9a9e * vm_core.h: remove rb_iseq_t::defined_method_id because it is not
needed.
* eval.c (frame_func_id): simplify. rb_callable_method_entry_t
  has enough information.
* eval.c (frame_called_id): ditto.
* iseq.c (prepare_iseq_build): catch up this fix.
* proc.c (rb_mod_define_method): ditto.
* vm.c (vm_define_method): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51168 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-06 19:08:05 +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
normal b49075cdf1 move RB_GC_GUARD responsibility to rb_add_method_iseq
This simplifies all the callers and makes code easier to use
and review.  I was confused about the need for RB_GC_GUARD
in define_{aset,aref}_method of struct.c without reading
rb_add_method_iseq.

Likewise, do the same for rb_iseq_clone, where the GC guard
only seems neccesary iff RGenGC is disabled.

* vm_method.c (rb_add_method_iseq): add RB_GC_GUARD
* class.c (clone_method): remove RB_GC_GUARD
* struct.c (define_aref_method): ditto
  (define_aset_method): ditto
* vm.c (vm_define_method):
* iseq.c (rb_iseq_clone): add RB_GC_GUARD

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51079 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-30 21:07:18 +00:00
ko1 7239111ef5 * iseq.c: constify.
* iseq.h: ditto.
* method.h: ditto.
* proc.c: ditto.
* vm_method.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50593 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-21 09:01:44 +00:00
ko1 0dba10a47f * proc.c (rb_method_get_iseq): rename to rb_method_iseq.
* iseq.c: catch up this fix.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50587 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-21 07:54:44 +00:00
ko1 08f923bdc1 * iseq.c (exception_type2symbol): show correct bug message.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50566 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-20 19:11:47 +00:00
nobu b813198627 iseq.c: check srouce type
* iseq.c (rb_iseq_compile_with_option): check srouce type, must be
  an IO or a String.  [ruby-core:69219] [Bug #11159]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50541 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-19 09:54:44 +00:00
ko1 4690e62284 * iseq.c (iseq_mark): skip some marking if iseq->orig is available.
* iseq.c (rb_iseq_clone): need WB for iseq1->klass = iseq0->klass
  (done in MEMCPY).



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50015 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-18 20:31:50 +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
nobu 467830e867 compile.c: struct accessors
* compile.c (rb_method_for_self_aref, rb_method_for_self_aset):
  move from iseq.c to build from node instead of arrays.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48876 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-17 03:20:58 +00:00
nobu 8d84693323 iseq.c: default option
* iseq.c (rb_iseq_new_with_opt): allow NULL option as
  COMPILE_OPTION_DEFAULT.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48873 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-17 02:57:51 +00:00
nobu d327d445c8 iseq.c: absolute_path
* iseq.c (caller_location): separate absolute_path.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48872 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-17 02:52:19 +00:00
nobu e4cf2f328d iseq.c: remove useless code
* iseq.c (rb_method_for_self_aref): remove unused declaration.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48865 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-16 07:38:52 +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
nobu 97628bff12 compile.c: wrap funcptr
* compile.c (iseq_build_from_ary_body): enclose funcptr with
  Integer as raw pointer cannot appear in an Array.

* iseq.c (iseq_data_to_ary): extract funcptr from Integer.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48863 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-16 05:54:32 +00:00
nobu 1d5c5ea153 iseq.c: show function name if possible
* iseq.c (rb_insn_operand_intern): show the name of the nearest
  run-time symbol if possible.

* compile.c (insn_data_to_s_detail): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48858 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-16 01:14:27 +00:00
nobu 389ea73014 compile.c: check funcptr
* compile.c (iseq_build_from_ary_body): cannot load dumped funcptr.

* iseq.c (iseq_data_to_ary): cannot dump funcptr.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48857 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-16 01:14:20 +00:00
nobu a3450f4733 iseq.c: use caller location
* iseq.c (rb_method_for_self_aref, rb_method_for_self_aset): set
  same location as the caller.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48851 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-15 19:13:15 +00:00
nobu 20748861d4 iseq.c: intermediate arrays
* iseq.c (rb_method_for_self_aref, rb_method_for_self_aset): hide
  and clear intermediate array objects.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48850 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-15 19:13:07 +00:00
ko1 1b6aa03eb9 * class.c (class_alloc): Strat from age == 2.
Class and Module objects can be living long life.
* iseq.c: Same for ISeq objects.
* gc.c (RVALUE_AGE_RESET): added.
* gc.c (newobj_of): allow to generate (age != 0) objects.
* gc.c (rb_copy_wb_protected_attribute): reset age for wb unprotected
  objects.
* include/ruby/ruby.h: add RUBY_TYPED_PROMOTED1 as an unrecommended
  flag.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48771 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-11 10:15:30 +00:00
nobu 8efe878d11 struct.c: use iseqval
* struct.c (define_aref_method, define_aset_method): use iseq
  VALUE instead of rb_iseq_t to prevent from GC, as RB_GC_GUARD
  makes sense only for local variables.  [Feature #10575]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48754 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-10 04:39:29 +00:00
normal 65651b34b1 struct: avoid all O(n) behavior on access
This avoids O(n) on lookups with structs over 10 members.
This also avoids O(n) behavior on all assignments on Struct members.
Members 0..9 still use existing C methods to read in O(1) time

Benchmark results:

vm2_struct_big_aref_hi*	1.305
vm2_struct_big_aref_lo*	1.157
vm2_struct_big_aset*	3.306
vm2_struct_small_aref*	1.015
vm2_struct_small_aset*	3.273

Note: I chose use loading instructions from an array instead of writing
directly to linked-lists in compile.c for ease-of-maintainability.  We
may move the method definitions to prelude.rb-like files in the future.

I have also tested this patch with the following patch to disable
the C ref_func methods and ensured the test suite and rubyspec works

	--- a/struct.c
	+++ b/struct.c
	@@ -209,7 +209,7 @@ setup_struct(VALUE nstr, VALUE members)
		ID id = SYM2ID(ptr_members[i]);
		VALUE off = LONG2NUM(i);

	-	if (i < N_REF_FUNC) {
	+	if (0 && i < N_REF_FUNC) {
		    rb_define_method_id(nstr, id, ref_func[i], 0);
		}
		else {

* iseq.c (rb_method_for_self_aref, rb_method_for_self_aset):
  new methods to generate bytecode for struct.c
  [Feature #10575]
* struct.c (rb_struct_ref, rb_struct_set): remove
  (define_aref_method, define_aset_method): new functions
  (setup_struct): use new functions
* test/ruby/test_struct.rb: add test for struct >10 members
* benchmark/bm_vm2_struct_big_aref_hi.rb: new benchmark
* benchmark/bm_vm2_struct_big_aref_lo.rb: ditto
* benchmark/bm_vm2_struct_big_aset.rb: ditto
* benchmark/bm_vm2_struct_small_aref.rb: ditto
* benchmark/bm_vm2_struct_small_aset.rb: ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48748 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-09 15:43:49 +00:00
normal d71c745b40 iseq.c: remove unused rb_iseq_new_with_bopt
* iseq.c (prepare_iseq_build): remove unused block_opt param
  (rb_iseq_new_with_bopt_and_opt): remove
  (rb_iseq_new_with_opt): inline removed function
  (rb_iseq_new_with_bopt): remove
  (iseq_load): adjust prepare_iseq_build call
  [Feature #10565]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48713 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-05 02:10:29 +00:00
normal 9581954a96 mostly fix rb_iseq_load
This allows reporters commenters of [Feature #8543] to load
instruction sequences directly.  Some test cases are still failing
but documented in test/-ext-/iseq_load/test_iseq_load.rb.

* compile.c (rb_iseq_build_from_exception): entry->sp is unsigned
  (iseq_build_callinfo_from_hash): account for kw_arg
  (iseq_build_from_ary_body): update for r35459
  (CHECK_STRING, CHECK_INTEGER): remove unused checks
  (int_param): new function for checking new `params' hash
  (iseq_build_kw): new function for loading rb_iseq_param_keyword
  (rb_iseq_build_from_ary): account for `misc' entry and general
   structure changes
  [Feature #8543]
* iseq.c (CHECK_HASH): new macro (for `misc' and `param' entries)
  (iseq_load): account for `misc' and `params' hashes
  (iseq_data_to_ary): add final opt to arg_opt_labels,
   fix kw support, account for unsigned entry->sp
* ext/-test-/iseq_load/iseq_load.c: new ext for test
* ext/-test-/iseq_load/extconf.rb: ditto
* test/-ext-/iseq_load/test_iseq_load.rb: new test

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48705 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-03 22:16:58 +00:00
normal 0c662b3431 iseq.c: avoid segfault on incomplete iseq
Compile failures will trigger iseq_free before
iseq->callinfo_entries are allocated at all.

* iseq.c (iseq_free): avoid segfault on incomplete iseq
* test/ruby/test_syntax.rb (test_invalid_next): new test
  for syntax error, not segfault

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48704 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-03 22:03:59 +00:00
nobu a81979ec55 iseq.c: use lvar index
* iseq.c (iseq_data_to_ary): use local variable indexes for hidden
  variable instead of meaningless ID values.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48679 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-02 04:54:57 +00:00
normal 7ec4604700 iseq.c (iseq_data_to_ary): keep hidden variables
We must not ignore hidden variables when rb_id2str fails.
Thanks to wanabe [ruby-core:66566]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48678 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-01 22:32:56 +00:00