From 10e5546a53dba6b8a80d3b8577c6bd44f9aa45b0 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 12 Jan 2014 16:09:19 +0900 Subject: [PATCH] functions defined by pic_defun will be implicitly renamed --- src/codegen.c | 25 ++++++++++++++++++------- src/vm.c | 9 +++++++++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/codegen.c b/src/codegen.c index 464daa8e..ffaa3fd0 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -932,17 +932,28 @@ pic_codegen(pic_state *pic, pic_value obj) } void -pic_defun(pic_state *pic, const char *name, pic_func_t cfunc) +pic_define(pic_state *pic, struct pic_lib *lib, const char *name, pic_value val) { - struct pic_proc *proc; int idx; + pic_sym gsym; + struct pic_lib *lib2; - proc = pic_proc_new(pic, cfunc); - idx = scope_global_define(pic, name); - pic->globals[idx] = pic_obj_value(proc); + gsym = pic_gensym(pic, pic_intern_cstr(pic, name)); - xh_put(pic->lib->senv->tbl, name, pic_intern_cstr(pic, name)); - xh_put(pic->lib->exports, name, pic_intern_cstr(pic, name)); + /* push to the global arena */ + idx = scope_global_define(pic, pic_symbol_name(pic, gsym)); + pic->globals[idx] = val; + + /* register to the senv */ + xh_put(lib->senv->tbl, name, gsym); + + /* export! */ + lib2 = pic->lib; + { + pic->lib = lib; + pic_export(pic, pic_intern_cstr(pic, name)); + pic->lib = lib2; + } } void diff --git a/src/vm.c b/src/vm.c index a5ea64de..9e8a26c3 100644 --- a/src/vm.c +++ b/src/vm.c @@ -300,6 +300,15 @@ pic_get_args(pic_state *pic, const char *format, ...) return i; } +void +pic_defun(pic_state *pic, const char *name, pic_func_t cfunc) +{ + struct pic_proc *proc; + + proc = pic_proc_new(pic, cfunc); + pic_define(pic, pic->lib, name, pic_obj_value(proc)); +} + pic_value pic_apply_argv(pic_state *pic, struct pic_proc *proc, size_t argc, ...) {