parent
294477ff13
commit
8610f5090d
|
@ -282,8 +282,8 @@ pic_callcc_callcc(pic_state *pic)
|
|||
void
|
||||
pic_init_callcc(pic_state *pic)
|
||||
{
|
||||
pic_deflibrary (pic, "(scheme base)") {
|
||||
pic_deflibrary(pic, "(scheme base)");
|
||||
|
||||
pic_redefun(pic, pic->PICRIN_BASE, "call-with-current-continuation", pic_callcc_callcc);
|
||||
pic_redefun(pic, pic->PICRIN_BASE, "call/cc", pic_callcc_callcc);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -284,7 +284,8 @@ pic_number_expt(pic_state *pic)
|
|||
void
|
||||
pic_init_math(pic_state *pic)
|
||||
{
|
||||
pic_deflibrary (pic, "(picrin math)") {
|
||||
pic_deflibrary(pic, "(picrin math)");
|
||||
|
||||
pic_defun(pic, "floor/", pic_number_floor2);
|
||||
pic_defun(pic, "truncate/", pic_number_trunc2);
|
||||
pic_defun(pic, "floor", pic_number_floor);
|
||||
|
@ -307,4 +308,3 @@ pic_init_math(pic_state *pic)
|
|||
pic_defun(pic, "abs", pic_number_abs);
|
||||
pic_defun(pic, "expt", pic_number_expt);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,7 +93,8 @@ pic_file_delete(pic_state *pic)
|
|||
void
|
||||
pic_init_file(pic_state *pic)
|
||||
{
|
||||
pic_deflibrary (pic, "(scheme file)") {
|
||||
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);
|
||||
|
@ -101,4 +102,3 @@ pic_init_file(pic_state *pic)
|
|||
pic_defun(pic, "file-exists?", pic_file_exists_p);
|
||||
pic_defun(pic, "delete-file", pic_file_delete);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ pic_load_load(pic_state *pic)
|
|||
void
|
||||
pic_init_load(pic_state *pic)
|
||||
{
|
||||
pic_deflibrary (pic, "(scheme load)") {
|
||||
pic_deflibrary(pic, "(scheme load)");
|
||||
|
||||
pic_defun(pic, "load", pic_load_load);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,9 +85,9 @@ pic_str_string_fill_ip(pic_state *pic)
|
|||
void
|
||||
pic_init_mutable_string(pic_state *pic)
|
||||
{
|
||||
pic_deflibrary (pic, "(picrin string)") {
|
||||
pic_deflibrary(pic, "(picrin string)");
|
||||
|
||||
pic_defun(pic, "string-set!", pic_str_string_set);
|
||||
pic_defun(pic, "string-copy!", pic_str_string_copy_ip);
|
||||
pic_defun(pic, "string-fill!", pic_str_string_fill_ip);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -127,11 +127,11 @@ pic_system_getenvs(pic_state *pic)
|
|||
void
|
||||
pic_init_system(pic_state *pic)
|
||||
{
|
||||
pic_deflibrary (pic, "(scheme process-context)") {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,9 +41,9 @@ pic_jiffies_per_second(pic_state *pic)
|
|||
void
|
||||
pic_init_time(pic_state *pic)
|
||||
{
|
||||
pic_deflibrary (pic, "(scheme time)") {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ pic_random_real(pic_state *pic)
|
|||
void
|
||||
pic_init_random(pic_state *pic)
|
||||
{
|
||||
pic_deflibrary (pic, "(srfi 27)") {
|
||||
pic_deflibrary(pic, "(srfi 27)");
|
||||
|
||||
pic_defun(pic, "random-real", pic_random_real);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -246,10 +246,13 @@ pic_rl_history_expand(pic_state *pic)
|
|||
void
|
||||
pic_init_readline(pic_state *pic){
|
||||
using_history();
|
||||
pic_deflibrary (pic, "(picrin readline)") {
|
||||
|
||||
pic_deflibrary(pic, "(picrin readline)");
|
||||
|
||||
pic_defun(pic, "readline", pic_rl_readline);
|
||||
}
|
||||
pic_deflibrary (pic, "(picrin readline history)") {
|
||||
|
||||
pic_deflibrary(pic, "(picrin readline history)");
|
||||
|
||||
/* pic_defun(pic, "history-offset", pic_rl_history_offset); */
|
||||
pic_defun(pic, "history-length", pic_rl_history_length);
|
||||
pic_defun(pic, "add-history", pic_rl_add_history);
|
||||
|
@ -271,4 +274,3 @@ pic_init_readline(pic_state *pic){
|
|||
pic_defun(pic, "truncate-file", pic_rl_truncate_file);
|
||||
pic_defun(pic, "history-expand", pic_rl_history_expand);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -178,7 +178,8 @@ pic_regexp_regexp_replace(pic_state *pic)
|
|||
void
|
||||
pic_init_regexp(pic_state *pic)
|
||||
{
|
||||
pic_deflibrary (pic, "(picrin regexp)") {
|
||||
pic_deflibrary(pic, "(picrin regexp)");
|
||||
|
||||
pic_defun(pic, "regexp", pic_regexp_regexp);
|
||||
pic_defun(pic, "regexp?", pic_regexp_regexp_p);
|
||||
pic_defun(pic, "regexp-match", pic_regexp_regexp_match);
|
||||
|
@ -186,4 +187,3 @@ pic_init_regexp(pic_state *pic)
|
|||
pic_defun(pic, "regexp-split", pic_regexp_regexp_split);
|
||||
pic_defun(pic, "regexp-replace", pic_regexp_regexp_replace);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -402,7 +402,8 @@ pic_init_srfi_106(pic_state *pic)
|
|||
#define pic_defun_(pic, name, f) pic_define(pic, pic->lib, name, pic_obj_value(pic_make_proc(pic, f, 0, NULL)))
|
||||
#define pic_define_(pic, name, v) pic_define(pic, pic->lib, name, v)
|
||||
|
||||
pic_deflibrary (pic, "(srfi 106)") {
|
||||
pic_deflibrary(pic, "(srfi 106)");
|
||||
|
||||
pic_defun_(pic, "socket?", pic_socket_socket_p);
|
||||
pic_defun_(pic, "make-socket", pic_socket_make_socket);
|
||||
pic_defun_(pic, "socket-accept", pic_socket_socket_accept);
|
||||
|
@ -521,4 +522,3 @@ pic_init_srfi_106(pic_state *pic)
|
|||
pic_define_(pic, "*shut-rdwr*", pic_false_value());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ pic_repl_tty_p(pic_state *pic)
|
|||
void
|
||||
pic_init_repl(pic_state *pic)
|
||||
{
|
||||
pic_deflibrary (pic, "(picrin repl)") {
|
||||
pic_deflibrary(pic, "(picrin repl)");
|
||||
|
||||
pic_defun(pic, "tty?", pic_repl_tty_p);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -219,16 +219,13 @@ pic_value pic_eval(pic_state *, pic_value, struct pic_lib *);
|
|||
|
||||
struct pic_proc *pic_make_var(pic_state *, pic_value, struct pic_proc *);
|
||||
|
||||
#define pic_deflibrary(pic, spec) \
|
||||
for (((assert(pic->prev_lib == NULL)), \
|
||||
(pic->prev_lib = pic->lib), \
|
||||
(pic->lib = pic_find_library(pic, pic_read_cstr(pic, (spec)))), \
|
||||
(pic->lib = pic->lib \
|
||||
? pic->lib \
|
||||
: pic_make_library(pic, pic_read_cstr(pic, (spec))))); \
|
||||
pic->prev_lib != NULL; \
|
||||
((pic->lib = pic->prev_lib), \
|
||||
(pic->prev_lib = NULL)))
|
||||
#define pic_deflibrary(pic, spec) do { \
|
||||
pic_value libname = pic_read_cstr(pic, spec); \
|
||||
if (pic_find_library(pic, libname) == NULL) { \
|
||||
pic_make_library(pic, libname); \
|
||||
} \
|
||||
pic_in_library(pic, libname); \
|
||||
} while (0)
|
||||
|
||||
void pic_warnf(pic_state *, const char *, ...);
|
||||
struct pic_string *pic_get_backtrace(pic_state *);
|
||||
|
|
|
@ -58,7 +58,7 @@ struct pic_state {
|
|||
|
||||
pic_value ptable; /* list of ephemerons */
|
||||
|
||||
struct pic_lib *lib, *prev_lib;
|
||||
struct pic_lib *lib;
|
||||
|
||||
pic_sym *sDEFINE, *sDEFINE_MACRO, *sLAMBDA, *sIF, *sBEGIN, *sSETBANG;
|
||||
pic_sym *sQUOTE, *sQUASIQUOTE, *sUNQUOTE, *sUNQUOTE_SPLICING;
|
||||
|
|
|
@ -55,6 +55,17 @@ pic_make_library(pic_state *pic, pic_value name)
|
|||
return lib;
|
||||
}
|
||||
|
||||
void
|
||||
pic_in_library(pic_state *pic, pic_value name)
|
||||
{
|
||||
struct pic_lib *lib;
|
||||
|
||||
if ((lib = pic_find_library(pic, name)) == NULL) {
|
||||
pic_errorf(pic, "library not found ~s", name);
|
||||
}
|
||||
pic->lib = lib;
|
||||
}
|
||||
|
||||
struct pic_lib *
|
||||
pic_find_library(pic_state *pic, pic_value spec)
|
||||
{
|
||||
|
|
|
@ -179,13 +179,8 @@ static pic_value
|
|||
vm_gref(pic_state *pic, pic_sym *uid)
|
||||
{
|
||||
if (! pic_weak_has(pic, pic->globals, uid)) {
|
||||
pic_weak_set(pic, pic->globals, uid, pic_invalid_value());
|
||||
|
||||
pic_errorf(pic, "uninitialized global variable: %s", pic_symbol_name(pic, uid));
|
||||
|
||||
return pic_invalid_value();
|
||||
}
|
||||
|
||||
return pic_weak_ref(pic, pic->globals, uid);
|
||||
}
|
||||
|
||||
|
|
|
@ -116,11 +116,13 @@ static void
|
|||
pic_init_core(pic_state *pic)
|
||||
{
|
||||
struct pic_box *pic_vm_gref_slot(pic_state *, pic_sym *);
|
||||
size_t ai;
|
||||
|
||||
pic_init_features(pic);
|
||||
|
||||
pic_deflibrary (pic, "(picrin base)") {
|
||||
size_t ai = pic_gc_arena_preserve(pic);
|
||||
pic_deflibrary(pic, "(picrin base)");
|
||||
|
||||
ai = pic_gc_arena_preserve(pic);
|
||||
|
||||
#define DONE pic_gc_arena_restore(pic, ai);
|
||||
|
||||
|
@ -182,7 +184,6 @@ pic_init_core(pic_state *pic)
|
|||
pic_panic(pic, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pic_state *
|
||||
pic_open(pic_allocf allocf, void *userdata)
|
||||
|
@ -348,7 +349,6 @@ pic_open(pic_allocf allocf, void *userdata)
|
|||
pic->PICRIN_BASE = pic_make_library(pic, pic_read_cstr(pic, "(picrin base)"));
|
||||
pic->PICRIN_USER = pic_make_library(pic, pic_read_cstr(pic, "(picrin user)"));
|
||||
pic->lib = pic->PICRIN_USER;
|
||||
pic->prev_lib = NULL;
|
||||
|
||||
pic_gc_arena_restore(pic, ai);
|
||||
|
||||
|
|
|
@ -26,9 +26,8 @@ pic_init_picrin(pic_state *pic)
|
|||
{
|
||||
pic_add_feature(pic, "r7rs");
|
||||
|
||||
pic_deflibrary (pic, "(picrin library)") {
|
||||
pic_deflibrary(pic, "(picrin library)");
|
||||
pic_defun(pic, "libraries", pic_libraries);
|
||||
}
|
||||
|
||||
pic_init_contrib(pic);
|
||||
pic_load_piclib(pic);
|
||||
|
|
Loading…
Reference in New Issue