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

« back to all changes in this revision

Viewing changes to src/6model/serialization.h

  • Committer: Package Import Robot
  • Author(s): Alessandro Ghedini
  • Date: 2012-06-08 14:57:52 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120608145752-ziumy2rhxboeuf3r
Tags: 0.1~2012.04.1-1
* New upstream release
* Bump required parrot version
* Refresh patches
* Bump upstream copyright years for dyncall
* Use dh_parrot debhelper plugin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This represents the root of the serialization data; everything hangs
 
2
 * off this. In read mode, we don't do much besides populate and then
 
3
 * read this. In write mode, however, the tables and data chunks will be
 
4
 * filled out and grown as needed. */
 
5
typedef struct {
 
6
    /* The version of the serialization format. */
 
7
    Parrot_Int4   version;
 
8
 
 
9
    /* The number of dependencies, as well as a pointer to the
 
10
     * dependencies table. */
 
11
    Parrot_Int4   num_dependencies;
 
12
    char         *dependencies_table;
 
13
    
 
14
    /* The SC we're serializing/deserializing. */
 
15
    PMC          *sc;
 
16
 
 
17
    /* List of the serialization context objects that we depend on. */
 
18
    PMC          *dependent_scs;
 
19
    
 
20
    /* The number of STables, as well as pointers to the STables
 
21
     * table and data chunk. */
 
22
    Parrot_Int4   num_stables;
 
23
    char         *stables_table;
 
24
    char         *stables_data;
 
25
    
 
26
    /* The number of objects, as well as pointers to the objects
 
27
     * table and data chunk. */
 
28
    Parrot_Int4   num_objects;
 
29
    char         *objects_table;
 
30
    char         *objects_data;
 
31
    
 
32
    /* The number of closures, as we as a pointer to the closures
 
33
     * table. */
 
34
    Parrot_Int4  num_closures;
 
35
    char        *closures_table;
 
36
    
 
37
    /* The number of contexts (e.g. lexpads), as well as pointers
 
38
     * to the contexts table and data chunk. */
 
39
    Parrot_Int4   num_contexts;
 
40
    char         *contexts_table;
 
41
    char         *contexts_data;
 
42
    
 
43
    /* The number of repossessions and pointer to repossessions table. */
 
44
    Parrot_Int4   num_repos;
 
45
    char         *repos_table;
 
46
    
 
47
    /* Array of STRINGs. */
 
48
    PMC          *string_heap;
 
49
} SerializationRoot;
 
50
 
 
51
/* Represents the serialization reader and the various functions available
 
52
 * on it. */
 
53
typedef struct SixModel_STable STable;
 
54
typedef struct SerializationReader {
 
55
    /* Serialization root data. */
 
56
    SerializationRoot root;
 
57
    
 
58
    /* The stables, objects code refs and contexts lists we're deserializing
 
59
     * things into. */
 
60
    PMC *stables_list;
 
61
    PMC *objects_list;
 
62
    PMC *codes_list;
 
63
    PMC *contexts_list;
 
64
    
 
65
    /* Current offsets for the data chunks (also correspond to the amount of
 
66
     * data written in to them). */
 
67
    Parrot_Int4 stables_data_offset;
 
68
    Parrot_Int4 objects_data_offset;
 
69
    Parrot_Int4 contexts_data_offset;
 
70
    
 
71
    /* Limits up to where we can read stables, objects and contexts data. */
 
72
    char *stables_data_end;
 
73
    char *objects_data_end;
 
74
    char *contexts_data_end;
 
75
    
 
76
    /* Where to find details related to the current buffer we're reading from:
 
77
     * the buffer pointer itself, the current offset and the amount that is
 
78
     * allocated. These are all pointers back into this data structure. */
 
79
    char        **cur_read_buffer;
 
80
    Parrot_Int4  *cur_read_offset;
 
81
    char        **cur_read_end;
 
82
    
 
83
    /* Various reading functions. */
 
84
    INTVAL   (*read_int) (PARROT_INTERP, struct SerializationReader *reader);
 
85
    FLOATVAL (*read_num) (PARROT_INTERP, struct SerializationReader *reader);
 
86
    STRING * (*read_str) (PARROT_INTERP, struct SerializationReader *reader);
 
87
    PMC *    (*read_ref) (PARROT_INTERP, struct SerializationReader *reader);
 
88
    STable * (*read_stable_ref) (PARROT_INTERP, struct SerializationReader *reader);
 
89
    
 
90
    /* The object we're currently deserializing. */
 
91
    PMC *cur_object;
 
92
    
 
93
    /* The data, which we'll want to free after deserialization. */
 
94
    char *data;
 
95
} SerializationReader;
 
