Permalink
Browse files

Implement freezing for types

  • Loading branch information...
1 parent ab35238 commit 3dc478933d31d45d62561283b9f3fbc2b281ae75 @sorear committed Oct 15, 2011
Showing with 80 additions and 15 deletions.
  1. +62 −15 lib/ObjModel.cs
  2. +18 −0 lib/Serialize.cs
View
@@ -126,38 +126,43 @@ public abstract class IndexHandler {
// NOT P6any; these things should only be exposed through a ClassHOW-like
// façade
- public class P6how {
+ public class P6how: IFreeze {
+ // true primitive data {{{
public STable stable;
public bool isRole, isSubset, isPackage, isComposed, isComposing;
public string rtype = "class"; // XXX used for compiler's inspection
public P6any roleFactory;
public P6any subsetWhereThunk;
public Variable subsetFilter;
- public Dictionary<string, P6any> instCache;
- // role type objects have an empty MRO cache so no methods can be
- // called against them; the fallback (NYI) is to pun.
- public Dictionary<STable, STable> butCache;
+ public STable[] local_does;
+ public List<MethodInfo> lmethods = new List<MethodInfo>();
+ public List<AttrInfo> local_attr = new List<AttrInfo>();
+
+ public List<STable> superclasses = new List<STable>();
+ // }}}
+ // calculated at compose time {{{
+ public STable[] mro = new STable[0];
+ // }}}
+ // strictly caches (mostly set when MRO changed) {{{
public Dictionary<string, DispatchEnt> inherit_methods;
public Dictionary<string, P6how.DispatchSet> up_protos;
public List<DispatchSet> here_protos;
public Dictionary<DispatchSet, List<MethodInfo>> multimethods;
- public STable[] local_does;
-
- public List<MethodInfo> lmethods = new List<MethodInfo>();
- public List<AttrInfo> local_attr = new List<AttrInfo>();
-
- public List<STable> superclasses = new List<STable>();
+ public HashSet<STable> isa = new HashSet<STable>();
internal SubscriberSet subclasses = new SubscriberSet();
Subscription[] mro_sub;
+ public Dictionary<string, P6any> instCache;
+ public Dictionary<STable, STable> butCache;
+ // role type objects have an empty MRO cache so no methods can be
+ // called against them; the fallback (NYI) is to pun.
+ // }}}
- public STable[] mro = new STable[0];
- public HashSet<STable> isa = new HashSet<STable>();
-
+ // types and constants {{{
public struct AttrInfo {
public string name;
public P6any init;
@@ -203,6 +208,7 @@ public class DispatchSet {
public string name;
public P6any proto;
}
+ // }}}
void CollectMMDs() {
// Superclass data already collected
@@ -620,6 +626,37 @@ public class DispatchSet {
}
return null;
}
+
+ void IFreeze.Freeze(FreezeBuffer fb) {
+ fb.ObjRef(stable);
+ fb.Byte((byte)(isComposed ? 2 : isComposing ? 1 : 0));
+ fb.String(rtype);
+ fb.ObjRef(roleFactory);
+ fb.ObjRef(subsetWhereThunk);
+ fb.ObjRef(subsetFilter);
+
+ // local_does not yet used
+ fb.Int(lmethods.Count);
+ // we do NOT save source position info here, it's only used
+ // intra-unit
+ foreach (MethodInfo mi in lmethods) {
+ fb.String(mi.short_name);
+ fb.String(mi.long_name);
+ fb.ObjRef(mi.impl);
+ fb.Byte(checked((byte) mi.flags));
+ }
+
+ fb.Int(local_attr.Count);
+ foreach (AttrInfo ai in local_attr) {
+ fb.String(ai.name);
+ fb.ObjRef(ai.init);
+ fb.Byte(checked((byte) ai.flags));
+ fb.ObjRef(ai.type);
+ }
+
+ fb.Refs<STable>(superclasses);
+ fb.Refs<STable>(mro);
+ }
}
// The role of STable is to hold stuff that needs to exist per
@@ -866,7 +903,17 @@ public class STable: IFreeze {
}
void IFreeze.Freeze(FreezeBuffer fb) {
- throw new NotImplementedException();
+ fb.ObjRef(mo);
+ fb.ObjRef(how);
+ fb.ObjRef(who);
+ fb.ObjRef(typeObject);
+ fb.ObjRef(initObject);
+ fb.ObjRef(typeVar);
+ fb.ObjRef(initVar);
+ fb.String(name);
+ fb.Byte((byte)(isSubset ? 1 : 0));
+ fb.String(box_type == null ? null : box_type.AssemblyQualifiedName);
+ fb.Strings(all_slot);
}
}
View
@@ -299,6 +299,14 @@ public class FreezeBuffer {
}
}
+ public void Strings(string[] s) {
+ if (s == null) Int(-1);
+ else {
+ Int(s.Length);
+ foreach (string ch in s) String(ch);
+ }
+ }
+
public void Ints(int[] s) {
if (s == null) {
Int(-1);
@@ -319,6 +327,16 @@ public class FreezeBuffer {
}
}
+ public void Refs<T> (IList<T> x) where T: IFreeze {
+ if (x == null) {
+ Int(-1);
+ } else {
+ Int(x.Count);
+ foreach (T y in x)
+ ObjRef(y);
+ }
+ }
+
// This is the main routine you should call from your Freeze
// callbacks to freeze an object
public void ObjRef(object o) {

0 comments on commit 3dc4789

Please sign in to comment.