Permalink
Browse files

Make CC, LIHint serializable

  • Loading branch information...
1 parent 3edbade commit 7ae298f4e9987a9f08b5e21a91362c5b3b4f7616 @sorear committed Oct 18, 2011
Showing with 42 additions and 12 deletions.
  1. +2 −0 lib/CodeGen.cs
  2. +10 −1 lib/Cursor.cs
  3. +7 −5 lib/Kernel.cs
  4. +23 −4 lib/Serialize.cs
  5. +0 −2 src/NieczaActions.pm6
View
@@ -513,6 +513,8 @@ sealed class Tokens {
P6any.GetField("mo");
public static readonly FieldInfo BValue_v =
BValue.GetField("v");
+ public static readonly FieldInfo StashEnt_v =
+ typeof(StashEnt).GetField("v");
public static readonly FieldInfo SubInfo_protosub =
SubInfo.GetField("protosub");
public static readonly FieldInfo SubInfo_protopad =
View
@@ -726,7 +726,7 @@ public Cursor(P6any proto, string text, P6any actions)
}
}
-public sealed class CC {
+public sealed class CC : IFreeze {
public readonly int[] vec;
public CC(int[] vec) {
@@ -845,6 +845,15 @@ public sealed class CC {
}
return Kernel.JoinS(",", clauses);
}
+
+ void IFreeze.Freeze(FreezeBuffer fb) {
+ fb.Byte((byte) SerializationCode.CC);
+ fb.Ints(vec);
+ }
+
+ internal static object Thaw(ThawBuffer tb) {
+ return tb.Register(new CC(tb.Ints()));
+ }
}
public sealed class NFA {
View
@@ -907,28 +907,30 @@ public class LICommon : LexInfo {
}
public class LIHint : LexInfo {
- public BValue var;
+ public StashEnt var;
public LIHint() { }
+ public LIHint(StashEnt var) { this.var = var; }
public override void Init(Frame f) { }
public override void BindFields() {
- var = new BValue(null);
+ var = new StashEnt();
}
public override object Get(Frame f) { return var.v; }
public override void Set(Frame f, object to) { var.v = (Variable)to; }
internal override ClrOp GetCode(int up) {
- return new ClrGetField(Tokens.BValue_v,
+ return new ClrGetField(Tokens.StashEnt_v,
Backend.currentUnit.RefConstant(name, var, null).head);
}
internal override ClrOp SetCode(int up, ClrOp to) {
- return new ClrSetField(Tokens.BValue_v,
+ return new ClrSetField(Tokens.StashEnt_v,
Backend.currentUnit.RefConstant(name, var, null).head, to);
}
internal override void DoFreeze(FreezeBuffer fb) {
fb.Byte((byte)LexSerCode.Hint);
+ fb.ObjRef(var);
}
}
@@ -1770,7 +1772,7 @@ public class UsedInScopeInfo {
li = new LICommon(tb.String());
break;
case (int) LexInfo.LexSerCode.Hint:
- li = new LIHint();
+ li = new LIHint((StashEnt) tb.ObjRef());
break;
case (int) LexInfo.LexSerCode.Package:
li = new LIPackage((STable) tb.ObjRef());
View
@@ -212,6 +212,8 @@ enum SerializationCode : byte {
RxFrame,
P6how,
ReflectObj,
+ CC,
+ AltInfo,
// types of P6any-reified object
P6opaque, // eventually let's specialize this
@@ -222,6 +224,8 @@ enum SerializationCode : byte {
String,
ArrP6any,
ArrVariable,
+ ArrString,
+ ArrCC,
Boolean,
Int,
Double,
@@ -415,7 +419,7 @@ public class FreezeBuffer {
internal static Type[] boxTypes = new Type[] {
null, typeof(Rat), typeof(FatRat), typeof(Complex),
- typeof(double), typeof(int), typeof(string),
+ typeof(double), typeof(int), typeof(string), typeof(VarHash),
typeof(Variable[]), typeof(VarDeque), typeof(STable),
};
internal static Func<P6opaque>[] boxCreate = new Func<P6opaque>[] {
@@ -428,6 +432,7 @@ public class FreezeBuffer {
static Type[] anyTypes = new Type[] {
typeof(string), typeof(P6any[]), typeof(Variable[]),
+ typeof(string[]), typeof(CC[]),
typeof(bool), typeof(int), typeof(double), typeof(Type),
};
@@ -448,15 +453,21 @@ public class FreezeBuffer {
Refs((Variable[])o);
break;
case 3:
- Byte((byte)((bool)o ? 1 : 0));
+ Refs((string[])o);
break;
case 4:
- Int((int)o);
+ Refs((CC[])o);
break;
case 5:
- Double((double)o);
+ Byte((byte)((bool)o ? 1 : 0));
break;
case 6:
+ Int((int)o);
+ break;
+ case 7:
+ Double((double)o);
+ break;
+ case 8:
String(((Type)o).AssemblyQualifiedName);
break;
default:
@@ -629,6 +640,10 @@ class ThawBuffer {
// return RxFrame.Thaw(this);
case SerializationCode.P6how:
return P6how.Thaw(this);
+ case SerializationCode.CC:
+ return CC.Thaw(this);
+ //case SerializationCode.AltInfo:
+ // return AltInfo.Thaw(this);
case SerializationCode.ReflectObj:
return ReflectObj.Thaw(this);
@@ -644,6 +659,10 @@ class ThawBuffer {
return Register(RefsA<P6any>());
case SerializationCode.ArrVariable:
return Register(RefsA<Variable>());
+ case SerializationCode.ArrString:
+ return Register(RefsA<string>());
+ case SerializationCode.ArrCC:
+ return Register(RefsA<CC>());
case SerializationCode.Boolean:
return Register(Byte() != 0);
case SerializationCode.Int:
View
@@ -436,7 +436,6 @@ method regex_def($/) {
}
my @lift = $ast.oplift;
my $ltm = ::GLOBAL::OptRxSimple.run_lad($ast.lad);
- say $ltm.perl;
$*CURLEX<!sub>.set_ltm($ltm);
($ast, my $mb) = ::GLOBAL::OptRxSimple.run($ast);
$*CURLEX<!sub>.finish(::Op::RegexBody.new(|node($/), pre => @lift,
@@ -2723,7 +2722,6 @@ method thunk_sub($code, :$params = [], :$name, :$class, :$ltm) {
cur_pkg => $*CURLEX<!sub>.cur_pkg,
in_class => $*CURLEX<!sub>.in_class);
$n.set_transparent;
- say $ltm.perl if $ltm;
$n.set_ltm($ltm) if $ltm;
$n.add_my_name($_, :noinit) for @$params;
$n.set_signature(Sig.simple(@$params));

0 comments on commit 7ae298f

Please sign in to comment.