internal int Undump(Stream stream, int sourceID, Table envTable, out bool hasUpvalues) { int baseAddress = m_RootChunk.Code.Count; SourceRef sourceRef = new SourceRef(sourceID, 0, 0, 0, 0, false); using (BinaryReader br = new BinDumpBinaryReader(stream, Encoding.UTF8)) { ulong headerMark = br.ReadUInt64(); if (headerMark != DUMP_CHUNK_MAGIC) { throw new ArgumentException("Not a MoonSharp chunk"); } int version = br.ReadInt32(); if (version != DUMP_CHUNK_VERSION) { throw new ArgumentException("Invalid version"); } hasUpvalues = br.ReadBoolean(); int len = br.ReadInt32(); int numSymbs = br.ReadInt32(); SymbolRef[] allSymbs = new SymbolRef[numSymbs]; for (int i = 0; i < numSymbs; i++) { allSymbs[i] = SymbolRef.ReadBinary(br); } for (int i = 0; i < numSymbs; i++) { allSymbs[i].ReadBinaryEnv(br, allSymbs); } for (int i = 0; i <= len; i++) { Instruction I = Instruction.ReadBinary(sourceRef, br, baseAddress, envTable, allSymbs); m_RootChunk.Code.Add(I); } return(baseAddress); } }
internal int Undump(Stream stream, int sourceID, Table envTable, out bool hasUpvalues) { int baseAddress = m_RootChunk.Code.Count; SourceRef sourceRef = new SourceRef(sourceID, 0, 0, 0, 0, false); var br = new BinDumpReader(stream); ulong headerMark = br.ReadUInt64(); if (headerMark != DUMP_CHUNK_MAGIC) { throw new ArgumentException("Not a MoonSharp chunk"); } int version = br.ReadByte(); if (version != DUMP_CHUNK_VERSION) { throw new ArgumentException("Invalid version"); } hasUpvalues = br.ReadBoolean(); int len = (int)br.ReadVarUInt32(); int numSymbs = (int)br.ReadVarUInt32(); SymbolRef[] allSymbs = new SymbolRef[numSymbs]; for (int i = 0; i < numSymbs; i++) { allSymbs[i] = SymbolRef.ReadBinary(br); } for (int i = 0; i < numSymbs; i++) { allSymbs[i].ReadBinaryEnv(br, allSymbs); } for (int i = 0; i <= len; i++) { Instruction I = Instruction.ReadBinary(br, baseAddress, envTable, allSymbs); m_RootChunk.Code.Add(I); } for (int i = 0; i <= len; i++) { var c = br.ReadByte(); if (c == 0) { m_RootChunk.SourceRefs.Add(sourceRef); } else if (c == 1) { m_RootChunk.SourceRefs.Add(m_RootChunk.SourceRefs[m_RootChunk.SourceRefs.Count - 1]); } else { m_RootChunk.SourceRefs.Add(SourceRef.ReadBinary(br, sourceID)); } } return(baseAddress); }