From f2eb51e53d02fccaf797f71d897ee19ae75cf120 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 18 Jan 2015 00:32:52 +0900 Subject: [PATCH] some procedures are moved to contrib/ system related procedures are moved to contrib/ file related procedures are moved to contrib/ load related procedures are moved to conrib/ --- contrib/03.file/CMakeLists.txt | 4 ++ {extlib/benz => contrib/03.file/src}/file.c | 14 +++--- contrib/03.load/CMakeLists.txt | 4 ++ contrib/03.load/src/load.c | 50 +++++++++++++++++++ contrib/03.system/CMakeLists.txt | 4 ++ .../benz => contrib/03.system/src}/system.c | 12 +++-- contrib/03.time/CMakeLists.txt | 4 ++ {extlib/benz => contrib/03.time/src}/time.c | 8 +-- contrib/05.r7rs/scheme/base.scm | 3 +- extlib/benz/include/picrin.h | 2 +- extlib/benz/init.c | 8 --- extlib/benz/load.c | 43 +--------------- piclib/picrin/base.scm | 22 ++------ piclib/picrin/test.scm | 5 +- 14 files changed, 94 insertions(+), 89 deletions(-) create mode 100644 contrib/03.file/CMakeLists.txt rename {extlib/benz => contrib/03.file/src}/file.c (82%) create mode 100644 contrib/03.load/CMakeLists.txt create mode 100644 contrib/03.load/src/load.c create mode 100644 contrib/03.system/CMakeLists.txt rename {extlib/benz => contrib/03.system/src}/system.c (86%) create mode 100644 contrib/03.time/CMakeLists.txt rename {extlib/benz => contrib/03.time/src}/time.c (72%) diff --git a/contrib/03.file/CMakeLists.txt b/contrib/03.file/CMakeLists.txt new file mode 100644 index 00000000..22987e3e --- /dev/null +++ b/contrib/03.file/CMakeLists.txt @@ -0,0 +1,4 @@ +file(GLOB PICRIN_FILE_SOURCES ${PROJECT_SOURCE_DIR}/contrib/03.file/src/*.c) + +list(APPEND PICRIN_CONTRIB_INITS file) +list(APPEND PICRIN_CONTRIB_SOURCES ${PICRIN_FILE_SOURCES}) diff --git a/extlib/benz/file.c b/contrib/03.file/src/file.c similarity index 82% rename from extlib/benz/file.c rename to contrib/03.file/src/file.c index d438c23a..e3aa1739 100644 --- a/extlib/benz/file.c +++ b/contrib/03.file/src/file.c @@ -108,10 +108,12 @@ pic_file_delete(pic_state *pic) void pic_init_file(pic_state *pic) { - pic_defun(pic, "open-input-file", pic_file_open_input_file); - pic_defun(pic, "open-binary-input-file", pic_file_open_binary_input_file); - pic_defun(pic, "open-output-file", pic_file_open_output_file); - pic_defun(pic, "open-binary-output-file", pic_file_open_binary_output_file); - pic_defun(pic, "file-exists?", pic_file_exists_p); - pic_defun(pic, "delete-file", pic_file_delete); + pic_deflibrary (pic, "(scheme file)") { + pic_defun(pic, "open-input-file", pic_file_open_input_file); + pic_defun(pic, "open-binary-input-file", pic_file_open_binary_input_file); + pic_defun(pic, "open-output-file", pic_file_open_output_file); + pic_defun(pic, "open-binary-output-file", pic_file_open_binary_output_file); + pic_defun(pic, "file-exists?", pic_file_exists_p); + pic_defun(pic, "delete-file", pic_file_delete); + } } diff --git a/contrib/03.load/CMakeLists.txt b/contrib/03.load/CMakeLists.txt new file mode 100644 index 00000000..bb0d6a3d --- /dev/null +++ b/contrib/03.load/CMakeLists.txt @@ -0,0 +1,4 @@ +file(GLOB PICRIN_LOAD_SOURCES ${PROJECT_SOURCE_DIR}/contrib/03.load/src/*.c) + +list(APPEND PICRIN_CONTRIB_INITS load) +list(APPEND PICRIN_CONTRIB_SOURCES ${PICRIN_LOAD_SOURCES}) diff --git a/contrib/03.load/src/load.c b/contrib/03.load/src/load.c new file mode 100644 index 00000000..93f832c6 --- /dev/null +++ b/contrib/03.load/src/load.c @@ -0,0 +1,50 @@ +/** + * See Copyright Notice in picrin.h + */ + +#include "picrin.h" +#include "picrin/pair.h" +#include "picrin/port.h" +#include "picrin/error.h" + +void +pic_load(pic_state *pic, const char *filename) +{ + struct pic_port *port; + xFILE *file; + + file = xfopen(filename, "r"); + if (file == NULL) { + pic_errorf(pic, "could not open file: %s", filename); + } + + port = (struct pic_port *)pic_obj_alloc(pic, sizeof(struct pic_port), PIC_TT_PORT); + port->file = file; + port->flags = PIC_PORT_IN | PIC_PORT_TEXT; + port->status = PIC_PORT_OPEN; + + pic_load_port(pic, port); + + pic_close_port(pic, port); +} + +static pic_value +pic_load_load(pic_state *pic) +{ + pic_value envid; + char *fn; + + pic_get_args(pic, "z|o", &fn, &envid); + + pic_load(pic, fn); + + return pic_none_value(); +} + +void +pic_init_load(pic_state *pic) +{ + pic_deflibrary (pic, "(scheme load)") { + pic_defun(pic, "load", pic_load_load); + } +} diff --git a/contrib/03.system/CMakeLists.txt b/contrib/03.system/CMakeLists.txt new file mode 100644 index 00000000..c18f3266 --- /dev/null +++ b/contrib/03.system/CMakeLists.txt @@ -0,0 +1,4 @@ +file(GLOB PICRIN_SYSTEM_SOURCES ${PROJECT_SOURCE_DIR}/contrib/03.system/src/*.c) + +list(APPEND PICRIN_CONTRIB_INITS system) +list(APPEND PICRIN_CONTRIB_SOURCES ${PICRIN_SYSTEM_SOURCES}) diff --git a/extlib/benz/system.c b/contrib/03.system/src/system.c similarity index 86% rename from extlib/benz/system.c rename to contrib/03.system/src/system.c index 1b251661..c46173b6 100644 --- a/extlib/benz/system.c +++ b/contrib/03.system/src/system.c @@ -126,9 +126,11 @@ pic_system_getenvs(pic_state *pic) void pic_init_system(pic_state *pic) { - 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); + 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); + } } diff --git a/contrib/03.time/CMakeLists.txt b/contrib/03.time/CMakeLists.txt new file mode 100644 index 00000000..dc69714a --- /dev/null +++ b/contrib/03.time/CMakeLists.txt @@ -0,0 +1,4 @@ +file(GLOB PICRIN_TIME_SOURCES ${PROJECT_SOURCE_DIR}/contrib/03.time/src/*.c) + +list(APPEND PICRIN_CONTRIB_INITS time) +list(APPEND PICRIN_CONTRIB_SOURCES ${PICRIN_TIME_SOURCES}) diff --git a/extlib/benz/time.c b/contrib/03.time/src/time.c similarity index 72% rename from extlib/benz/time.c rename to contrib/03.time/src/time.c index 83716db8..6ed8420d 100644 --- a/extlib/benz/time.c +++ b/contrib/03.time/src/time.c @@ -41,7 +41,9 @@ pic_jiffies_per_second(pic_state *pic) void pic_init_time(pic_state *pic) { - 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); + 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); + } } diff --git a/contrib/05.r7rs/scheme/base.scm b/contrib/05.r7rs/scheme/base.scm index 89d4b6a5..08d438c0 100644 --- a/contrib/05.r7rs/scheme/base.scm +++ b/contrib/05.r7rs/scheme/base.scm @@ -3,7 +3,8 @@ (picrin macro) (picrin record) (picrin syntax-rules) - (picrin string)) + (picrin string) + (scheme file)) ;; 4.1.2. Literal expressions diff --git a/extlib/benz/include/picrin.h b/extlib/benz/include/picrin.h index 707a5c2a..418cff2c 100644 --- a/extlib/benz/include/picrin.h +++ b/extlib/benz/include/picrin.h @@ -186,7 +186,7 @@ bool pic_interned_p(pic_state *, pic_sym); pic_value pic_read(pic_state *, struct pic_port *); pic_value pic_read_cstr(pic_state *, const char *); -void pic_load(pic_state *, const char *); +void pic_load_port(pic_state *, struct pic_port *); void pic_load_cstr(pic_state *, const char *); pic_value pic_funcall(pic_state *pic, struct pic_lib *, const char *, pic_list); diff --git a/extlib/benz/init.c b/extlib/benz/init.c index 06e97ca2..6a1e05a3 100644 --- a/extlib/benz/init.c +++ b/extlib/benz/init.c @@ -18,9 +18,6 @@ void pic_init_bool(pic_state *); void pic_init_pair(pic_state *); void pic_init_port(pic_state *); void pic_init_number(pic_state *); -void pic_init_time(pic_state *); -void pic_init_system(pic_state *); -void pic_init_file(pic_state *); void pic_init_proc(pic_state *); void pic_init_symbol(pic_state *); void pic_init_vector(pic_state *); @@ -31,7 +28,6 @@ void pic_init_error(pic_state *); void pic_init_str(pic_state *); void pic_init_macro(pic_state *); void pic_init_var(pic_state *); -void pic_init_load(pic_state *); void pic_init_write(pic_state *); void pic_init_read(pic_state *); void pic_init_dict(pic_state *); @@ -119,9 +115,6 @@ pic_init_core(pic_state *pic) pic_init_pair(pic); DONE; pic_init_port(pic); DONE; pic_init_number(pic); DONE; - pic_init_time(pic); DONE; - pic_init_system(pic); DONE; - pic_init_file(pic); DONE; pic_init_proc(pic); DONE; pic_init_symbol(pic); DONE; pic_init_vector(pic); DONE; @@ -132,7 +125,6 @@ pic_init_core(pic_state *pic) pic_init_str(pic); DONE; pic_init_macro(pic); DONE; pic_init_var(pic); DONE; - pic_init_load(pic); DONE; pic_init_write(pic); DONE; pic_init_read(pic); DONE; pic_init_dict(pic); DONE; diff --git a/extlib/benz/load.c b/extlib/benz/load.c index 83deb212..a6f2eb8d 100644 --- a/extlib/benz/load.c +++ b/extlib/benz/load.c @@ -3,11 +3,10 @@ */ #include "picrin.h" -#include "picrin/pair.h" #include "picrin/port.h" #include "picrin/error.h" -static void +void pic_load_port(pic_state *pic, struct pic_port *port) { pic_value form; @@ -35,43 +34,3 @@ pic_load_cstr(pic_state *pic, const char *src) pic_close_port(pic, port); } - -void -pic_load(pic_state *pic, const char *filename) -{ - struct pic_port *port; - xFILE *file; - - file = xfopen(filename, "r"); - if (file == NULL) { - pic_errorf(pic, "could not open file: %s", filename); - } - - port = (struct pic_port *)pic_obj_alloc(pic, sizeof(struct pic_port), PIC_TT_PORT); - port->file = file; - port->flags = PIC_PORT_IN | PIC_PORT_TEXT; - port->status = PIC_PORT_OPEN; - - pic_load_port(pic, port); - - pic_close_port(pic, port); -} - -static pic_value -pic_load_load(pic_state *pic) -{ - pic_value envid; - char *fn; - - pic_get_args(pic, "z|o", &fn, &envid); - - pic_load(pic, fn); - - return pic_none_value(); -} - -void -pic_init_load(pic_state *pic) -{ - pic_defun(pic, "load", pic_load_load); -} diff --git a/piclib/picrin/base.scm b/piclib/picrin/base.scm index 1af0e5c7..baf00023 100644 --- a/piclib/picrin/base.scm +++ b/piclib/picrin/base.scm @@ -178,6 +178,8 @@ dictionary-set! dictionary-delete! dictionary-size + dictionary-map + dictionary-for-each dictionary->plist plist->dictionary dictionary->alist @@ -204,10 +206,6 @@ port-open? close-port - open-input-file - open-output-file - open-binary-input-file - open-binary-output-file open-input-string open-output-string get-output-string @@ -271,18 +269,4 @@ write-shared display) - (export command-line - exit - emergency-exit - file-exists? - delete-file - get-environment-variable - get-environment-variables) - - (export current-second - current-jiffy - jiffies-per-second) - - (export eval) - - (export load)) + (export eval)) diff --git a/piclib/picrin/test.scm b/piclib/picrin/test.scm index d1dfbc9d..f3fd920e 100644 --- a/piclib/picrin/test.scm +++ b/piclib/picrin/test.scm @@ -75,11 +75,8 @@ (define (test-failure-count) (length fails)) - (define (test-exit) - (exit (= (test-failure-count) 0))) - (define-syntax test-syntax-error (syntax-rules () ((_) (syntax-error "invalid use of test-syntax-error")))) - (export test test-begin test-end test-values test-exit test-syntax-error)) + (export test test-begin test-end test-values test-syntax-error))