2014-08-25 00:38:09 -04:00
|
|
|
/**
|
|
|
|
* See Copyright Notice in picrin.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "picrin.h"
|
2017-05-05 23:53:20 -04:00
|
|
|
#include "value.h"
|
2017-03-28 10:09:40 -04:00
|
|
|
#include "object.h"
|
2014-08-25 00:38:09 -04:00
|
|
|
|
2016-02-20 03:27:13 -05:00
|
|
|
pic_value
|
2017-03-28 10:09:40 -04:00
|
|
|
pic_make_record(pic_state *pic, pic_value type, pic_value datum)
|
2014-08-25 00:38:09 -04:00
|
|
|
{
|
2016-02-21 06:32:00 -05:00
|
|
|
struct record *rec;
|
2014-08-25 00:38:09 -04:00
|
|
|
|
2017-04-12 00:18:06 -04:00
|
|
|
rec = (struct record *)pic_obj_alloc(pic, PIC_TYPE_RECORD);
|
2017-04-09 04:34:56 -04:00
|
|
|
rec->type = sym_ptr(pic, type);
|
2016-02-06 12:58:18 -05:00
|
|
|
rec->datum = datum;
|
2014-08-25 00:38:09 -04:00
|
|
|
|
2017-03-28 19:32:28 -04:00
|
|
|
return obj_value(pic, rec);
|
2014-08-25 00:38:09 -04:00
|
|
|
}
|
|
|
|
|
2017-04-04 01:54:58 -04:00
|
|
|
pic_value
|
|
|
|
pic_record_type(pic_state *pic, pic_value rec)
|
|
|
|
{
|
2017-04-09 04:34:56 -04:00
|
|
|
return obj_value(pic, rec_ptr(pic, rec)->type);
|
2017-04-04 01:54:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pic_value
|
|
|
|
pic_record_datum(pic_state *pic, pic_value rec)
|
|
|
|
{
|
2017-04-06 09:29:02 -04:00
|
|
|
return rec_ptr(pic, rec)->datum;
|
2017-04-04 01:54:58 -04:00
|
|
|
}
|
|
|
|
|
2014-08-25 00:38:09 -04:00
|
|
|
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
|
|
|
|
2017-04-09 04:34:56 -04:00
|
|
|
pic_get_args(pic, "mo", &type, &datum);
|
2014-08-25 00:38:09 -04:00
|
|
|
|
2017-03-28 10:09:40 -04:00
|
|
|
return pic_make_record(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);
|
|
|
|
|
2016-02-18 06:15:42 -05:00
|
|
|
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
|
|
|
{
|
2016-02-20 03:27:13 -05:00
|
|
|
pic_value rec;
|
2014-08-25 00:38:09 -04:00
|
|
|
|
|
|
|
pic_get_args(pic, "r", &rec);
|
|
|
|
|
2017-04-04 01:54:58 -04:00
|
|
|
return pic_record_type(pic, rec);
|
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
|
|
|
{
|
2016-02-20 03:27:13 -05:00
|
|
|
pic_value rec;
|
2014-08-25 00:38:09 -04:00
|
|
|
|
2016-02-06 12:58:18 -05:00
|
|
|
pic_get_args(pic, "r", &rec);
|
2014-08-25 00:38:09 -04:00
|
|
|
|
2017-04-04 01:54:58 -04:00
|
|
|
return pic_record_datum(pic, rec);
|
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
|
|
|
}
|