move pic_import and pic_export to lib.c
This commit is contained in:
parent
bc94a35b62
commit
81c3147695
37
src/lib.c
37
src/lib.c
|
@ -60,3 +60,40 @@ pic_find_library(pic_state *pic, pic_value spec)
|
||||||
}
|
}
|
||||||
return pic_lib_ptr(pic_cdr(pic, v));
|
return pic_lib_ptr(pic_cdr(pic, v));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
pic_import(pic_state *pic, pic_value spec)
|
||||||
|
{
|
||||||
|
struct pic_lib *lib;
|
||||||
|
xh_iter it;
|
||||||
|
|
||||||
|
lib = pic_find_library(pic, spec);
|
||||||
|
if (! lib) {
|
||||||
|
pic_errorf(pic, "library not found: ~a", spec);
|
||||||
|
}
|
||||||
|
xh_begin(&it, &lib->exports);
|
||||||
|
while (xh_next(&it)) {
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
printf("* importing %s as %s\n", pic_symbol_name(pic, xh_key(it.e, pic_sym)), pic_symbol_name(pic, xh_val(it.e, pic_sym)));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
pic_put_rename(pic, pic->lib->senv, xh_key(it.e, pic_sym), xh_val(it.e, pic_sym));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
pic_export(pic_state *pic, pic_sym sym)
|
||||||
|
{
|
||||||
|
pic_sym rename;
|
||||||
|
|
||||||
|
if (! pic_find_rename(pic, pic->lib->senv, sym, &rename)) {
|
||||||
|
pic_errorf(pic, "export: symbol not defined %s", pic_symbol_name(pic, sym));
|
||||||
|
}
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
printf("* exporting %s as %s\n", pic_symbol_name(pic, sym), pic_symbol_name(pic, rename));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
xh_put(&pic->lib->exports, sym, &rename);
|
||||||
|
}
|
||||||
|
|
37
src/macro.c
37
src/macro.c
|
@ -71,43 +71,6 @@ pic_find_rename(pic_state *pic, struct pic_senv *senv, pic_sym sym, pic_sym *ren
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
pic_import(pic_state *pic, pic_value spec)
|
|
||||||
{
|
|
||||||
struct pic_lib *lib;
|
|
||||||
xh_iter it;
|
|
||||||
|
|
||||||
lib = pic_find_library(pic, spec);
|
|
||||||
if (! lib) {
|
|
||||||
pic_errorf(pic, "library not found: ~a", spec);
|
|
||||||
}
|
|
||||||
xh_begin(&it, &lib->exports);
|
|
||||||
while (xh_next(&it)) {
|
|
||||||
|
|
||||||
#if DEBUG
|
|
||||||
printf("* importing %s as %s\n", pic_symbol_name(pic, xh_key(it.e, pic_sym)), pic_symbol_name(pic, xh_val(it.e, pic_sym)));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
pic_put_rename(pic, pic->lib->senv, xh_key(it.e, pic_sym), xh_val(it.e, pic_sym));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
pic_export(pic_state *pic, pic_sym sym)
|
|
||||||
{
|
|
||||||
pic_sym rename;
|
|
||||||
|
|
||||||
if (! pic_find_rename(pic, pic->lib->senv, sym, &rename)) {
|
|
||||||
pic_errorf(pic, "export: symbol not defined %s", pic_symbol_name(pic, sym));
|
|
||||||
}
|
|
||||||
|
|
||||||
#if DEBUG
|
|
||||||
printf("* exporting %s as %s\n", pic_symbol_name(pic, sym), pic_symbol_name(pic, rename));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
xh_put(&pic->lib->exports, sym, &rename);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
define_macro(pic_state *pic, pic_sym rename, struct pic_proc *proc, struct pic_senv *senv)
|
define_macro(pic_state *pic, pic_sym rename, struct pic_proc *proc, struct pic_senv *senv)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue