2013-12-07 10:05:06 -05:00
|
|
|
#include "picrin.h"
|
|
|
|
#include "picrin/lib.h"
|
|
|
|
#include "picrin/pair.h"
|
|
|
|
#include "picrin/macro.h"
|
|
|
|
#include "xhash/xhash.h"
|
|
|
|
|
2013-12-07 21:44:14 -05:00
|
|
|
struct pic_lib *
|
2013-12-07 21:27:08 -05:00
|
|
|
pic_make_library(pic_state *pic, pic_value name)
|
2013-12-07 10:05:06 -05:00
|
|
|
{
|
|
|
|
struct pic_lib *lib;
|
|
|
|
|
|
|
|
lib = (struct pic_lib *)pic_obj_alloc(pic, sizeof(struct pic_lib), PIC_TT_LIB);
|
2013-12-07 10:14:35 -05:00
|
|
|
lib->senv = pic_core_syntactic_env(pic);
|
2013-12-07 10:05:06 -05:00
|
|
|
lib->exports = xh_new();
|
|
|
|
|
2013-12-07 21:44:14 -05:00
|
|
|
/* register! */
|
2013-12-07 21:27:08 -05:00
|
|
|
pic->lib_tbl = pic_acons(pic, name, pic_obj_value(lib), pic->lib_tbl);
|
2013-12-07 21:44:14 -05:00
|
|
|
|
|
|
|
return lib;
|
2013-12-07 10:05:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-12-07 21:27:08 -05:00
|
|
|
pic_in_library(pic_state *pic, pic_value name)
|
2013-12-07 10:05:06 -05:00
|
|
|
{
|
2013-12-07 21:27:08 -05:00
|
|
|
pic_value v;
|
2013-12-07 10:05:06 -05:00
|
|
|
|
2013-12-07 21:27:08 -05:00
|
|
|
v = pic_assoc(pic, name, pic->lib_tbl);
|
2013-12-07 10:05:06 -05:00
|
|
|
if (pic_false_p(v)) {
|
|
|
|
pic_error(pic, "library not found");
|
|
|
|
}
|
|
|
|
pic->lib = pic_lib_ptr(pic_cdr(pic, v));
|
|
|
|
}
|
2013-12-07 12:42:34 -05:00
|
|
|
|
|
|
|
struct pic_lib *
|
|
|
|
pic_find_library(pic_state *pic, pic_value spec)
|
|
|
|
{
|
|
|
|
pic_value v;
|
|
|
|
|
|
|
|
v = pic_assoc(pic, spec, pic->lib_tbl);
|
|
|
|
if (pic_false_p(v)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return pic_lib_ptr(pic_cdr(pic, v));
|
|
|
|
}
|