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/
This commit is contained in:
parent
4cc423d815
commit
f2eb51e53d
|
@ -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})
|
|
@ -108,6 +108,7 @@ pic_file_delete(pic_state *pic)
|
||||||
void
|
void
|
||||||
pic_init_file(pic_state *pic)
|
pic_init_file(pic_state *pic)
|
||||||
{
|
{
|
||||||
|
pic_deflibrary (pic, "(scheme file)") {
|
||||||
pic_defun(pic, "open-input-file", pic_file_open_input_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-binary-input-file", pic_file_open_binary_input_file);
|
||||||
pic_defun(pic, "open-output-file", pic_file_open_output_file);
|
pic_defun(pic, "open-output-file", pic_file_open_output_file);
|
||||||
|
@ -115,3 +116,4 @@ pic_init_file(pic_state *pic)
|
||||||
pic_defun(pic, "file-exists?", pic_file_exists_p);
|
pic_defun(pic, "file-exists?", pic_file_exists_p);
|
||||||
pic_defun(pic, "delete-file", pic_file_delete);
|
pic_defun(pic, "delete-file", pic_file_delete);
|
||||||
}
|
}
|
||||||
|
}
|
|
@ -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})
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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})
|
|
@ -126,9 +126,11 @@ pic_system_getenvs(pic_state *pic)
|
||||||
void
|
void
|
||||||
pic_init_system(pic_state *pic)
|
pic_init_system(pic_state *pic)
|
||||||
{
|
{
|
||||||
|
pic_deflibrary (pic, "(scheme process-context)") {
|
||||||
pic_defun(pic, "command-line", pic_system_cmdline);
|
pic_defun(pic, "command-line", pic_system_cmdline);
|
||||||
pic_defun(pic, "exit", pic_system_exit);
|
pic_defun(pic, "exit", pic_system_exit);
|
||||||
pic_defun(pic, "emergency-exit", pic_system_emergency_exit);
|
pic_defun(pic, "emergency-exit", pic_system_emergency_exit);
|
||||||
pic_defun(pic, "get-environment-variable", pic_system_getenv);
|
pic_defun(pic, "get-environment-variable", pic_system_getenv);
|
||||||
pic_defun(pic, "get-environment-variables", pic_system_getenvs);
|
pic_defun(pic, "get-environment-variables", pic_system_getenvs);
|
||||||
}
|
}
|
||||||
|
}
|
|
@ -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})
|
|
@ -41,7 +41,9 @@ pic_jiffies_per_second(pic_state *pic)
|
||||||
void
|
void
|
||||||
pic_init_time(pic_state *pic)
|
pic_init_time(pic_state *pic)
|
||||||
{
|
{
|
||||||
|
pic_deflibrary (pic, "(scheme time)") {
|
||||||
pic_defun(pic, "current-second", pic_current_second);
|
pic_defun(pic, "current-second", pic_current_second);
|
||||||
pic_defun(pic, "current-jiffy", pic_current_jiffy);
|
pic_defun(pic, "current-jiffy", pic_current_jiffy);
|
||||||
pic_defun(pic, "jiffies-per-second", pic_jiffies_per_second);
|
pic_defun(pic, "jiffies-per-second", pic_jiffies_per_second);
|
||||||
}
|
}
|
||||||
|
}
|
|
@ -3,7 +3,8 @@
|
||||||
(picrin macro)
|
(picrin macro)
|
||||||
(picrin record)
|
(picrin record)
|
||||||
(picrin syntax-rules)
|
(picrin syntax-rules)
|
||||||
(picrin string))
|
(picrin string)
|
||||||
|
(scheme file))
|
||||||
|
|
||||||
;; 4.1.2. Literal expressions
|
;; 4.1.2. Literal expressions
|
||||||
|
|
||||||
|
|
|
@ -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(pic_state *, struct pic_port *);
|
||||||
pic_value pic_read_cstr(pic_state *, const char *);
|
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 *);
|
void pic_load_cstr(pic_state *, const char *);
|
||||||
|
|
||||||
pic_value pic_funcall(pic_state *pic, struct pic_lib *, const char *, pic_list);
|
pic_value pic_funcall(pic_state *pic, struct pic_lib *, const char *, pic_list);
|
||||||
|
|
|
@ -18,9 +18,6 @@ void pic_init_bool(pic_state *);
|
||||||
void pic_init_pair(pic_state *);
|
void pic_init_pair(pic_state *);
|
||||||
void pic_init_port(pic_state *);
|
void pic_init_port(pic_state *);
|
||||||
void pic_init_number(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_proc(pic_state *);
|
||||||
void pic_init_symbol(pic_state *);
|
void pic_init_symbol(pic_state *);
|
||||||
void pic_init_vector(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_str(pic_state *);
|
||||||
void pic_init_macro(pic_state *);
|
void pic_init_macro(pic_state *);
|
||||||
void pic_init_var(pic_state *);
|
void pic_init_var(pic_state *);
|
||||||
void pic_init_load(pic_state *);
|
|
||||||
void pic_init_write(pic_state *);
|
void pic_init_write(pic_state *);
|
||||||
void pic_init_read(pic_state *);
|
void pic_init_read(pic_state *);
|
||||||
void pic_init_dict(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_pair(pic); DONE;
|
||||||
pic_init_port(pic); DONE;
|
pic_init_port(pic); DONE;
|
||||||
pic_init_number(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_proc(pic); DONE;
|
||||||
pic_init_symbol(pic); DONE;
|
pic_init_symbol(pic); DONE;
|
||||||
pic_init_vector(pic); DONE;
|
pic_init_vector(pic); DONE;
|
||||||
|
@ -132,7 +125,6 @@ pic_init_core(pic_state *pic)
|
||||||
pic_init_str(pic); DONE;
|
pic_init_str(pic); DONE;
|
||||||
pic_init_macro(pic); DONE;
|
pic_init_macro(pic); DONE;
|
||||||
pic_init_var(pic); DONE;
|
pic_init_var(pic); DONE;
|
||||||
pic_init_load(pic); DONE;
|
|
||||||
pic_init_write(pic); DONE;
|
pic_init_write(pic); DONE;
|
||||||
pic_init_read(pic); DONE;
|
pic_init_read(pic); DONE;
|
||||||
pic_init_dict(pic); DONE;
|
pic_init_dict(pic); DONE;
|
||||||
|
|
|
@ -3,11 +3,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "picrin.h"
|
#include "picrin.h"
|
||||||
#include "picrin/pair.h"
|
|
||||||
#include "picrin/port.h"
|
#include "picrin/port.h"
|
||||||
#include "picrin/error.h"
|
#include "picrin/error.h"
|
||||||
|
|
||||||
static void
|
void
|
||||||
pic_load_port(pic_state *pic, struct pic_port *port)
|
pic_load_port(pic_state *pic, struct pic_port *port)
|
||||||
{
|
{
|
||||||
pic_value form;
|
pic_value form;
|
||||||
|
@ -35,43 +34,3 @@ pic_load_cstr(pic_state *pic, const char *src)
|
||||||
|
|
||||||
pic_close_port(pic, port);
|
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);
|
|
||||||
}
|
|
||||||
|
|
|
@ -178,6 +178,8 @@
|
||||||
dictionary-set!
|
dictionary-set!
|
||||||
dictionary-delete!
|
dictionary-delete!
|
||||||
dictionary-size
|
dictionary-size
|
||||||
|
dictionary-map
|
||||||
|
dictionary-for-each
|
||||||
dictionary->plist
|
dictionary->plist
|
||||||
plist->dictionary
|
plist->dictionary
|
||||||
dictionary->alist
|
dictionary->alist
|
||||||
|
@ -204,10 +206,6 @@
|
||||||
port-open?
|
port-open?
|
||||||
close-port
|
close-port
|
||||||
|
|
||||||
open-input-file
|
|
||||||
open-output-file
|
|
||||||
open-binary-input-file
|
|
||||||
open-binary-output-file
|
|
||||||
open-input-string
|
open-input-string
|
||||||
open-output-string
|
open-output-string
|
||||||
get-output-string
|
get-output-string
|
||||||
|
@ -271,18 +269,4 @@
|
||||||
write-shared
|
write-shared
|
||||||
display)
|
display)
|
||||||
|
|
||||||
(export command-line
|
(export eval))
|
||||||
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))
|
|
||||||
|
|
|
@ -75,11 +75,8 @@
|
||||||
(define (test-failure-count)
|
(define (test-failure-count)
|
||||||
(length fails))
|
(length fails))
|
||||||
|
|
||||||
(define (test-exit)
|
|
||||||
(exit (= (test-failure-count) 0)))
|
|
||||||
|
|
||||||
(define-syntax test-syntax-error
|
(define-syntax test-syntax-error
|
||||||
(syntax-rules ()
|
(syntax-rules ()
|
||||||
((_) (syntax-error "invalid use of test-syntax-error"))))
|
((_) (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))
|
||||||
|
|
Loading…
Reference in New Issue