Skip to content
Browse files

Thaw routines for P6opaque, DispatchEnt, double, int, Type, string, b…

…ool, arrays
  • Loading branch information...
1 parent 8035d26 commit be108f90f42cace101ac84a58b8fc7207bbb42e8 @sorear committed Oct 15, 2011
Showing with 72 additions and 16 deletions.
  1. +9 −0 lib/Kernel.cs
  2. +30 −5 lib/ObjModel.cs
  3. +33 −11 lib/Serialize.cs
View
9 lib/Kernel.cs
@@ -41,6 +41,15 @@ public sealed class DispatchEnt : IFreeze {
fb.ObjRef(outer);
fb.ObjRef(ip6);
}
+ internal static DispatchEnt Thaw(ThawBuffer tb) {
+ DispatchEnt de = new DispatchEnt();
+ tb.Register(de);
+ de.next = (DispatchEnt) tb.ObjRef();
+ de.info = (SubInfo) tb.ObjRef();
+ de.outer = (Frame) tb.ObjRef();
+ de.ip6 = (P6any) tb.ObjRef();
+ return de;
+ }
}
// A Variable is the meaning of function arguments, of any subexpression
View
35 lib/ObjModel.cs
@@ -916,6 +916,7 @@ public class P6opaque: P6any {
// containers are objects now
public object[] slots;
+ internal P6opaque() { }
public P6opaque(STable klass) {
this.mo = klass;
this.slots = (klass.nslots != 0) ? new object[klass.nslots] : null;
@@ -946,25 +947,49 @@ public class P6opaque: P6any {
}
public override void Freeze(FreezeBuffer fb) {
- FreezeSelf(fb);
- fb.ObjRef(null);
+ FreezeSelf(fb, null);
}
- protected void FreezeSelf(FreezeBuffer fb) {
+ protected void FreezeSelf(FreezeBuffer fb, Type t) {
fb.Byte((byte) SerializationCode.P6opaque);
+ int i;
+ for (i = 0; i < FreezeBuffer.boxTypes.Length &&
+ FreezeBuffer.boxTypes[i] != t; i++) { }
+ if (i == FreezeBuffer.boxTypes.Length)
+ throw new NotImplementedException(t.FullName);
+ fb.Byte((byte)i);
fb.ObjRef(mo);
int l = slots == null ? 0 : slots.Length;
fb.Int(l);
- for (int i = 0; i < l; i++)
+ for (i = 0; i < l; i++)
fb.ObjRef(slots[i]);
}
+ protected virtual void SetData(object o) { }
+ internal static P6opaque Create() { return new P6opaque(); }
+ internal static P6opaque Thaw(ThawBuffer tb) {
+ int k = tb.Byte();
+ P6opaque o = FreezeBuffer.boxCreate[k]();
+ tb.Register(o);
+ o.mo = (STable) tb.ObjRef();
+ int l = tb.Int();
+ if (l > 0) {
+ o.slots = new object[l];
+ for (int i = 0; i < l; i++)
+ o.slots[i] = tb.ObjRef();
+ }
+ if (k != 0)
+ o.SetData(tb.ObjRef());
+ return o;
+ }
}
public class BoxObject<T> : P6opaque {
public T value;
+ private BoxObject() { }
public BoxObject(T x, STable klass) : base(klass) { value = x; }
public BoxObject(T x, STable klass, int na) : base(klass,na) { value = x; }
+ internal static new P6opaque Create() { return new BoxObject<T>(); }
public override void Freeze(FreezeBuffer fb) {
- FreezeSelf(fb);
+ FreezeSelf(fb, typeof(T));
fb.ObjRef(value);
}
}
View
44 lib/Serialize.cs
@@ -413,6 +413,19 @@ public class FreezeBuffer {
}
}
+ internal static Type[] boxTypes = new Type[] {
+ null, typeof(Rat), typeof(FatRat), typeof(Complex),
+ typeof(double), typeof(int), typeof(string),
+ typeof(Variable[]), typeof(VarDeque), typeof(STable),
+ };
+ internal static Func<P6opaque>[] boxCreate = new Func<P6opaque>[] {
+ P6opaque.Create, BoxObject<Rat>.Create, BoxObject<FatRat>.Create,
+ BoxObject<Complex>.Create, BoxObject<double>.Create,
+ BoxObject<int>.Create, BoxObject<string>.Create,
+ BoxObject<Variable[]>.Create, BoxObject<VarDeque>.Create,
+ BoxObject<STable>.Create,
+ };
+
static Type[] anyTypes = new Type[] {
typeof(string), typeof(P6any[]), typeof(Variable[]),
typeof(bool), typeof(int), typeof(double), typeof(Type),
@@ -584,26 +597,34 @@ class ThawBuffer {
return VarDeque.Thaw(this);
case SerializationCode.VarHash:
return VarHash.Thaw(this);
- //case SerializationCode.DispatchEnt:
- // return DispatchEnt.Thaw(this);
+ case SerializationCode.DispatchEnt:
+ return DispatchEnt.Thaw(this);
//case SerializationCode.RxFrame:
// return RxFrame.Thaw(this);
//case SerializationCode.P6how:
// return P6how.Thaw(this);
case SerializationCode.ReflectObj:
return ReflectObj.Thaw(this);
- //P6opaque,
+ case SerializationCode.P6opaque:
+ return P6opaque.Thaw(this);
//Frame,
//Cursor,
- //String,
- //ArrP6any,
- //ArrVariable,
- //Boolean,
- //Int,
- //Double,
- //Type,
+ case SerializationCode.String:
+ return Register(String());
+ case SerializationCode.ArrP6any:
+ return Register(RefsA<P6any>());
+ case SerializationCode.ArrVariable:
+ return Register(RefsA<Variable>());
+ case SerializationCode.Boolean:
+ return Register(Byte() != 0);
+ case SerializationCode.Int:
+ return Register(Int());
+ case SerializationCode.Double:
+ return Register(Double());
+ case SerializationCode.Type:
+ return Register(Type.GetType(String(), true));
case SerializationCode.SimpleVariable:
case SerializationCode.SimpleVariable_1:
@@ -639,8 +660,9 @@ class ThawBuffer {
}
// call this when thawing any new object
- internal void Register(object o) {
+ internal object Register(object o) {
reg.RegisterThawed(unit, o);
+ return o;
}
object LoadNewUnit() {

0 comments on commit be108f9

Please sign in to comment.
Something went wrong with that request. Please try again.