This commit is contained in:
Yuichi Nishiwaki 2014-02-20 20:44:30 +09:00
parent 19f426a4f4
commit 078b72ff17
3 changed files with 67 additions and 66 deletions

View File

@ -50,12 +50,13 @@ struct pic_cont {
} \
} while (0)
pic_value pic_callcc(pic_state *, struct pic_proc *);
pic_value pic_values(pic_state *, size_t, ...);
pic_value pic_values_by_array(pic_state *, size_t, pic_value *);
pic_value pic_values_by_list(pic_state *, pic_value);
size_t pic_receive(pic_state *, size_t, pic_value *);
pic_value pic_callcc(pic_state *, struct pic_proc *);
#if defined(__cplusplus)
}
#endif

View File

@ -909,7 +909,7 @@
(lambda (form rename compare?)
(let ((expr (cadr form)))
`(make-promise% #f (lambda () ,expr))))))
(define-syntax delay
(ir-macro-transformer
(lambda (form rename compare?)
@ -919,7 +919,7 @@
(define (promise-update! new old)
(promise-done! old (promise-done? new))
(promise-value! old (promise-value new)))
(define (force promise)
(if (promise-done? promise)
(promise-value promise)

View File

@ -11,6 +11,69 @@
#include "picrin/cont.h"
#include "picrin/pair.h"
pic_value
pic_values(pic_state *pic, size_t c, ...)
{
va_list ap;
size_t i;
va_start(ap, c);
for (i = 0; i < c; ++i) {
pic->sp[i] = va_arg(ap, pic_value);
}
pic->ci->retc = c;
va_end(ap);
return c == 0 ? pic_none_value() : pic->sp[0];
}
pic_value
pic_values_by_array(pic_state *pic, size_t argc, pic_value *argv)
{
size_t i;
for (i = 0; i < argc; ++i) {
pic->sp[i] = argv[i];
}
pic->ci->retc = argc;
return argc == 0 ? pic_none_value() : pic->sp[0];
}
pic_value
pic_values_by_list(pic_state *pic, pic_value list)
{
pic_value v;
size_t i;
i = 0;
pic_for_each (v, list) {
pic->sp[i++] = v;
}
pic->ci->retc = i;
return pic_nil_p(list) ? pic_none_value() : pic->sp[0];
}
size_t
pic_receive(pic_state *pic, size_t n, pic_value *argv)
{
pic_callinfo *ci;
size_t i, retc;
/* take info from discarded frame */
ci = pic->ci + 1;
retc = ci->retc;
for (i = 0; i < retc && i < n; ++i) {
argv[i] = ci->fp[i];
}
return retc;
}
static void save_cont(pic_state *, struct pic_cont **);
static void restore_cont(pic_state *, struct pic_cont *);
@ -172,69 +235,6 @@ pic_callcc(pic_state *pic, struct pic_proc *proc)
}
}
pic_value
pic_values(pic_state *pic, size_t c, ...)
{
va_list ap;
size_t i;
va_start(ap, c);
for (i = 0; i < c; ++i) {
pic->sp[i] = va_arg(ap, pic_value);
}
pic->ci->retc = c;
va_end(ap);
return c == 0 ? pic_none_value() : pic->sp[0];
}
pic_value
pic_values_by_array(pic_state *pic, size_t argc, pic_value *argv)
{
size_t i;
for (i = 0; i < argc; ++i) {
pic->sp[i] = argv[i];
}
pic->ci->retc = argc;
return argc == 0 ? pic_none_value() : pic->sp[0];
}
pic_value
pic_values_by_list(pic_state *pic, pic_value list)
{
pic_value v;
size_t i;
i = 0;
pic_for_each (v, list) {
pic->sp[i++] = v;
}
pic->ci->retc = i;
return pic_nil_p(list) ? pic_none_value() : pic->sp[0];
}
size_t
pic_receive(pic_state *pic, size_t n, pic_value *argv)
{
pic_callinfo *ci;
size_t i, retc;
/* take info from discarded frame */
ci = pic->ci + 1;
retc = ci->retc;
for (i = 0; i < retc && i < n; ++i) {
argv[i] = ci->fp[i];
}
return retc;
}
static pic_value
pic_callcc_trampoline(pic_state *pic, struct pic_proc *proc)
{