Example #1
0
        public void Test_CreateInterpreter_IsInitialized()
        {
            InputOutputMock      ioMock      = new InputOutputMock();
            BrainfuckInterpreter interpreter = BrainfuckInterpreter.Create(ioMock);
            string input = "+++++--";

            char[] inputChars = input.ToCharArray();
            using (ICpu cpu = interpreter.CreateCpu(input))
            {
                Assert.IsNotNull(cpu.IO);
                Assert.Equals(cpu.IO, ioMock);
                Assert.IsNotNull(cpu.Rom);
                Assert.IsNotNull(cpu.IO);
                Assert.IsTrue(cpu.Rom.Address == 0);
                Assert.IsTrue(cpu.Rom.Size == input.Length);
                Assert.IsTrue(cpu.Memory.Address == 0);

                int i = 0;
                foreach (byte b in cpu.Rom.Dump())
                {
                    Assert.IsTrue(inputChars[i] == (char)b);
                    i++;
                }
            }
        }
Example #2
0
        static async Task Main(string[] args)
        {
            var brainfuck = BrainfuckInterpreter.Create();

            ICpu cpu = brainfuck.CreateCpu("++++++++++[>+>+++>+++<<<-]>>++>++++++++++++>+[>+>+<<-]>+++++++++[<<<.>>>-]>[<<<.>>>-]<<<<<.>>>+++[>+>+<<-]>++++++[<<<.>>>-]>[<<<.>>>-]<<<<<.>>>+++++[>+>+<<-]>+++[<<<.>>>-]>[<<<.>>>-]<<<<<.>>>+++++++[>+>+<<-]>[<<<.>>>-]>[<<<.>>>-]<<<<<.>>>++++++++++[>++++++<-]>+++++<<<...>>>+++++.-.+++++++.---.+++++++++++++++++.<<<.>>>------------.-------------.+++++++++++++++++++++.-------------------.+++++++++++.<<<.>>>-----------.+++++++++++++++.------------.---.");
            await cpu.Process();

            Console.ReadKey();
            // dump the memory in screen.
            int i = 0;

            foreach (var @byte in cpu.Memory.Dump())
            {
                Console.Write($"[{i}] {@byte}");
                if (i == cpu.Memory.Address)
                {
                    Console.Write("*");
                }

                Console.WriteLine();
                i++;
            }

            Console.WriteLine("Finished.");
            Console.ReadKey();
        }
Example #3
0
        public MainPage()
        {
            _brainfuck = BrainfuckInterpreter.Create(this);
            this.InitializeComponent();
            RichEditBox richEditBox = BrainfuckInputRichTextBox;

            richEditBox.CharacterReceived += RichEditBox_CharacterReceived;
        }