From 81c314769541785afe080f24f06dd5b074c907b3 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Tue, 3 Jun 2014 23:30:00 +0900 Subject: [PATCH] move pic_import and pic_export to lib.c --- src/lib.c | 37 +++++++++++++++++++++++++++++++++++++ src/macro.c | 37 ------------------------------------- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/lib.c b/src/lib.c index 726f3a53..c33f694f 100644 --- a/src/lib.c +++ b/src/lib.c @@ -60,3 +60,40 @@ pic_find_library(pic_state *pic, pic_value spec) } return pic_lib_ptr(pic_cdr(pic, v)); } + +void +pic_import(pic_state *pic, pic_value spec) +{ + struct pic_lib *lib; + xh_iter it; + + lib = pic_find_library(pic, spec); + if (! lib) { + pic_errorf(pic, "library not found: ~a", spec); + } + xh_begin(&it, &lib->exports); + while (xh_next(&it)) { + +#if DEBUG + printf("* importing %s as %s\n", pic_symbol_name(pic, xh_key(it.e, pic_sym)), pic_symbol_name(pic, xh_val(it.e, pic_sym))); +#endif + + pic_put_rename(pic, pic->lib->senv, xh_key(it.e, pic_sym), xh_val(it.e, pic_sym)); + } +} + +void +pic_export(pic_state *pic, pic_sym sym) +{ + pic_sym rename; + + if (! pic_find_rename(pic, pic->lib->senv, sym, &rename)) { + pic_errorf(pic, "export: symbol not defined %s", pic_symbol_name(pic, sym)); + } + +#if DEBUG + printf("* exporting %s as %s\n", pic_symbol_name(pic, sym), pic_symbol_name(pic, rename)); +#endif + + xh_put(&pic->lib->exports, sym, &rename); +} diff --git a/src/macro.c b/src/macro.c index 2790efb0..bcea0909 100644 --- a/src/macro.c +++ b/src/macro.c @@ -71,43 +71,6 @@ pic_find_rename(pic_state *pic, struct pic_senv *senv, pic_sym sym, pic_sym *ren return true; } -void -pic_import(pic_state *pic, pic_value spec) -{ - struct pic_lib *lib; - xh_iter it; - - lib = pic_find_library(pic, spec); - if (! lib) { - pic_errorf(pic, "library not found: ~a", spec); - } - xh_begin(&it, &lib->exports); - while (xh_next(&it)) { - -#if DEBUG - printf("* importing %s as %s\n", pic_symbol_name(pic, xh_key(it.e, pic_sym)), pic_symbol_name(pic, xh_val(it.e, pic_sym))); -#endif - - pic_put_rename(pic, pic->lib->senv, xh_key(it.e, pic_sym), xh_val(it.e, pic_sym)); - } -} - -void -pic_export(pic_state *pic, pic_sym sym) -{ - pic_sym rename; - - if (! pic_find_rename(pic, pic->lib->senv, sym, &rename)) { - pic_errorf(pic, "export: symbol not defined %s", pic_symbol_name(pic, sym)); - } - -#if DEBUG - printf("* exporting %s as %s\n", pic_symbol_name(pic, sym), pic_symbol_name(pic, rename)); -#endif - - xh_put(&pic->lib->exports, sym, &rename); -} - static void define_macro(pic_state *pic, pic_sym rename, struct pic_proc *proc, struct pic_senv *senv) {