add 'k' specifier to pic_get_args format

This commit is contained in:
Yuichi Nishiwaki 2014-09-27 17:47:47 +09:00
parent 4ac6c2b7ab
commit bfc45a228b
1 changed files with 28 additions and 0 deletions

28
vm.c
View File

@ -40,6 +40,7 @@ pic_get_proc(pic_state *pic)
* o pic_value * object
* i int * int
* I int *, bool * int with exactness
* k size_t * size_t implicitly converted from int
* f double * float
* F double *, bool * float with exactness
* s pic_str ** string object
@ -196,6 +197,33 @@ pic_get_args(pic_state *pic, const char *format, ...)
}
break;
}
case 'k': {
size_t *k;
k = va_arg(ap, size_t *);
if (i < argc) {
pic_value v;
int x;
v = GET_OPERAND(pic, i);
switch (pic_type(v)) {
case PIC_TT_INT:
x = pic_int(v);
if (x < 0) {
pic_errorf(pic, "pic_get_args: expected non-negative int, but got ~s", v);
}
if (sizeof(unsigned) > sizeof(size_t) && (unsigned)x > (unsigned)SIZE_MAX) {
pic_errorf(pic, "pic_get_args: int unrepresentable with size_t ~s", v);
}
*k = (size_t)x;
break;
default:
pic_errorf(pic, "pic_get_args: expected int, but got ~s", v);
}
i++;
}
break;
}
case 's': {
pic_str **str;
pic_value v;