~ubuntu-branches/ubuntu/vivid/nqp/vivid-proposed

« back to all changes in this revision

Viewing changes to src/6model/reprs/CStruct.h

  • Committer: Package Import Robot
  • Author(s): Alessandro Ghedini
  • Date: 2013-11-01 12:09:18 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20131101120918-kx51sl0sxl3exsxi
Tags: 2013.10-1
* New upstream release
* Bump versioned (Build-)Depends on parrot
* Update patches
* Install new README.pod
* Fix vcs-field-not-canonical
* Do not install rubyish examples
* Do not Depends on parrot-devel anymore
* Add 07_disable-serialization-tests.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef CSTRUCT_H_GUARD
2
 
#define CSTRUCT_H_GUARD
3
 
 
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
8
 
 * sync. */
9
 
typedef struct {
10
 
    /* GC-marked objects that our C structure points into. */
11
 
    PMC **child_objs;
12
 
 
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. */
16
 
    void *cstruct;
17
 
} CStructBody;
18
 
 
19
 
/* This is how an instance with the CStruct representation looks. */
20
 
typedef struct {
21
 
    SixModelObjectCommonalities common;
22
 
    CStructBody body;
23
 
} CStructInstance;
24
 
 
25
 
/* This is used in the name to class mapping. */
26
 
typedef struct {
27
 
    PMC *class_key;
28
 
    PMC *name_map;
29
 
} CStructNameMap;
30
 
 
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
41
 
 
42
 
/* The CStruct REPR data contains info we need to do allocations, look up
43
 
 * attributes and so forth. */
44
 
typedef struct {
45
 
    /* The size of the structure. */
46
 
    INTVAL struct_size;
47
 
 
48
 
    /* The number of attributes we have allocated slots for. Note that
49
 
     * slots can vary in size. */
50
 
    INTVAL num_attributes;
51
 
    
52
 
    /* Number of child objects we store. */
53
 
    INTVAL num_child_objs;
54
 
    
55
 
    /* Number of child strings we store. */
56
 
    INTVAL num_child_strs;
57
 
    
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;
64
 
 
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;
69
 
 
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;
74
 
 
75
 
    /* For reference type members, we cache the relevant type objects.
76
 
     * Flattened types have NULL here. */
77
 
    PMC **member_types;
78
 
 
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;
82
 
 
83
 
    /* Slots holding flattened objects that need another REPR to initialize
84
 
     * them; terminated with -1. */
85
 
    INTVAL *initialize_slots;
86
 
} CStructREPRData;
87
 
 
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));
92
 
 
93
 
#endif