Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 929 lines (808 sloc) 30.9 kb
8184302 @sorear Start draft of serialization/deserialization code
authored
1 using System;
d832c02 @sorear Second draft of serialization code
authored
2 using System.IO;
3 using System.Security.Cryptography;
b25256f @sorear Add Serialize.cs to build, fix build errors
authored
4 using System.Collections.Generic;
ee02ddf @sorear Tweaks to allow saving and thawing cross-unit deep sub clones, such as w...
authored
5 using System.Reflection;
d832c02 @sorear Second draft of serialization code
authored
6 using System.Text;
9083142 @sorear Switch to single-AppDomain execution
authored
7 using Niecza.CLRBackend;
8184302 @sorear Start draft of serialization/deserialization code
authored
8
cdde7e0 @sorear Notes on four kinds of module scope
authored
9 // Here in Niecza we have four different kinds of unit scopes:
10 //
11 // * COMPILING::UNIT, aka RuntimeUnit: one of these exists for every
12 // call into the compiler, whether eval or module. The REPL will
13 // be considered as if it were eval.
14 //
15 // * Serialization scopes, which are created when compiling modules
16 // or when pre-compiling a main program. During execution there is
17 // no current serialization scope; evals inherit the serialization
18 // scope or lack thereof that was in effect.
19 //
20 // * Assembly scopes, which are an artifact of the CLR and almost align
21 // with precompilation scopes, except that they have to exist always
22 // because methods cannot be created free-floating in CLR 2.x.
23 //
24 // An assembly scope is created for all serialization scopes, and
25 // non-saved anonymous assemblies are created for eval-and-run of
26 // a file and non-BEGIN-time evals.
27 //
28 // * GLOBAL scope is very much like serialization scope except that there
29 // is a "true globals" scope that is used when not serializing.
30
8184302 @sorear Start draft of serialization/deserialization code
authored
31 // This implements "bounded serialization" for Niecza. Unfortunately
32 // the CLR's builtin serialization can't efficiently be made bounded,
33 // and anyway it would be nice if the serialization format could be
34 // transported across backends.
35
36 // TODO: implement a more Storable-like interface.
d832c02 @sorear Second draft of serialization code
authored
37
38 // Note, the serialization subsystem is *NOT* thread safe !
8184302 @sorear Start draft of serialization/deserialization code
authored
39 namespace Niecza.Serialization {
d832c02 @sorear Second draft of serialization code
authored
40 // Information kept on a serialization unit after loading or storing,
41 // but not before storing.
42 class SerUnit {
43 internal string name; // eg "File.Copy"
44 internal byte[] hash; // hash of entire file, filled at write time
8ed36ea @sorear Wire up serializer to run after pre-compiler
authored
45 internal object[] bynum = new object[8]; // objects in unit
d832c02 @sorear Second draft of serialization code
authored
46 internal object root; // the RuntimeUnit object
8ed36ea @sorear Wire up serializer to run after pre-compiler
authored
47 internal int nobj; // = 0
69f2cee @sorear A scheme for serializing CLR wrappers (fixes #117)
authored
48
49 internal bool fake; // true for CLR reference units
d832c02 @sorear Second draft of serialization code
authored
50 }
8184302 @sorear Start draft of serialization/deserialization code
authored
51
52 // The central feature of *bounded* serialization is that object
53 // registries are kept distinct from the (de)serializer, and can
54 // be shared between serialization runs.
55 class ObjectRegistry {
d832c02 @sorear Second draft of serialization code
authored
56 // TODO: investigate a more specialized representation,
57 // ideally not having to hash as many objects
58 struct ObjRef {
b25256f @sorear Add Serialize.cs to build, fix build errors
authored
59 public SerUnit unit;
60 public int id;
8184302 @sorear Start draft of serialization/deserialization code
authored
61 }
c80570d @sorear misc top removal: MakePair, LHF
authored
62 Compartment setting;
d832c02 @sorear Second draft of serialization code
authored
63 Dictionary<object,ObjRef> byref = new Dictionary<object,ObjRef>();
8184302 @sorear Start draft of serialization/deserialization code
authored
64
d832c02 @sorear Second draft of serialization code
authored
65 Dictionary<string,SerUnit> units =
66 new Dictionary<string,SerUnit>();
67
cdb4548 @sorear Checkpoint of global-variable inventory
authored
68 internal static HashAlgorithm NewHash() { return new SHA256Managed(); }
69
ee02ddf @sorear Tweaks to allow saving and thawing cross-unit deep sub clones, such as w...
authored
70 internal Dictionary<string,Dictionary<string,MethodInfo>> methods =
71 new Dictionary<string,Dictionary<string,MethodInfo>>();
c592587 @sorear Change constant table to use instance fields
authored
72 internal Dictionary<string,object> instances =
73 new Dictionary<string,object>();
ee02ddf @sorear Tweaks to allow saving and thawing cross-unit deep sub clones, such as w...
authored
74
d832c02 @sorear Second draft of serialization code
authored
75 static readonly string signature = "Niecza-Serialized-Module";
1d0c020 @sorear Forward compatibility for extending the set of kernel-defined types
authored
76 public const int VersionMin = 31;
77 public const int VersionExplicitSave = 32;
78 public const int VersionCur = 32;
d832c02 @sorear Second draft of serialization code
authored
79
c80570d @sorear misc top removal: MakePair, LHF
authored
80 public ObjectRegistry(Compartment s) { setting = s; }
81
d832c02 @sorear Second draft of serialization code
authored
82 // Routines for use by serialization code
83 public bool CheckWriteObject(SerUnit into, object o,
84 out SerUnit lui, out int id) {
85 ObjRef or;
86 if (byref.TryGetValue(o, out or)) {
87 lui = or.unit;
88 id = or.id;
8184302 @sorear Start draft of serialization/deserialization code
authored
89 return true;
d832c02 @sorear Second draft of serialization code
authored
90 }
8184302 @sorear Start draft of serialization/deserialization code
authored
91
d832c02 @sorear Second draft of serialization code
authored
92 if (into.nobj == into.bynum.Length)
93 Array.Resize(ref into.bynum, into.nobj * 2);
8184302 @sorear Start draft of serialization/deserialization code
authored
94
b25256f @sorear Add Serialize.cs to build, fix build errors
authored
95 or.unit = lui = into;
d832c02 @sorear Second draft of serialization code
authored
96 id = or.id = into.nobj++;
97 into.bynum[id] = o;
98
99 byref[o] = or;
8184302 @sorear Start draft of serialization/deserialization code
authored
100
101 return false;
102 }
d832c02 @sorear Second draft of serialization code
authored
103
54921c8 @sorear Prevent choking when trying to serialize a multi-dispatch cache
authored
104 // Undo previous method...
105 public void DeleteLastObject(SerUnit into) {
106 byref.Remove(into.bynum[--into.nobj]);
107 into.bynum[into.nobj] = null;
108 }
109
1c5bb04 @sorear Small refactor to AssemblyBuilder setup, start thaw coding
authored
110 public void RegisterThawed(SerUnit into, object o) {
111 ObjRef or;
112 if (into.nobj == into.bynum.Length)
113 Array.Resize(ref into.bynum, into.nobj * 2);
114
115 or.unit = into;
116 or.id = into.nobj++;
117 into.bynum[or.id] = o;
118
119 byref[o] = or;
120 }
121
d832c02 @sorear Second draft of serialization code
authored
122 // Routines for use by compilation manager
69f2cee @sorear A scheme for serializing CLR wrappers (fixes #117)
authored
123 public void InstallFakeUnit(string name, params object[] items) {
124 SerUnit su = new SerUnit();
125 su.fake = true;
126 su.name = name;
127 su.bynum = items;
128 su.hash = new byte[0];
129 units[name] = su;
130
131 ObjRef or;
132 or.unit = su;
133 for (or.id = 0; or.id < items.Length; or.id++)
134 byref[items[or.id]] = or;
135 }
d832c02 @sorear Second draft of serialization code
authored
136
64f16b5 @sorear Support multiple object directories
authored
137 public bool DeleteTopUnit(string name) {
138 string path = Path.Combine(setting.obj_dirs[ setting.obj_dirs.Length - 1 ],
139 name.Replace("::",".") + ".ser");
140 if (File.Exists(path)) {
141 File.Delete(path);
142 return true;
143 } else {
144 return false;
145 }
146 }
147
d832c02 @sorear Second draft of serialization code
authored
148 // Loads a single unit from the compiled-data directory.
149 // Will throw a ThawException if a stale reference is encountered
150 // or other data format error.
69f2cee @sorear A scheme for serializing CLR wrappers (fixes #117)
authored
151 public SerUnit LoadUnit(string name, bool fake = false) {
d832c02 @sorear Second draft of serialization code
authored
152 SerUnit su;
153
154 // is the unit already loaded?
155 if (units.TryGetValue(name, out su))
156 return su;
157
69f2cee @sorear A scheme for serializing CLR wrappers (fixes #117)
authored
158 if (fake) {
159 if (name.StartsWith("CLR,"))
c80570d @sorear misc top removal: MakePair, LHF
authored
160 CLRWrapperProvider.LoadWrapper(setting, name.Substring(4));
69f2cee @sorear A scheme for serializing CLR wrappers (fixes #117)
authored
161 else
162 throw new ThawException("No handler for fake unit name " + name);
163
164 return units[name];
165 }
166
64f16b5 @sorear Support multiple object directories
authored
167 // Probe for the topmost cache that contains our module
168 string file = null;
169 byte[] bytes = null;
170 for (int i = setting.obj_dirs.Length - 1; i >= 0; i--) {
171 file = Path.Combine(setting.obj_dirs[i], name.Replace("::",".") + ".ser");
172 if (File.Exists(file)) {
173 bytes = File.ReadAllBytes(file);
174 break;
175 }
176 }
177 if (bytes == null)
178 throw new ThawException("unit not found: " + name);
d832c02 @sorear Second draft of serialization code
authored
179
180 su = new SerUnit();
181 su.name = name;
cdb4548 @sorear Checkpoint of global-variable inventory
authored
182 su.hash = NewHash().ComputeHash(bytes);
d832c02 @sorear Second draft of serialization code
authored
183
c80570d @sorear misc top removal: MakePair, LHF
authored
184 ThawBuffer tb = new ThawBuffer(setting, this, su, bytes);
64f16b5 @sorear Support multiple object directories
authored
185 tb.file = file;
d832c02 @sorear Second draft of serialization code
authored
186
8ed36ea @sorear Wire up serializer to run after pre-compiler
authored
187 units[name] = su;
d832c02 @sorear Second draft of serialization code
authored
188 bool success = false;
189 try {
190 string rsig = tb.String();
191 if (rsig != signature)
192 throw new ThawException("signature mismatch loading " + file);
193 int rver = tb.Int();
1d0c020 @sorear Forward compatibility for extending the set of kernel-defined types
authored
194 if (rver < VersionMin || rver > VersionCur)
d832c02 @sorear Second draft of serialization code
authored
195 throw new ThawException("version mismatch loading " + file);
1d0c020 @sorear Forward compatibility for extending the set of kernel-defined types
authored
196 tb.version = rver;
d832c02 @sorear Second draft of serialization code
authored
197
b25256f @sorear Add Serialize.cs to build, fix build errors
authored
198 su.root = tb.ObjRef();
c0af787 @sorear Fix fixup call order (oops!), serialization-compatible calling of phaser...
authored
199 tb.RunFixups();
d832c02 @sorear Second draft of serialization code
authored
200 success = true;
201 } finally {
202 // don't leave half-read units in the map
203 if (!success)
204 UnloadUnit(name);
205 }
206
207 return su;
208 }
209
210 // removes a stale unit so a new version can be saved over it.
211 public void UnloadUnit(string name) {
8ed36ea @sorear Wire up serializer to run after pre-compiler
authored
212 if (!units.ContainsKey(name))
213 return;
d832c02 @sorear Second draft of serialization code
authored
214 SerUnit su = units[name];
215 units.Remove(name);
216
217 for (int i = 0; i < su.nobj; i++)
218 byref.Remove(su.bynum[i]);
219 }
220
221 public SerUnit SaveUnit(string name, IFreeze root) {
222 SerUnit su = new SerUnit();
223 su.name = name;
224 su.root = root;
225
226 if (units.ContainsKey(name))
b25256f @sorear Add Serialize.cs to build, fix build errors
authored
227 throw new InvalidOperationException("unit " +name+ " exists");
d832c02 @sorear Second draft of serialization code
authored
228
229 bool success = false;
64f16b5 @sorear Support multiple object directories
authored
230 string file = Path.Combine(setting.obj_dirs[ setting.obj_dirs.Length - 1],
9083142 @sorear Switch to single-AppDomain execution
authored
231 name.Replace("::",".") + ".ser");
d832c02 @sorear Second draft of serialization code
authored
232
233 FreezeBuffer fb = new FreezeBuffer(this, su);
234
8ed36ea @sorear Wire up serializer to run after pre-compiler
authored
235 units[name] = su;
236
d832c02 @sorear Second draft of serialization code
authored
237 try {
238 fb.String(signature);
1d0c020 @sorear Forward compatibility for extending the set of kernel-defined types
authored
239 fb.Int(VersionCur);
d832c02 @sorear Second draft of serialization code
authored
240 fb.ObjRef(root);
241
242 byte[] data = fb.GetData();
cdb4548 @sorear Checkpoint of global-variable inventory
authored
243 su.hash = NewHash().ComputeHash(data);
d832c02 @sorear Second draft of serialization code
authored
244 File.WriteAllBytes(file, data);
245 success = true;
246 } finally {
247 if (!success)
248 UnloadUnit(name);
249 }
250
251 return su;
252 }
8184302 @sorear Start draft of serialization/deserialization code
authored
253 }
254
255 // One of these codes is written at the beginning of every object ref
1993029 @sorear Start implementing serialization for our objects
authored
256 enum SerializationCode : byte {
d832c02 @sorear Second draft of serialization code
authored
257 // special
258 Null,
259
8184302 @sorear Start draft of serialization/deserialization code
authored
260 // existing objects
261 ForeignRef,
262 SelfRef,
263 NewUnitRef,
69f2cee @sorear A scheme for serializing CLR wrappers (fixes #117)
authored
264 FakeUnitRef,
1993029 @sorear Start implementing serialization for our objects
authored
265
266 // types of new object
267 RuntimeUnit,
268 SubInfo,
269 STable,
270 StashEnt,
d91ecdf @sorear Serialization for objects of type Rat, FatRat, Complex, BigInteger, Int3...
authored
271 Rat,
272 FatRat,
273 Complex,
274 BigInteger,
275 VarDeque,
276 VarHash,
dc6dd55 @sorear Implement serialization for Frame, finally kill off hashtable lexicals
authored
277 DispatchEnt,
278 RxFrame,
279 P6how,
3f80fca @sorear A procedure for serializing ContextHandler et al
authored
280 ReflectObj,
7ae298f @sorear Make CC, LIHint serializable
authored
281 CC,
282 AltInfo,
10ba66d @sorear Turn Signatures into real objects
authored
283 Signature,
284 Parameter,
1993029 @sorear Start implementing serialization for our objects
authored
285
286 // types of P6any-reified object
d91ecdf @sorear Serialization for objects of type Rat, FatRat, Complex, BigInteger, Int3...
authored
287 P6opaque, // eventually let's specialize this
1993029 @sorear Start implementing serialization for our objects
authored
288 Frame,
289 Cursor,
290
1c5bb04 @sorear Small refactor to AssemblyBuilder setup, start thaw coding
authored
291 // miscellany - keep these in same order as FallbackFreeze
292 String,
293 ArrP6any,
294 ArrVariable,
7ae298f @sorear Make CC, LIHint serializable
authored
295 ArrString,
296 ArrCC,
fe6e595 @sorear Thaw for SimpleVariable, StashEnt
authored
297 Boolean,
1c5bb04 @sorear Small refactor to AssemblyBuilder setup, start thaw coding
authored
298 Int,
299 Double,
3f80fca @sorear A procedure for serializing ContextHandler et al
authored
300 Type,
d91ecdf @sorear Serialization for objects of type Rat, FatRat, Complex, BigInteger, Int3...
authored
301
ab35238 @sorear Tidy up STable fields a bit, add TiedVariable serialize
authored
302 // variables
40e1779 @sorear Split ListVariable out of SimpleVariable
authored
303 RWVariable, // allow 2 for flag
304 RWVariable_1,
305 ListVariable,
fe6e595 @sorear Thaw for SimpleVariable, StashEnt
authored
306 SubstrLValue,
ab35238 @sorear Tidy up STable fields a bit, add TiedVariable serialize
authored
307 TiedVariable,
037f4b7 @sorear Make * a "blackhole" container that ignores writes
authored
308 Blackhole,
1993029 @sorear Start implementing serialization for our objects
authored
309
310 // vivification hooks
ab35238 @sorear Tidy up STable fields a bit, add TiedVariable serialize
authored
311 SubViviHook,
1993029 @sorear Start implementing serialization for our objects
authored
312 ArrayViviHook,
313 NewArrayViviHook,
314 HashViviHook,
315 NewHashViviHook,
b1088dc @sorear implement serialization for SubInfo, LAD, LexInfo
authored
316
317 // Longest-token automaton descriptors
318 LADNone, // no-args
319 LADNull,
320 LADDot,
321 LADDispatcher,
322 LADImp,
323 LADStr, // string
324 LADStrNoCase,
325 LADMethod,
326 LADParam,
b8a5ff0 @sorear Treat quantifiers as partially declarative whenever at all possible
authored
327 LADQuant, // byte,LAD,LAD
b1088dc @sorear implement serialization for SubInfo, LAD, LexInfo
authored
328 LADSequence, // LAD[]
329 LADAny,
330 LADCC, // CC
8184302 @sorear Start draft of serialization/deserialization code
authored
331 }
332
333 // An instance of this class is used to serialize serialization units
1993029 @sorear Start implementing serialization for our objects
authored
334 public class FreezeBuffer {
8184302 @sorear Start draft of serialization/deserialization code
authored
335 byte[] data;
336 int wpointer;
337
d832c02 @sorear Second draft of serialization code
authored
338 Dictionary<SerUnit,int> unit_to_offset;
339 int usedunits;
8184302 @sorear Start draft of serialization/deserialization code
authored
340
341 ObjectRegistry reg;
d832c02 @sorear Second draft of serialization code
authored
342 SerUnit unit;
8184302 @sorear Start draft of serialization/deserialization code
authored
343
d832c02 @sorear Second draft of serialization code
authored
344 internal FreezeBuffer(ObjectRegistry reg, SerUnit unit) {
8ed36ea @sorear Wire up serializer to run after pre-compiler
authored
345 if (reg == null || unit == null)
346 throw new ArgumentNullException();
8184302 @sorear Start draft of serialization/deserialization code
authored
347 this.reg = reg;
d832c02 @sorear Second draft of serialization code
authored
348 this.unit = unit;
349 unit_to_offset = new Dictionary<SerUnit,int>();
8184302 @sorear Start draft of serialization/deserialization code
authored
350 data = new byte[256];
351 }
352
b25256f @sorear Add Serialize.cs to build, fix build errors
authored
353 internal byte[] GetData() {
354 byte[] ret = new byte[wpointer];
355 Array.Copy(data, ret, ret.Length);
356 return ret;
357 }
358
8184302 @sorear Start draft of serialization/deserialization code
authored
359 void Ensure(int ct) {
360 while (ct + wpointer > data.Length)
361 Array.Resize(ref data, data.Length * 2);
362 }
363
364 public void Byte(byte x) {
365 Ensure(1);
366 data[wpointer++] = x;
367 }
368
19ada5b @sorear Implement variable-length coding for serialization
authored
369 public void Long(long x) {
370 //Console.WriteLine("Saving {0} at {1}", x, wpointer);
371 Ensure(10);
372 while (true) {
373 if (x >= -64 && x <= 63) {
374 data[wpointer++] = (byte) (127 & (byte)x);
375 break;
376 } else {
377 data[wpointer++] = (byte) (128 | (byte)x);
378 x >>= 7;
379 }
380 }
8184302 @sorear Start draft of serialization/deserialization code
authored
381 }
382
19ada5b @sorear Implement variable-length coding for serialization
authored
383 public void ULong(ulong x) {
384 //Console.WriteLine("Saving {0} at {1}", x, wpointer);
385 Ensure(10);
386 while (true) {
387 if (x <= 127) {
388 data[wpointer++] = (byte) (127 & (byte)x);
389 break;
390 } else {
391 data[wpointer++] = (byte) (128 | (byte)x);
392 x >>= 7;
393 }
394 }
8184302 @sorear Start draft of serialization/deserialization code
authored
395 }
396
19ada5b @sorear Implement variable-length coding for serialization
authored
397 public void Short(short x) { Long(x); }
398 public void Int(int x) { Long(x); }
8184302 @sorear Start draft of serialization/deserialization code
authored
399
8035d26 @sorear Thaw code for VarDeque, VarHash, BigInteger, Complex, Rat, FatRat
authored
400 public void Double(double x) {
401 Long(BitConverter.DoubleToInt64Bits(x));
402 }
403
8184302 @sorear Start draft of serialization/deserialization code
authored
404 public void String(string s) {
405 if (s == null) {
406 Int(-1);
407 } else {
408 Int(s.Length);
409 foreach (char ch in s)
19ada5b @sorear Implement variable-length coding for serialization
authored
410 ULong((ulong)ch);
8184302 @sorear Start draft of serialization/deserialization code
authored
411 }
412 }
413
3dc4789 @sorear Implement freezing for types
authored
414 public void Strings(string[] s) {
415 if (s == null) Int(-1);
416 else {
417 Int(s.Length);
418 foreach (string ch in s) String(ch);
419 }
420 }
421
b1088dc @sorear implement serialization for SubInfo, LAD, LexInfo
authored
422 public void Ints(int[] s) {
423 if (s == null) {
424 Int(-1);
425 } else {
426 Int(s.Length);
427 foreach (int ch in s)
428 Int(ch);
429 }
430 }
431
dc6dd55 @sorear Implement serialization for Frame, finally kill off hashtable lexicals
authored
432 public void Refs<T> (T[] x) {
d91ecdf @sorear Serialization for objects of type Rat, FatRat, Complex, BigInteger, Int3...
authored
433 if (x == null) {
434 Int(-1);
435 } else {
436 Int(x.Length);
437 foreach (T y in x)
438 ObjRef(y);
439 }
440 }
441
dc6dd55 @sorear Implement serialization for Frame, finally kill off hashtable lexicals
authored
442 public void Refs<T> (IList<T> x) {
3dc4789 @sorear Implement freezing for types
authored
443 if (x == null) {
444 Int(-1);
445 } else {
446 Int(x.Count);
447 foreach (T y in x)
448 ObjRef(y);
449 }
450 }
451
54921c8 @sorear Prevent choking when trying to serialize a multi-dispatch cache
authored
452 public void Ephemeralize() {
453 Byte((byte)SerializationCode.Null);
454 reg.DeleteLastObject(unit);
455 }
456
d832c02 @sorear Second draft of serialization code
authored
457 // This is the main routine you should call from your Freeze
458 // callbacks to freeze an object
ff557f5 @sorear Usability improvements for NIECZA_SER_TRACE, indenting
authored
459 static int depth;
d91ecdf @sorear Serialization for objects of type Rat, FatRat, Complex, BigInteger, Int3...
authored
460 public void ObjRef(object o) {
d832c02 @sorear Second draft of serialization code
authored
461 int id;
462 SerUnit altunit;
ff557f5 @sorear Usability improvements for NIECZA_SER_TRACE, indenting
authored
463 if (Config.SerTrace) {
464 Console.WriteLine("{0}Saving {1} at {2}:", new string(' ',depth), o, wpointer);
465 }
466
d832c02 @sorear Second draft of serialization code
authored
467 if (o == null) { // null pointers are special
468 Byte((byte)SerializationCode.Null);
469 return;
470 }
471
472 if (reg.CheckWriteObject(unit, o, out altunit, out id)) {
8184302 @sorear Start draft of serialization/deserialization code
authored
473 if (altunit == unit) {
474 Byte((byte)SerializationCode.SelfRef);
475 } else {
d832c02 @sorear Second draft of serialization code
authored
476 int altcode;
477 if (!unit_to_offset.TryGetValue(altunit, out altcode)) {
69f2cee @sorear A scheme for serializing CLR wrappers (fixes #117)
authored
478 Byte(altunit.fake ?
479 (byte)SerializationCode.FakeUnitRef :
480 (byte)SerializationCode.NewUnitRef);
b25256f @sorear Add Serialize.cs to build, fix build errors
authored
481 String(altunit.name);
d832c02 @sorear Second draft of serialization code
authored
482 // save the hash too so stale refs can be caught
483 foreach (byte b in altunit.hash) Byte(b);
484
8184302 @sorear Start draft of serialization/deserialization code
authored
485 unit_to_offset[altunit] = usedunits++;
486 } else {
487 Byte((byte)SerializationCode.ForeignRef);
d832c02 @sorear Second draft of serialization code
authored
488 Int(altcode);
8184302 @sorear Start draft of serialization/deserialization code
authored
489 }
490 }
491 Int((int)id);
492 } else {
d832c02 @sorear Second draft of serialization code
authored
493 // must take responsibility for saving the tag
d91ecdf @sorear Serialization for objects of type Rat, FatRat, Complex, BigInteger, Int3...
authored
494 IFreeze f = o as IFreeze;
ff557f5 @sorear Usability improvements for NIECZA_SER_TRACE, indenting
authored
495 if (Config.SerTrace) depth++;
d91ecdf @sorear Serialization for objects of type Rat, FatRat, Complex, BigInteger, Int3...
authored
496 if (f != null) {
497 f.Freeze(this);
498 } else {
499 FallbackFreeze(o);
500 }
ff557f5 @sorear Usability improvements for NIECZA_SER_TRACE, indenting
authored
501 if (Config.SerTrace) depth--;
d91ecdf @sorear Serialization for objects of type Rat, FatRat, Complex, BigInteger, Int3...
authored
502 }
503 }
504
cdb4548 @sorear Checkpoint of global-variable inventory
authored
505 [Immutable]
be108f9 @sorear Thaw routines for P6opaque, DispatchEnt, double, int, Type, string, bool...
authored
506 internal static Type[] boxTypes = new Type[] {
507 null, typeof(Rat), typeof(FatRat), typeof(Complex),
7ae298f @sorear Make CC, LIHint serializable
authored
508 typeof(double), typeof(int), typeof(string), typeof(VarHash),
be108f9 @sorear Thaw routines for P6opaque, DispatchEnt, double, int, Type, string, bool...
authored
509 typeof(Variable[]), typeof(VarDeque), typeof(STable),
eba5eb3 @sorear Take a first crack at implementing constant folding
authored
510 typeof(BigInteger),
be108f9 @sorear Thaw routines for P6opaque, DispatchEnt, double, int, Type, string, bool...
authored
511 };
cdb4548 @sorear Checkpoint of global-variable inventory
authored
512 [Immutable]
be108f9 @sorear Thaw routines for P6opaque, DispatchEnt, double, int, Type, string, bool...
authored
513 internal static Func<P6opaque>[] boxCreate = new Func<P6opaque>[] {
514 P6opaque.Create, BoxObject<Rat>.Create, BoxObject<FatRat>.Create,
515 BoxObject<Complex>.Create, BoxObject<double>.Create,
516 BoxObject<int>.Create, BoxObject<string>.Create,
19ada5b @sorear Implement variable-length coding for serialization
authored
517 BoxObject<VarHash>.Create, BoxObject<Variable[]>.Create,
518 BoxObject<VarDeque>.Create, BoxObject<STable>.Create,
eba5eb3 @sorear Take a first crack at implementing constant folding
authored
519 BoxObject<BigInteger>.Create,
be108f9 @sorear Thaw routines for P6opaque, DispatchEnt, double, int, Type, string, bool...
authored
520 };
cdb4548 @sorear Checkpoint of global-variable inventory
authored
521 [Immutable]
d91ecdf @sorear Serialization for objects of type Rat, FatRat, Complex, BigInteger, Int3...
authored
522 static Type[] anyTypes = new Type[] {
523 typeof(string), typeof(P6any[]), typeof(Variable[]),
7ae298f @sorear Make CC, LIHint serializable
authored
524 typeof(string[]), typeof(CC[]),
3f80fca @sorear A procedure for serializing ContextHandler et al
authored
525 typeof(bool), typeof(int), typeof(double), typeof(Type),
d91ecdf @sorear Serialization for objects of type Rat, FatRat, Complex, BigInteger, Int3...
authored
526 };
527
528 void FallbackFreeze(object o) {
529 int ix = 0;
530 Type t = o.GetType();
fe6e595 @sorear Thaw for SimpleVariable, StashEnt
authored
531 while (ix != anyTypes.Length && anyTypes[ix] != t) ix++;
1c5bb04 @sorear Small refactor to AssemblyBuilder setup, start thaw coding
authored
532 Byte((byte)(((int)SerializationCode.String) + ix));
d91ecdf @sorear Serialization for objects of type Rat, FatRat, Complex, BigInteger, Int3...
authored
533
534 switch(ix) {
535 case 0:
536 String((string)o);
537 break;
538 case 1:
539 Refs((P6any[])o);
540 break;
541 case 2:
542 Refs((Variable[])o);
543 break;
544 case 3:
7ae298f @sorear Make CC, LIHint serializable
authored
545 Refs((string[])o);
d91ecdf @sorear Serialization for objects of type Rat, FatRat, Complex, BigInteger, Int3...
authored
546 break;
547 case 4:
7ae298f @sorear Make CC, LIHint serializable
authored
548 Refs((CC[])o);
fe6e595 @sorear Thaw for SimpleVariable, StashEnt
authored
549 break;
550 case 5:
7ae298f @sorear Make CC, LIHint serializable
authored
551 Byte((byte)((bool)o ? 1 : 0));
d91ecdf @sorear Serialization for objects of type Rat, FatRat, Complex, BigInteger, Int3...
authored
552 break;
3f80fca @sorear A procedure for serializing ContextHandler et al
authored
553 case 6:
7ae298f @sorear Make CC, LIHint serializable
authored
554 Int((int)o);
555 break;
556 case 7:
557 Double((double)o);
558 break;
559 case 8:
3f80fca @sorear A procedure for serializing ContextHandler et al
authored
560 String(((Type)o).AssemblyQualifiedName);
561 break;
d91ecdf @sorear Serialization for objects of type Rat, FatRat, Complex, BigInteger, Int3...
authored
562 default:
563 throw new NotImplementedException(t.FullName);
8184302 @sorear Start draft of serialization/deserialization code
authored
564 }
565 }
566 }
567
568 // Note that this interface only handles freezing - thaw is done using
569 // a switch statement.
1993029 @sorear Start implementing serialization for our objects
authored
570 public interface IFreeze {
8184302 @sorear Start draft of serialization/deserialization code
authored
571 void Freeze(FreezeBuffer fb);
572 }
fe6e595 @sorear Thaw for SimpleVariable, StashEnt
authored
573 // implement this if you need to copy in data from other objects, &c
574 interface IFixup {
eafdf64 @sorear Top removal: Parameter & Signature
authored
575 void Fixup(Compartment c);
fe6e595 @sorear Thaw for SimpleVariable, StashEnt
authored
576 }
8184302 @sorear Start draft of serialization/deserialization code
authored
577
578 class ThawBuffer {
579 byte[] data;
580 int rpointer;
b344401 @sorear ThawBuffer knows its setting
authored
581 internal readonly ObjectRegistry reg;
582 internal readonly Compartment setting;
8184302 @sorear Start draft of serialization/deserialization code
authored
583
d832c02 @sorear Second draft of serialization code
authored
584 SerUnit[] unit_map = new SerUnit[8];
8184302 @sorear Start draft of serialization/deserialization code
authored
585 int refed_units;
d832c02 @sorear Second draft of serialization code
authored
586 SerUnit unit;
8184302 @sorear Start draft of serialization/deserialization code
authored
587
fe6e595 @sorear Thaw for SimpleVariable, StashEnt
authored
588 List<IFixup> fixups_needed = new List<IFixup>();
2ff6525 @sorear Thaw routines for types
authored
589 List<object> revalidate = new List<object>();
fe6e595 @sorear Thaw for SimpleVariable, StashEnt
authored
590
288db48 @sorear Use precompiled IL when using a precompiled module
authored
591 public Type type;
64f16b5 @sorear Support multiple object directories
authored
592 public string file;
1d0c020 @sorear Forward compatibility for extending the set of kernel-defined types
authored
593 public int version;
288db48 @sorear Use precompiled IL when using a precompiled module
authored
594
b344401 @sorear ThawBuffer knows its setting
authored
595 internal ThawBuffer(Compartment setting, ObjectRegistry reg, SerUnit unit, byte[] data) {
596 this.data = data;
597 this.setting = setting;
598 this.reg = reg;
599 this.unit = unit;
8184302 @sorear Start draft of serialization/deserialization code
authored
600 }
601
fe6e595 @sorear Thaw for SimpleVariable, StashEnt
authored
602 internal void RunFixups() {
2ff6525 @sorear Thaw routines for types
authored
603 P6how.BulkRevalidate(revalidate);
fe6e595 @sorear Thaw for SimpleVariable, StashEnt
authored
604 foreach (IFixup f in fixups_needed)
eafdf64 @sorear Top removal: Parameter & Signature
authored
605 f.Fixup(setting);
fe6e595 @sorear Thaw for SimpleVariable, StashEnt
authored
606 fixups_needed.Clear();
607 }
608
609 internal void PushFixup(IFixup f) {
610 fixups_needed.Add(f);
611 }
612
2ff6525 @sorear Thaw routines for types
authored
613 internal void PushRevalidate(STable f) {
614 revalidate.Add(f);
615 }
616
b25256f @sorear Add Serialize.cs to build, fix build errors
authored
617 public byte Byte() { return data[rpointer++]; }
618
19ada5b @sorear Implement variable-length coding for serialization
authored
619 public long Long() {
620 int shift = 0;
621 long accum = 0;
622 while (true) {
623 byte b = Byte();
624 accum |= (((long)(b & 127)) << shift);
625 shift += 7;
626 if ((b & 128) == 0) {
3a82e24 @sorear Fix deserialization of 64-bit values between -2**62-1 and -2**63
authored
627 if ((b & 64) != 0 && shift < 64) {
19ada5b @sorear Implement variable-length coding for serialization
authored
628 accum |= ((-1L) << shift);
629 }
630 //Console.WriteLine("Read {0} end {1}", accum, rpointer);
631 return accum;
632 }
633 }
b25256f @sorear Add Serialize.cs to build, fix build errors
authored
634 }
635
19ada5b @sorear Implement variable-length coding for serialization
authored
636 public ulong ULong() {
637 int shift = 0;
638 ulong accum = 0;
639 while (true) {
640 byte b = Byte();
641 accum |= (((ulong)(b & 127)) << shift);
642 shift += 7;
643 if ((b & 128) == 0) {
644 //Console.WriteLine("Read {0} end {1}", accum, rpointer);
645 return accum;
646 }
647 }
b25256f @sorear Add Serialize.cs to build, fix build errors
authored
648 }
649
19ada5b @sorear Implement variable-length coding for serialization
authored
650 public short Short() {
651 return checked((short)Long());
652 }
653
654 public int Int() {
655 return checked((int)Long());
b25256f @sorear Add Serialize.cs to build, fix build errors
authored
656 }
657
8035d26 @sorear Thaw code for VarDeque, VarHash, BigInteger, Complex, Rat, FatRat
authored
658 public double Double() {
659 return BitConverter.Int64BitsToDouble(Long());
660 }
661
b25256f @sorear Add Serialize.cs to build, fix build errors
authored
662 public string String() {
663 int l = Int();
664
665 if (l < 0) return null;
666 char[] cb = new char[l];
667
668 for (int i = 0; i < l; i++)
19ada5b @sorear Implement variable-length coding for serialization
authored
669 cb[i] = (char)ULong();
b25256f @sorear Add Serialize.cs to build, fix build errors
authored
670
671 return new string(cb);
672 }
673
674 public byte[] Bytes(int k) {
675 byte[] buf = new byte[k];
676
677 for (int i = 0; i < k; i++)
678 buf[i] = Byte();
679
680 return buf;
681 }
682
1c5bb04 @sorear Small refactor to AssemblyBuilder setup, start thaw coding
authored
683 public List<T> RefsL<T>() where T : class {
684 int ct = Int();
685 if (ct < 0) return null;
686 List<T> ret = new List<T>();
687 for (int i = 0; i < ct; i++)
688 ret.Add((T) ObjRef());
689 return ret;
690 }
691
2ff6525 @sorear Thaw routines for types
authored
692 public int[] Ints() {
693 int ct = Int();
694 if (ct < 0) return null;
695 int[] ret = new int[ct];
696 for (int i = 0; i < ct; i++) ret[i] = Int();
697 return ret;
698 }
699
700 public string[] Strings() {
701 int ct = Int();
702 if (ct < 0) return null;
703 string[] ret = new string[ct];
704 for (int i = 0; i < ct; i++) ret[i] = String();
705 return ret;
706 }
707
1c5bb04 @sorear Small refactor to AssemblyBuilder setup, start thaw coding
authored
708 public T[] RefsA<T>() where T : class {
709 int ct = Int();
710 if (ct < 0) return null;
711 T[] ret = new T[ct];
712 for (int i = 0; i < ct; i++)
713 ret[i] = (T) ObjRef();
714 return ret;
715 }
716
604037a @sorear Fix generic thawing of array objects
authored
717 // used from ObjRef only so guaranteed non-null
718 T[] RefsARegister<T>() where T : class {
719 int ct = Int();
720 T[] ret = new T[ct];
721 Register(ret);
722 for (int i = 0; i < ct; i++)
723 ret[i] = (T) ObjRef();
724 return ret;
725 }
726
b25256f @sorear Add Serialize.cs to build, fix build errors
authored
727 public object ObjRef() {
8184302 @sorear Start draft of serialization/deserialization code
authored
728 var tag = (SerializationCode)Byte();
19ada5b @sorear Implement variable-length coding for serialization
authored
729 if (Config.SerTrace)
730 Console.WriteLine("Reading {0} from {1}...", tag, rpointer-1);
8184302 @sorear Start draft of serialization/deserialization code
authored
731 int i, j;
732 switch(tag) {
d832c02 @sorear Second draft of serialization code
authored
733 case SerializationCode.Null:
734 return null;
8035d26 @sorear Thaw code for VarDeque, VarHash, BigInteger, Complex, Rat, FatRat
authored
735
8184302 @sorear Start draft of serialization/deserialization code
authored
736 case SerializationCode.ForeignRef:
737 i = Int();
738 j = Int();
d832c02 @sorear Second draft of serialization code
authored
739 return unit_map[i].bynum[j];
8035d26 @sorear Thaw code for VarDeque, VarHash, BigInteger, Complex, Rat, FatRat
authored
740 case SerializationCode.SelfRef:
741 i = Int();
742 return unit.bynum[i];
8184302 @sorear Start draft of serialization/deserialization code
authored
743 case SerializationCode.NewUnitRef:
69f2cee @sorear A scheme for serializing CLR wrappers (fixes #117)
authored
744 return LoadNewUnit(false);
745 case SerializationCode.FakeUnitRef:
746 return LoadNewUnit(true);
8035d26 @sorear Thaw code for VarDeque, VarHash, BigInteger, Complex, Rat, FatRat
authored
747
1c5bb04 @sorear Small refactor to AssemblyBuilder setup, start thaw coding
authored
748 case SerializationCode.RuntimeUnit:
749 return RuntimeUnit.Thaw(this);
2671ab4 @sorear Add thaw routine for SubInfo
authored
750 case SerializationCode.SubInfo:
751 return SubInfo.Thaw(this);
2ff6525 @sorear Thaw routines for types
authored
752 case SerializationCode.STable:
753 return STable.Thaw(this);
fe6e595 @sorear Thaw for SimpleVariable, StashEnt
authored
754 case SerializationCode.StashEnt:
755 return StashEnt.Thaw(this);
8035d26 @sorear Thaw code for VarDeque, VarHash, BigInteger, Complex, Rat, FatRat
authored
756 case SerializationCode.Rat:
757 return Rat.Thaw(this);
758 case SerializationCode.FatRat:
759 return FatRat.Thaw(this);
760 case SerializationCode.Complex:
761 return Complex.Thaw(this);
762 case SerializationCode.BigInteger:
763 return BigInteger.Thaw(this);
764 case SerializationCode.VarDeque:
765 return VarDeque.Thaw(this);
766 case SerializationCode.VarHash:
767 return VarHash.Thaw(this);
be108f9 @sorear Thaw routines for P6opaque, DispatchEnt, double, int, Type, string, bool...
authored
768 case SerializationCode.DispatchEnt:
769 return DispatchEnt.Thaw(this);
8035d26 @sorear Thaw code for VarDeque, VarHash, BigInteger, Complex, Rat, FatRat
authored
770 //case SerializationCode.RxFrame:
771 // return RxFrame.Thaw(this);
2ff6525 @sorear Thaw routines for types
authored
772 case SerializationCode.P6how:
773 return P6how.Thaw(this);
7ae298f @sorear Make CC, LIHint serializable
authored
774 case SerializationCode.CC:
775 return CC.Thaw(this);
e7d3f3f @sorear Reimplement regex_infix:<|> table generation
authored
776 case SerializationCode.AltInfo:
777 return AltInfo.Thaw(this);
10ba66d @sorear Turn Signatures into real objects
authored
778 case SerializationCode.Signature:
779 return Signature.Thaw(this);
780 case SerializationCode.Parameter:
781 return Parameter.Thaw(this);
8035d26 @sorear Thaw code for VarDeque, VarHash, BigInteger, Complex, Rat, FatRat
authored
782
3f80fca @sorear A procedure for serializing ContextHandler et al
authored
783 case SerializationCode.ReflectObj:
784 return ReflectObj.Thaw(this);
be108f9 @sorear Thaw routines for P6opaque, DispatchEnt, double, int, Type, string, bool...
authored
785 case SerializationCode.P6opaque:
786 return P6opaque.Thaw(this);
9b6504a @sorear Thaw routines for Frame
authored
787 case SerializationCode.Frame:
788 return Frame.Thaw(this);
8035d26 @sorear Thaw code for VarDeque, VarHash, BigInteger, Complex, Rat, FatRat
authored
789 //Cursor,
790
be108f9 @sorear Thaw routines for P6opaque, DispatchEnt, double, int, Type, string, bool...
authored
791 case SerializationCode.String:
792 return Register(String());
793 case SerializationCode.ArrP6any:
604037a @sorear Fix generic thawing of array objects
authored
794 return RefsARegister<P6any>();
be108f9 @sorear Thaw routines for P6opaque, DispatchEnt, double, int, Type, string, bool...
authored
795 case SerializationCode.ArrVariable:
604037a @sorear Fix generic thawing of array objects
authored
796 return RefsARegister<Variable>();
7ae298f @sorear Make CC, LIHint serializable
authored
797 case SerializationCode.ArrString:
604037a @sorear Fix generic thawing of array objects
authored
798 return RefsARegister<string>();
7ae298f @sorear Make CC, LIHint serializable
authored
799 case SerializationCode.ArrCC:
604037a @sorear Fix generic thawing of array objects
authored
800 return RefsARegister<CC>();
be108f9 @sorear Thaw routines for P6opaque, DispatchEnt, double, int, Type, string, bool...
authored
801 case SerializationCode.Boolean:
802 return Register(Byte() != 0);
803 case SerializationCode.Int:
804 return Register(Int());
805 case SerializationCode.Double:
806 return Register(Double());
807 case SerializationCode.Type:
808 return Register(Type.GetType(String(), true));
8035d26 @sorear Thaw code for VarDeque, VarHash, BigInteger, Complex, Rat, FatRat
authored
809
40e1779 @sorear Split ListVariable out of SimpleVariable
authored
810 case SerializationCode.ListVariable:
811 return ListVariable.Thaw(this);
812 case SerializationCode.RWVariable:
813 case SerializationCode.RWVariable_1:
814 return RWVariable.Thaw(this,
815 (int)tag - (int)SerializationCode.RWVariable);
054561b @sorear Thaw code for all LAD, Variable, ViviHook subclasses
authored
816 case SerializationCode.SubstrLValue:
817 return SubstrLValue.Thaw(this);
818 case SerializationCode.TiedVariable:
819 return TiedVariable.Thaw(this);
037f4b7 @sorear Make * a "blackhole" container that ignores writes
authored
820 case SerializationCode.Blackhole:
821 return Builtins.Blackhole.Thaw(this);
054561b @sorear Thaw code for all LAD, Variable, ViviHook subclasses
authored
822
823 case SerializationCode.SubViviHook:
824 return SubViviHook.Thaw(this);
825 case SerializationCode.ArrayViviHook:
826 return ArrayViviHook.Thaw(this);
827 case SerializationCode.NewArrayViviHook:
828 return NewArrayViviHook.Thaw(this);
829 case SerializationCode.HashViviHook:
830 return HashViviHook.Thaw(this);
831 case SerializationCode.NewHashViviHook:
832 return NewHashViviHook.Thaw(this);
833
834 case SerializationCode.LADNone:
835 return Register(new LADNone());
836 case SerializationCode.LADNull:
837 return Register(new LADNull());
838 case SerializationCode.LADDot:
839 return Register(new LADDot());
840 case SerializationCode.LADDispatcher:
841 return Register(new LADDispatcher());
842 case SerializationCode.LADImp:
843 return Register(new LADImp());
844 case SerializationCode.LADStr:
845 return LADStr.Thaw(this);
846 case SerializationCode.LADStrNoCase:
847 return LADStrNoCase.Thaw(this);
848 case SerializationCode.LADMethod:
849 return LADMethod.Thaw(this);
850 case SerializationCode.LADParam:
851 return LADParam.Thaw(this);
b8a5ff0 @sorear Treat quantifiers as partially declarative whenever at all possible
authored
852 case SerializationCode.LADQuant:
853 return LADQuant.Thaw(this);
054561b @sorear Thaw code for all LAD, Variable, ViviHook subclasses
authored
854 case SerializationCode.LADSequence:
855 return LADSequence.Thaw(this);
856 case SerializationCode.LADAny:
857 return LADAny.Thaw(this);
858 case SerializationCode.LADCC:
859 return LADCC.Thaw(this);
8184302 @sorear Start draft of serialization/deserialization code
authored
860 default:
1c5bb04 @sorear Small refactor to AssemblyBuilder setup, start thaw coding
authored
861 throw new ThawException("unexpected object tag " + tag);
8184302 @sorear Start draft of serialization/deserialization code
authored
862 }
863 }
d832c02 @sorear Second draft of serialization code
authored
864
1c5bb04 @sorear Small refactor to AssemblyBuilder setup, start thaw coding
authored
865 // call this when thawing any new object
be108f9 @sorear Thaw routines for P6opaque, DispatchEnt, double, int, Type, string, bool...
authored
866 internal object Register(object o) {
1c5bb04 @sorear Small refactor to AssemblyBuilder setup, start thaw coding
authored
867 reg.RegisterThawed(unit, o);
be108f9 @sorear Thaw routines for P6opaque, DispatchEnt, double, int, Type, string, bool...
authored
868 return o;
1c5bb04 @sorear Small refactor to AssemblyBuilder setup, start thaw coding
authored
869 }
870
69f2cee @sorear A scheme for serializing CLR wrappers (fixes #117)
authored
871 object LoadNewUnit(bool fake) {
d832c02 @sorear Second draft of serialization code
authored
872 string name = String();
873 if (refed_units == unit_map.Length)
874 Array.Resize(ref unit_map, refed_units * 2);
875
69f2cee @sorear A scheme for serializing CLR wrappers (fixes #117)
authored
876 SerUnit su = reg.LoadUnit(name, fake);
d832c02 @sorear Second draft of serialization code
authored
877 unit_map[refed_units++] = su;
878
879 byte[] hash = Bytes(su.hash.Length);
880
881 for (int i = 0; i < hash.Length; i++)
882 if (hash[i] != su.hash[i])
883 goto badhash;
884
885 int ix = Int();
886 return su.bynum[ix];
887
888 badhash:
eee0cbb @sorear Add framework for detecting stale precompiled modules
authored
889 throw new ThawException(string.Format("Hash mismatch for " +
890 "unit {0} referenced from {1}, wanted {2}, got {3}",
891 su.name, unit.name, Utils.HashToStr(unit.hash),
892 Utils.HashToStr(su.hash)));
d832c02 @sorear Second draft of serialization code
authored
893 }
894 }
895
896 // Thrown to indicate data format problems in the serialized stream
897 // Not necessarily bugs; could also indicate stale files, including
898 // cases where the data format is changed and cases where a depended
899 // file was recreated
900 class ThawException : Exception {
901 public ThawException(string s) : base(s) { }
902 public ThawException() : base() { }
8184302 @sorear Start draft of serialization/deserialization code
authored
903 }
3f80fca @sorear A procedure for serializing ContextHandler et al
authored
904
905 public class ReflectObj : IFreeze {
c5fd4d7 @sorear Top removal: context handlers
authored
906 internal Compartment setting; // set on installation in WrapHandler0 et al
3f80fca @sorear A procedure for serializing ContextHandler et al
authored
907 protected virtual object[] GetData() { return new object[0]; }
908 protected virtual void SetData(object[] a) { }
909 void IFreeze.Freeze(FreezeBuffer fb) {
910 fb.Byte((byte)SerializationCode.ReflectObj);
911 fb.String(GetType().AssemblyQualifiedName);
912 fb.Refs(GetData());
913 }
914
915 internal static ReflectObj Thaw(ThawBuffer tb) {
ead51d9 @sorear Skeleton of -gen-app; use named methods for builtin methods to reduce fr...
authored
916 string nm = tb.String();
917 if (Backend.cross_level_load)
918 nm = nm.Replace("Run.", "");
919 Type nt = Type.GetType(nm, true);
3f80fca @sorear A procedure for serializing ContextHandler et al
authored
920 ReflectObj n = (ReflectObj)
f0788e8 @sorear Small bugfixes, use correct form of Invoke for .net
authored
921 nt.GetConstructor(new Type[0]).Invoke(new object[0]);
3f80fca @sorear A procedure for serializing ContextHandler et al
authored
922 tb.Register(n);
c5fd4d7 @sorear Top removal: context handlers
authored
923 n.setting = tb.setting;
3f80fca @sorear A procedure for serializing ContextHandler et al
authored
924 n.SetData(tb.RefsA<object>());
925 return n;
926 }
927 }
8184302 @sorear Start draft of serialization/deserialization code
authored
928 }
Something went wrong with that request. Please try again.