inline pic_car and pic_cdr

This commit is contained in:
Yuichi Nishiwaki 2014-09-17 01:07:25 +09:00
parent 565ee431af
commit dbbc2c1a25
2 changed files with 28 additions and 34 deletions

View File

@ -18,9 +18,33 @@ struct pic_pair {
#define pic_pair_p(v) (pic_type(v) == PIC_TT_PAIR) #define pic_pair_p(v) (pic_type(v) == PIC_TT_PAIR)
#define pic_pair_ptr(o) ((struct pic_pair *)pic_ptr(o)) #define pic_pair_ptr(o) ((struct pic_pair *)pic_ptr(o))
static inline pic_value
pic_car(pic_state *pic, pic_value obj)
{
struct pic_pair *pair;
if (! pic_pair_p(obj)) {
pic_errorf(pic, "pair required, but got ~s", obj);
}
pair = pic_pair_ptr(obj);
return pair->car;
}
static inline pic_value
pic_cdr(pic_state *pic, pic_value obj)
{
struct pic_pair *pair;
if (! pic_pair_p(obj)) {
pic_errorf(pic, "pair required, but got ~s", obj);
}
pair = pic_pair_ptr(obj);
return pair->cdr;
}
pic_value pic_cons(pic_state *, pic_value, pic_value); pic_value pic_cons(pic_state *, pic_value, pic_value);
pic_value pic_car(pic_state *, pic_value);
pic_value pic_cdr(pic_state *, pic_value);
void pic_set_car(pic_state *, pic_value, pic_value); void pic_set_car(pic_state *, pic_value, pic_value);
void pic_set_cdr(pic_state *, pic_value, pic_value); void pic_set_cdr(pic_state *, pic_value, pic_value);

34
pair.c
View File

@ -19,32 +19,6 @@ pic_cons(pic_state *pic, pic_value car, pic_value cdr)
return pic_obj_value(pair); return pic_obj_value(pair);
} }
pic_value
pic_car(pic_state *pic, pic_value obj)
{
struct pic_pair *pair;
if (! pic_pair_p(obj)) {
pic_errorf(pic, "pair required, but got ~s", obj);
}
pair = pic_pair_ptr(obj);
return pair->car;
}
pic_value
pic_cdr(pic_state *pic, pic_value obj)
{
struct pic_pair *pair;
if (! pic_pair_p(obj)) {
pic_errorf(pic, "pair required, but got ~s", obj);
}
pair = pic_pair_ptr(obj);
return pair->cdr;
}
void void
pic_set_car(pic_state *pic, pic_value obj, pic_value val) pic_set_car(pic_state *pic, pic_value obj, pic_value val)
{ {
@ -519,10 +493,8 @@ pic_pair_set_car(pic_state *pic)
pic_get_args(pic, "oo", &v, &w); pic_get_args(pic, "oo", &v, &w);
if (! pic_pair_p(v)) pic_set_car(pic, v, w);
pic_errorf(pic, "pair expected");
pic_pair_ptr(v)->car = w;
return pic_none_value(); return pic_none_value();
} }
@ -533,10 +505,8 @@ pic_pair_set_cdr(pic_state *pic)
pic_get_args(pic, "oo", &v, &w); pic_get_args(pic, "oo", &v, &w);
if (! pic_pair_p(v)) pic_set_cdr(pic, v, w);
pic_errorf(pic, "pair expected");
pic_pair_ptr(v)->cdr = w;
return pic_none_value(); return pic_none_value();
} }