From 8625f7547072fa9ac48997b823d372791ffc77d1 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Wed, 19 Mar 2014 17:43:53 +0900 Subject: [PATCH] move utility macros to picrin/util.h --- include/picrin.h | 25 +------------------------ include/picrin/util.h | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 24 deletions(-) create mode 100644 include/picrin/util.h diff --git a/include/picrin.h b/include/picrin.h index 62c05775..af333461 100644 --- a/include/picrin.h +++ b/include/picrin.h @@ -39,31 +39,8 @@ extern "C" { #include "xfile/xfile.h" #include "xrope/xrope.h" -#if __STDC_VERSION__ >= 201112L -# define noreturn _Noreturn -#elif __GNUC__ || __clang__ -# define noreturn __attribute__((noreturn)) -#endif - -#define FALLTHROUGH ((void)0) -#define UNUSED(v) ((void)(v)) - -#define GENSYM2__(x,y) x##y -#define GENSYM1__(x,y) GENSYM2__(x,y) -#if defined(__COUNTER__) -# define GENSYM(x) GENSYM1__(x,__COUNTER__) -#else -# define GENSYM(x) GENSYM1__(x,__LINE__) -#endif - -#if __GNUC__ || __clang__ -# define UNREACHABLE() (__builtin_unreachable()) -#else -# include -# define UNREACHABLE() (assert(false)) -#endif - #include "config.h" +#include "picrin/util.h" #include "picrin/value.h" typedef struct pic_code pic_code; diff --git a/include/picrin/util.h b/include/picrin/util.h new file mode 100644 index 00000000..ec4b2a9d --- /dev/null +++ b/include/picrin/util.h @@ -0,0 +1,40 @@ +/** + * See Copyright Notice in picrin.h + */ + +#ifndef PICRIN_UTIL_H__ +#define PICRIN_UTIL_H__ + +#if defined(__cplusplus) +extern "C" { +#endif + +#if __STDC_VERSION__ >= 201112L +# define noreturn _Noreturn +#elif __GNUC__ || __clang__ +# define noreturn __attribute__((noreturn)) +#endif + +#define FALLTHROUGH ((void)0) +#define UNUSED(v) ((void)(v)) + +#define GENSYM2__(x,y) x##y +#define GENSYM1__(x,y) GENSYM2__(x,y) +#if defined(__COUNTER__) +# define GENSYM(x) GENSYM1__(x,__COUNTER__) +#else +# define GENSYM(x) GENSYM1__(x,__LINE__) +#endif + +#if __GNUC__ || __clang__ +# define UNREACHABLE() (__builtin_unreachable()) +#else +# include +# define UNREACHABLE() (assert(false)) +#endif + +#if defined(__cplusplus) +} +#endif + +#endif