Skip to content

Commit 29fdcd0

Browse files
committed
Start to stub in reference serialization.
1 parent cec284e commit 29fdcd0

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/6model/serialization.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@
2222
#define DEFAULT_STABLE_DATA_SIZE 4096
2323
#define OBJECT_SIZE_GUESS 8
2424

25+
/* Possible reference types we can serialize. */
26+
#define REFVAR_NULL 1
27+
#define REFVAR_OBJECT 2
28+
#define REFVAR_VM_INT 3
29+
#define REFVAR_VM_NUM 4
30+
#define REFVAR_VM_STR 5
31+
#define REFVAR_VM_ARR_VAR 6
32+
#define REFVAR_VM_ARR_STR 7
33+
#define REFVAR_VM_ARR_INT 8
34+
#define REFVAR_VM_HASH_STR_VAR 9
35+
#define REFVAR_STATIC_CODEREF 10
36+
2537
/* ***************************************************************************
2638
* Serialization (writing related)
2739
* ***************************************************************************/
@@ -167,6 +179,28 @@ void write_str_func(PARROT_INTERP, SerializationWriter *writer, STRING *value) {
167179
}
168180
}
169181

182+
/* Writing function for references to things. */
183+
void write_ref_func(PARROT_INTERP, SerializationWriter *writer, PMC *ref) {
184+
/* Work out what kind of thing we have and determine the discriminator. */
185+
Parrot_Int2 discrim = 0;
186+
/* XXX */
187+
188+
/* Write the discriminator. */
189+
expand_storage_if_needed(interp, writer, 2);
190+
if (writer->writing_object) {
191+
write_int16(writer->root.objects_data, writer->objects_data_offset, discrim);
192+
writer->objects_data_offset += 2;
193+
}
194+
else {
195+
write_int16(writer->root.stables_data, writer->stables_data_offset, discrim);
196+
writer->stables_data_offset += 2;
197+
}
198+
199+
/* Now take appropriate action. */
200+
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
201+
"write_ref not yet implemented");
202+
}
203+
170204
/* Concatenates the various output segments into a single binary string. */
171205
static STRING * concatenate_outputs(PARROT_INTERP, SerializationWriter *writer) {
172206
char *output = NULL;
@@ -345,6 +379,7 @@ STRING * Serialization_serialize(PARROT_INTERP, PMC *sc, PMC *empty_string_heap)
345379
writer->write_int = write_int_func;
346380
writer->write_num = write_num_func;
347381
writer->write_str = write_str_func;
382+
writer->write_ref = write_ref_func;
348383

349384
/* Start serializing. */
350385
serialize(interp, writer);
@@ -489,6 +524,25 @@ STRING * read_str_func(PARROT_INTERP, SerializationReader *reader) {
489524
}
490525
}
491526

527+
/* Reading function for native strings. */
528+
PMC * read_ref_func(PARROT_INTERP, SerializationReader *reader) {
529+
/* Read the discriminator. */
530+
Parrot_Int2 discrim;
531+
assert_can_read(interp, reader, 2);
532+
if (reader->reading_object) {
533+
discrim = read_int16(reader->root.objects_data, reader->objects_data_offset);
534+
reader->objects_data_offset += 2;
535+
}
536+
else {
537+
discrim = read_int16(reader->root.stables_data, reader->stables_data_offset);
538+
reader->stables_data_offset += 2;
539+
}
540+
541+
/* Decide what to do based on it. */
542+
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
543+
"read_ref not yet implemented");
544+
}
545+
492546
/* Checks the header looks sane and all of the places it points to make sense.
493547
* Also disects the input string into the tables and data segments and populates
494548
* the reader data structure more fully. */
@@ -647,6 +701,7 @@ void Serialization_deserialize(PARROT_INTERP, PMC *sc, PMC *string_heap, STRING
647701
reader->read_int = read_int_func;
648702
reader->read_num = read_num_func;
649703
reader->read_str = read_str_func;
704+
reader->read_ref = read_ref_func;
650705

651706
/* Read header and disect the data into its parts. */
652707
check_and_disect_input(interp, reader, data);

src/6model/serialization.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ typedef struct SerializationReader {
5959
INTVAL (*read_int) (PARROT_INTERP, struct SerializationReader *reader);
6060
FLOATVAL (*read_num) (PARROT_INTERP, struct SerializationReader *reader);
6161
STRING * (*read_str) (PARROT_INTERP, struct SerializationReader *reader);
62+
PMC * (*read_ref) (PARROT_INTERP, struct SerializationReader *reader);
6263
} SerializationReader;
6364

6465
/* Represents the serialization writer and the various functions available
@@ -98,6 +99,7 @@ typedef struct SerializationWriter {
9899
void (*write_int) (PARROT_INTERP, struct SerializationWriter *writer, INTVAL value);
99100
void (*write_num) (PARROT_INTERP, struct SerializationWriter *writer, FLOATVAL value);
100101
void (*write_str) (PARROT_INTERP, struct SerializationWriter *writer, STRING *value);
102+
void (*write_ref) (PARROT_INTERP, struct SerializationWriter *writer, PMC *value);
101103
} SerializationWriter;
102104

103105
/* Core serialize and deserialize functions. */

0 commit comments

Comments
 (0)