insert type checks in pic_get_args

This commit is contained in:
Yuichi Nishiwaki 2013-10-28 00:40:10 +09:00
parent 5133e04c39
commit c77b8be011
2 changed files with 26 additions and 11 deletions

View File

@ -92,5 +92,6 @@ pic_value pic_int_value(int);
#define pic_int_p(v) ((v).type == PIC_VTYPE_INT) #define pic_int_p(v) ((v).type == PIC_VTYPE_INT)
#define pic_pair_p(v) (pic_type(v) == PIC_TT_PAIR) #define pic_pair_p(v) (pic_type(v) == PIC_TT_PAIR)
#define pic_symbol_p(v) (pic_type(v) == PIC_TT_SYMBOL) #define pic_symbol_p(v) (pic_type(v) == PIC_TT_SYMBOL)
#define pic_str_p(v) (pic_type(v) == PIC_TT_STRING)
#endif #endif

View File

@ -56,14 +56,17 @@ pic_get_args(pic_state *pic, const char *format, ...)
pic_value v; pic_value v;
v = GET_OPERAND(pic, i); v = GET_OPERAND(pic, i);
if (pic_type(v) == PIC_TT_FLOAT) { switch (pic_type(v)) {
case PIC_TT_FLOAT:
*f = pic_float(v); *f = pic_float(v);
i++; break;
} case PIC_TT_INT:
else {
*f = pic_int(v); *f = pic_int(v);
i++; break;
default:
pic_error(pic, "pic_get_args: expected float or int");
} }
i++;
} }
} }
break; break;
@ -78,13 +81,17 @@ pic_get_args(pic_state *pic, const char *format, ...)
pic_value v; pic_value v;
v = GET_OPERAND(pic, i); v = GET_OPERAND(pic, i);
if (pic_type(v) == PIC_TT_FLOAT) { switch (pic_type(v)) {
case PIC_TT_FLOAT:
*f = pic_float(v); *f = pic_float(v);
*e = false; *e = false;
} break;
else { case PIC_TT_INT:
*f = pic_int(v); *f = pic_int(v);
*e = true; *e = true;
break;
default:
pic_error(pic, "pic_get_args: expected float or int");
} }
i++; i++;
} }
@ -101,13 +108,17 @@ pic_get_args(pic_state *pic, const char *format, ...)
pic_value v; pic_value v;
v = GET_OPERAND(pic, i); v = GET_OPERAND(pic, i);
if (pic_type(v) == PIC_TT_FLOAT) { switch (pic_type(v)) {
case PIC_TT_FLOAT:
*k = (int)pic_float(v); *k = (int)pic_float(v);
*e = false; *e = false;
} break;
else { case PIC_TT_INT:
*k = pic_int(v); *k = pic_int(v);
*e = true; *e = true;
break;
default:
pic_error(pic, "pic_get_args: expected float or int");
} }
i++; i++;
} }
@ -123,6 +134,9 @@ pic_get_args(pic_state *pic, const char *format, ...)
len = va_arg(ap, size_t *); len = va_arg(ap, size_t *);
if (i < argc) { if (i < argc) {
str = GET_OPERAND(pic,i); str = GET_OPERAND(pic,i);
if (! pic_str_p(str)) {
pic_error(pic, "pic_get_args: expected string");
}
*cstr = pic_str_ptr(str)->str; *cstr = pic_str_ptr(str)->str;
*len = pic_str_ptr(str)->len; *len = pic_str_ptr(str)->len;
i++; i++;