Beispiel #1
0
        public void MemoryCells()
        {
            const string script = ",>+++>>+";

            IReadOnlyMachineState machineState = Brainf_ckInterpreter
                                                 .CreateReleaseConfiguration()
                                                 .WithSource(script)
                                                 .WithStdin("a")
                                                 .TryRun().Value !.MachineState;

            Assert.AreEqual(machineState[0].Index, 0);
            Assert.AreEqual(machineState[0].Value, (ushort)'a');
            Assert.AreEqual(machineState[0].IsSelected, false);

            Assert.AreEqual(machineState[1].Index, 1);
            Assert.AreEqual(machineState[1].Value, 3);
            Assert.AreEqual(machineState[1].IsSelected, false);

            Assert.AreEqual(machineState[2].Index, 2);
            Assert.AreEqual(machineState[2].Value, 0);
            Assert.AreEqual(machineState[2].IsSelected, false);

            Assert.AreEqual(machineState[3].Index, 3);
            Assert.AreEqual(machineState[3].Value, 1);
            Assert.AreEqual(machineState[3].IsSelected, true);
        }
Beispiel #2
0
        /// <summary>
        /// Creates a new <see cref="Brainf_ckMemoryCellChunk"/> instance with the specified parameters
        /// </summary>
        /// <param name="state">The input <see cref="IReadOnlyMachineState"/> instance to read data from</param>
        /// <param name="offset">The offset of the first memory cell in the chunk with respect to the source memory state</param>
        public Brainf_ckMemoryCellChunk(IReadOnlyMachineState state, int offset)
        {
            BaseOffset = offset;

            _Zero  = state[BaseOffset];
            _One   = state[BaseOffset + 1];
            _Two   = state[BaseOffset + 2];
            _Three = state[BaseOffset + 3];

            _SelectedIndex = state.Position;
        }
 /// <summary>
 /// Creates a new <see cref="InterpreterResult"/> instance with the specified parameters
 /// </summary>
 /// <param name="sourceCode">The original source code for the interpreted script</param>
 /// <param name="exitCode">The exit code of the interpreter result</param>
 /// <param name="haltingInfo">The debug info for the current script, if available</param>
 /// <param name="machineState">The resulting memory state after running the script</param>
 /// <param name="functions">The sequence of functions that were defined when running the script</param>
 /// <param name="stdin">The stdin buffer used to run the script</param>
 /// <param name="stdout">The resulting stdout buffer after running the script</param>
 /// <param name="elapsedTime">The execution time for the interpreted script</param>
 /// <param name="totalOperations">The total numer of evaluated operators for the current result</param>
 internal InterpreterResult(
     string sourceCode,
     ExitCode exitCode,
     HaltedExecutionInfo?haltingInfo,
     IReadOnlyMachineState machineState,
     IReadOnlyList <FunctionDefinition> functions,
     string stdin,
     string stdout,
     TimeSpan elapsedTime,
     int totalOperations)
 {
     SourceCode      = sourceCode;
     ExitCode        = exitCode;
     HaltingInfo     = haltingInfo;
     MachineState    = machineState;
     Functions       = functions;
     Stdin           = stdin;
     Stdout          = stdout;
     ElapsedTime     = elapsedTime;
     TotalOperations = totalOperations;
 }