From f5789c7c6f66758c99343a721f1c996dd4c44f2b Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Wed, 24 Jun 2015 02:02:26 +0900 Subject: [PATCH] added c functions to define private varaibles. see discussion on #271 --- extlib/benz/include/picrin.h | 4 ++++ extlib/benz/vm.c | 27 +++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/extlib/benz/include/picrin.h b/extlib/benz/include/picrin.h index e5419c24..c1b16cd9 100644 --- a/extlib/benz/include/picrin.h +++ b/extlib/benz/include/picrin.h @@ -193,6 +193,10 @@ void pic_load_cstr(pic_state *, const char *); void pic_define(pic_state *, const char *, pic_value); void pic_defun(pic_state *, const char *, pic_func_t); void pic_defvar(pic_state *, const char *, pic_value, struct pic_proc *); +/* functions suffixed with '_' will not perform automatic export */ +void pic_define_(pic_state *, const char *, pic_value); +void pic_defun_(pic_state *, const char *, pic_func_t); +void pic_defvar_(pic_state *, const char *, pic_value, struct pic_proc *); pic_value pic_ref(pic_state *, struct pic_lib *, const char *); void pic_set(pic_state *, struct pic_lib *, const char *, pic_value); diff --git a/extlib/benz/vm.c b/extlib/benz/vm.c index 6989c465..f661f10a 100644 --- a/extlib/benz/vm.c +++ b/extlib/benz/vm.c @@ -1137,7 +1137,7 @@ pic_defun_vm(pic_state *pic, const char *name, pic_sym *uid, pic_func_t func) } void -pic_define(pic_state *pic, const char *name, pic_value val) +pic_define_(pic_state *pic, const char *name, pic_value val) { pic_sym *sym, *uid; @@ -1150,20 +1150,39 @@ pic_define(pic_state *pic, const char *name, pic_value val) } pic_dict_set(pic, pic->globals, uid, val); +} - pic_export(pic, sym); +void +pic_define(pic_state *pic, const char *name, pic_value val) +{ + pic_define_(pic, name, val); + pic_export(pic, pic_intern_cstr(pic, name)); +} + +void +pic_defun_(pic_state *pic, const char *name, pic_func_t cfunc) +{ + pic_define_(pic, name, pic_obj_value(pic_make_proc(pic, cfunc, name))); } void pic_defun(pic_state *pic, const char *name, pic_func_t cfunc) { - pic_define(pic, name, pic_obj_value(pic_make_proc(pic, cfunc, name))); + pic_defun_(pic, name, cfunc); + pic_export(pic, pic_intern_cstr(pic, name)); +} + +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))); } 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))); + pic_defvar_(pic, name, init, conv); + pic_export(pic, pic_intern_cstr(pic, name)); } pic_value