add pic_defvar

This commit is contained in:
Yuichi Nishiwaki 2014-09-16 00:16:30 +09:00
parent 678d2484ec
commit 9c4d815864
3 changed files with 16 additions and 8 deletions

View File

@ -143,15 +143,13 @@ void pic_close(pic_state *);
void pic_add_feature(pic_state *, const char *); void pic_add_feature(pic_state *, const char *);
void pic_define(pic_state *, const char *, pic_value); /* automatic export */
bool pic_defined_p(pic_state *, struct pic_lib *, const char *); bool pic_defined_p(pic_state *, struct pic_lib *, const char *);
pic_value pic_ref(pic_state *, struct pic_lib *, const char *); void pic_define(pic_state *, const char *, pic_value); /* automatic export */
void pic_set(pic_state *, struct pic_lib *, const char *, pic_value); void pic_defun(pic_state *, const char *, pic_func_t);
pic_value pic_funcall(pic_state *pic, const char *name, pic_list args); void pic_defvar(pic_state *, const char *, pic_value, struct pic_proc *);
struct pic_proc *pic_get_proc(pic_state *); struct pic_proc *pic_get_proc(pic_state *);
int pic_get_args(pic_state *, const char *, ...); int pic_get_args(pic_state *, const char *, ...);
void pic_defun(pic_state *, const char *, pic_func_t);
bool pic_equal_p(pic_state *, pic_value, pic_value); bool pic_equal_p(pic_state *, pic_value, pic_value);
@ -172,6 +170,10 @@ pic_value pic_read_cstr(pic_state *, const char *);
void pic_load(pic_state *, const char *); void pic_load(pic_state *, const char *);
void pic_load_cstr(pic_state *, const char *); void pic_load_cstr(pic_state *, const char *);
pic_value pic_funcall(pic_state *pic, const char *, pic_list);
pic_value pic_ref(pic_state *, struct pic_lib *, const char *);
void pic_set(pic_state *, struct pic_lib *, const char *, pic_value);
pic_value pic_apply(pic_state *, struct pic_proc *, pic_value); pic_value pic_apply(pic_state *, struct pic_proc *, pic_value);
pic_value pic_apply0(pic_state *, struct pic_proc *); pic_value pic_apply0(pic_state *, struct pic_proc *);
pic_value pic_apply1(pic_state *, struct pic_proc *, pic_value); pic_value pic_apply1(pic_state *, struct pic_proc *, pic_value);

6
port.c
View File

@ -681,9 +681,9 @@ pic_port_flush(pic_state *pic)
void void
pic_init_port(pic_state *pic) pic_init_port(pic_state *pic)
{ {
pic_define(pic, "current-input-port", pic_obj_value(pic_make_var(pic, pic_obj_value(pic->xSTDIN), NULL))); pic_defvar(pic, "current-input-port", pic_obj_value(pic->xSTDIN), NULL);
pic_define(pic, "current-output-port", pic_obj_value(pic_make_var(pic, pic_obj_value(pic->xSTDOUT), NULL))); pic_defvar(pic, "current-output-port", pic_obj_value(pic->xSTDOUT), NULL);
pic_define(pic, "current-error-port", pic_obj_value(pic_make_var(pic, pic_obj_value(pic->xSTDERR), NULL))); pic_defvar(pic, "current-error-port", pic_obj_value(pic->xSTDERR), NULL);
pic_defun(pic, "call-with-port", pic_port_call_with_port); pic_defun(pic, "call-with-port", pic_port_call_with_port);

6
vm.c
View File

@ -479,6 +479,12 @@ pic_defun(pic_state *pic, const char *name, pic_func_t cfunc)
pic_define(pic, name, pic_obj_value(proc)); pic_define(pic, name, pic_obj_value(proc));
} }
void
pic_defvar(pic_state *pic, const char *name, pic_value init, struct pic_proc *conv)
{
pic_define(pic, name, pic_obj_value(pic_make_var(pic, init, conv)));
}
static void static void
vm_push_env(pic_state *pic) vm_push_env(pic_state *pic)
{ {