diff --git a/include/picrin/cont.h b/include/picrin/cont.h index 67c86f6c..38cfc131 100644 --- a/include/picrin/cont.h +++ b/include/picrin/cont.h @@ -40,7 +40,7 @@ struct pic_cont { } while (0) #define PIC_BLK_DECREF(pic,blk) do { \ - pic_block *_a = (blk), *_b; \ + pic_block *_a = (blk), *_b; \ while (_a) { \ if (! --_a->refcnt) { \ _b = _a->prev; \ @@ -52,6 +52,17 @@ struct pic_cont { } \ } while (0) +#define PIC_BLK_EXIT(pic) do { \ + pic_block *_a; \ + while (pic->blk) { \ + if (pic->blk->out) \ + pic_apply_argv(pic, pic->blk->out, 0); \ + _a = pic->blk->prev; \ + PIC_BLK_DECREF(pic, pic->blk); \ + pic->blk = _a; \ + } \ + } while (0) + 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); diff --git a/src/system.c b/src/system.c index 2591fa20..b5108af1 100644 --- a/src/system.c +++ b/src/system.c @@ -7,6 +7,7 @@ #include "picrin.h" #include "picrin/string.h" #include "picrin/pair.h" +#include "picrin/cont.h" static pic_value pic_system_cmdline(pic_state *pic) @@ -31,7 +32,6 @@ pic_system_exit(pic_state *pic) { pic_value v; int argc, status = EXIT_SUCCESS; - pic_block *blk; argc = pic_get_args(pic, "|o", &v); if (argc == 1) { @@ -47,11 +47,7 @@ pic_system_exit(pic_state *pic) } } - blk = pic->blk; - while (blk) { - pic_apply_argv(pic, blk->out, 0); - blk = blk->prev; - } + PIC_BLK_EXIT(pic); exit(status); }