summaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-11-03 04:43:07 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-11-03 04:43:07 +0000
commitef25be739196ce019f1918736151e0daa0e93f19 (patch)
tree7240be35b2b2e0a699fe10e81989776f0e8cb5b9 /compile.c
parent888e16c51ec6dd4b6aeb94cb44ee70e8f2d102b4 (diff)
* 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
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/compile.c b/compile.c
index c80bd55..2f3abe2 100644
--- a/compile.c
+++ b/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++) {