Permalink
Browse files

P6opaque adding list/hash delegation to P6opaque.

  • Loading branch information...
jnthn committed Feb 9, 2013
1 parent e387b52 commit 723aae488de4907d4667f004180cd98bcd7d1de7
Showing with 47 additions and 1 deletion.
  1. +40 −0 src/6model/reprs/P6opaque.c
  2. +6 −0 src/6model/reprs/P6opaque.h
  3. +1 −1 src/6model/serialization.c
@@ -129,6 +129,8 @@ static void compute_allocation_strategy(PARROT_INTERP, PMC *repr_info, P6opaqueR
STRING *type_str = Parrot_str_new_constant(interp, "type");
STRING *box_target_str = Parrot_str_new_constant(interp, "box_target");
STRING *avcont_str = Parrot_str_new_constant(interp, "auto_viv_container");
+ STRING *pos_del_str = Parrot_str_new_constant(interp, "positional_delegate");
+ STRING *ass_del_str = Parrot_str_new_constant(interp, "associative_delegate");
PMC *flat_list;
/*
@@ -172,6 +174,8 @@ static void compute_allocation_strategy(PARROT_INTERP, PMC *repr_info, P6opaqueR
repr_data->unbox_int_slot = -1;
repr_data->unbox_num_slot = -1;
repr_data->unbox_str_slot = -1;
+ repr_data->pos_del_slot = -1;
+ repr_data->ass_del_slot = -1;
/* Go over the attributes and arrange their allocation. */
for (i = 0; i < num_attrs; i++) {
@@ -277,6 +281,28 @@ static void compute_allocation_strategy(PARROT_INTERP, PMC *repr_info, P6opaqueR
}
}
+ /* Is it a positional or associative delegate? */
+ if (VTABLE_exists_keyed_str(interp, attr_hash, pos_del_str)) {
+ if (repr_data->pos_del_slot != -1)
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
+ "Duplicate positional delegate attribute");
+ if (unboxed_type == STORAGE_SPEC_BP_NONE)
+ repr_data->pos_del_slot = i;
+ else
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
+ "Positional delegate attribute must be a reference type");
+ }
+ if (VTABLE_exists_keyed_str(interp, attr_hash, ass_del_str)) {
+ if (repr_data->ass_del_slot != -1)
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
+ "Duplicate associative delegate attribute");
+ if (unboxed_type == STORAGE_SPEC_BP_NONE)
+ repr_data->ass_del_slot = i;
+ else
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
+ "Associative delegate attribute must be a reference type");
+ }
+
/* Increment object size by the allocated bytes. */
cur_size += bits / 8;
}
@@ -971,6 +997,11 @@ static void serialize_repr_data(PARROT_INTERP, STable *st, SerializationWriter *
writer->write_ref(interp, writer, repr_data->name_to_index_mapping[i].class_key);
writer->write_ref(interp, writer, repr_data->name_to_index_mapping[i].name_map);
}
+
+ if (writer->root.version >= 3) {
+ writer->write_int(interp, writer, repr_data->pos_del_slot);
+ writer->write_int(interp, writer, repr_data->ass_del_slot);
+ }
}
/* Deserializes the data. */
@@ -1014,6 +1045,15 @@ static void deserialize_repr_data(PARROT_INTERP, STable *st, SerializationReader
repr_data->name_to_index_mapping[i].name_map = reader->read_ref(interp, reader);
}
+ if (reader->root.version >= 3) {
+ repr_data->pos_del_slot = reader->read_int(interp, reader);
+ repr_data->ass_del_slot = reader->read_int(interp, reader);
+ }
+ else {
+ repr_data->pos_del_slot = -1;
+ repr_data->ass_del_slot = -1;
+ }
+
/* Re-calculate the remaining info, which is platform specific or
* derived information. */
repr_data->attribute_offsets = (INTVAL *)mem_sys_allocate(MAX(repr_data->num_attributes, 1) * sizeof(INTVAL));
@@ -63,6 +63,12 @@ typedef struct {
/* If we have any other boxings, this maps repr ID to slot. */
P6opaqueBoxedTypeMap *unbox_slots;
+
+ /* Slot containing object to delegate for positional things. */
+ INTVAL pos_del_slot;
+
+ /* Slot containing object to delegate for associative things. */
+ INTVAL ass_del_slot;
/* A table mapping attribute names to indexes (which can then be looked
* up in the offset table). Uses a final null entry as a sentinel. */
@@ -19,7 +19,7 @@
/* Version of the serialization format that we are currently at and lowest
* version we support. */
-#define CURRENT_VERSION 2
+#define CURRENT_VERSION 3
#define MIN_VERSION 1
/* Various sizes (in bytes). */

0 comments on commit 723aae4

Please sign in to comment.