Esempio n. 1
0
 /// <summary>
 /// Creates a new <see cref="InterpreterSession"/> with the specified parameters
 /// </summary>
 /// <param name="opcodes">The sequence of parsed opcodes to execute</param>
 /// <param name="breakpoints">The table of breakpoints for the current executable</param>
 /// <param name="jumpTable">The jump table for loops and function declarations</param>
 /// <param name="functions">The mapping of functions for the current execution</param>
 /// <param name="definitions">The lookup table to check which functions are defined</param>
 /// <param name="stackFrames">The sequence of stack frames for the current execution</param>
 /// <param name="stdin">The input <see cref="ReadOnlyMemory{T}"/> to read characters from</param>
 /// <param name="machineState">The target machine state to use to run the script</param>
 /// <param name="executionToken">A <see cref="CancellationToken"/> that can be used to halt the execution</param>
 /// <param name="debugToken">A <see cref="CancellationToken"/> that is used to ignore/respect existing breakpoints</param>
 internal InterpreterSession(
     MemoryOwner <Brainf_ckOperator> opcodes,
     MemoryOwner <bool> breakpoints,
     MemoryOwner <int> jumpTable,
     MemoryOwner <Range> functions,
     MemoryOwner <ushort> definitions,
     MemoryOwner <StackFrame> stackFrames,
     ReadOnlyMemory <char> stdin,
     TuringMachineState machineState,
     CancellationToken executionToken,
     CancellationToken debugToken)
 {
     Opcodes        = opcodes;
     Breakpoints    = breakpoints;
     JumpTable      = jumpTable;
     Functions      = functions;
     Definitions    = definitions;
     StackFrames    = stackFrames;
     MachineState   = machineState;
     StdinBuffer    = new StdinBuffer(stdin);
     StdoutBuffer   = StdoutBuffer.Allocate();
     ExecutionToken = executionToken;
     DebugToken     = debugToken;
     Stopwatch      = new Stopwatch();
     SourceCode     = Brainf_ckParser.ExtractSource(opcodes.Span);
 }
Esempio n. 2
0
        private void HandleProcessExited(object sender, EventArgs e)
        {
            ProgramDescription dontCare;

            _launchedInstances.TryRemove(this, out dontCare);
            try
            {
                var process = sender as Process;
                System.Diagnostics.Debug.WriteLine("jzIntv EXIT: " + process.ExitCode);
                if ((process.ExitCode != 0) && (ErrorReporter != null))
                {
                    var errorMessage = new System.Text.StringBuilder().AppendFormat("jzIntv encountered an error when running\n  '{0}'\n\nand exited with error: {1}\n", ((Rom == null) || (Rom.Rom == null)) ? "<Invalid ROM>" : Rom.Rom.RomPath, process.ExitCode);
                    if (StderrBuffer.Any(l => !string.IsNullOrWhiteSpace(l)) || StdoutBuffer.Any(l => !string.IsNullOrWhiteSpace(l)))
                    {
                        errorMessage.AppendLine();
                    }
                    var maxLinesToReport = 12;
                    if (AppendDataFromBuffer(errorMessage, StderrBuffer, maxLinesToReport))
                    {
                        errorMessage.AppendLine();
                    }
                    else if (AppendDataFromBuffer(errorMessage, StdoutBuffer, maxLinesToReport))
                    {
                        errorMessage.AppendLine();
                    }
                    errorMessage.AppendFormat("Command line arguments:\n{0}", process.StartInfo.Arguments);
                    ErrorReporter(this, errorMessage.ToString(), process.ExitCode, null);
                }
            }
            catch (Exception)
            {
            }
        }
Esempio n. 3
0
 private void HandleOutputDataReceived(object sender, DataReceivedEventArgs e)
 {
     System.Diagnostics.Debug.WriteLine("jzIntv STDOUT: " + e.Data);
     StdoutBuffer.Enqueue(e.Data);
 }