Revert "change APIs of library functions"

This reverts commit 0115ede4de.

Conflicts:
	include/picrin.h
This commit is contained in:
Yuichi Nishiwaki 2013-12-07 18:27:08 -08:00
parent 818430bb81
commit 6b2d6a98eb
3 changed files with 9 additions and 24 deletions

View File

@ -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 *);

View File

@ -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));
}

View File

@ -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);