Permalink
Browse files

Use precompiled IL when using a precompiled module

  • Loading branch information...
1 parent eee0cbb commit 288db483afb2c5ae8c618337d74c7c9b5a95069f @sorear committed Oct 17, 2011
Showing with 34 additions and 12 deletions.
  1. +31 −12 lib/Kernel.cs
  2. +1 −0 lib/ObjModel.cs
  3. +2 −0 lib/Serialize.cs
View
@@ -349,6 +349,7 @@ public sealed class RuntimeUnit : IFreeze {
public SubInfo mainline, bottom;
public bool is_mainish;
public Type type;
+ public Assembly assembly;
public List<SubInfo> our_subs;
// used during construction only
@@ -420,6 +421,8 @@ class IdentityComparer : IEqualityComparer<object> {
for (int i = 0; i < ths.Length; i++) {
ths[i].FillSubInfo(type);
+ our_subs[i].nam_str = null;
+ our_subs[i].nam_refs = null;
}
}
@@ -432,15 +435,17 @@ class IdentityComparer : IEqualityComparer<object> {
}
public void PrepareEval() {
- GenerateCode(true);
+ if (type == null) {
+ GenerateCode(true);
+
+ foreach (KeyValuePair<object, FieldBuilder> kv in constants)
+ type.GetField(kv.Value.Name).SetValue(null, kv.Key);
+ }
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;
Kernel.TraceCount = Kernel.TraceFreq = 1;
@@ -677,6 +682,12 @@ class IdentityComparer : IEqualityComparer<object> {
fb.String(asm_name);
fb.String(dll_name);
+ fb.Int(constants.Count);
+ foreach (KeyValuePair<object,FieldBuilder> kv in constants) {
+ fb.String(kv.Value.Name);
+ fb.ObjRef(kv.Key);
+ }
+
fb.Int(globals.Count);
foreach (KeyValuePair<string, StashEnt> kv in globals) {
fb.String(kv.Key);
@@ -714,13 +725,21 @@ class IdentityComparer : IEqualityComparer<object> {
if (result != "ok")
throw new ThawException("dated sources");
}
- // load assembly here
n.filename = tb.String();
n.source = tb.String();
n.asm_name = tb.String();
n.dll_name = tb.String();
+ n.assembly = Assembly.LoadFrom(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, n.dll_name));
+ n.type = tb.type = n.assembly.GetType(n.name, true);
+
+ int ncon = tb.Int();
+ while (ncon-- > 0) {
+ FieldInfo fi = n.type.GetField(tb.String());
+ fi.SetValue(null, tb.ObjRef());
+ }
+
int ct = tb.Int();
n.globals = new Dictionary<string, StashEnt>();
for (int i = 0; i < ct; i++) {
@@ -1637,15 +1656,14 @@ public class UsedInScopeInfo {
void IFreeze.Freeze(FreezeBuffer fb) {
fb.Byte((byte)SerializationCode.SubInfo);
- // TODO - saving constant pools NYI
string mn = null;
string tn = null;
if (code != null) {
Type t = code.Method.DeclaringType;
if (t.Assembly == typeof(Kernel).Assembly) {
tn = t.FullName;
- mn = code.Method.Name;
}
+ mn = code.Method.Name;
}
fb.String(mn);
fb.String(tn);
@@ -1697,15 +1715,16 @@ public class UsedInScopeInfo {
internal static SubInfo Thaw(ThawBuffer tb) {
SubInfo n = new SubInfo();
tb.Register(n);
- // TODO - saving constant pools NYI
string mn = tb.String();
string tn = tb.String();
- if (tn != null) {
+ if (mn != null) {
+ Type t = tn == null ? tb.type :
+ typeof(Kernel).Assembly.GetType(tn, true);
+
n.code = (DynBlockDelegate) Delegate.CreateDelegate(
typeof(DynBlockDelegate),
- typeof(Kernel).Assembly.GetType(tn, true).GetMethod(mn,
- BindingFlags.Public | BindingFlags.NonPublic |
- BindingFlags.Static));
+ t.GetMethod(mn, BindingFlags.Public |
+ BindingFlags.NonPublic | BindingFlags.Static));
}
n.nspill = tb.Int();
View
@@ -1059,6 +1059,7 @@ public class BoxObject<T> : P6opaque {
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>(); }
+ protected override void SetData(object o) { value = (T)o; }
public override void Freeze(FreezeBuffer fb) {
FreezeSelf(fb, typeof(T));
fb.ObjRef(value);
View
@@ -487,6 +487,8 @@ class ThawBuffer {
List<IFixup> fixups_needed = new List<IFixup>();
List<object> revalidate = new List<object>();
+ public Type type;
+
internal ThawBuffer(ObjectRegistry reg, SerUnit unit, byte[] data) {
this.data = data;
this.reg = reg;

0 comments on commit 288db48

Please sign in to comment.