From b983c77767464e04f4c7f156190d156d20711128 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Tue, 9 Jun 2015 18:36:39 +0900 Subject: [PATCH] use registries for parameter table --- extlib/benz/include/picrin.h | 5 ++--- extlib/benz/state.c | 1 - extlib/benz/var.c | 28 +++++++++------------------- 3 files changed, 11 insertions(+), 23 deletions(-) diff --git a/extlib/benz/include/picrin.h b/extlib/benz/include/picrin.h index 97edecaf..9c59ce59 100644 --- a/extlib/benz/include/picrin.h +++ b/extlib/benz/include/picrin.h @@ -92,6 +92,8 @@ typedef struct { pic_code *ip; + pic_value ptable; + struct pic_lib *lib, *prev_lib; pic_sym *sDEFINE, *sLAMBDA, *sIF, *sBEGIN, *sQUOTE, *sSETBANG; @@ -130,9 +132,6 @@ typedef struct { pic_value libs; struct pic_reg *attrs; - pic_value ptable; - size_t pnum; - struct pic_reader *reader; bool gc_enable; diff --git a/extlib/benz/state.c b/extlib/benz/state.c index 3190c346..4724b87a 100644 --- a/extlib/benz/state.c +++ b/extlib/benz/state.c @@ -237,7 +237,6 @@ pic_open(int argc, char *argv[], char **envp, pic_allocf allocf) /* parameter table */ pic->ptable = pic_nil_value(); - pic->pnum = 0; /* native stack marker */ pic->native_stack_start = &t; diff --git a/extlib/benz/var.c b/extlib/benz/var.c index 95da6b16..5fd44c0b 100644 --- a/extlib/benz/var.c +++ b/extlib/benz/var.c @@ -17,15 +17,12 @@ static pic_value var_get(pic_state *pic, struct pic_proc *var) { pic_value elem, it; - pic_sym *id; - struct pic_dict *dict; - - id = pic_sym_ptr(pic_proc_env_ref(pic, var, "id")); + struct pic_reg *reg; pic_for_each (elem, pic->ptable, it) { - dict = pic_dict_ptr(elem); - if (pic_dict_has(pic, dict, id)) { - return pic_dict_ref(pic, dict, id); + reg = pic_reg_ptr(elem); + if (pic_reg_has(pic, reg, var)) { + return pic_reg_ref(pic, reg, var); } } pic_panic(pic, "logic flaw"); @@ -34,14 +31,11 @@ var_get(pic_state *pic, struct pic_proc *var) static pic_value var_set(pic_state *pic, struct pic_proc *var, pic_value val) { - pic_sym *id; - struct pic_dict *dict; + struct pic_reg *reg; - id = pic_sym_ptr(pic_proc_env_ref(pic, var, "id")); + reg = pic_reg_ptr(pic_car(pic, pic->ptable)); - dict = pic_dict_ptr(pic_car(pic, pic->ptable)); - - pic_dict_set(pic, dict, id, val); + pic_reg_set(pic, reg, var, val); return pic_undef_value(); } @@ -66,16 +60,12 @@ struct pic_proc * pic_make_var(pic_state *pic, pic_value init, struct pic_proc *conv) { struct pic_proc *var; - pic_value converter = conv ? pic_obj_value(conv) : pic_false_value(); - pic_sym *id; var = pic_make_proc(pic, var_call, ""); if (conv != NULL) { - pic_proc_env_set(pic, var, "conv", converter); + pic_proc_env_set(pic, var, "conv", pic_obj_value(conv)); } - id = pic_intern(pic, pic_format(pic, "%d", pic->pnum++)); - pic_proc_env_set(pic, var, "id", pic_obj_value(id)); pic_apply1(pic, var, init); @@ -101,7 +91,7 @@ pic_var_with_parameter(pic_state *pic) pic_get_args(pic, "l", &body); - pic->ptable = pic_cons(pic, pic_obj_value(pic_make_dict(pic)), pic->ptable); + pic->ptable = pic_cons(pic, pic_obj_value(pic_make_reg(pic)), pic->ptable); val = pic_apply0(pic, body);