add pic_acons function

This commit is contained in:
Yuichi Nishiwaki 2013-10-20 14:04:39 +09:00
parent 40c996bd03
commit bde09e063a
3 changed files with 13 additions and 6 deletions

View File

@ -8,5 +8,6 @@ pic_value pic_cdr(pic_state *, pic_value);
pic_value pic_list(pic_state *, size_t, ...); pic_value pic_list(pic_state *, size_t, ...);
pic_value pic_assq(pic_state *, pic_value key, pic_value assoc); pic_value pic_assq(pic_state *, pic_value key, pic_value assoc);
pic_value pic_acons(pic_state *, pic_value key, pic_value val, pic_value assoc);
#endif #endif

View File

@ -50,3 +50,9 @@ pic_assq(pic_state *pic, pic_value key, pic_value assoc)
assoc = pic_cdr(pic, assoc); assoc = pic_cdr(pic, assoc);
goto enter; goto enter;
} }
pic_value
pic_acons(pic_state *pic, pic_value key, pic_value val, pic_value assoc)
{
return pic_cons(pic, pic_cons(pic, key, val), assoc);
}

View File

@ -37,7 +37,7 @@ env_lookup(pic_state *pic, pic_value sym, struct pic_env *env, int *depth, int *
static int static int
env_global_define(pic_state *pic, pic_value sym) env_global_define(pic_state *pic, pic_value sym)
{ {
pic_value cell; pic_value f;
int d, idx; int d, idx;
if (env_lookup(pic, sym, pic->global_env, &d, &idx)) { if (env_lookup(pic, sym, pic->global_env, &d, &idx)) {
@ -45,8 +45,8 @@ env_global_define(pic_state *pic, pic_value sym)
} }
idx = pic->glen++; idx = pic->glen++;
cell = pic_cons(pic, sym, pic_float_value(idx)); f = pic_float_value(idx);
pic->global_env->assoc = pic_cons(pic, cell, pic->global_env->assoc); pic->global_env->assoc = pic_acons(pic, sym, f, pic->global_env->assoc);
return idx; return idx;
} }
@ -55,7 +55,7 @@ static struct pic_env *
env_new(pic_state *pic, pic_value args, struct pic_env *env) env_new(pic_state *pic, pic_value args, struct pic_env *env)
{ {
struct pic_env *inner_env; struct pic_env *inner_env;
pic_value v, cell; pic_value v, f;
int i; int i;
inner_env = (struct pic_env *)pic_alloc(pic, sizeof(struct pic_env)); inner_env = (struct pic_env *)pic_alloc(pic, sizeof(struct pic_env));
@ -66,8 +66,8 @@ env_new(pic_state *pic, pic_value args, struct pic_env *env)
for (v = args; ! pic_nil_p(v); v = pic_cdr(pic, v)) { for (v = args; ! pic_nil_p(v); v = pic_cdr(pic, v)) {
pic_value sym = pic_car(pic, v); pic_value sym = pic_car(pic, v);
cell = pic_cons(pic, sym, pic_float_value(i--)); f = pic_float_value(i--);
inner_env->assoc = pic_cons(pic, cell, inner_env->assoc); inner_env->assoc = pic_acons(pic, sym, f, inner_env->assoc);
} }
return inner_env; return inner_env;