/home/travis/build/MoarVM/MoarVM/src/6model/reprs/CUnion.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* Attribute location flags. */ |
2 | 0 | #define MVM_CUNION_ATTR_IN_STRUCT 0 |
3 | 0 | #define MVM_CUNION_ATTR_CSTRUCT 1 |
4 | 0 | #define MVM_CUNION_ATTR_CARRAY 2 |
5 | 0 | #define MVM_CUNION_ATTR_CPTR 3 |
6 | 0 | #define MVM_CUNION_ATTR_STRING 4 |
7 | 0 | #define MVM_CUNION_ATTR_CUNION 5 |
8 | 0 | #define MVM_CUNION_ATTR_CPPSTRUCT 6 |
9 | 0 | #define MVM_CUNION_ATTR_MASK 7 |
10 | | |
11 | 0 | #define MVM_CUNION_ATTR_INLINED 8 |
12 | | |
13 | | /* Bits to shift a slot position to make room for MVM_CUNION_ATTR_*. */ |
14 | 0 | #define MVM_CUNION_ATTR_SHIFT 4 |
15 | | |
16 | | /* The CUnion representation maintains a chunk of memory that it can |
17 | | * always pass off to C land. If we in turn embed any strings, pointers |
18 | | * to other CUnion REPR objects and so forth, we need to both keep the |
19 | | * C-friendly bit of memory and a copy to the GC-able, 6model objects in |
20 | | * sync. */ |
21 | | struct MVMCUnionBody { |
22 | | /* GC-marked objects that our C structure points into. */ |
23 | | MVMObject **child_objs; |
24 | | |
25 | | /* Pointer to the actual C structure memory; we don't inline it |
26 | | * directly in the body, since it doesn't work so well if we get |
27 | | * something returned and are wrapping it. */ |
28 | | void *cunion; |
29 | | }; |
30 | | |
31 | | struct MVMCUnion { |
32 | | MVMObject common; |
33 | | MVMCUnionBody body; |
34 | | }; |
35 | | |
36 | | /* This is used in the name to class mapping. */ |
37 | | struct MVMCUnionNameMap { |
38 | | MVMObject *class_key; |
39 | | MVMObject *name_map; |
40 | | }; |
41 | | |
42 | | /* The CUnion REPR data contains info we need to do allocations, look up |
43 | | * attributes and so forth. */ |
44 | | struct MVMCUnionREPRData { |
45 | | /* The size and alignment of the structure in bytes. */ |
46 | | MVMint32 struct_size; |
47 | | MVMint32 struct_align; |
48 | | |
49 | | /* The number of attributes we have allocated slots for. Note that |
50 | | * slots can vary in size. */ |
51 | | MVMint32 num_attributes; |
52 | | |
53 | | /* Number of child objects we store. */ |
54 | | MVMint32 num_child_objs; |
55 | | |
56 | | /* Lower bits are flags indicating what kind of attribute we have; |
57 | | * whether it's one that is just a simple value that we can always |
58 | | * access directly in the C struct body, or a more complex one that |
59 | | * we need to maintain in the C struct and in the GC-able list. Upper |
60 | | * bits say where to find it. */ |
61 | | MVMint32 *attribute_locations; |
62 | | |
63 | | /* Maps attribute position numbers to their location in the C struct. |
64 | | * Note that this will not be the only place we need to update for |
65 | | * any reference type. */ |
66 | | MVMint32 *struct_offsets; |
67 | | |
68 | | /* If the attribute was actually flattened in to this object from another |
69 | | * representation, this is the s-table of the type of that attribute. NULL |
70 | | * for attributes that are reference types. */ |
71 | | MVMSTable **flattened_stables; |
72 | | |
73 | | /* For reference type members, we cache the relevant type objects. |
74 | | * Flattened types have NULL here. */ |
75 | | MVMObject **member_types; |
76 | | |
77 | | /* A table mapping attribute names to indexes (which can then be looked |
78 | | * up in the offset table). Uses a final null entry as a sentinel. */ |
79 | | MVMCUnionNameMap *name_to_index_mapping; |
80 | | |
81 | | /* Slots holding flattened objects that need another REPR to initialize |
82 | | * them; terminated with -1. */ |
83 | | MVMint32 *initialize_slots; |
84 | | }; |
85 | | |
86 | | /* Initializes the CUnion REPR. */ |
87 | | const MVMREPROps * MVMCUnion_initialize(MVMThreadContext *tc); |