Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Thaw routines for types
  • Loading branch information
sorear committed Oct 16, 2011
1 parent be108f9 commit 2ff6525
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 4 deletions.
72 changes: 71 additions & 1 deletion lib/ObjModel.cs
Expand Up @@ -126,7 +126,7 @@ public abstract class IndexHandler : ReflectObj {

// NOT P6any; these things should only be exposed through a ClassHOW-like
// façade
public class P6how: IFreeze {
public class P6how: IFreeze, IFixup {
// true primitive data {{{
public STable stable;

Expand Down Expand Up @@ -658,6 +658,52 @@ public class DispatchSet {
fb.Refs<STable>(superclasses);
fb.Refs<STable>(mro);
}

internal static P6how Thaw(ThawBuffer tb) {
P6how n = new P6how();
tb.Register(n);
n.stable = (STable)tb.ObjRef();
int state = tb.Byte();
n.isComposing = state >= 1;
n.isComposed = state >= 2;
n.rtype = tb.String();
n.isRole = n.rtype == "role" || n.rtype == "prole";
n.isSubset = n.rtype == "subset";
n.isPackage = n.rtype == "package";
n.roleFactory = (P6any)tb.ObjRef();
n.subsetWhereThunk = (P6any)tb.ObjRef();
n.subsetFilter = (Variable)tb.ObjRef();

// local_does not yet used
int mcount = tb.Int();
while (mcount-- > 0) {
MethodInfo mi = default(MethodInfo);
mi.short_name = tb.String();
mi.long_name = tb.String();
mi.impl = (P6any)tb.ObjRef();
mi.flags = tb.Byte();
n.lmethods.Add(mi);
}

int acount = tb.Int();
while (acount-- > 0) {
AttrInfo ai = default(AttrInfo);
ai.name = tb.String();
ai.init = (P6any)tb.ObjRef();
ai.flags = tb.Byte();
ai.type = (STable)tb.ObjRef();
n.local_attr.Add(ai);
}

n.superclasses = tb.RefsL<STable>();
n.mro = tb.RefsA<STable>();
tb.PushFixup(n);
return n;
}

void IFixup.Fixup() {
SetMRO(mro);
}
}

// The role of STable is to hold stuff that needs to exist per
Expand Down Expand Up @@ -773,6 +819,7 @@ public class STable: IFreeze {
public bool is_any = false;
/// }}}

private STable() {}
public STable(string name) {
this.name = name;
mo = new P6how();
Expand Down Expand Up @@ -907,6 +954,29 @@ public class STable: IFreeze {
fb.String(box_type == null ? null : box_type.AssemblyQualifiedName);
fb.Strings(all_slot);
}

internal static STable Thaw(ThawBuffer tb) {
STable n = new STable();
tb.Register(n);
n.mo = (P6how)tb.ObjRef();
n.how = (P6any)tb.ObjRef();
n.who = (P6any)tb.ObjRef();
n.typeObject = (P6any)tb.ObjRef();
n.initObject = (P6any)tb.ObjRef();
n.typeVar = (Variable)tb.ObjRef();
n.initVar = (Variable)tb.ObjRef();
n.name = tb.String();
n.isSubset = tb.Byte() != 0;
string box_type = tb.String();
n.box_type = box_type == null ? null : Type.GetType(box_type,true);
n.all_slot = tb.Strings();

foreach (string s in n.all_slot)
n.slotMap[s] = n.nslots++;

tb.PushRevalidate(n);
return n;
}
}

// This is quite similar to DynFrame and I wonder if I can unify them.
Expand Down
29 changes: 26 additions & 3 deletions lib/Serialize.cs
Expand Up @@ -485,6 +485,7 @@ class ThawBuffer {
SerUnit unit;

List<IFixup> fixups_needed = new List<IFixup>();
List<object> revalidate = new List<object>();

internal ThawBuffer(ObjectRegistry reg, SerUnit unit, byte[] data) {
this.data = data;
Expand All @@ -493,6 +494,7 @@ class ThawBuffer {
}

internal void RunFixups() {
P6how.BulkRevalidate(revalidate);
foreach (IFixup f in fixups_needed)
f.Fixup();
fixups_needed.Clear();
Expand All @@ -502,6 +504,10 @@ class ThawBuffer {
fixups_needed.Add(f);
}

internal void PushRevalidate(STable f) {
revalidate.Add(f);
}

public byte Byte() { return data[rpointer++]; }

public short Short() {
Expand Down Expand Up @@ -553,6 +559,22 @@ class ThawBuffer {
return ret;
}

public int[] Ints() {
int ct = Int();
if (ct < 0) return null;
int[] ret = new int[ct];
for (int i = 0; i < ct; i++) ret[i] = Int();
return ret;
}

public string[] Strings() {
int ct = Int();
if (ct < 0) return null;
string[] ret = new string[ct];
for (int i = 0; i < ct; i++) ret[i] = String();
return ret;
}

public T[] RefsA<T>() where T : class {
int ct = Int();
if (ct < 0) return null;
Expand Down Expand Up @@ -582,7 +604,8 @@ class ThawBuffer {
case SerializationCode.RuntimeUnit:
return RuntimeUnit.Thaw(this);
//SubInfo,
//STable,
case SerializationCode.STable:
return STable.Thaw(this);
case SerializationCode.StashEnt:
return StashEnt.Thaw(this);
case SerializationCode.Rat:
Expand All @@ -601,8 +624,8 @@ class ThawBuffer {
return DispatchEnt.Thaw(this);
//case SerializationCode.RxFrame:
// return RxFrame.Thaw(this);
//case SerializationCode.P6how:
// return P6how.Thaw(this);
case SerializationCode.P6how:
return P6how.Thaw(this);

case SerializationCode.ReflectObj:
return ReflectObj.Thaw(this);
Expand Down

0 comments on commit 2ff6525

Please sign in to comment.