Created
September 18, 2013 20:49
-
-
Save FROGGS/e907c786f7b18ff0c345 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/6model/reprs/P6opaque.c b/src/6model/reprs/P6opaque.c | |
index e4c89bb..b5e6342 100644 | |
--- a/src/6model/reprs/P6opaque.c | |
+++ b/src/6model/reprs/P6opaque.c | |
@@ -816,6 +816,126 @@ static void deserialize_stable_size(MVMThreadContext *tc, MVMSTable *st, MVMSeri | |
} | |
/* Deserializes representation data. */ | |
+static void serialize_repr_data(MVMThreadContext *tc, MVMSTable *st, MVMSerializationWriter *writer) { | |
+ MVMP6opaqueREPRData *repr_data = (MVMP6opaqueREPRData *)st->REPR_data; | |
+ MVMuint16 i, j, num_classes, cur_offset; | |
+ MVMint16 cur_initialize_slot, cur_gc_mark_slot, cur_gc_cleanup_slot; | |
+ MVMObject *info; | |
+ | |
+ if (!repr_data) | |
+ MVM_exception_throw_adhoc(tc, | |
+ "Representation must be composed before it can be serialized"); | |
+ | |
+ writer->write_int(tc, writer, repr_data->num_attributes); | |
+ | |
+ for (i = 0; i < repr_data->num_attributes; i++) { | |
+ writer->write_int(tc, writer, repr_data->flattened_stables[i] != NULL); | |
+ if (repr_data->flattened_stables[i]) | |
+ writer->write_stable_ref(tc, writer, repr_data->flattened_stables[i]); | |
+ } | |
+ | |
+ writer->write_int(tc, writer, repr_data->mi); | |
+ | |
+ if (repr_data->auto_viv_values) { | |
+ writer->write_int(tc, writer, 1); | |
+ for (i = 0; i < repr_data->num_attributes; i++) | |
+ writer->write_ref(tc, writer, repr_data->auto_viv_values[i]); | |
+ } | |
+ else { | |
+ writer->write_int(tc, writer, 0); | |
+ } | |
+ | |
+ writer->write_int(tc, writer, repr_data->unbox_int_slot); | |
+ writer->write_int(tc, writer, repr_data->unbox_num_slot); | |
+ writer->write_int(tc, writer, repr_data->unbox_str_slot); | |
+ | |
+ if (repr_data->unbox_slots) { | |
+ writer->write_int(tc, writer, 1); | |
+ for (i = 0; i < repr_data->num_attributes; i++) { | |
+ writer->write_int(tc, writer, repr_data->unbox_slots[i].repr_id); | |
+ writer->write_int(tc, writer, repr_data->unbox_slots[i].slot); | |
+ } | |
+ } | |
+ else { | |
+ writer->write_int(tc, writer, 0); | |
+ } | |
+ | |
+ //~ info = REPR(st->WHAT)->ass_funcs->at_key_boxed(tc, STABLE(st->WHAT), st->WHAT, | |
+ //~ OBJECT_BODY(st->WHAT), (MVMObject *)str_attribute); | |
+ //~ if (info == NULL) | |
+ //~ MVM_exception_throw_adhoc(tc, "P6opaque: missing attribute protocol in serialize_repr_data"); | |
+ | |
+ //~ num_classes = REPR(info)->elems(tc, STABLE(info), info, OBJECT_BODY(info)); | |
+ | |
+ writer->write_int(tc, writer, num_classes); | |
+ for (i = 0; i < num_classes; i++) { | |
+ MVMint32 num_attrs = repr_data->name_to_index_mapping[i].num_attrs; | |
+ writer->write_ref(tc, writer, repr_data->name_to_index_mapping[i].class_key); | |
+ | |
+ | |
+ | |
+ //~ MVMint16 discrim = 0; | |
+ //~ if (ref == NULL) { | |
+ //~ discrim = REFVAR_NULL; | |
+ //~ } | |
+ //~ else if (STABLE(ref) == STABLE(tc->instance->boot_types->BOOTInt)) { | |
+ //~ discrim = REFVAR_VM_INT; | |
+ //~ } | |
+ //~ else if (STABLE(ref) == STABLE(tc->instance->boot_types->BOOTNum)) { | |
+ //~ discrim = REFVAR_VM_NUM; | |
+ //~ } | |
+ //~ else if (STABLE(ref) == STABLE(tc->instance->boot_types->BOOTStr)) { | |
+ //~ discrim = REFVAR_VM_STR; | |
+ //~ } | |
+ //~ else if (STABLE(ref) == STABLE(tc->instance->boot_types->BOOTArray)) { | |
+ //~ discrim = REFVAR_VM_ARR_VAR; | |
+ //~ } | |
+ //~ else if (STABLE(ref) == STABLE(tc->instance->boot_types->BOOTIntArray)) { | |
+ //~ discrim = REFVAR_VM_ARR_INT; | |
+ //~ } | |
+ //~ else if (STABLE(ref) == STABLE(tc->instance->boot_types->BOOTStrArray)) { | |
+ //~ discrim = REFVAR_VM_ARR_STR; | |
+ //~ } | |
+ //~ else if (STABLE(ref) == STABLE(tc->instance->boot_types->BOOTHash)) { | |
+ //~ discrim = REFVAR_VM_HASH_STR_VAR; | |
+ //~ } | |
+ //~ else if (REPR(ref)->ID == MVM_REPR_ID_MVMCode) { | |
+ //~ if (ref->header.sc && ((MVMCode *)ref)->body.is_static) { | |
+ //~ /* Static code reference. */ | |
+ //~ discrim = REFVAR_STATIC_CODEREF; | |
+ //~ } | |
+ //~ else if (ref->header.sc) { | |
+ //~ /* Closure, but already seen and serialization already handled. */ | |
+ //~ discrim = REFVAR_CLONED_CODEREF; | |
+ //~ } | |
+ //~ else { | |
+ //~ /* Closure but didn't see it yet. Take care of its serialization, which | |
+ //~ * gets it marked with this SC. Then it's just a normal code ref that | |
+ //~ * needs serializing. */ | |
+ //~ serialize_closure(tc, writer, ref); | |
+ //~ discrim = REFVAR_CLONED_CODEREF; | |
+ //~ } | |
+ //~ } | |
+ //~ else { | |
+ //~ discrim = REFVAR_OBJECT; | |
+ //~ } | |
+ | |
+ | |
+ writer->write_int16(tc, writer, 1); | |
+ //~ if (reader->read_int16(tc, reader) == REFVAR_VM_HASH_STR_VAR) { | |
+ //~ writer->write_int32(tc, writer, num_attrs); | |
+ //~ for (j = 0; j < num_attrs; j++) { | |
+ //~ writer->write_str(tc, writer, repr_data->name_to_index_mapping[i].names[j]); | |
+ //~ writer->write_ref(tc, writer, repr_data->name_to_index_mapping[i].slots[j]); | |
+ //~ } | |
+ //~ } | |
+ } | |
+ | |
+ writer->write_int(tc, writer, repr_data->pos_del_slot); | |
+ writer->write_int(tc, writer, repr_data->ass_del_slot); | |
+} | |
+ | |
+/* Deserializes representation data. */ | |
static void deserialize_repr_data(MVMThreadContext *tc, MVMSTable *st, MVMSerializationReader *reader) { | |
MVMuint16 i, j, num_classes, cur_offset; | |
MVMint16 cur_initialize_slot, cur_gc_mark_slot, cur_gc_cleanup_slot; | |
@@ -1250,6 +1370,7 @@ MVMREPROps * MVMP6opaque_initialize(MVMThreadContext *tc) { | |
this_repr->deserialize_stable_size = deserialize_stable_size; | |
this_repr->deserialize_repr_data = deserialize_repr_data; | |
this_repr->deserialize = deserialize; | |
+ this_repr->serialize_repr_data = serialize_repr_data; | |
this_repr->serialize = serialize; | |
return this_repr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment