diff --git a/Makefile b/Makefile index 757c480e..6aab7070 100644 --- a/Makefile +++ b/Makefile @@ -49,7 +49,7 @@ src/init_contrib.c: lib/libbenz.a: $(BENZ_OBJS) $(AR) $(ARFLAGS) $@ $(BENZ_OBJS) -%.o: extlib/benz/include/picrin.h extlib/benz/include/picrin/*.h +$(PICRIN_OBJS) $(CONTRIB_OBJS): extlib/benz/include/picrin.h extlib/benz/include/picrin/*.h doc: docs/*.rst docs/contrib.rst $(MAKE) -C docs html diff --git a/extlib/benz/include/picrin.h b/extlib/benz/include/picrin.h index 84ab6f45..46da1afe 100644 --- a/extlib/benz/include/picrin.h +++ b/extlib/benz/include/picrin.h @@ -203,13 +203,16 @@ struct pic_proc *pic_compile(pic_state *, pic_value, struct pic_lib *); pic_value pic_macroexpand(pic_state *, pic_value, struct pic_lib *); void pic_in_library(pic_state *, pic_value); -struct pic_lib *pic_open_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(pic, spec) \ for (((assert(pic->prev_lib == NULL)), \ (pic->prev_lib = pic->lib), \ - (pic->lib = pic_open_library(pic, pic_read_cstr(pic, (spec))))); \ + (pic->lib = pic_find_library(pic, pic_read_cstr(pic, (spec)))), \ + (pic->lib = pic->lib \ + ? pic->lib \ + : pic_make_library(pic, pic_read_cstr(pic, (spec))))); \ pic->prev_lib != NULL; \ ((pic->lib = pic->prev_lib), \ (pic->prev_lib = NULL))) diff --git a/extlib/benz/lib.c b/extlib/benz/lib.c index ffa0583b..8eff0bb7 100644 --- a/extlib/benz/lib.c +++ b/extlib/benz/lib.c @@ -5,21 +5,14 @@ #include "picrin.h" struct pic_lib * -pic_open_library(pic_state *pic, pic_value name) +pic_make_library(pic_state *pic, pic_value name) { struct pic_lib *lib; struct pic_env *env; struct pic_dict *exports; if ((lib = pic_find_library(pic, name)) != NULL) { - -#if DEBUG - printf("* reopen library: "); - pic_debug(pic, name); - puts(""); -#endif - - return lib; + pic_errorf(pic, "library name already in use: ~s", name); } env = pic_null_syntactic_environment(pic); @@ -295,7 +288,9 @@ pic_lib_define_library(pic_state *pic) pic_get_args(pic, "o*", &spec, &argc, &argv); - pic_open_library(pic, spec); + if (! pic_find_library(pic, spec)) { + pic_make_library(pic, spec); + } pic_try { pic_in_library(pic, spec); diff --git a/extlib/benz/state.c b/extlib/benz/state.c index c4207987..521b9a0d 100644 --- a/extlib/benz/state.c +++ b/extlib/benz/state.c @@ -322,8 +322,8 @@ pic_open(int argc, char *argv[], char **envp, pic_allocf allocf) pic->xSTDERR = pic_make_standard_port(pic, xstderr, PIC_PORT_OUT); /* standard libraries */ - pic->PICRIN_BASE = pic_open_library(pic, pic_read_cstr(pic, "(picrin base)")); - pic->PICRIN_USER = pic_open_library(pic, pic_read_cstr(pic, "(picrin user)")); + pic->PICRIN_BASE = pic_make_library(pic, pic_read_cstr(pic, "(picrin base)")); + pic->PICRIN_USER = pic_make_library(pic, pic_read_cstr(pic, "(picrin user)")); pic->lib = pic->PICRIN_USER; pic->prev_lib = NULL;