summaryrefslogtreecommitdiff
path: root/vm_insnhelper.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-24 11:13:49 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-24 11:13:49 +0000
commit5ee9513a7104078d9d2f51aecc354ae67f1ba002 (patch)
tree52e299b3ec089f27e306012ee11d4e70d82ff848 /vm_insnhelper.c
parentd0d32ba1e8e30443cadc0580e3f1e534af547f07 (diff)
Lazy Proc allocation for block parameters
[Feature #14045] * insns.def (getblockparam, setblockparam): add special access instructions for block parameters. getblockparam checks VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM and if it is not set this instruction creates a Proc object from a given blcok and set VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM. setblockparam is similar to setlocal, but set VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM. * compile.c: use get/setblockparm instead get/setlocal instructions. Note that they are used for method local block parameters (def m(&b)), not for block local method parameters (iter{|&b|). * proc.c (get_local_variable_ptr): creates Proc object for Binding#local_variable_get/set. * safe.c (safe_setter): we need to create Proc objects for postponed block parameters when $SAFE is changed. * vm_args.c (args_setup_block_parameter): used only for block local blcok parameters. * vm_args.c (vm_caller_setup_arg_block): if called with VM_CALL_ARGS_BLOCKARG_BLOCKPARAM flag then passed block values should be a block handler. * test/ruby/test_optimization.rb: add tests. * benchmark/bm_vm1_blockparam*: added. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60397 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_insnhelper.c')
-rw-r--r--vm_insnhelper.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 0d23359f5a..3e3e7d5d6d 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -359,6 +359,26 @@ rb_vm_env_write(const VALUE *ep, int index, VALUE v)
vm_env_write(ep, index, v);
}
+VALUE
+rb_vm_bh_to_procval(rb_thread_t *th, VALUE block_handler)
+{
+ if (block_handler == VM_BLOCK_HANDLER_NONE) {
+ return Qnil;
+ }
+ else {
+ switch (vm_block_handler_type(block_handler)) {
+ case block_handler_type_iseq:
+ case block_handler_type_ifunc:
+ return rb_vm_make_proc(th, VM_BH_TO_CAPT_BLOCK(block_handler), rb_cProc);
+ case block_handler_type_symbol:
+ return rb_sym_to_proc(VM_BH_TO_SYMBOL(block_handler));
+ case block_handler_type_proc:
+ return VM_BH_TO_PROC(block_handler);
+ default:
+ VM_UNREACHABLE(rb_vm_bh_to_procval);
+ }
+ }
+}
/* svar */