rewrite deflibrary using gensym
This commit is contained in:
parent
c789200f5b
commit
47f4060086
|
@ -176,16 +176,22 @@ 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);
|
||||
|
||||
#define DEFLIBRARY(pic,name) \
|
||||
do { \
|
||||
struct pic_lib *lib__ = pic->lib; \
|
||||
pic_make_library(pic, pic_parse(pic, name)); \
|
||||
pic_in_library(pic, pic_parse(pic, name)); \
|
||||
do
|
||||
#define ENDLIBRARY(pic) \
|
||||
while (0); \
|
||||
pic->lib = lib__; \
|
||||
} while (0)
|
||||
#define PIC_DEFLIBRARY_HELPER2(tmp1, tmp2, tmp3, spec) \
|
||||
for (struct pic_lib *tmp1 = pic->lib, \
|
||||
*tmp2 = (pic_make_library(pic, pic_parse(pic, spec)), \
|
||||
pic_in_library(pic, pic_parse(pic, spec)), \
|
||||
NULL); \
|
||||
tmp3 < 1; \
|
||||
(pic->lib = tmp1), ((void)tmp2), ++tmp3)
|
||||
|
||||
#define PIC_DEFLIBRARY_HELPER1(tmp1, tmp2, spec) \
|
||||
for (int tmp1 = 0, tmp2 = 0; tmp1 < 1; ++tmp1) \
|
||||
PIC_DEFLIBRARY_HELPER2(GENSYM(pic_deflib_tmp3__), \
|
||||
GENSYM(pic_deflib_tmp4__), \
|
||||
tmp2, spec)
|
||||
|
||||
#define pic_deflibrary(spec) \
|
||||
PIC_DEFLIBRARY_HELPER1(GENSYM(pic_deflib_tmp1__), GENSYM(pic_deflib_tmp2__), spec)
|
||||
|
||||
void pic_import(pic_state *, pic_value);
|
||||
void pic_export(pic_state *, pic_sym);
|
||||
|
|
|
@ -109,8 +109,7 @@ pic_file_delete(pic_state *pic)
|
|||
void
|
||||
pic_init_file(pic_state *pic)
|
||||
{
|
||||
DEFLIBRARY(pic, "(scheme file)")
|
||||
{
|
||||
pic_deflibrary ("(scheme file)") {
|
||||
pic_defun(pic, "open-input-file", pic_file_open_input_file);
|
||||
pic_defun(pic, "open-input-binary-file", pic_file_open_input_binary_file);
|
||||
pic_defun(pic, "open-output-file", pic_file_open_output_file);
|
||||
|
@ -118,5 +117,4 @@ pic_init_file(pic_state *pic)
|
|||
pic_defun(pic, "file-exists?", pic_file_exists_p);
|
||||
pic_defun(pic, "delete-file", pic_file_delete);
|
||||
}
|
||||
ENDLIBRARY(pic);
|
||||
}
|
||||
|
|
|
@ -730,12 +730,10 @@ pic_macro_er_macro_transformer(pic_state *pic)
|
|||
void
|
||||
pic_init_macro(pic_state *pic)
|
||||
{
|
||||
DEFLIBRARY(pic, "(picrin macro)")
|
||||
{
|
||||
pic_deflibrary ("(picrin macro)") {
|
||||
pic_defun(pic, "make-syntactic-closure", pic_macro_make_sc);
|
||||
pic_defun(pic, "identifier?", pic_macro_identifier_p);
|
||||
pic_defun(pic, "identifier=?", pic_macro_identifier_eq_p);
|
||||
pic_defun(pic, "er-macro-transformer", pic_macro_er_macro_transformer);
|
||||
}
|
||||
ENDLIBRARY(pic);
|
||||
}
|
||||
|
|
|
@ -745,8 +745,7 @@ pic_init_number(pic_state *pic)
|
|||
pic_defun(pic, "exact", pic_number_exact);
|
||||
pic_gc_arena_restore(pic, ai);
|
||||
|
||||
DEFLIBRARY(pic, "(scheme inexact)")
|
||||
{
|
||||
pic_deflibrary ("(scheme inexact)") {
|
||||
pic_defun(pic, "finite?", pic_number_finite_p);
|
||||
pic_defun(pic, "infinite?", pic_number_infinite_p);
|
||||
pic_defun(pic, "nan?", pic_number_nan_p);
|
||||
|
@ -762,5 +761,4 @@ pic_init_number(pic_state *pic)
|
|||
|
||||
pic_defun(pic, "sqrt", pic_number_sqrt);
|
||||
}
|
||||
ENDLIBRARY(pic);
|
||||
}
|
||||
|
|
|
@ -126,13 +126,11 @@ pic_system_getenvs(pic_state *pic)
|
|||
void
|
||||
pic_init_system(pic_state *pic)
|
||||
{
|
||||
DEFLIBRARY(pic, "(scheme process-context)")
|
||||
{
|
||||
pic_deflibrary ("(scheme process-context)") {
|
||||
pic_defun(pic, "command-line", pic_system_cmdline);
|
||||
pic_defun(pic, "exit", pic_system_exit);
|
||||
pic_defun(pic, "emergency-exit", pic_system_emergency_exit);
|
||||
pic_defun(pic, "get-environment-variable", pic_system_getenv);
|
||||
pic_defun(pic, "get-environment-variables", pic_system_getenvs);
|
||||
}
|
||||
ENDLIBRARY(pic);
|
||||
}
|
||||
|
|
|
@ -41,11 +41,9 @@ pic_jiffies_per_second(pic_state *pic)
|
|||
void
|
||||
pic_init_time(pic_state *pic)
|
||||
{
|
||||
DEFLIBRARY(pic, "(scheme time)")
|
||||
{
|
||||
pic_deflibrary ("(scheme time)") {
|
||||
pic_defun(pic, "current-second", pic_current_second);
|
||||
pic_defun(pic, "current-jiffy", pic_current_jiffy);
|
||||
pic_defun(pic, "jiffies-per-second", pic_jiffies_per_second);
|
||||
}
|
||||
ENDLIBRARY(pic);
|
||||
}
|
||||
|
|
|
@ -173,12 +173,10 @@ pic_var_parameter_converter(pic_state *pic)
|
|||
void
|
||||
pic_init_var(pic_state *pic)
|
||||
{
|
||||
DEFLIBRARY(pic, "(picrin parameter)")
|
||||
{
|
||||
pic_deflibrary ("(picrin parameter)") {
|
||||
pic_defun(pic, "make-parameter", pic_var_make_parameter);
|
||||
pic_defun(pic, "parameter-ref", pic_var_parameter_ref);
|
||||
pic_defun(pic, "parameter-set!", pic_var_parameter_set); /* no convert */
|
||||
pic_defun(pic, "parameter-converter", pic_var_parameter_converter);
|
||||
}
|
||||
ENDLIBRARY(pic);
|
||||
}
|
||||
|
|
|
@ -174,9 +174,7 @@ pic_port_write_simple(pic_state *pic)
|
|||
void
|
||||
pic_init_write(pic_state *pic)
|
||||
{
|
||||
DEFLIBRARY(pic, "(scheme write)")
|
||||
{
|
||||
pic_deflibrary ("(scheme write)") {
|
||||
pic_defun(pic, "write-simple", pic_port_write_simple);
|
||||
}
|
||||
ENDLIBRARY(pic);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue