Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement serialization of KnowHOWREPR.
  • Loading branch information
jnthn committed Mar 9, 2013
1 parent b3747d7 commit 975f9b0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/org/perl6/nqp/sixmodel/SerializationWriter.java
Expand Up @@ -4,6 +4,8 @@
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.perl6.nqp.runtime.*;
import org.perl6.nqp.sixmodel.reprs.*;
Expand Down Expand Up @@ -197,6 +199,24 @@ public void writeObjRef(SixModelObject ref) {
outputs[currentBuffer].putInt(ref.sc.root_objects.indexOf(ref));
}

public void writeList(List<SixModelObject> list) {
growToHold(currentBuffer, 6);
outputs[currentBuffer].putShort(REFVAR_VM_ARR_VAR);
outputs[currentBuffer].putInt(list.size());
for (SixModelObject item : list)
writeRef(item);
}

public void writeHash(Map<String, SixModelObject> hash) {
growToHold(currentBuffer, 6);
outputs[currentBuffer].putShort(REFVAR_VM_HASH_STR_VAR);
outputs[currentBuffer].putInt(hash.size());
for (String key : hash.keySet()) {
writeStr(key);
writeRef(hash.get(key));
}
}

/* Writing function for references to things. */
public void writeRef(SixModelObject ref) {
/* Work out what kind of thing we have and determine the discriminator. */
Expand Down Expand Up @@ -459,12 +479,7 @@ private void serializeStable(STable st) {
/* Method cache and v-table. */
growToHold(currentBuffer, 2);
if (st.MethodCache != null) {
outputs[currentBuffer].putShort(REFVAR_VM_HASH_STR_VAR);
writeInt32(st.MethodCache.size());
for (String meth : st.MethodCache.keySet()) {
writeStr(meth);
writeRef(st.MethodCache.get(meth));
}
writeHash(st.MethodCache);
}
else {
outputs[currentBuffer].putShort(REFVAR_VM_NULL);
Expand Down
8 changes: 8 additions & 0 deletions src/org/perl6/nqp/sixmodel/reprs/KnowHOWREPR.java
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;

import org.perl6.nqp.runtime.ExceptionHandling;
import org.perl6.nqp.runtime.ThreadContext;
import org.perl6.nqp.sixmodel.*;

Expand Down Expand Up @@ -39,4 +40,11 @@ public void deserialize_finish(ThreadContext tc, STable st,

body.methods = ((VMHashInstance)reader.readRef()).storage;
}

public void serialize(ThreadContext tc, SerializationWriter writer, SixModelObject obj) {
KnowHOWREPRInstance kh = (KnowHOWREPRInstance)obj;
writer.writeStr(kh.name);
writer.writeList(kh.attributes);
writer.writeHash(kh.methods);
}
}

0 comments on commit 975f9b0

Please sign in to comment.