change APIs of library functions
This commit is contained in:
parent
9cb777eec3
commit
0115ede4de
|
@ -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);
|
struct pic_proc *pic_codegen(pic_state *, pic_value);
|
||||||
pic_value pic_macroexpand(pic_state *, pic_value);
|
pic_value pic_macroexpand(pic_state *, pic_value);
|
||||||
|
|
||||||
void pic_make_library(pic_state *, pic_value);
|
void pic_make_library(pic_state *, const char *);
|
||||||
void pic_in_library(pic_state *, pic_value);
|
void pic_in_library(pic_state *, const char *);
|
||||||
|
|
||||||
void pic_abort(pic_state *, const char *);
|
void pic_abort(pic_state *, const char *);
|
||||||
void pic_raise(pic_state *, pic_value);
|
void pic_raise(pic_state *, pic_value);
|
||||||
|
|
25
src/lib.c
25
src/lib.c
|
@ -4,26 +4,41 @@
|
||||||
#include "picrin/macro.h"
|
#include "picrin/macro.h"
|
||||||
#include "xhash/xhash.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
|
void
|
||||||
pic_make_library(pic_state *pic, pic_value name)
|
pic_make_library(pic_state *pic, const char *name)
|
||||||
{
|
{
|
||||||
struct pic_lib *lib;
|
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 = (struct pic_lib *)pic_obj_alloc(pic, sizeof(struct pic_lib), PIC_TT_LIB);
|
||||||
lib->senv = pic_minimal_syntactic_env(pic);
|
lib->senv = pic_minimal_syntactic_env(pic);
|
||||||
lib->exports = xh_new();
|
lib->exports = xh_new();
|
||||||
|
|
||||||
pic->lib_tbl = pic_acons(pic, name, pic_obj_value(lib), pic->lib_tbl);
|
pic->lib_tbl = pic_acons(pic, spec, pic_obj_value(lib), pic->lib_tbl);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
pic_in_library(pic_state *pic, pic_value name)
|
pic_in_library(pic_state *pic, const char *name)
|
||||||
{
|
{
|
||||||
pic_value v;
|
pic_value v, spec = lib_spec(pic, name);
|
||||||
|
|
||||||
v = pic_assoc(pic, name, pic->lib_tbl);
|
v = pic_assoc(pic, spec, pic->lib_tbl);
|
||||||
if (pic_false_p(v)) {
|
if (pic_false_p(v)) {
|
||||||
pic_error(pic, "library not found");
|
pic_error(pic, "library not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
pic->lib = pic_lib_ptr(pic_cdr(pic, v));
|
pic->lib = pic_lib_ptr(pic_cdr(pic, v));
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,8 +119,8 @@ pic_open(int argc, char *argv[], char **envp)
|
||||||
pic_gc_arena_restore(pic, ai);
|
pic_gc_arena_restore(pic, ai);
|
||||||
|
|
||||||
/* set library */
|
/* set library */
|
||||||
pic_make_library(pic, pic_symbol_value(pic_intern_cstr(pic, "user")));
|
pic_make_library(pic, "user");
|
||||||
pic_in_library(pic, pic_symbol_value(pic_intern_cstr(pic, "user")));
|
pic_in_library(pic, "user");
|
||||||
|
|
||||||
pic_init_core(pic);
|
pic_init_core(pic);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue