-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobj_record.h
68 lines (55 loc) · 1.8 KB
/
obj_record.h
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
#ifndef OBJ_RECORD_INCLUDED
#define OBJ_RECORD_INCLUDED
#include "mem.h"
#include "obj_boolean.h"
#include "obj_rtd.h"
// MAKE_RECORD(rtd, field_values...)
#define MAKE_RECORD(...) (make_record_(__VA_ARGS__, END_OF_ARGS))
extern mem_ops_t record_ops;
typedef struct record_obj {
obj_t rec_rtd;
} record_obj_t;
extern obj_t make_record_ (obj_t rtd, ...);
extern obj_t make_record_va (obj_t rtd, va_list fields);
static inline bool is_record (obj_t obj);
static inline bool is_nonopaque_record(obj_t obj);
static inline bool is_instance (obj_t rec, obj_t rtd);
static inline obj_t record_rtd (obj_t rec);
static inline size_t record_len (obj_t rec);
extern obj_t record_field_name (obj_t rec, size_t index);
extern obj_t record_get_field (obj_t rec, size_t index);
extern void record_set_field (obj_t rec, size_t index, obj_t value);
static inline bool is_record(obj_t obj)
{
return (is_heap(obj) &&
((heap_object_t *)obj)->ho_ops->mo_start_marker !=
MEM_OPS_PRIMITIVE);
}
static inline bool is_nonopaque_record(obj_t obj)
{
return is_record(obj) &&
!rtd_is_opaque(((record_obj_t *)obj)->rec_rtd);
}
static inline bool is_instance(obj_t rec, obj_t rtd)
{
CHECK(is_record(rec), "must be record", rec);
CHECK(is_rtd(rtd), "must be rtd", rtd);
//return ((record_obj_t *)rec)->rec_rtd == rtd;
obj_t p = record_rtd(rec);
while (p != FALSE_OBJ) {
if (p == rtd)
return true;
p = rtd_parent(p);
}
return false;
}
static inline obj_t record_rtd(obj_t rec)
{
CHECK(is_record(rec), "must be record", rec);
return ((record_obj_t *)rec)->rec_rtd;
}
static inline size_t record_len(obj_t rec)
{
return rtd_field_count(record_rtd(rec));
}
#endif /* !OBJ_RECORD_INCLUDED */