|
22 | 22 | #define DEFAULT_STABLE_DATA_SIZE 4096
|
23 | 23 | #define OBJECT_SIZE_GUESS 8
|
24 | 24 |
|
| 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 | + |
25 | 37 | /* ***************************************************************************
|
26 | 38 | * Serialization (writing related)
|
27 | 39 | * ***************************************************************************/
|
@@ -167,6 +179,28 @@ void write_str_func(PARROT_INTERP, SerializationWriter *writer, STRING *value) {
|
167 | 179 | }
|
168 | 180 | }
|
169 | 181 |
|
| 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 | + |
170 | 204 | /* Concatenates the various output segments into a single binary string. */
|
171 | 205 | static STRING * concatenate_outputs(PARROT_INTERP, SerializationWriter *writer) {
|
172 | 206 | char *output = NULL;
|
@@ -345,6 +379,7 @@ STRING * Serialization_serialize(PARROT_INTERP, PMC *sc, PMC *empty_string_heap)
|
345 | 379 | writer->write_int = write_int_func;
|
346 | 380 | writer->write_num = write_num_func;
|
347 | 381 | writer->write_str = write_str_func;
|
| 382 | + writer->write_ref = write_ref_func; |
348 | 383 |
|
349 | 384 | /* Start serializing. */
|
350 | 385 | serialize(interp, writer);
|
@@ -489,6 +524,25 @@ STRING * read_str_func(PARROT_INTERP, SerializationReader *reader) {
|
489 | 524 | }
|
490 | 525 | }
|
491 | 526 |
|
| 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 | + |
492 | 546 | /* Checks the header looks sane and all of the places it points to make sense.
|
493 | 547 | * Also disects the input string into the tables and data segments and populates
|
494 | 548 | * the reader data structure more fully. */
|
@@ -647,6 +701,7 @@ void Serialization_deserialize(PARROT_INTERP, PMC *sc, PMC *string_heap, STRING
|
647 | 701 | reader->read_int = read_int_func;
|
648 | 702 | reader->read_num = read_num_func;
|
649 | 703 | reader->read_str = read_str_func;
|
| 704 | + reader->read_ref = read_ref_func; |
650 | 705 |
|
651 | 706 | /* Read header and disect the data into its parts. */
|
652 | 707 | check_and_disect_input(interp, reader, data);
|
|
0 commit comments