7
7
#include "parrot/extend.h"
8
8
#include "sixmodelobject.h"
9
9
#include "serialization_context.h"
10
+ #include "pmc_serializationcontext.h"
10
11
11
12
/* Version of the serialization format that we are currently at. */
12
13
#define CURRENT_VERSION 1
@@ -98,17 +99,69 @@ static STRING * concatenate_outputs(PARROT_INTERP, SerializationWriter *writer)
98
99
Parrot_binary_encoding_ptr , PObj_external_FLAG );
99
100
}
100
101
102
+ /* This handles the serialization of an STable, and calls off to serialize
103
+ * its representation data also. */
104
+ static void serialize_stable (PARROT_INTERP , SerializationWriter * writer , PMC * st ) {
105
+ Parrot_ex_throw_from_c_args (interp , NULL , EXCEPTION_INVALID_OPERATION ,
106
+ "STable serialization not yet implemented" );
107
+ }
108
+
109
+ /* This handles the serialization of an object, which largely involves a
110
+ * delegation to its representation. */
111
+ static void serialize_object (PARROT_INTERP , SerializationWriter * writer , PMC * obj ) {
112
+ Parrot_ex_throw_from_c_args (interp , NULL , EXCEPTION_INVALID_OPERATION ,
113
+ "Object serialization not yet implemented" );
114
+ }
115
+
116
+ /* This is the overall serialization loop. It keeps an index into the list of
117
+ * STables and objects in the SC. As we discover new ones, they get added. We
118
+ * finished when we've serialized everything. */
119
+ static void serialize (PARROT_INTERP , SerializationWriter * writer ) {
120
+ INTVAL work_todo = 1 ;
121
+ while (work_todo ) {
122
+ /* Current work list sizes. */
123
+ INTVAL stables_todo = VTABLE_elements (interp , writer -> stables_list );
124
+ INTVAL objects_todo = VTABLE_elements (interp , writer -> objects_list );
125
+
126
+ /* Reset todo flag - if we do some work we'll go round again as it
127
+ * may have generated more. */
128
+ work_todo = 0 ;
129
+
130
+ /* Serialize any STables on the todo list. */
131
+ while (writer -> stables_list_pos < stables_todo ) {
132
+ serialize_stable (interp , writer , VTABLE_get_pmc_keyed_int (interp ,
133
+ writer -> stables_list , writer -> stables_list_pos ));
134
+ writer -> stables_list_pos ++ ;
135
+ work_todo = 1 ;
136
+ }
137
+
138
+ /* Serialize any objects on the todo list. */
139
+ while (writer -> objects_list_pos < objects_todo ) {
140
+ serialize_object (interp , writer , VTABLE_get_pmc_keyed_int (interp ,
141
+ writer -> objects_list , writer -> objects_list_pos ));
142
+ writer -> objects_list_pos ++ ;
143
+ work_todo = 1 ;
144
+ }
145
+ }
146
+ }
147
+
101
148
/* Takes a serialization context along with an empty string array. Taking the
102
149
* serialization context's contents as the roots, recursively walks them until
103
150
* everything is serialized or a reference to something already serialized in
104
151
* another context. */
105
152
STRING * Serialization_serialize (PARROT_INTERP , PMC * sc , PMC * empty_string_heap ) {
106
- STRING * result = STRINGNULL ;
153
+ PMC * stables = PMCNULL ;
154
+ PMC * objects = PMCNULL ;
155
+ STRING * result = STRINGNULL ;
107
156
Parrot_Int4 sc_elems = (Parrot_Int4 )VTABLE_elements (interp , sc );
108
157
109
158
/* Set up writer with some initial settings. */
110
159
SerializationWriter * writer = mem_allocate_zeroed_typed (SerializationWriter );
160
+ GETATTR_SerializationContext_root_stables (interp , sc , stables );
161
+ GETATTR_SerializationContext_root_objects (interp , sc , objects );
111
162
writer -> root .version = CURRENT_VERSION ;
163
+ writer -> stables_list = stables ;
164
+ writer -> objects_list = objects ;
112
165
writer -> root .string_heap = empty_string_heap ;
113
166
writer -> root .dependent_scs = Parrot_pmc_new (interp , enum_class_ResizablePMCArray );
114
167
@@ -124,9 +177,12 @@ STRING * Serialization_serialize(PARROT_INTERP, PMC *sc, PMC *empty_string_heap)
124
177
writer -> objects_data_alloc = OBJECT_SIZE_GUESS * (sc_elems || 1 );
125
178
writer -> root .objects_data = mem_sys_allocate (writer -> objects_data_alloc );
126
179
127
- /* Start serializing. */
128
-
180
+ /* Populate write functions table. */
129
181
182
+
183
+ /* Start serializing. */
184
+ serialize (interp , writer );
185
+
130
186
/* Build a single result string out of the serialized data. */
131
187
result = concatenate_outputs (interp , writer );
132
188
0 commit comments