Example #1
0
        private void assemble()
        {
            txtErrorsAndWarnings.Text = string.Empty;

            var assembler = new Assembler();
            var lines = txtInput.Text.Split('\n');
            try
            {
                var gekkoAssembly = assembler.AssembleAllLines(lines);

                ICodeWriter writer;

                if (cmbType.SelectedItem.ToString() == "Gecko")
                {
                    writer = new GeckoWriter();
                }
                else if (cmbType.SelectedItem.ToString() == "Action Replay")
                {
                    writer = new ActionReplayWriter();
                }
                else
                {
                    writer = new ByteCodeWriter();
                }

                var code = writer.WriteCode(gekkoAssembly);

                txtOutput.Text = string.Join(Environment.NewLine, code.Lines);
                txtErrorsAndWarnings.Text = string.Join(Environment.NewLine, code.Errors.Select(x => $"Error: {x}").Concat(code.Warnings.Select(x => $"Warning: {x}")));
            }
            catch (Exception ex)
            {
                txtErrorsAndWarnings.Text = $"Error: {ex.Message}";
            }
        }
        private void Test(string input, string output, string message)
        {
            var inputLines = input.Replace("\r", "").Split('\n');
            var outputLines = output.Replace("\r", "").Split('\n');

            var assembler = new Assembler();
            var gekkoAssembly = assembler.AssembleAllLines(inputLines);

            var writer = new ActionReplayWriter();
            var code = writer.WriteCode(gekkoAssembly);
            var actualLines = code.Lines;

            for (var i = 0; i < Math.Min(outputLines.Length, actualLines.Count); ++i)
            {
                Assert.AreEqual(outputLines[i], actualLines[i], $"Line {i + 1}: {message}");
            }
        }