internal MondProgram(byte[] bytecode, IEnumerable <double> numbers, IEnumerable <string> strings, MondDebugInfo debugInfo = null) { Bytecode = bytecode; Numbers = numbers.Select(MondValue.Number).ToList(); Strings = strings.Select(MondValue.String).ToList(); DebugInfo = debugInfo; }
public static int FirstLineNumber(MondDebugInfo debugInfo) { var lines = debugInfo.Lines; var firstLineNumber = lines.Count > 0 ? lines[0].LineNumber : 1; return(firstLineNumber); }
private static bool IsMissingDebugInfo(MondDebugInfo debugInfo) { return (debugInfo == null || debugInfo.SourceCode == null || debugInfo.Functions == null || debugInfo.Lines == null || debugInfo.Statements == null || debugInfo.Scopes == null); }
internal MondDebugContext( MondState state, MondProgram program, int address, Frame locals, Frame args, ReturnAddress[] callStack, int callStackTop, int callStackBottom) { _state = state; _address = address; _locals = locals; _args = args; Program = program; DebugInfo = program.DebugInfo; CallStack = GenerateCallStack(address, callStack, callStackTop, callStackBottom).AsReadOnly(); _localObject = CreateLocalObject(); }
internal MondProgram(int[] bytecode, IList <double> numbers, IList <string> strings, MondDebugInfo debugInfo = null) { Bytecode = bytecode; Numbers = new MondValue[numbers.Count]; for (var i = 0; i < Numbers.Length; i++) { Numbers[i] = MondValue.Number(numbers[i]); } Strings = new MondValue[strings.Count]; for (var i = 0; i < Strings.Length; i++) { Strings[i] = MondValue.String(strings[i]); } DebugInfo = debugInfo; }
public static int FirstLineNumber(MondDebugInfo debugInfo) { var lines = debugInfo.Lines; var firstLineNumber = lines.Count > 0 ? lines[0].LineNumber : 1; return firstLineNumber; }
/// <summary> /// Loads Mond bytecode from the specified stream. /// </summary> /// <param name="stream">Stream to read from.</param> public static MondProgram LoadBytecode(Stream stream) { var reader = new BinaryReader(stream, Encoding.UTF8); if (reader.ReadUInt32() != MagicId) { throw new NotSupportedException("Stream data is not valid Mond bytecode."); } byte version; if ((version = reader.ReadByte()) != FormatVersion) { throw new NotSupportedException(string.Format("Wrong bytecode version. Expected 0x{0:X2}, got 0x{1:X2}.", FormatVersion, version)); } var hasDebugInfo = reader.ReadBoolean(); var stringCount = reader.ReadInt32(); var strings = new List <string>(stringCount); for (var i = 0; i < stringCount; ++i) { var len = reader.ReadInt32(); var buf = reader.ReadBytes(len); var str = Encoding.UTF8.GetString(buf); strings.Add(str); } var numberCount = reader.ReadInt32(); var numbers = new List <double>(numberCount); for (var i = 0; i < numberCount; ++i) { numbers.Add(reader.ReadDouble()); } var bytecodeLength = reader.ReadInt32(); var bytecode = new int[bytecodeLength]; for (var i = 0; i < bytecodeLength; i++) { bytecode[i] = reader.ReadInt32(); } MondDebugInfo debugInfo = null; if (hasDebugInfo) { var fileName = reader.ReadString(); var sourceCode = reader.ReadString(); var functionCount = reader.ReadInt32(); List <MondDebugInfo.Function> functions = null; if (functionCount >= 0) { functions = new List <MondDebugInfo.Function>(functionCount); for (var i = 0; i < functionCount; ++i) { var address = reader.ReadInt32(); var name = reader.ReadInt32(); var function = new MondDebugInfo.Function(address, name); functions.Add(function); } } var lineCount = reader.ReadInt32(); List <MondDebugInfo.Position> lines = null; if (lineCount >= 0) { lines = new List <MondDebugInfo.Position>(lineCount); for (var i = 0; i < lineCount; ++i) { var address = reader.ReadInt32(); var lineNumber = reader.ReadInt32(); var columnNumber = reader.ReadInt32(); var line = new MondDebugInfo.Position(address, lineNumber, columnNumber); lines.Add(line); } } var statementCount = reader.ReadInt32(); List <MondDebugInfo.Statement> statements = null; if (statementCount >= 0) { statements = new List <MondDebugInfo.Statement>(statementCount); for (var i = 0; i < statementCount; ++i) { var address = reader.ReadInt32(); var startLine = reader.ReadInt32(); var startColumn = reader.ReadInt32(); var endLine = reader.ReadInt32(); var endColumn = reader.ReadInt32(); var statement = new MondDebugInfo.Statement(address, startLine, startColumn, endLine, endColumn); statements.Add(statement); } } var scopeCount = reader.ReadInt32(); List <MondDebugInfo.Scope> scopes = null; if (scopeCount >= 0) { scopes = new List <MondDebugInfo.Scope>(scopeCount); for (var i = 0; i < scopeCount; ++i) { var id = reader.ReadInt32(); var depth = reader.ReadInt32(); var parentId = reader.ReadInt32(); var startAddress = reader.ReadInt32(); var endAddress = reader.ReadInt32(); var identCount = reader.ReadInt32(); var idents = new List <MondDebugInfo.Identifier>(identCount); for (var j = 0; j < identCount; ++j) { var name = reader.ReadInt32(); var isReadOnly = reader.ReadBoolean(); var frameIndex = reader.ReadInt32(); var idx = reader.ReadInt32(); idents.Add(new MondDebugInfo.Identifier(name, isReadOnly, frameIndex, idx)); } scopes.Add(new MondDebugInfo.Scope(id, depth, parentId, startAddress, endAddress, idents)); } } debugInfo = new MondDebugInfo(fileName, sourceCode, functions, lines, statements, scopes); } return(new MondProgram(bytecode, numbers, strings, debugInfo)); }