Commit 7ed26ead authored by dearblue's avatar dearblue

Integrate `i` and `arg_i` in `mrb_get_args()`

The behavior of these two variables is the same.
parent fd1cff77
...@@ -589,7 +589,6 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) ...@@ -589,7 +589,6 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
char c; char c;
mrb_int i = 0; mrb_int i = 0;
va_list ap; va_list ap;
mrb_int arg_i = 0;
mrb_int argc = mrb->c->ci->argc; mrb_int argc = mrb->c->ci->argc;
mrb_value *array_argv = mrb->c->stack+1; mrb_value *array_argv = mrb->c->stack+1;
mrb_bool argv_on_stack = argc >= 0; mrb_bool argv_on_stack = argc >= 0;
...@@ -677,8 +676,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) ...@@ -677,8 +676,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
p = va_arg(ap, mrb_value*); p = va_arg(ap, mrb_value*);
if (i < argc) { if (i < argc) {
*p = argv[arg_i++]; *p = argv[i++];
i++;
} }
} }
break; break;
...@@ -690,12 +688,11 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) ...@@ -690,12 +688,11 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
if (i < argc) { if (i < argc) {
mrb_value ss; mrb_value ss;
ss = argv[arg_i++]; ss = argv[i++];
if (!class_ptr_p(ss)) { if (!class_ptr_p(ss)) {
mrb_raisef(mrb, E_TYPE_ERROR, "%v is not class/module", ss); mrb_raisef(mrb, E_TYPE_ERROR, "%v is not class/module", ss);
} }
*p = ss; *p = ss;
i++;
} }
} }
break; break;
...@@ -705,8 +702,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) ...@@ -705,8 +702,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
p = va_arg(ap, mrb_value*); p = va_arg(ap, mrb_value*);
if (i < argc) { if (i < argc) {
*p = argv[arg_i++]; *p = argv[i++];
i++;
if (!(altmode && mrb_nil_p(*p))) { if (!(altmode && mrb_nil_p(*p))) {
mrb_to_str(mrb, *p); mrb_to_str(mrb, *p);
} }
...@@ -719,8 +715,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) ...@@ -719,8 +715,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
p = va_arg(ap, mrb_value*); p = va_arg(ap, mrb_value*);
if (i < argc) { if (i < argc) {
*p = argv[arg_i++]; *p = argv[i++];
i++;
if (!(altmode && mrb_nil_p(*p))) { if (!(altmode && mrb_nil_p(*p))) {
*p = to_ary(mrb, *p); *p = to_ary(mrb, *p);
} }
...@@ -733,8 +728,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) ...@@ -733,8 +728,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
p = va_arg(ap, mrb_value*); p = va_arg(ap, mrb_value*);
if (i < argc) { if (i < argc) {
*p = argv[arg_i++]; *p = argv[i++];
i++;
if (!(altmode && mrb_nil_p(*p))) { if (!(altmode && mrb_nil_p(*p))) {
*p = to_hash(mrb, *p); *p = to_hash(mrb, *p);
} }
...@@ -750,8 +744,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) ...@@ -750,8 +744,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
ps = va_arg(ap, char**); ps = va_arg(ap, char**);
pl = va_arg(ap, mrb_int*); pl = va_arg(ap, mrb_int*);
if (i < argc) { if (i < argc) {
ss = argv[arg_i++]; ss = argv[i++];
i++;
if (altmode && mrb_nil_p(ss)) { if (altmode && mrb_nil_p(ss)) {
*ps = NULL; *ps = NULL;
*pl = 0; *pl = 0;
...@@ -771,8 +764,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) ...@@ -771,8 +764,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
ps = va_arg(ap, const char**); ps = va_arg(ap, const char**);
if (i < argc) { if (i < argc) {
ss = argv[arg_i++]; ss = argv[i++];
i++;
if (altmode && mrb_nil_p(ss)) { if (altmode && mrb_nil_p(ss)) {
*ps = NULL; *ps = NULL;
} }
...@@ -793,8 +785,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) ...@@ -793,8 +785,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
pb = va_arg(ap, mrb_value**); pb = va_arg(ap, mrb_value**);
pl = va_arg(ap, mrb_int*); pl = va_arg(ap, mrb_int*);
if (i < argc) { if (i < argc) {
aa = argv[arg_i++]; aa = argv[i++];
i++;
if (altmode && mrb_nil_p(aa)) { if (altmode && mrb_nil_p(aa)) {
*pb = 0; *pb = 0;
*pl = 0; *pl = 0;
...@@ -815,14 +806,12 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) ...@@ -815,14 +806,12 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
p = va_arg(ap, void**); p = va_arg(ap, void**);
if (i < argc) { if (i < argc) {
ss = argv[arg_i]; ss = argv[i++];
if (!mrb_istruct_p(ss)) if (!mrb_istruct_p(ss))
{ {
mrb_raisef(mrb, E_TYPE_ERROR, "%v is not inline struct", ss); mrb_raisef(mrb, E_TYPE_ERROR, "%v is not inline struct", ss);
} }
*p = mrb_istruct_ptr(ss); *p = mrb_istruct_ptr(ss);
arg_i++;
i++;
} }
} }
break; break;
...@@ -833,9 +822,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) ...@@ -833,9 +822,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
p = va_arg(ap, mrb_float*); p = va_arg(ap, mrb_float*);
if (i < argc) { if (i < argc) {
*p = mrb_to_flo(mrb, argv[arg_i]); *p = mrb_to_flo(mrb, argv[i++]);
arg_i++;
i++;
} }
} }
break; break;
...@@ -846,9 +833,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) ...@@ -846,9 +833,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
p = va_arg(ap, mrb_int*); p = va_arg(ap, mrb_int*);
if (i < argc) { if (i < argc) {
*p = mrb_fixnum(mrb_to_int(mrb, argv[arg_i])); *p = mrb_fixnum(mrb_to_int(mrb, argv[i++]));
arg_i++;
i++;
} }
} }
break; break;
...@@ -857,9 +842,8 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) ...@@ -857,9 +842,8 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
mrb_bool *boolp = va_arg(ap, mrb_bool*); mrb_bool *boolp = va_arg(ap, mrb_bool*);
if (i < argc) { if (i < argc) {
mrb_value b = argv[arg_i++]; mrb_value b = argv[i++];
*boolp = mrb_test(b); *boolp = mrb_test(b);
i++;
} }
} }
break; break;
...@@ -871,9 +855,8 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) ...@@ -871,9 +855,8 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
if (i < argc) { if (i < argc) {
mrb_value ss; mrb_value ss;
ss = argv[arg_i++]; ss = argv[i++];
*symp = to_sym(mrb, ss); *symp = to_sym(mrb, ss);
i++;
} }
} }
break; break;
...@@ -885,8 +868,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) ...@@ -885,8 +868,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
datap = va_arg(ap, void**); datap = va_arg(ap, void**);
type = va_arg(ap, struct mrb_data_type const*); type = va_arg(ap, struct mrb_data_type const*);
if (i < argc) { if (i < argc) {
mrb_value dd = argv[arg_i++]; mrb_value dd = argv[i++];
i++;
if (altmode && mrb_nil_p(dd)) { if (altmode && mrb_nil_p(dd)) {
*datap = 0; *datap = 0;
} }
...@@ -939,16 +921,15 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) ...@@ -939,16 +921,15 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
*pl = argc-i; *pl = argc-i;
if (*pl > 0) { if (*pl > 0) {
if (nocopy) { if (nocopy) {
*var = argv+arg_i; *var = argv+i;
} }
else { else {
mrb_value args = mrb_ary_new_from_values(mrb, *pl, argv+arg_i); mrb_value args = mrb_ary_new_from_values(mrb, *pl, argv+i);
RARRAY(args)->c = NULL; RARRAY(args)->c = NULL;
*var = RARRAY_PTR(args); *var = RARRAY_PTR(args);
} }
} }
i = argc; i = argc;
arg_i += *pl;
} }
else { else {
*pl = 0; *pl = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment