Commit f09c5158 authored by skandhas's avatar skandhas

format some source code (class.c)

parent c567a28f
...@@ -407,7 +407,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) ...@@ -407,7 +407,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
break; break;
default: default:
if (argc <= i && !opt) { if (argc <= i && !opt) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments"); mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments");
} }
} }
...@@ -417,10 +417,10 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) ...@@ -417,10 +417,10 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
mrb_value *p; mrb_value *p;
p = va_arg(ap, mrb_value*); p = va_arg(ap, mrb_value*);
if (i < argc) { if (i < argc) {
*p = *sp++; *p = *sp++;
i++; i++;
} }
} }
break; break;
case 'S': case 'S':
...@@ -428,10 +428,10 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) ...@@ -428,10 +428,10 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
mrb_value *p; mrb_value *p;
p = va_arg(ap, mrb_value*); p = va_arg(ap, mrb_value*);
if (i < argc) { if (i < argc) {
*p = to_str(mrb, *sp++); *p = to_str(mrb, *sp++);
i++; i++;
} }
} }
break; break;
case 'A': case 'A':
...@@ -439,10 +439,10 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) ...@@ -439,10 +439,10 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
mrb_value *p; mrb_value *p;
p = va_arg(ap, mrb_value*); p = va_arg(ap, mrb_value*);
if (i < argc) { if (i < argc) {
*p = to_ary(mrb, *sp++); *p = to_ary(mrb, *sp++);
i++; i++;
} }
} }
break; break;
case 'H': case 'H':
...@@ -450,64 +450,64 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) ...@@ -450,64 +450,64 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
mrb_value *p; mrb_value *p;
p = va_arg(ap, mrb_value*); p = va_arg(ap, mrb_value*);
if (i < argc) { if (i < argc) {
*p = to_hash(mrb, *sp++); *p = to_hash(mrb, *sp++);
i++; i++;
} }
} }
break; break;
case 's': case 's':
{ {
mrb_value ss; mrb_value ss;
struct RString *s; struct RString *s;
char **ps = 0; char **ps = 0;
int *pl = 0; int *pl = 0;
ps = va_arg(ap, char**); ps = va_arg(ap, char**);
pl = va_arg(ap, int*); pl = va_arg(ap, int*);
if (i < argc) { if (i < argc) {
ss = to_str(mrb, *sp++); ss = to_str(mrb, *sp++);
s = mrb_str_ptr(ss); s = mrb_str_ptr(ss);
*ps = s->ptr; *ps = s->ptr;
*pl = s->len; *pl = s->len;
i++; i++;
} }
} }
break; break;
case 'z': case 'z':
{ {
mrb_value ss; mrb_value ss;
struct RString *s; struct RString *s;
char **ps; char **ps;
ps = va_arg(ap, char**); ps = va_arg(ap, char**);
if (i < argc) { if (i < argc) {
ss = to_str(mrb, *sp++); ss = to_str(mrb, *sp++);
s = mrb_str_ptr(ss); s = mrb_str_ptr(ss);
if (strlen(s->ptr) != s->len) { if (strlen(s->ptr) != s->len) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "String contains NUL"); mrb_raise(mrb, E_ARGUMENT_ERROR, "String contains NUL");
} }
*ps = s->ptr; *ps = s->ptr;
i++; i++;
} }
} }
break; break;
case 'a': case 'a':
{ {
mrb_value aa; mrb_value aa;
struct RArray *a; struct RArray *a;
mrb_value **pb; mrb_value **pb;
int *pl; int *pl;
pb = va_arg(ap, mrb_value**); pb = va_arg(ap, mrb_value**);
pl = va_arg(ap, int*); pl = va_arg(ap, int*);
if (i < argc) { if (i < argc) {
aa = to_ary(mrb, *sp++); aa = to_ary(mrb, *sp++);
a = mrb_ary_ptr(aa); a = mrb_ary_ptr(aa);
*pb = a->ptr; *pb = a->ptr;
*pl = a->len; *pl = a->len;
i++; i++;
} }
} }
break; break;
case 'f': case 'f':
...@@ -515,29 +515,29 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) ...@@ -515,29 +515,29 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
mrb_float *p; mrb_float *p;
p = va_arg(ap, mrb_float*); p = va_arg(ap, mrb_float*);
if (i < argc) { if (i < argc) {
switch (mrb_type(*sp)) { switch (mrb_type(*sp)) {
case MRB_TT_FLOAT: case MRB_TT_FLOAT:
*p = mrb_float(*sp); *p = mrb_float(*sp);
break; break;
case MRB_TT_FIXNUM: case MRB_TT_FIXNUM:
*p = (mrb_float)mrb_fixnum(*sp); *p = (mrb_float)mrb_fixnum(*sp);
break; break;
case MRB_TT_STRING: case MRB_TT_STRING:
mrb_raise(mrb, E_TYPE_ERROR, "String can't be coerced into Float"); mrb_raise(mrb, E_TYPE_ERROR, "String can't be coerced into Float");
break; break;
default: default:
{ {
mrb_value tmp; mrb_value tmp;
tmp = mrb_convert_type(mrb, *sp, MRB_TT_FLOAT, "Float", "to_f"); tmp = mrb_convert_type(mrb, *sp, MRB_TT_FLOAT, "Float", "to_f");
*p = mrb_float(tmp); *p = mrb_float(tmp);
} }
break; break;
} }
sp++; sp++;
i++; i++;
} }
} }
break; break;
case 'i': case 'i':
...@@ -545,71 +545,71 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) ...@@ -545,71 +545,71 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
mrb_int *p; mrb_int *p;
p = va_arg(ap, mrb_int*); p = va_arg(ap, mrb_int*);
if (i < argc) { if (i < argc) {
switch (mrb_type(*sp)) { switch (mrb_type(*sp)) {
case MRB_TT_FIXNUM: case MRB_TT_FIXNUM:
*p = mrb_fixnum(*sp); *p = mrb_fixnum(*sp);
break; break;
case MRB_TT_FLOAT: case MRB_TT_FLOAT:
{ {
mrb_float f = mrb_float(*sp); mrb_float f = mrb_float(*sp);
if (!FIXABLE(f)) { if (!FIXABLE(f)) {
mrb_raise(mrb, E_RANGE_ERROR, "float too big for int"); mrb_raise(mrb, E_RANGE_ERROR, "float too big for int");
} }
*p = (mrb_int)f; *p = (mrb_int)f;
} }
break; break;
case MRB_TT_FALSE: case MRB_TT_FALSE:
*p = 0; *p = 0;
break; break;
default: default:
{ {
mrb_value tmp; mrb_value tmp;
tmp = mrb_convert_type(mrb, *sp, MRB_TT_FIXNUM, "Integer", "to_int"); tmp = mrb_convert_type(mrb, *sp, MRB_TT_FIXNUM, "Integer", "to_int");
*p = mrb_fixnum(tmp); *p = mrb_fixnum(tmp);
} }
break; break;
} }
sp++; sp++;
i++; i++;
} }
} }
break; break;
case 'b': case 'b':
{ {
int *boolp = va_arg(ap, int*); int *boolp = va_arg(ap, int*);
if (i < argc) { if (i < argc) {
mrb_value b = *sp++; mrb_value b = *sp++;
*boolp = mrb_test(b); *boolp = mrb_test(b);
i++; i++;
} }
} }
break; break;
case 'n': case 'n':
{ {
mrb_sym *symp; mrb_sym *symp;
symp = va_arg(ap, mrb_sym*); symp = va_arg(ap, mrb_sym*);
if (i < argc) { if (i < argc) {
mrb_value ss; mrb_value ss;
ss = *sp++; ss = *sp++;
if (mrb_type(ss) == MRB_TT_SYMBOL) { if (mrb_type(ss) == MRB_TT_SYMBOL) {
*symp = mrb_symbol(ss); *symp = mrb_symbol(ss);
} }
else if (mrb_string_p(ss)) { else if (mrb_string_p(ss)) {
*symp = mrb_intern_str(mrb, to_str(mrb, ss)); *symp = mrb_intern_str(mrb, to_str(mrb, ss));
} }
else { else {
mrb_value obj = mrb_funcall(mrb, ss, "inspect", 0); mrb_value obj = mrb_funcall(mrb, ss, "inspect", 0);
mrb_raisef(mrb, E_TYPE_ERROR, "%s is not a symbol", mrb_raisef(mrb, E_TYPE_ERROR, "%s is not a symbol",
mrb_string_value_ptr(mrb, obj)); mrb_string_value_ptr(mrb, obj));
} }
i++; i++;
} }
} }
break; break;
...@@ -621,9 +621,9 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) ...@@ -621,9 +621,9 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
if (mrb->ci->argc < 0) { if (mrb->ci->argc < 0) {
bp = mrb->stack + 2; bp = mrb->stack + 2;
} }
else { else {
bp = mrb->stack + mrb->ci->argc + 1; bp = mrb->stack + mrb->ci->argc + 1;
} }
*p = *bp; *p = *bp;
} }
break; break;
...@@ -634,18 +634,18 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) ...@@ -634,18 +634,18 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
case '*': case '*':
{ {
mrb_value **var; mrb_value **var;
int *pl; int *pl;
var = va_arg(ap, mrb_value**); var = va_arg(ap, mrb_value**);
pl = va_arg(ap, int*); pl = va_arg(ap, int*);
if (argc > i) { if (argc > i) {
*pl = argc-i; *pl = argc-i;
if (*pl > 0) { if (*pl > 0) {
*var = sp; *var = sp;
i = argc; i = argc;
} }
i = argc; i = argc;
sp += *pl; sp += *pl;
} }
else { else {
*pl = 0; *pl = 0;
...@@ -689,13 +689,13 @@ mrb_include_module(mrb_state *mrb, struct RClass *c, struct RClass *m) ...@@ -689,13 +689,13 @@ mrb_include_module(mrb_state *mrb, struct RClass *c, struct RClass *m)
while(p) { while(p) {
if (c != p && p->tt == MRB_TT_CLASS) { if (c != p && p->tt == MRB_TT_CLASS) {
superclass_seen = 1; superclass_seen = 1;
} }
else if (p->mt == m->mt){ else if (p->mt == m->mt){
if (p->tt == MRB_TT_ICLASS && !superclass_seen) { if (p->tt == MRB_TT_ICLASS && !superclass_seen) {
ins_pos = p; ins_pos = p;
} }
goto skip; goto skip;
} }
p = p->super; p = p->super;
} }
......
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