pic_return -> pic_values

This commit is contained in:
Yuichi Nishiwaki 2017-03-30 21:53:49 +09:00
parent 637047fa83
commit e7953146c3
4 changed files with 26 additions and 29 deletions

View File

@ -18,13 +18,13 @@ pic_number_floor2(pic_state *pic)
? i / j
: (i / j) - 1;
return pic_return(pic, 2, pic_int_value(pic, k), pic_int_value(pic, i - k * j));
return pic_values(pic, 2, pic_int_value(pic, k), pic_int_value(pic, i - k * j));
} else {
double q, r;
q = floor((double)i/j);
r = i - j * q;
return pic_return(pic, 2, pic_float_value(pic, q), pic_float_value(pic, r));
return pic_values(pic, 2, pic_float_value(pic, q), pic_float_value(pic, r));
}
}
@ -37,14 +37,14 @@ pic_number_trunc2(pic_state *pic)
pic_get_args(pic, "II", &i, &e1, &j, &e2);
if (e1 && e2) {
return pic_return(pic, 2, pic_int_value(pic, i/j), pic_int_value(pic, i - (i/j) * j));
return pic_values(pic, 2, pic_int_value(pic, i/j), pic_int_value(pic, i - (i/j) * j));
} else {
double q, r;
q = trunc((double)i/j);
r = i - j * q;
return pic_return(pic, 2, pic_float_value(pic, q), pic_float_value(pic, r));
return pic_values(pic, 2, pic_float_value(pic, q), pic_float_value(pic, r));
}
}

View File

@ -120,7 +120,7 @@ pic_regexp_regexp_match(pic_state *pic)
matches = pic_reverse(pic, matches);
positions = pic_reverse(pic, positions);
}
return pic_return(pic, 2, matches, positions);
return pic_values(pic, 2, matches, positions);
}
static pic_value

View File

@ -144,6 +144,19 @@ pic_alloca_cont(pic_state *pic)
return pic_alloca(pic, sizeof(struct cont));
}
static pic_value
values(pic_state *pic, int argc, pic_value *argv)
{
int i;
for (i = 0; i < argc; ++i) {
pic->sp[i] = argv[i];
}
pic->ci->retc = argc;
return argc == 0 ? pic_undef_value(pic) : pic->sp[0];
}
static pic_value
pic_callcc(pic_state *pic, pic_value proc)
{
@ -151,7 +164,7 @@ pic_callcc(pic_state *pic, pic_value proc)
volatile struct cont *cont = pic_alloca_cont(pic);
if (PIC_SETJMP(pic, jmp)) {
return pic_valuesk(pic, cont->retc, cont->retv);
return values(pic, cont->retc, cont->retv);
}
else {
pic_value val;
@ -167,19 +180,19 @@ pic_callcc(pic_state *pic, pic_value proc)
}
pic_value
pic_return(pic_state *pic, int n, ...)
pic_values(pic_state *pic, int n, ...)
{
va_list ap;
pic_value ret;
va_start(ap, n);
ret = pic_vreturn(pic, n, ap);
ret = pic_vvalues(pic, n, ap);
va_end(ap);
return ret;
}
pic_value
pic_vreturn(pic_state *pic, int n, va_list ap)
pic_vvalues(pic_state *pic, int n, va_list ap)
{
pic_value *retv = pic_alloca(pic, sizeof(pic_value) * n);
int i;
@ -187,20 +200,7 @@ pic_vreturn(pic_state *pic, int n, va_list ap)
for (i = 0; i < n; ++i) {
retv[i] = va_arg(ap, pic_value);
}
return pic_valuesk(pic, n, retv);
}
pic_value
pic_valuesk(pic_state *pic, int argc, pic_value *argv)
{
int i;
for (i = 0; i < argc; ++i) {
pic->sp[i] = argv[i];
}
pic->ci->retc = argc;
return argc == 0 ? pic_undef_value(pic) : pic->sp[0];
return values(pic, n, retv);
}
int
@ -247,7 +247,7 @@ pic_cont_values(pic_state *pic)
pic_get_args(pic, "*", &argc, &argv);
return pic_valuesk(pic, argc, argv);
return values(pic, argc, argv);
}
static pic_value
@ -273,9 +273,7 @@ pic_init_cont(pic_state *pic)
{
pic_defun(pic, "call-with-current-continuation", pic_cont_callcc);
pic_defun(pic, "call/cc", pic_cont_callcc);
pic_defun(pic, "escape", pic_cont_callcc);
pic_defun(pic, "dynamic-wind", pic_cont_dynamic_wind);
pic_defun(pic, "values", pic_cont_values);
pic_defun(pic, "call-with-values", pic_cont_call_with_values);
}

View File

@ -349,9 +349,8 @@ pic_value pic_make_var(pic_state *, pic_value init, pic_value conv);
void pic_defun(pic_state *, const char *name, pic_func_t f);
void pic_defvar(pic_state *, const char *name, pic_value v);
pic_value pic_funcall(pic_state *, const char *lib, const char *name, int n, ...);
pic_value pic_return(pic_state *, int n, ...);
pic_value pic_vreturn(pic_state *, int n, va_list);
pic_value pic_valuesk(pic_state *, int n, pic_value *retv);
pic_value pic_values(pic_state *, int n, ...);
pic_value pic_vvalues(pic_state *, int n, va_list);
int pic_receive(pic_state *, int n, pic_value *retv);