From 4a2cb90095f7249fadd5f8ad836cf8ca548b4ab8 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 24 Mar 2014 12:30:21 +0900 Subject: [PATCH] move pic_try/pic_catch macros to error.h --- include/picrin.h | 9 --------- include/picrin/error.h | 9 +++++++++ src/init.c | 1 + tools/main.c | 1 + 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/include/picrin.h b/include/picrin.h index b69141ac..0767b008 100644 --- a/include/picrin.h +++ b/include/picrin.h @@ -134,15 +134,6 @@ void pic_define(pic_state *, const char *, pic_value); /* automatic export */ pic_value pic_ref(pic_state *, const char *); void pic_set(pic_state *, const char *, pic_value); -#define pic_try \ - pic_try_helper__(GENSYM(i), GENSYM(here), GENSYM(prev_jmp)) -#define pic_try_helper__(i, here, prev_jmp) \ - for (int i = 0; ! i; ) \ - for (jmp_buf here, *prev_jmp = pic->jmp; ! i; ) \ - for (pic->jmp = &here; ! i++; pic->jmp = prev_jmp) \ - if (setjmp(here) == 0) -#define pic_catch else - struct pic_proc *pic_get_proc(pic_state *); int pic_get_args(pic_state *, const char *, ...); void pic_defun(pic_state *, const char *, pic_func_t); diff --git a/include/picrin/error.h b/include/picrin/error.h index 475fd661..69db71c9 100644 --- a/include/picrin/error.h +++ b/include/picrin/error.h @@ -24,6 +24,15 @@ struct pic_error { #define pic_error_p(v) (pic_type(v) == PIC_TT_ERROR) #define pic_error_ptr(v) ((struct pic_error *)pic_ptr(v)) +#define pic_try \ + pic_try_helper__(GENSYM(i), GENSYM(here), GENSYM(prev_jmp)) +#define pic_try_helper__(i, here, prev_jmp) \ + for (int i = 0; ! i; ) \ + for (jmp_buf here, *prev_jmp = pic->jmp; ! i; ) \ + for (pic->jmp = &here; ! i++; pic->jmp = prev_jmp) \ + if (setjmp(here) == 0) +#define pic_catch else + pic_value pic_raise_continuable(pic_state *, pic_value); #if defined(__cplusplus) diff --git a/src/init.c b/src/init.c index 0b6a11ff..537dbdf6 100644 --- a/src/init.c +++ b/src/init.c @@ -8,6 +8,7 @@ #include "picrin/pair.h" #include "picrin/lib.h" #include "picrin/macro.h" +#include "picrin/error.h" void pic_init_bool(pic_state *); void pic_init_pair(pic_state *); diff --git a/tools/main.c b/tools/main.c index 9be04045..ea00782b 100644 --- a/tools/main.c +++ b/tools/main.c @@ -9,6 +9,7 @@ #include "picrin.h" #include "picrin/pair.h" +#include "picrin/error.h" #if PIC_ENABLE_READLINE # include