This repository was archived by the owner on Feb 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrecord.c
79 lines (60 loc) · 1.39 KB
/
record.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
* See Copyright Notice in picrin.h
*/
#include "picrin.h"
#include "object.h"
pic_value
pic_make_record(pic_state *pic, pic_value type, pic_value datum)
{
struct record *rec;
rec = (struct record *)pic_obj_alloc(pic, PIC_TYPE_RECORD);
rec->type = sym_ptr(pic, type);
rec->datum = datum;
return obj_value(pic, rec);
}
pic_value
pic_record_type(pic_state *pic, pic_value rec)
{
return obj_value(pic, rec_ptr(pic, rec)->type);
}
pic_value
pic_record_datum(pic_state *pic, pic_value rec)
{
return rec_ptr(pic, rec)->datum;
}
static pic_value
pic_rec_make_record(pic_state *pic)
{
pic_value type, datum;
pic_get_args(pic, "mo", &type, &datum);
return pic_make_record(pic, type, datum);
}
static pic_value
pic_rec_record_p(pic_state *pic)
{
pic_value rec;
pic_get_args(pic, "o", &rec);
return pic_bool_value(pic, pic_rec_p(pic, rec));
}
static pic_value
pic_rec_record_type(pic_state *pic)
{
pic_value rec;
pic_get_args(pic, "r", &rec);
return pic_record_type(pic, rec);
}
static pic_value
pic_rec_record_datum(pic_state *pic)
{
pic_value rec;
pic_get_args(pic, "r", &rec);
return pic_record_datum(pic, rec);
}
void
pic_init_record(pic_state *pic)
{
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);
}