diff --git a/include/picrin.h b/include/picrin.h index 7130e470..11287003 100644 --- a/include/picrin.h +++ b/include/picrin.h @@ -127,6 +127,9 @@ void pic_in_library(pic_state *, pic_value); struct pic_lib *pic_make_library(pic_state *, pic_value); struct pic_lib *pic_find_library(pic_state *, pic_value); +void pic_export(pic_state *, pic_sym); +void pic_export_as(pic_state *, pic_sym, pic_sym); + void pic_abort(pic_state *, const char *); void pic_raise(pic_state *, pic_value); void pic_error(pic_state *, const char *); diff --git a/src/macro.c b/src/macro.c index 46ed6ee9..408fcb88 100644 --- a/src/macro.c +++ b/src/macro.c @@ -176,6 +176,18 @@ pic_identifier_p(pic_value obj) return false; } +void +pic_export(pic_state *pic, pic_sym sym) +{ + pic_export_as(pic, sym, sym); +} + +void +pic_export_as(pic_state *pic, pic_sym sym, pic_sym alias) +{ + xh_put(pic->lib->exports, pic_symbol_name(pic, sym), (int)alias); +} + static void pic_defsyntax(pic_state *pic, const char *name, struct pic_proc *macro, struct pic_senv *mac_env) { @@ -276,7 +288,7 @@ macroexpand(pic_state *pic, pic_value expr, struct pic_senv *senv) if (pic_symbol_p(v)) { ren = pic_sym(v); } - xh_put(pic->lib->exports, pic_symbol_name(pic, orig), (int)ren); + pic_export_as(pic, orig, ren); return pic_false_value(); } case PIC_STX_DEFSYNTAX: {