add some pair functions

This commit is contained in:
Yuichi Nishiwaki 2013-10-10 17:06:26 +09:00
parent 177d2c7098
commit 9038939bd1
2 changed files with 37 additions and 0 deletions

View File

@ -13,4 +13,8 @@ void pic_free(pic_state *, void *);
pic_state *pic_open();
void pic_close(pic_state *);
pic_value pic_cons(pic_state *pic, pic_value, pic_value);
pic_value pic_car(pic_state *pic, pic_value);
pic_value pic_cdr(pic_state *pic, pic_value);
#endif

33
src/pair.c Normal file
View File

@ -0,0 +1,33 @@
#include "picrin.h"
pic_value
pic_cons(pic_state *pic, pic_value car, pic_value cdr)
{
struct pic_pair *pair;
pair = (struct pic_pair *)pic_gc_alloc(pic, sizeof(struct pic_pair), PIC_TT_PAIR);
pair->car = car;
pair->cdr = cdr;
return pic_obj_value(pair);
}
pic_value
pic_car(pic_state *pic, pic_value obj)
{
struct pic_pair *pair;
pair = (struct pic_pair *)obj->u->data;
return pair->car;
}
pic_value
pic_cdr(pic_state *pic, pic_value obj)
{
struct pic_pair *pair;
pair = (struct pic_pair *)obj->u->data;
return pair->cdr;
}