change the behavior of pic_define

This commit is contained in:
Yuichi Nishiwaki 2016-02-14 13:25:18 +09:00
parent 549d939ce6
commit 417a44b786
3 changed files with 10 additions and 30 deletions

View File

@ -399,6 +399,9 @@ pic_socket_call_with_socket(pic_state *pic)
void
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)))
#define pic_define_(pic, name, v) pic_define(pic, pic->lib, name, v)
pic_deflibrary (pic, "(srfi 106)") {
pic_defun_(pic, "socket?", pic_socket_socket_p);
pic_defun_(pic, "make-socket", pic_socket_make_socket);

View File

@ -145,14 +145,10 @@ void pic_gc(pic_state *);
void pic_add_feature(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 '_' do not involve 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 *);
void pic_define(pic_state *, struct pic_lib *, const char *, pic_value);
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, struct pic_lib *, const char *, pic_value);

View File

@ -900,53 +900,34 @@ pic_apply5(pic_state *pic, struct pic_proc *proc, pic_value arg1, pic_value arg2
}
void
pic_define_(pic_state *pic, const char *name, pic_value val)
pic_define(pic_state *pic, struct pic_lib *lib, const char *name, pic_value val)
{
pic_sym *sym, *uid;
sym = pic_intern_cstr(pic, name);
if ((uid = pic_find_identifier(pic, (pic_id *)sym, pic->lib->env)) == NULL) {
uid = pic_add_identifier(pic, (pic_id *)sym, pic->lib->env);
if ((uid = pic_find_identifier(pic, (pic_id *)sym, lib->env)) == NULL) {
uid = pic_add_identifier(pic, (pic_id *)sym, lib->env);
} else {
if (pic_weak_has(pic, pic->globals, uid)) {
pic_warnf(pic, "redefining variable: ~s", pic_obj_value(uid));
}
}
pic_set(pic, pic->lib, name, val);
}
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)));
pic_set(pic, lib, name, val);
}
void
pic_defun(pic_state *pic, const char *name, pic_func_t cfunc)
{
pic_defun_(pic, name, cfunc);
pic_define(pic, pic->lib, name, pic_obj_value(pic_make_proc(pic, 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_defvar_(pic, name, init, conv);
pic_define(pic, pic->lib, name, pic_obj_value(pic_make_var(pic, init, conv)));
pic_export(pic, pic_intern_cstr(pic, name));
}