picrin/extlib/benz/record.c

68 lines
1.2 KiB
C
Raw Normal View History

2014-08-25 00:38:09 -04:00
/**
* See Copyright Notice in picrin.h
*/
#include "picrin.h"
2016-02-18 10:59:45 -05:00
#include "picrin/object.h"
2014-08-25 00:38:09 -04:00
struct pic_record *
2016-02-06 12:58:18 -05:00
pic_make_rec(pic_state *pic, pic_value type, pic_value datum)
2014-08-25 00:38:09 -04:00
{
struct pic_record *rec;
rec = (struct pic_record *)pic_obj_alloc(pic, sizeof(struct pic_record), PIC_TYPE_RECORD);
2015-08-10 12:34:45 -04:00
rec->type = type;
2016-02-06 12:58:18 -05:00
rec->datum = datum;
2014-08-25 00:38:09 -04:00
return rec;
}
static pic_value
2016-02-06 12:58:18 -05:00
pic_rec_make_record(pic_state *pic)
2014-08-25 00:38:09 -04:00
{
2016-02-06 12:58:18 -05:00
pic_value type, datum;
2015-08-10 12:34:45 -04:00
2016-02-06 12:58:18 -05:00
pic_get_args(pic, "oo", &type, &datum);
2014-08-25 00:38:09 -04:00
2016-02-06 12:58:18 -05:00
return pic_obj_value(pic_make_rec(pic, type, datum));
2014-08-25 00:38:09 -04:00
}
static pic_value
2016-02-06 12:58:18 -05:00
pic_rec_record_p(pic_state *pic)
2014-08-25 00:38:09 -04:00
{
pic_value rec;
pic_get_args(pic, "o", &rec);
return pic_bool_value(pic, pic_rec_p(pic, rec));
2014-08-25 00:38:09 -04:00
}
static pic_value
2016-02-06 12:58:18 -05:00
pic_rec_record_type(pic_state *pic)
2014-08-25 00:38:09 -04:00
{
struct pic_record *rec;
pic_get_args(pic, "r", &rec);
2016-02-18 10:59:45 -05:00
return rec->type;
2014-08-25 00:38:09 -04:00
}
static pic_value
2016-02-06 12:58:18 -05:00
pic_rec_record_datum(pic_state *pic)
2014-08-25 00:38:09 -04:00
{
struct pic_record *rec;
2016-02-06 12:58:18 -05:00
pic_get_args(pic, "r", &rec);
2014-08-25 00:38:09 -04:00
2016-02-18 10:59:45 -05:00
return rec->datum;
2014-08-25 00:38:09 -04:00
}
void
pic_init_record(pic_state *pic)
{
2016-02-06 12:58:18 -05:00
pic_defun(pic, "make-record", pic_rec_make_record);
pic_defun(pic, "record?", pic_rec_record_p);
pic_defun(pic, "record-type", pic_rec_record_type);
pic_defun(pic, "record-datum", pic_rec_record_datum);
2014-08-25 00:38:09 -04:00
}