diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-11-02 18:02:55 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-11-02 18:02:55 +0000 |
commit | fbebd502f9f374d1eef31c63c10c7d8adcd63280 (patch) | |
tree | 69dc3dbcdd12509100d01fce6e5d95343b3337c9 /insns.def | |
parent | 055a465ac4222f314917c1d682fbd9d0d73535af (diff) | |
download | ruby-fbebd502f9f374d1eef31c63c10c7d8adcd63280.tar.gz |
* 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
Diffstat (limited to 'insns.def')
-rw-r--r-- | insns.def | 40 |
1 files changed, 30 insertions, 10 deletions
@@ -834,6 +834,30 @@ checkmatch /** @c setting + @e check keywords are specified or not. + @j キーワードが指定されているかどうかチェックする + */ +DEFINE_INSN +checkkeyword +(lindex_t kw_bits_index, rb_num_t keyword_index) +() +(VALUE ret) +{ + const VALUE *ep = GET_EP(); + const VALUE kw_bits = *(ep - kw_bits_index); + + if (FIXNUM_P(kw_bits)) { + int bits = FIX2INT(kw_bits); + ret = (bits & (0x01 << keyword_index)) ? Qfalse : Qtrue; + } + else { + assert(RB_TYPE_P(kw_bits, T_HASH)); + ret = rb_hash_has_key(kw_bits, INT2FIX(keyword_index)) ? Qfalse : Qtrue; + } +} + +/** + @c setting @e trace @j trace 用の命令。 */ @@ -995,8 +1019,7 @@ send (VALUE val) // inc += - (int)(ci->orig_argc + ((ci->flag & VM_CALL_ARGS_BLOCKARG) ? 1 : 0)); { ci->argc = ci->orig_argc; - ci->blockptr = 0; - vm_caller_setup_args(th, reg_cfp, ci); + vm_caller_setup_arg_block(th, reg_cfp, ci, FALSE); vm_search_method(ci, ci->recv = TOPN(ci->argc)); CALL_METHOD(ci); } @@ -1017,15 +1040,16 @@ opt_str_freeze /** @c optimize - @e Invoke method without block, splat - @j Invoke method without block, splat + @e Invoke method without block + @j Invoke method without block */ DEFINE_INSN -opt_send_simple +opt_send_without_block (CALL_INFO ci) (...) (VALUE val) // inc += -ci->orig_argc; { + ci->argc = ci->orig_argc; vm_search_method(ci, ci->recv = TOPN(ci->argc)); CALL_METHOD(ci); } @@ -1042,11 +1066,7 @@ invokesuper (VALUE val) // inc += - (int)(ci->orig_argc + ((ci->flag & VM_CALL_ARGS_BLOCKARG) ? 1 : 0)); { ci->argc = ci->orig_argc; - ci->blockptr = !(ci->flag & VM_CALL_ARGS_BLOCKARG) ? GET_BLOCK_PTR() : 0; - - if (UNLIKELY(!(ci->flag & VM_CALL_ARGS_SKIP_SETUP))) { - vm_caller_setup_args(th, reg_cfp, ci); - } + vm_caller_setup_arg_block(th, reg_cfp, ci, TRUE); ci->recv = GET_SELF(); vm_search_super_method(th, GET_CFP(), ci); CALL_METHOD(ci); |