From 887b6a9f911132aa6c743668ea533275811cf44e Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 2 Mar 2014 22:23:57 +0900 Subject: [PATCH] refactor pic_deflib --- include/picrin.h | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/include/picrin.h b/include/picrin.h index d576b021..63d645c5 100644 --- a/include/picrin.h +++ b/include/picrin.h @@ -179,22 +179,13 @@ void pic_in_library(pic_state *, pic_value); struct pic_lib *pic_make_library(pic_state *, pic_value); struct pic_lib *pic_find_library(pic_state *, pic_value); -#define PIC_DEFLIBRARY_HELPER2(tmp1, tmp2, tmp3, spec) \ - for (struct pic_lib *tmp1 = pic->lib, \ - *tmp2 = (pic_make_library(pic, pic_read(pic, spec)), \ - pic_in_library(pic, pic_read(pic, spec)), \ - NULL); \ - tmp3 < 1; \ - (pic->lib = tmp1), ((void)tmp2), ++tmp3) - -#define PIC_DEFLIBRARY_HELPER1(tmp1, tmp2, spec) \ - for (int tmp1 = 0, tmp2 = 0; tmp1 < 1; ++tmp1) \ - PIC_DEFLIBRARY_HELPER2(GENSYM(pic_deflib_tmp3__), \ - GENSYM(pic_deflib_tmp4__), \ - tmp2, spec) +#define pic_deflibrary_helper__(i, prev_lib, spec) \ + for (int i = 0; ! i; ) \ + for (struct pic_lib *prev_lib; ! i; ) \ + for ((prev_lib = pic->lib), pic_make_library(pic, pic_read(pic, spec)), pic_in_library(pic, pic_read(pic, spec)); ! i++; pic->lib = prev_lib) \ #define pic_deflibrary(spec) \ - PIC_DEFLIBRARY_HELPER1(GENSYM(pic_deflib_tmp1__), GENSYM(pic_deflib_tmp2__), spec) + pic_deflibrary_helper__(GENSYM(pic_deflib_i__), GENSYM(pic_deflib_prev_lib__), spec) void pic_import(pic_state *, pic_value); void pic_export(pic_state *, pic_sym);