1
#ifndef CSTRUCT_H_GUARD
2
#define CSTRUCT_H_GUARD
4
/* The CStruct representation maintains a chunk of memory that it can
5
* always pass off to C land. If we in turn embed any strings, pointers
6
* to other CStruct REPR objects and so forth, we need to both keep the
7
* C-friendly bit of memory and a copy to the GC-able, 6model objects in
10
/* GC-marked objects that our C structure points into. */
13
/* Pointer to the actual C structure memory; we don't inline it
14
* directly in the body, since it doesn't work so well if we get
15
* something returned and are wrapping it. */
19
/* This is how an instance with the CStruct representation looks. */
21
SixModelObjectCommonalities common;
25
/* This is used in the name to class mapping. */
31
/* TODO: Better description here. */
32
/* Attribute location flags. */
33
#define CSTRUCT_ATTR_IN_STRUCT 0
34
#define CSTRUCT_ATTR_CSTRUCT 1
35
#define CSTRUCT_ATTR_CARRAY 2
36
#define CSTRUCT_ATTR_CPTR 3
37
#define CSTRUCT_ATTR_STRING 4
38
#define CSTRUCT_ATTR_MASK 7
39
/* Bits to shift a slot position to make room for CSTRUCT_ATTR_*. */
40
#define CSTRUCT_ATTR_SHIFT 3
42
/* The CStruct REPR data contains info we need to do allocations, look up
43
* attributes and so forth. */
45
/* The size of the structure. */
48
/* The number of attributes we have allocated slots for. Note that
49
* slots can vary in size. */
50
INTVAL num_attributes;
52
/* Number of child objects we store. */
53
INTVAL num_child_objs;
55
/* Number of child strings we store. */
56
INTVAL num_child_strs;
58
/* Lower bits are flags indicating what kind of attribute we have;
59
* whether it's one that is just a simple value that we can always
60
* access directly in the C struct body, or a more complex one that
61
* we need to maintain in the C struct and in the GC-able list. Upper
62
* bits say where to find it. */
63
INTVAL *attribute_locations;
65
/* Maps attribute position numbers to their location in the C struct.
66
* Note that this will not be the only place we need to update for
67
* any reference type. */
68
INTVAL *struct_offsets;
70
/* If the attribute was actually flattened in to this object from another
71
* representation, this is the s-table of the type of that attribute. NULL
72
* for attributes that are reference types. */
73
STable **flattened_stables;
75
/* For reference type members, we cache the relevant type objects.
76
* Flattened types have NULL here. */
79
/* A table mapping attribute names to indexes (which can then be looked
80
* up in the offset table). Uses a final null entry as a sentinel. */
81
CStructNameMap *name_to_index_mapping;
83
/* Slots holding flattened objects that need another REPR to initialize
84
* them; terminated with -1. */
85
INTVAL *initialize_slots;
88
/* Initializes the CStruct REPR. */
89
REPROps * CStruct_initialize(PARROT_INTERP,
90
PMC * (* wrap_object_func_ptr) (PARROT_INTERP, void *obj),
91
PMC * (* create_stable_func_ptr) (PARROT_INTERP, REPROps *REPR, PMC *HOW));