Permalink
Browse files

Thaw code for all LAD, Variable, ViviHook subclasses

  • Loading branch information...
1 parent 19ada5b commit 054561b145da06221386fdb1408d84a77306a07d @sorear committed Oct 18, 2011
Showing with 206 additions and 89 deletions.
  1. +53 −44 lib/Builtins.cs
  2. +82 −17 lib/Cursor.cs
  3. +25 −6 lib/Kernel.cs
  4. +46 −22 lib/Serialize.cs
View
@@ -92,6 +92,59 @@ class PosixWrapper {
f_ctime = Stat.GetField("st_ctime");
}
}
+
+ class SubstrLValue: Variable {
+ Variable backing;
+ int from;
+ int length;
+
+ private SubstrLValue() {}
+ public SubstrLValue(Variable backing, int from, int length) {
+ this.backing = backing;
+ this.from = from;
+ this.length = length;
+ // XXX Should binding a substr lvalue count as binding the original?
+ this.whence = null;
+ this.rw = backing.rw;
+ this.type = Kernel.StrMO;
+ }
+
+ public override P6any Fetch() {
+ string str = backing.Fetch().mo.mro_raw_Str.Get(backing);
+ string sub = Builtins.LaxSubstring2(str, from, length);
+ return sub == null ? Kernel.StrMO.typeObject :
+ Kernel.BoxRaw(sub,Kernel.StrMO);
+ }
+
+ public override void Store(P6any v) {
+ string str = backing.Fetch().mo.mro_raw_Str.Get(backing);
+ int left = (from < 0) ? 0 : (from > str.Length) ? str.Length : from;
+ int right = ((length > (str.Length - left)) ? (str.Length - left) :
+ (length < 0) ? 0 : length) + left;
+ string lfr = str.Substring(0, left);
+ string mfr = v.mo.mro_raw_Str.Get(Kernel.NewROScalar(v));
+ string rfr = str.Substring(right);
+ backing.Store(Kernel.BoxRaw<string>(lfr + mfr + rfr, Kernel.StrMO));
+ }
+
+ public override Variable GetVar() {
+ return Kernel.BoxAnyMO<Variable>(this, Kernel.ScalarMO);
+ }
+ public override void Freeze(Niecza.Serialization.FreezeBuffer fb) {
+ fb.Byte((byte)Niecza.Serialization.SerializationCode.SubstrLValue);
+ fb.ObjRef(backing);
+ fb.Int(from);
+ fb.Int(length);
+ }
+ internal static object Thaw(Niecza.Serialization.ThawBuffer tb) {
+ var n = new SubstrLValue();
+ tb.Register(n);
+ n.backing = (Variable) tb.ObjRef();
+ n.from = tb.Int();
+ n.length = tb.Int();
+ return n;
+ }
+ }
}
public partial class Builtins {
@@ -187,50 +240,6 @@ public partial class Builtins {
}
}
- class SubstrLValue: Variable {
- Variable backing;
- int from;
- int length;
-
- public SubstrLValue(Variable backing, int from, int length) {
- this.backing = backing;
- this.from = from;
- this.length = length;
- // XXX Should binding a substr lvalue count as binding the original?
- this.whence = null;
- this.rw = backing.rw;
- this.type = Kernel.StrMO;
- }
-
- public override P6any Fetch() {
- string str = backing.Fetch().mo.mro_raw_Str.Get(backing);
- string sub = Builtins.LaxSubstring2(str, from, length);
- return sub == null ? Kernel.StrMO.typeObject :
- Kernel.BoxRaw(sub,Kernel.StrMO);
- }
-
- public override void Store(P6any v) {
- string str = backing.Fetch().mo.mro_raw_Str.Get(backing);
- int left = (from < 0) ? 0 : (from > str.Length) ? str.Length : from;
- int right = ((length > (str.Length - left)) ? (str.Length - left) :
- (length < 0) ? 0 : length) + left;
- string lfr = str.Substring(0, left);
- string mfr = v.mo.mro_raw_Str.Get(Kernel.NewROScalar(v));
- string rfr = str.Substring(right);
- backing.Store(Kernel.BoxRaw<string>(lfr + mfr + rfr, Kernel.StrMO));
- }
-
- public override Variable GetVar() {
- return Kernel.BoxAnyMO<Variable>(this, Kernel.ScalarMO);
- }
- public override void Freeze(Niecza.Serialization.FreezeBuffer fb) {
- fb.Byte((byte)Niecza.Serialization.SerializationCode.SubstrLValue);
- fb.ObjRef(backing);
- fb.Int(from);
- fb.Int(length);
- }
- }
-
public static string LaxSubstring(string str, int from) {
if (from < 0 || from > str.Length)
return null;
View
@@ -957,7 +957,7 @@ public abstract class LAD : IFreeze {
}
public class LADStr : LAD {
- public readonly string text;
+ public string text;
public LADStr(string text) { this.text = text; }
public override LAD Reify(NFA pad) { return this; }
@@ -985,11 +985,18 @@ public class LADStr : LAD {
fb.Byte((byte) SerializationCode.LADStr);
fb.String(text);
}
+ internal static LADStr Thaw(ThawBuffer tb) {
+ LADStr n = new LADStr(null);
+ tb.Register(n);
+ n.text = tb.String();
+ return n;
+ }
}
public class LADStrNoCase : LAD {
- public readonly string text;
+ public string text;
public LADStrNoCase(string text) { this.text = text; }
+ private LADStrNoCase() { }
public override LAD Reify(NFA pad) { return this; }
public override void QueryLiteral(NFA pad, out int len, out bool cont) {
@@ -1016,10 +1023,17 @@ public class LADStrNoCase : LAD {
fb.Byte((byte) SerializationCode.LADStrNoCase);
fb.String(text);
}
+ internal static LADStrNoCase Thaw(ThawBuffer tb) {
+ LADStrNoCase n = new LADStrNoCase();
+ tb.Register(n);
+ n.text = tb.String();
+ return n;
+ }
}
public class LADCC : LAD {
- public readonly CC cc;
+ public CC cc;
+ private LADCC() { }
public LADCC(CC cc) { this.cc = cc; }
public override LAD Reify(NFA pad) { return this; }
@@ -1032,7 +1046,13 @@ public class LADCC : LAD {
}
public override void Freeze(FreezeBuffer fb) {
fb.Byte((byte) SerializationCode.LADCC);
- fb.Ints(cc.vec);
+ fb.ObjRef(cc);
+ }
+ internal static LADCC Thaw(ThawBuffer tb) {
+ LADCC n = new LADCC();
+ tb.Register(n);
+ n.cc = (CC) tb.ObjRef();
+ return n;
}
}
@@ -1098,8 +1118,9 @@ public class LADDot : LAD {
}
public class LADStar : LAD {
- public readonly LAD child;
+ public LAD child;
public LADStar(LAD child) { this.child = child; }
+ private LADStar() {}
public override LAD Reify(NFA pad) { return new LADStar(child.Reify(pad)); }
public override void ToNFA(NFA pad, int from, int to) {
@@ -1117,12 +1138,19 @@ public class LADStar : LAD {
fb.Byte((byte) SerializationCode.LADStar);
fb.ObjRef(child);
}
+ internal static object Thaw(ThawBuffer tb) {
+ var n = new LADStar();
+ tb.Register(n);
+ n.child = (LAD) tb.ObjRef();
+ return n;
+ }
}
public class LADOpt : LAD {
- public readonly LAD child;
+ public LAD child;
public override LAD Reify(NFA pad) { return new LADOpt(child.Reify(pad)); }
public LADOpt(LAD child) { this.child = child; }
+ private LADOpt() {}
public override void ToNFA(NFA pad, int from, int to) {
pad.AddEdge(from, to, null);
@@ -1137,12 +1165,19 @@ public class LADOpt : LAD {
fb.Byte((byte) SerializationCode.LADOpt);
fb.ObjRef(child);
}
+ internal static object Thaw(ThawBuffer tb) {
+ var n = new LADOpt();
+ tb.Register(n);
+ n.child = (LAD) tb.ObjRef();
+ return n;
+ }
}
public class LADPlus : LAD {
- public readonly LAD child;
+ public LAD child;
public override LAD Reify(NFA pad) { return new LADPlus(child.Reify(pad)); }
public LADPlus(LAD child) { this.child = child; }
+ private LADPlus() { }
public override void QueryLiteral(NFA pad, out int len, out bool cont) {
child.QueryLiteral(pad, out len, out cont);
@@ -1165,11 +1200,18 @@ public class LADPlus : LAD {
fb.Byte((byte) SerializationCode.LADPlus);
fb.ObjRef(child);
}
+ internal static object Thaw(ThawBuffer tb) {
+ var n = new LADPlus();
+ tb.Register(n);
+ n.child = (LAD) tb.ObjRef();
+ return n;
+ }
}
public class LADSequence : LAD {
- public readonly LAD[] args;
+ public LAD[] args;
public LADSequence(LAD[] args) { this.args = args; }
+ private LADSequence() { }
public override LAD Reify(NFA pad) {
LAD[] nc = new LAD[args.Length];
for (int i = 0; i < args.Length; i++)
@@ -1204,15 +1246,20 @@ public class LADSequence : LAD {
}
public override void Freeze(FreezeBuffer fb) {
fb.Byte((byte) SerializationCode.LADSequence);
- fb.Int(args.Length);
- foreach (LAD l in args)
- fb.ObjRef(l);
+ fb.Refs(args);
+ }
+ internal static object Thaw(ThawBuffer tb) {
+ var n = new LADSequence();
+ tb.Register(n);
+ n.args = tb.RefsA<LAD>();
+ return n;
}
}
public class LADAny : LAD {
- public readonly LAD[] zyg;
+ public LAD[] zyg;
public LADAny(LAD[] zyg) { this.zyg = zyg; }
+ private LADAny() { }
public override LAD Reify(NFA pad) {
LAD[] nc = new LAD[zyg.Length];
for (int i = 0; i < zyg.Length; i++)
@@ -1232,14 +1279,19 @@ public class LADAny : LAD {
}
public override void Freeze(FreezeBuffer fb) {
fb.Byte((byte) SerializationCode.LADAny);
- fb.Int(zyg.Length);
- foreach (LAD l in zyg)
- fb.ObjRef(l);
+ fb.Refs(zyg);
+ }
+ internal static object Thaw(ThawBuffer tb) {
+ var n = new LADAny();
+ tb.Register(n);
+ n.zyg = tb.RefsA<LAD>();
+ return n;
}
}
public class LADParam : LAD {
- public readonly string name;
+ public string name;
+ private LADParam() {}
public LADParam(string name) { this.name = name; }
public override LAD Reify(NFA pad) {
@@ -1303,12 +1355,19 @@ public class LADParam : LAD {
fb.Byte((byte) SerializationCode.LADParam);
fb.String(name);
}
+ internal static LADParam Thaw(ThawBuffer tb) {
+ LADParam n = new LADParam();
+ tb.Register(n);
+ n.name = tb.String();
+ return n;
+ }
}
public class LADMethod : LAD {
- public readonly string name;
+ public string name;
public LADMethod(string name) { this.name = name; }
+ private LADMethod() {}
public override void ToNFA(NFA pad, int from, int to) {
throw new InvalidOperationException();
@@ -1358,6 +1417,12 @@ public class LADMethod : LAD {
fb.Byte((byte) SerializationCode.LADMethod);
fb.String(name);
}
+ internal static LADMethod Thaw(ThawBuffer tb) {
+ LADMethod n = new LADMethod();
+ tb.Register(n);
+ n.name = tb.String();
+ return n;
+ }
}
// Only really makes sense if used in the static scope of a proto
View
@@ -93,8 +93,11 @@ public class SubViviHook : ViviHook {
fb.Byte((byte)SerializationCode.SubViviHook);
fb.ObjRef(sub);
}
- internal static SubViviHook Thaw(ThawBuffer tb) {
- return new SubViviHook((P6any)tb.ObjRef());
+ internal static object Thaw(ThawBuffer tb) {
+ var n = new SubViviHook(null);
+ tb.Register(n);
+ n.sub = (P6any) tb.ObjRef();
+ return n;
}
}
@@ -112,7 +115,11 @@ public class HashViviHook : ViviHook {
fb.String(key);
}
internal static IFreeze Thaw(ThawBuffer tb) {
- return new HashViviHook((P6any)tb.ObjRef(), tb.String());
+ var n = new HashViviHook(null, null);
+ tb.Register(n);
+ n.hash = (P6any) tb.ObjRef();
+ n.key = tb.String();
+ return n;
}
}
@@ -131,7 +138,11 @@ public class NewHashViviHook : ViviHook {
fb.String(key);
}
internal static IFreeze Thaw(ThawBuffer tb) {
- return new NewHashViviHook((Variable)tb.ObjRef(), tb.String());
+ var n = new NewHashViviHook(null, null);
+ tb.Register(n);
+ n.hashv = (Variable) tb.ObjRef();
+ n.key = tb.String();
+ return n;
}
}
@@ -151,7 +162,11 @@ public class ArrayViviHook : ViviHook {
fb.Int(key);
}
internal static IFreeze Thaw(ThawBuffer tb) {
- return new ArrayViviHook((P6any)tb.ObjRef(), tb.Int());
+ var n = new ArrayViviHook(null, 0);
+ tb.Register(n);
+ n.ary = (P6any) tb.ObjRef();
+ n.key = tb.Int();
+ return n;
}
}
@@ -175,7 +190,11 @@ public class NewArrayViviHook : ViviHook {
fb.Int(key);
}
internal static IFreeze Thaw(ThawBuffer tb) {
- return new NewArrayViviHook((Variable)tb.ObjRef(), tb.Int());
+ var n = new NewArrayViviHook(null, 0);
+ tb.Register(n);
+ n.ary = (Variable) tb.ObjRef();
+ n.key = tb.Int();
+ return n;
}
}
Oops, something went wrong. Retry.

0 comments on commit 054561b

Please sign in to comment.