Skip to content

Commit

Permalink
Serialization of P6opaque instances.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Mar 9, 2013
1 parent 784d31f commit 908bcb4
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/org/perl6/nqp/sixmodel/reprs/P6Opaque.java
Expand Up @@ -67,8 +67,8 @@ public void compose(ThreadContext tc, STable st, SixModelObject repr_info_hash)
indexes.put(attrName, curAttr++);
AttrInfo info = new AttrInfo();
info.st = attrType.st;
if (st.REPR.get_storage_spec(tc, st).inlineable == StorageSpec.INLINED)
flattenedSTables.add(st);
if (attrType.st.REPR.get_storage_spec(tc, attrType.st).inlineable == StorageSpec.INLINED)
flattenedSTables.add(attrType.st);
else
flattenedSTables.add(null);
info.boxTarget = attrHash.exists_key(tc, "box_target") != 0;
Expand Down Expand Up @@ -601,9 +601,30 @@ public void deserialize_finish(ThreadContext tc, STable st,
}
}
}
catch (Exception e)
catch (IllegalAccessException | NoSuchFieldException | InstantiationException e)
{
throw new RuntimeException(e);
}
}

public void serialize(ThreadContext tc, SerializationWriter writer, SixModelObject obj) {
try {
STable[] flattenedSTables = ((P6OpaqueREPRData)obj.st.REPRData).flattenedSTables;
if (flattenedSTables == null)
throw ExceptionHandling.dieInternal(tc,
"Representation must be composed before it can be serialized");
for (int i = 0; i < flattenedSTables.length; i++) {
if (flattenedSTables[i] == null) {
writer.writeRef((SixModelObject)obj.getClass().getField("field_" + i).get(obj));
}
else {
flattenedSTables[i].REPR.serialize_inlined(tc, flattenedSTables[i],
writer, "field_" + i, obj);
}
}
}
catch (IllegalAccessException | NoSuchFieldException e) {
throw new RuntimeException(e);
}
}
}

0 comments on commit 908bcb4

Please sign in to comment.