diff options
author | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-12-26 14:20:15 +0000 |
---|---|---|
committer | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-12-26 14:20:15 +0000 |
commit | d0baa0dd52fb1d72e23633bb2ba5a551957a4776 (patch) | |
tree | 545695dce21f3d2cce8ff50117a427f03795ddf3 /iseq.c | |
parent | a0a2c144b8b078cea668a703e2308ea64d4eb161 (diff) |
* vm_core.h (struct rb_iseq_struct), compile.c (iseq_set_arguments), iseq.c (rb_iseq_parameters), vm_insnhelper.c (vm_callee_setup_arg_complex): support Method#parameters for keyword arguments. The provisional spec is what Benoit Daloze proposed. [ruby-core:40518]
* test/ruby/test_keyword.rb: add a test for above.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34137 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'iseq.c')
-rw-r--r-- | iseq.c | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -1386,7 +1386,7 @@ rb_iseq_parameters(const rb_iseq_t *iseq, int is_proc) { int i, r; VALUE a, args = rb_ary_new2(iseq->arg_size); - ID req, opt, rest, block; + ID req, opt, rest, block, key, keyrest; #define PARAM_TYPE(type) rb_ary_push(a = rb_ary_new2(2), ID2SYM(type)) #define PARAM_ID(i) iseq->local_table[(i)] #define PARAM(i, type) ( \ @@ -1412,7 +1412,9 @@ rb_iseq_parameters(const rb_iseq_t *iseq, int is_proc) r = iseq->arg_rest != -1 ? iseq->arg_rest : iseq->arg_post_len > 0 ? iseq->arg_post_start : iseq->arg_block != -1 ? iseq->arg_block : + iseq->arg_keyword != -1 ? iseq->arg_keyword : iseq->arg_size; + if (iseq->arg_keyword != -1) r -= iseq->arg_keywords; for (; i < r; i++) { PARAM_TYPE(opt); if (rb_id2name(PARAM_ID(i))) { @@ -1437,6 +1439,20 @@ rb_iseq_parameters(const rb_iseq_t *iseq, int is_proc) rb_ary_push(args, PARAM(i, req)); } } + if (iseq->arg_keyword != -1) { + CONST_ID(key, "key"); + for (i = 0; i < iseq->arg_keywords; i++) { + PARAM_TYPE(key); + if (rb_id2name(iseq->arg_keyword_table[i])) { + rb_ary_push(a, ID2SYM(iseq->arg_keyword_table[i])); + } + rb_ary_push(args, a); + } + if (rb_id2name(iseq->local_table[iseq->arg_keyword])) { + CONST_ID(keyrest, "keyrest"); + rb_ary_push(args, PARAM(iseq->arg_keyword, keyrest)); + } + } if (iseq->arg_block != -1) { CONST_ID(block, "block"); rb_ary_push(args, PARAM(iseq->arg_block, block)); |