From 6b2d6a98eba36e0b714213f10cbc05ae3e25e7ac Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sat, 7 Dec 2013 18:27:08 -0800 Subject: [PATCH] Revert "change APIs of library functions" This reverts commit 0115ede4de05318535277549f5a40dd842ae9d30. Conflicts: include/picrin.h --- include/picrin.h | 4 ++-- src/lib.c | 25 +++++-------------------- src/state.c | 4 ++-- 3 files changed, 9 insertions(+), 24 deletions(-) diff --git a/include/picrin.h b/include/picrin.h index fec7bd9d..aa60ea75 100644 --- a/include/picrin.h +++ b/include/picrin.h @@ -122,8 +122,8 @@ pic_value pic_apply_argv(pic_state *pic, struct pic_proc *, size_t, ...); struct pic_proc *pic_codegen(pic_state *, pic_value); pic_value pic_macroexpand(pic_state *, pic_value); -void pic_make_library(pic_state *, const char *); -void pic_in_library(pic_state *, const char *); +void pic_make_library(pic_state *, pic_value); +void pic_in_library(pic_state *, pic_value); struct pic_lib *pic_find_library(pic_state *, pic_value); void pic_abort(pic_state *, const char *); diff --git a/src/lib.c b/src/lib.c index ba7ac212..3fbcdba4 100644 --- a/src/lib.c +++ b/src/lib.c @@ -4,42 +4,27 @@ #include "picrin/macro.h" #include "xhash/xhash.h" -static pic_value -lib_spec(pic_state *pic, const char *name) -{ - pic_value vs; - int r; - - r = pic_parse_cstr(pic, name, &vs); - if (r != 1) { - pic_error(pic, "invalid library spec given"); - } - return pic_car(pic, vs); -} - void -pic_make_library(pic_state *pic, const char *name) +pic_make_library(pic_state *pic, pic_value name) { struct pic_lib *lib; - pic_value spec = lib_spec(pic, name); lib = (struct pic_lib *)pic_obj_alloc(pic, sizeof(struct pic_lib), PIC_TT_LIB); lib->senv = pic_core_syntactic_env(pic); lib->exports = xh_new(); - pic->lib_tbl = pic_acons(pic, spec, pic_obj_value(lib), pic->lib_tbl); + pic->lib_tbl = pic_acons(pic, name, pic_obj_value(lib), pic->lib_tbl); } void -pic_in_library(pic_state *pic, const char *name) +pic_in_library(pic_state *pic, pic_value name) { - pic_value v, spec = lib_spec(pic, name); + pic_value v; - v = pic_assoc(pic, spec, pic->lib_tbl); + v = pic_assoc(pic, name, pic->lib_tbl); if (pic_false_p(v)) { pic_error(pic, "library not found"); } - pic->lib = pic_lib_ptr(pic_cdr(pic, v)); } diff --git a/src/state.c b/src/state.c index c322e5e7..9afa08c1 100644 --- a/src/state.c +++ b/src/state.c @@ -119,8 +119,8 @@ pic_open(int argc, char *argv[], char **envp) pic_gc_arena_restore(pic, ai); /* set library */ - pic_make_library(pic, "user"); - pic_in_library(pic, "user"); + pic_make_library(pic, pic_symbol_value(pic_intern_cstr(pic, "user"))); + pic_in_library(pic, pic_symbol_value(pic_intern_cstr(pic, "user"))); pic_init_core(pic);