96
 
 
97
/* Represents the serialization writer and the various functions available
 
98
 * on it. */
 
99
typedef struct SerializationWriter {
 
100
    /* Serialization root data. */
 
101
    SerializationRoot root;
 
102
    
 
103
    /* The stables, objects, code refs and contexts lists we're working
 
104
     * through/adding to. */
 
105
    PMC *stables_list;
 
106
    PMC *objects_list;
 
107
    PMC *codes_list;
 
108
    PMC *contexts_list;
 
109
    
 
110
    /* Current position in the stables, objects and contexts lists. */
 
111
    INTVAL stables_list_pos;
 
112
    INTVAL objects_list_pos;
 
113
    INTVAL contexts_list_pos;
 
114
 
 
115
    /* Hash of strings we've already seen while serializing to the index they
 
116
     * are placed at in the string heap. */
 
117
    PMC *seen_strings;
 
118
    
 
119
    /* Amount of memory allocated for various things. */
 
120
    Parrot_Int4 dependencies_table_alloc;
 
121
    Parrot_Int4 stables_table_alloc;
 
122
    Parrot_Int4 stables_data_alloc;
 
123
    Parrot_Int4 objects_table_alloc;
 
124
    Parrot_Int4 objects_data_alloc;
 
125
    Parrot_Int4 closures_table_alloc;
 
126
    Parrot_Int4 contexts_table_alloc;
 
127
    Parrot_Int4 contexts_data_alloc;
 
128
    Parrot_Int4 repos_table_alloc;
 
129
    
 
130
    /* Current offsets for the data chunks (also correspond to the amount of
 
131
     * data written in to them). */
 
132
    Parrot_Int4 stables_data_offset;
 
133
    Parrot_Int4 objects_data_offset;
 
134
    Parrot_Int4 contexts_data_offset;
 
135
    
 
136
    /* Where to find details related to the current buffer we're writing in
 
137
     * to: the buffer pointer itself, the current offset and the amount that
 
138
     * is allocated. These are all pointers back into this data structure. */
 
139
    char        **cur_write_buffer;
 
140
    Parrot_Int4  *cur_write_offset;
 
141
    Parrot_Int4  *cur_write_limit;
 
142
    
 
143
    /* Various writing functions. */
 
144
    void (*write_int) (PARROT_INTERP, struct SerializationWriter *writer, INTVAL value);
 
145
    void (*write_num) (PARROT_INTERP, struct SerializationWriter *writer, FLOATVAL value);
 
146
    void (*write_str) (PARROT_INTERP, struct SerializationWriter *writer, STRING *value);
 
147
    void (*write_ref) (PARROT_INTERP, struct SerializationWriter *writer, PMC *value);
 
148
    void (*write_stable_ref) (PARROT_INTERP, struct SerializationWriter *writer, STable *st);
 
149
} SerializationWriter;
 
150
 
 
151
/* Core serialize and deserialize functions. */
 
152
STRING * Serialization_serialize(PARROT_INTERP, PMC *sc, PMC *empty_string_heap);
 
153
void Serialization_deserialize(PARROT_INTERP, PMC *sc, PMC *string_heap, PMC *codes_static, STRING *data);