mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* vm_core.h: change semantics of opt_num and opt_table.
`opt_num' was the number of optional parameters + 1. `opt_table' has "opt_num" entries. Change them to: `opt_num' is the number of optional parameters. `opt_talbe' has "opt_num + 1" entries. This change simplify parameter fitting logics. * compile.c: catch up this change. * iseq.c: ditto. * proc.c: ditto. * vm_args.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48247 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
888e16c51e
commit
ef25be7391
6 changed files with 56 additions and 27 deletions
20
ChangeLog
20
ChangeLog
|
@ -1,3 +1,23 @@
|
|||
Mon Nov 3 13:38:28 2014 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* vm_core.h: change semantics of opt_num and opt_table.
|
||||
`opt_num' was the number of optional parameters + 1.
|
||||
`opt_table' has "opt_num" entries.
|
||||
|
||||
Change them to:
|
||||
`opt_num' is the number of optional parameters.
|
||||
`opt_talbe' has "opt_num + 1" entries.
|
||||
|
||||
This change simplify parameter fitting logics.
|
||||
|
||||
* compile.c: catch up this change.
|
||||
|
||||
* iseq.c: ditto.
|
||||
|
||||
* proc.c: ditto.
|
||||
|
||||
* vm_args.c: ditto.
|
||||
|
||||
Mon Nov 3 11:47:44 2014 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
|
||||
|
||||
* NEWS: added period into Matrix section. [ci skip]
|
||||
|
|
19
compile.c
19
compile.c
|
@ -1112,12 +1112,11 @@ iseq_set_arguments(rb_iseq_t *iseq, LINK_ANCHOR *optargs, NODE *node_args)
|
|||
label = NEW_LABEL(nd_line(node_args));
|
||||
rb_ary_push(labels, (VALUE)label | 1);
|
||||
ADD_LABEL(optargs, label);
|
||||
i += 1;
|
||||
|
||||
iseq->param.opt_num = i;
|
||||
iseq->param.opt_table = ALLOC_N(VALUE, i);
|
||||
MEMCPY(iseq->param.opt_table, RARRAY_CONST_PTR(labels), VALUE, i);
|
||||
for (j = 0; j < i; j++) {
|
||||
iseq->param.opt_table = ALLOC_N(VALUE, i+1);
|
||||
MEMCPY(iseq->param.opt_table, RARRAY_CONST_PTR(labels), VALUE, i+1);
|
||||
for (j = 0; j < i+1; j++) {
|
||||
iseq->param.opt_table[j] &= ~1;
|
||||
}
|
||||
rb_ary_clear(labels);
|
||||
|
@ -1230,7 +1229,7 @@ iseq_set_arguments(rb_iseq_t *iseq, LINK_ANCHOR *optargs, NODE *node_args)
|
|||
iseq->param.size = iseq->param.rest_start + 1;
|
||||
}
|
||||
else if (iseq->param.flags.has_opt) {
|
||||
iseq->param.size = iseq->param.lead_num + iseq->param.opt_num - 1;
|
||||
iseq->param.size = iseq->param.lead_num + iseq->param.opt_num;
|
||||
}
|
||||
else {
|
||||
rb_bug("unreachable");
|
||||
|
@ -1687,7 +1686,7 @@ iseq_set_optargs_table(rb_iseq_t *iseq)
|
|||
int i;
|
||||
|
||||
if (iseq->param.flags.has_opt) {
|
||||
for (i = 0; i < iseq->param.opt_num; i++) {
|
||||
for (i = 0; i < iseq->param.opt_num + 1; i++) {
|
||||
iseq->param.opt_table[i] = label_get_position((LABEL *)iseq->param.opt_table[i]);
|
||||
}
|
||||
}
|
||||
|
@ -4495,7 +4494,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
|
|||
if (liseq->param.flags.has_opt) {
|
||||
/* optional arguments */
|
||||
int j;
|
||||
for (j = 0; j < liseq->param.opt_num - 1; j++) {
|
||||
for (j = 0; j < liseq->param.opt_num; j++) {
|
||||
int idx = liseq->local_size - (i + j);
|
||||
ADD_INSN2(args, line, getlocal, INT2FIX(idx), INT2FIX(lvar_level));
|
||||
}
|
||||
|
@ -5896,8 +5895,8 @@ rb_iseq_build_from_ary(rb_iseq_t *iseq, VALUE locals, VALUE args,
|
|||
iseq->param.post_num = FIX2INT(arg_post_num);
|
||||
iseq->param.post_start = FIX2INT(arg_post_start);
|
||||
iseq->param.block_start = FIX2INT(arg_block);
|
||||
iseq->param.opt_num = RARRAY_LENINT(arg_opt_labels);
|
||||
iseq->param.opt_table = (VALUE *)ALLOC_N(VALUE, iseq->param.opt_num);
|
||||
iseq->param.opt_num = RARRAY_LENINT(arg_opt_labels) - 1;
|
||||
iseq->param.opt_table = (VALUE *)ALLOC_N(VALUE, iseq->param.opt_num + 1);
|
||||
|
||||
if (iseq->param.flags.has_block) {
|
||||
iseq->param.size = iseq->param.block_start + 1;
|
||||
|
@ -5909,7 +5908,7 @@ rb_iseq_build_from_ary(rb_iseq_t *iseq, VALUE locals, VALUE args,
|
|||
iseq->param.size = iseq->param.rest_start + 1;
|
||||
}
|
||||
else {
|
||||
iseq->param.size = iseq->param.lead_num + (iseq->param.opt_num - (iseq->param.flags.has_opt == TRUE));
|
||||
iseq->param.size = iseq->param.lead_num + iseq->param.opt_num;
|
||||
}
|
||||
|
||||
for (i=0; i<RARRAY_LEN(arg_opt_labels); i++) {
|
||||
|
|
13
iseq.c
13
iseq.c
|
@ -143,7 +143,7 @@ iseq_memsize(const void *ptr)
|
|||
if (iseq->catch_table) {
|
||||
size += iseq_catch_table_bytes(iseq->catch_table->size);
|
||||
}
|
||||
size += iseq->param.opt_num * sizeof(VALUE);
|
||||
size += (iseq->param.opt_num + 1) * sizeof(VALUE);
|
||||
size += iseq->is_size * sizeof(union iseq_inline_storage_entry);
|
||||
size += iseq->callinfo_size * sizeof(rb_call_info_t);
|
||||
|
||||
|
@ -1420,7 +1420,7 @@ rb_iseq_disasm(VALUE self)
|
|||
"[opts: %d, rest: %d, post: %d, block: %d, kw: %d@%d, kwrest: %d])\n",
|
||||
iseqdat->local_size,
|
||||
iseqdat->param.lead_num,
|
||||
iseqdat->param.opt_num - (iseqdat->param.flags.has_opt == TRUE),
|
||||
iseqdat->param.opt_num,
|
||||
iseqdat->param.flags.has_rest ? iseqdat->param.rest_start : -1,
|
||||
iseqdat->param.post_num,
|
||||
iseqdat->param.flags.has_block ? iseqdat->param.block_start : -1,
|
||||
|
@ -1437,7 +1437,7 @@ rb_iseq_disasm(VALUE self)
|
|||
if (iseqdat->param.flags.has_opt) {
|
||||
int argc = iseqdat->param.lead_num;
|
||||
int opts = iseqdat->param.opt_num;
|
||||
if (i >= argc && i < argc + opts - 1) {
|
||||
if (i >= argc && i < argc + opts) {
|
||||
snprintf(opti, sizeof(opti), "Opt=%"PRIdVALUE,
|
||||
iseqdat->param.opt_table[i - argc]);
|
||||
}
|
||||
|
@ -1720,7 +1720,7 @@ iseq_data_to_ary(rb_iseq_t *iseq)
|
|||
VALUE arg_opt_labels = rb_ary_new();
|
||||
int j;
|
||||
|
||||
for (j=0; j<iseq->param.opt_num; j++) {
|
||||
for (j=0; j < iseq->param.opt_num; j++) {
|
||||
rb_ary_push(arg_opt_labels, register_label(labels_table, iseq->param.opt_table[j]));
|
||||
}
|
||||
|
||||
|
@ -1969,7 +1969,7 @@ rb_iseq_parameters(const rb_iseq_t *iseq, int is_proc)
|
|||
rb_ary_push(args, PARAM(i, req));
|
||||
}
|
||||
}
|
||||
r = iseq->param.lead_num + iseq->param.opt_num - 1;
|
||||
r = iseq->param.lead_num + iseq->param.opt_num;
|
||||
for (; i < r; i++) {
|
||||
PARAM_TYPE(opt);
|
||||
if (rb_id2str(PARAM_ID(i))) {
|
||||
|
@ -2122,8 +2122,7 @@ rb_iseq_build_for_ruby2cext(
|
|||
struct iseq_catch_table_entry, iseq->catch_table->size);
|
||||
}
|
||||
|
||||
ALLOC_AND_COPY(iseq->param.opt_table, arg_opt_table,
|
||||
VALUE, iseq->param.opt_num);
|
||||
ALLOC_AND_COPY(iseq->param.opt_table, arg_opt_table, VALUE, iseq->param.opt_num + 1);
|
||||
|
||||
set_relation(iseq, 0);
|
||||
|
||||
|
|
6
proc.c
6
proc.c
|
@ -848,10 +848,8 @@ static inline int
|
|||
rb_iseq_min_max_arity(const rb_iseq_t *iseq, int *max)
|
||||
{
|
||||
*max = iseq->param.flags.has_rest == FALSE ?
|
||||
iseq->param.lead_num + iseq->param.post_num +
|
||||
iseq->param.opt_num - (iseq->param.flags.has_opt == TRUE) +
|
||||
(iseq->param.flags.has_kw == TRUE) +
|
||||
(iseq->param.flags.has_kwrest == TRUE)
|
||||
iseq->param.lead_num + iseq->param.opt_num + iseq->param.post_num +
|
||||
(iseq->param.flags.has_kw == TRUE || iseq->param.flags.has_kwrest == TRUE)
|
||||
: UNLIMITED_ARGUMENTS;
|
||||
return iseq->param.lead_num + iseq->param.post_num + (iseq->param.flags.has_kw && iseq->param.keyword->required_num > 0);
|
||||
}
|
||||
|
|
|
@ -523,7 +523,7 @@ setup_parameters_complex(rb_thread_t * const th, const rb_iseq_t * const iseq, r
|
|||
VALUE * const locals, const enum arg_setup_type arg_setup_type)
|
||||
{
|
||||
const int min_argc = iseq->param.lead_num + iseq->param.post_num;
|
||||
const int max_argc = (iseq->param.flags.has_rest == FALSE) ? min_argc + (iseq->param.opt_num - (iseq->param.flags.has_opt == TRUE)) : UNLIMITED_ARGUMENTS;
|
||||
const int max_argc = (iseq->param.flags.has_rest == FALSE) ? min_argc + iseq->param.opt_num : UNLIMITED_ARGUMENTS;
|
||||
int opt_pc = 0;
|
||||
int given_argc;
|
||||
struct args_info args_body, *args;
|
||||
|
@ -570,8 +570,8 @@ setup_parameters_complex(rb_thread_t * const th, const rb_iseq_t * const iseq, r
|
|||
break; /* do nothing special */
|
||||
case arg_setup_block:
|
||||
if (given_argc == 1 &&
|
||||
(min_argc > 0 ||
|
||||
iseq->param.opt_num > 2 || iseq->param.flags.has_kw || iseq->param.flags.has_kwrest) && /* TODO: can be shrink with flags */
|
||||
(min_argc > 0 || iseq->param.opt_num > 1 ||
|
||||
iseq->param.flags.has_kw || iseq->param.flags.has_kwrest) &&
|
||||
!iseq->param.flags.ambiguous_param0 &&
|
||||
args_check_block_arg0(args, th, msl)) {
|
||||
given_argc = RARRAY_LENINT(args->rest);
|
||||
|
@ -632,7 +632,7 @@ setup_parameters_complex(rb_thread_t * const th, const rb_iseq_t * const iseq, r
|
|||
}
|
||||
|
||||
if (iseq->param.flags.has_opt) {
|
||||
int opt = args_setup_opt_parameters(args, iseq->param.opt_num - 1, locals + iseq->param.lead_num);
|
||||
int opt = args_setup_opt_parameters(args, iseq->param.opt_num, locals + iseq->param.lead_num);
|
||||
opt_pc = (int)iseq->param.opt_table[opt];
|
||||
}
|
||||
|
||||
|
|
17
vm_core.h
17
vm_core.h
|
@ -252,7 +252,7 @@ struct rb_iseq_struct {
|
|||
* =>
|
||||
*
|
||||
* lead_num = M
|
||||
* opt_num = N+1
|
||||
* opt_num = N
|
||||
* rest_start = M+N
|
||||
* post_start = M+N+(*1)
|
||||
* post_num = O
|
||||
|
@ -284,7 +284,20 @@ struct rb_iseq_struct {
|
|||
int post_num;
|
||||
int block_start;
|
||||
|
||||
VALUE *opt_table;
|
||||
VALUE *opt_table; /* (opt_num + 1) entries. */
|
||||
/* opt_num and opt_table:
|
||||
*
|
||||
* def foo o1=e1, o2=e2, ..., oN=eN
|
||||
* #=>
|
||||
* # prologue code
|
||||
* A1: e1
|
||||
* A2: e2
|
||||
* ...
|
||||
* AN: eN
|
||||
* AL: body
|
||||
* opt_num = N
|
||||
* opt_table = [A1, A2, ..., AN, AL]
|
||||
*/
|
||||
|
||||
struct rb_iseq_param_keyword {
|
||||
int num;
|
||||
|
|
Loading…
Reference in a new issue