/// <summary> /// Reads a symbolref from a binary stream /// </summary> internal static SymbolRef ReadBinary(BinDumpReader br) { SymbolRef that = new SymbolRef(); that.i_Type = (SymbolRefType)br.ReadByte(); that.i_Index = br.ReadVarInt32(); that.i_Name = br.ReadString(); return(that); }
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); }