split built-in functins into libraries

This commit is contained in:
Yuichi Nishiwaki 2013-12-07 23:17:28 -08:00
parent 906f2c8a93
commit dda8ad367c
5 changed files with 42 additions and 16 deletions

View File

@ -127,6 +127,15 @@ 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) \
{ \
struct pic_lib *lib__ = pic->lib; \
pic_make_library(pic, pic_parse(pic, name)); \
pic_in_library(pic, pic_parse(pic, name));
#define ENDLIBRARY(pic) \
pic->lib = lib__; \
}
void pic_export(pic_state *, pic_sym);
void pic_export_as(pic_state *, pic_sym, pic_sym);

View File

@ -105,10 +105,14 @@ pic_file_delete(pic_state *pic)
void
pic_init_file(pic_state *pic)
{
DEFLIBRARY(pic, "(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);
pic_defun(pic, "open-output-binary-file", pic_file_open_output_binary_file);
pic_defun(pic, "file-exists?", pic_file_exists_p);
pic_defun(pic, "delete-file", pic_file_delete);
}
ENDLIBRARY(pic)
}

View File

@ -331,11 +331,16 @@ pic_init_port(pic_state *pic)
pic_defun(pic, "port?", pic_port_port_p);
pic_defun(pic, "input-port-open?", pic_port_input_port_open_p);
pic_defun(pic, "output-port-open?", pic_port_output_port_open_p);
pic_defun(pic, "write", pic_port_write);
pic_defun(pic, "newline", pic_port_newline);
pic_defun(pic, "eof-object?", pic_port_eof_object_p);
pic_defun(pic, "eof-object", pic_port_eof_object);
pic_defun(pic, "close-port", pic_port_close_port);
pic_defun(pic, "close-input-port", pic_port_close_port);
pic_defun(pic, "close-output-port", pic_port_close_port);
DEFLIBRARY(pic, "(scheme write)")
{
pic_defun(pic, "write", pic_port_write);
pic_defun(pic, "newline", pic_port_newline);
}
ENDLIBRARY(pic)
}

View File

@ -115,9 +115,13 @@ pic_system_getenvs(pic_state *pic)
void
pic_init_system(pic_state *pic)
{
DEFLIBRARY(pic, "(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)
}

View File

@ -37,7 +37,11 @@ pic_jiffies_per_second(pic_state *pic)
void
pic_init_time(pic_state *pic)
{
DEFLIBRARY(pic, "(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)
}