diff --git a/include/picrin.h b/include/picrin.h index 8719b79e..37830c1a 100644 --- a/include/picrin.h +++ b/include/picrin.h @@ -143,15 +143,13 @@ void pic_close(pic_state *); 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 *); -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_funcall(pic_state *pic, const char *name, pic_list args); +void pic_define(pic_state *, const char *, pic_value); /* automatic export */ +void pic_defun(pic_state *, const char *, pic_func_t); +void pic_defvar(pic_state *, const char *, pic_value, struct pic_proc *); struct pic_proc *pic_get_proc(pic_state *); 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); @@ -172,6 +170,10 @@ pic_value pic_read_cstr(pic_state *, const char *); void pic_load(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_apply0(pic_state *, struct pic_proc *); pic_value pic_apply1(pic_state *, struct pic_proc *, pic_value); diff --git a/port.c b/port.c index 6b27040d..11ef26ab 100644 --- a/port.c +++ b/port.c @@ -681,9 +681,9 @@ pic_port_flush(pic_state *pic) void 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_define(pic, "current-output-port", pic_obj_value(pic_make_var(pic, 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-input-port", pic_obj_value(pic->xSTDIN), NULL); + pic_defvar(pic, "current-output-port", pic_obj_value(pic->xSTDOUT), NULL); + pic_defvar(pic, "current-error-port", pic_obj_value(pic->xSTDERR), NULL); pic_defun(pic, "call-with-port", pic_port_call_with_port); diff --git a/vm.c b/vm.c index 05ddda7c..d2270ccb 100644 --- a/vm.c +++ b/vm.c @@ -479,6 +479,12 @@ pic_defun(pic_state *pic, const char *name, pic_func_t cfunc) 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 vm_push_env(pic_state *pic) {