Permalink
Browse files

Wire up serializer to run after pre-compiler

  • Loading branch information...
1 parent dc6dd55 commit 8ed36eab47f0df9887b6736146684783882edd93 @sorear committed Oct 15, 2011
Showing with 38 additions and 14 deletions.
  1. +4 −0 lib/CodeGen.cs
  2. +24 −11 lib/Kernel.cs
  3. +9 −2 lib/Serialize.cs
  4. +1 −1 src/NieczaBackendDotnet.pm6
View
@@ -4086,6 +4086,10 @@ public class DowncallReceiver : CallReceiver {
for (int i = 0; i < s.nam_refs.Length; i++)
s.nam_refs[i] = Handle.Unbox(args[i+3]);
return null;
+ } else if (cmd == "save_unit") {
+ RuntimeUnit ru = (RuntimeUnit)Handle.Unbox(args[1]);
+ ru.Save();
+ return null;
} else if (cmd == "run_unit") {
RuntimeUnit ru = (RuntimeUnit)Handle.Unbox(args[1]);
bool evalmode = (bool)args[2];
View
@@ -351,11 +351,11 @@ class IdentityComparer : IEqualityComparer<object> {
this.dll_name = asm_name + (main ? ".exe" : ".dll");
this.asm_builder = AppDomain.CurrentDomain.DefineDynamicAssembly(
new AssemblyName(asm_name),
- (runnow ? AssemblyBuilderAccess.RunAndSave :
+ (runnow ? AssemblyBuilderAccess.Run :
AssemblyBuilderAccess.Save), obj_dir);
- //mod_builder = runnow ? asm_builder.DefineDynamicModule(asm_name) :
- // asm_builder.DefineDynamicModule(asm_name, filename);
- mod_builder = asm_builder.DefineDynamicModule(asm_name, dll_name);
+ mod_builder = runnow ? asm_builder.DefineDynamicModule(asm_name) :
+ asm_builder.DefineDynamicModule(asm_name, dll_name);
+ //mod_builder = asm_builder.DefineDynamicModule(asm_name, dll_name);
type_builder = mod_builder.DefineType(asm_name,
TypeAttributes.Public | TypeAttributes.Sealed |
@@ -367,7 +367,7 @@ class IdentityComparer : IEqualityComparer<object> {
our_subs = new List<SubInfo>();
}
- public void PrepareEval() {
+ void GenerateCode() {
NamProcessor[] ths = new NamProcessor[our_subs.Count];
for (int i = 0; i < ths.Length; i++) {
SubInfo z = our_subs[i];
@@ -379,16 +379,29 @@ class IdentityComparer : IEqualityComparer<object> {
}
type = type_builder.CreateType();
- asm_builder.Save(dll_name);
-
- foreach (KeyValuePair<object, FieldBuilder> kv in constants)
- type.GetField(kv.Value.Name).SetValue(null, kv.Key);
for (int i = 0; i < ths.Length; i++) {
ths[i].FillSubInfo(type);
- if ((our_subs[i].special & SubInfo.UNSAFE) != 0)
- Kernel.CheckUnsafe(our_subs[i]);
}
+ }
+
+ static ObjectRegistry reg = new ObjectRegistry();
+
+ public void Save() {
+ GenerateCode();
+ asm_builder.Save(dll_name);
+ reg.SaveUnit(asm_name, this);
+ }
+
+ public void PrepareEval() {
+ GenerateCode();
+
+ foreach (SubInfo z in our_subs)
+ if ((z.special & SubInfo.UNSAFE) != 0)
+ Kernel.CheckUnsafe(z);
+
+ foreach (KeyValuePair<object, FieldBuilder> kv in constants)
+ type.GetField(kv.Value.Name).SetValue(null, kv.Key);
if (Environment.GetEnvironmentVariable("NIECZA_DEFER_TRACE") != null) {
Kernel.TraceFlags = Kernel.TRACE_CUR;
View
@@ -40,9 +40,9 @@ namespace Niecza.Serialization {
class SerUnit {
internal string name; // eg "File.Copy"
internal byte[] hash; // hash of entire file, filled at write time
- internal object[] bynum; // objects in unit
+ internal object[] bynum = new object[8]; // objects in unit
internal object root; // the RuntimeUnit object
- internal int nobj;
+ internal int nobj; // = 0
}
// The central feature of *bounded* serialization is that object
@@ -108,6 +108,7 @@ struct ObjRef {
ThawBuffer tb = new ThawBuffer(this, su, bytes);
+ units[name] = su;
bool success = false;
try {
string rsig = tb.String();
@@ -130,6 +131,8 @@ struct ObjRef {
// removes a stale unit so a new version can be saved over it.
public void UnloadUnit(string name) {
+ if (!units.ContainsKey(name))
+ return;
SerUnit su = units[name];
units.Remove(name);
@@ -151,6 +154,8 @@ struct ObjRef {
FreezeBuffer fb = new FreezeBuffer(this, su);
+ units[name] = su;
+
try {
fb.String(signature);
fb.Int(version);
@@ -244,6 +249,8 @@ public class FreezeBuffer {
SerUnit unit;
internal FreezeBuffer(ObjectRegistry reg, SerUnit unit) {
+ if (reg == null || unit == null)
+ throw new ArgumentNullException();
this.reg = reg;
this.unit = unit;
unit_to_offset = new Dictionary<SerUnit,int>();
@@ -73,7 +73,7 @@ method accept($unitname, $unit, :$main, :$run, :$evalmode, :$repl) { #OK not use
$*repl_outer = $unit.get_mainline if $repl;
return;
}
- downcall("save_unit", $unit, ?$main);
+ downcall("save_unit", $unit);
$*repl_outer = $unit.get_mainline if $repl;
}

0 comments on commit 8ed36ea

Please sign in to comment.