Skip to content

Commit 2f738dc

Browse files
committed
Sketch out main serialization work loop.
1 parent 01163e3 commit 2f738dc

File tree

2 files changed

+67
-3
lines changed

2 files changed

+67
-3
lines changed

src/6model/serialization.c

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "parrot/extend.h"
88
#include "sixmodelobject.h"
99
#include "serialization_context.h"
10+
#include "pmc_serializationcontext.h"
1011

1112
/* Version of the serialization format that we are currently at. */
1213
#define CURRENT_VERSION 1
@@ -98,17 +99,69 @@ static STRING * concatenate_outputs(PARROT_INTERP, SerializationWriter *writer)
9899
Parrot_binary_encoding_ptr, PObj_external_FLAG);
99100
}
100101

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+
101148
/* Takes a serialization context along with an empty string array. Taking the
102149
* serialization context's contents as the roots, recursively walks them until
103150
* everything is serialized or a reference to something already serialized in
104151
* another context. */
105152
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;
107156
Parrot_Int4 sc_elems = (Parrot_Int4)VTABLE_elements(interp, sc);
108157

109158
/* Set up writer with some initial settings. */
110159
SerializationWriter *writer = mem_allocate_zeroed_typed(SerializationWriter);
160+
GETATTR_SerializationContext_root_stables(interp, sc, stables);
161+
GETATTR_SerializationContext_root_objects(interp, sc, objects);
111162
writer->root.version = CURRENT_VERSION;
163+
writer->stables_list = stables;
164+
writer->objects_list = objects;
112165
writer->root.string_heap = empty_string_heap;
113166
writer->root.dependent_scs = Parrot_pmc_new(interp, enum_class_ResizablePMCArray);
114167

@@ -124,9 +177,12 @@ STRING * Serialization_serialize(PARROT_INTERP, PMC *sc, PMC *empty_string_heap)
124177
writer->objects_data_alloc = OBJECT_SIZE_GUESS * (sc_elems || 1);
125178
writer->root.objects_data = mem_sys_allocate(writer->objects_data_alloc);
126179

127-
/* Start serializing. */
128-
180+
/* Populate write functions table. */
129181

182+
183+
/* Start serializing. */
184+
serialize(interp, writer);
185+
130186
/* Build a single result string out of the serialized data. */
131187
result = concatenate_outputs(interp, writer);
132188

src/6model/serialization.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ typedef struct {
4242
typedef struct {
4343
/* Serialization root data. */
4444
SerializationRoot root;
45+
46+
/* The stables list and object list we're working through. */
47+
PMC *stables_list;
48+
PMC *objects_list;
49+
50+
/* Current position in the stables list and objects list. */
51+
INTVAL stables_list_pos;
52+
INTVAL objects_list_pos;
4553

4654
/* Hash of strings we've already seen while serializing to the index they
4755
* are placed at in the string heap. */

0 commit comments

Comments
 (0)