Beispiel #1
0
 public InteropManager(CompilerEnvironment env)
 {
     this.env = env;
     rootEnv = env.Global.Environment();
     attributeHelper = env.AttributeHelper;
     typeRepresentationCache = new Map<CST.QualifiedTypeName, TypeRepresentation>();
 }
Beispiel #2
0
        public void TestHandleLabelAndReturnLine_whenLabelNameIncorrect_thenThrowException()
        {
            var compilerModel = new CompilerModel(null, null, null);
            var line          = "l2!:test";
            var env           = new CompilerEnvironment();

            compilerModel.HandleLabelAndReturnLine(line, env);
        }
Beispiel #3
0
        public void TestHandleDirective_whenSetIncorrectStackSegment_thenThrowException()
        {
            var compilerModel = new CompilerModel(null, null, null);
            var line          = ".sx2";
            var env           = new CompilerEnvironment();

            compilerModel.HandleDirective(line, env);
        }
Beispiel #4
0
        public void TestHandleDirective_whenSetTooBigDataSegment_thenThrowException()
        {
            var compilerModel = new CompilerModel(null, null, null);
            var line          = ".d4";
            var env           = new CompilerEnvironment();

            compilerModel.HandleDirective(line, env);
        }
Beispiel #5
0
        public void TestHandleLabelAndReturnLine_whenLabelNameStartsWithNumber_thenThrowException()
        {
            var compilerModel = new CompilerModel(null, null, null);
            var line          = "2:test";
            var env           = new CompilerEnvironment();

            compilerModel.HandleLabelAndReturnLine(line, env);
        }
Beispiel #6
0
        public void TestHandleCommand_whenCommandNotFound_thenThrowException()
        {
            var env           = new CompilerEnvironment();
            var line          = "test arg1";
            var commands      = new Dictionary <string, CommandProcessorFactory.CommandProcessor>();
            var compilerModel = new CompilerModel(null, null, commands);

            compilerModel.HandleCommand(line, env);
        }
Beispiel #7
0
        public void TestHandleLabelAndReturnLine_whenThereAreTwoSameLabels_thenThrowException()
        {
            var compilerModel = new CompilerModel(null, null, null);
            var line          = "l:test";
            var line2         = "l: test2";
            var env           = new CompilerEnvironment();

            compilerModel.HandleLabelAndReturnLine(line, env);
            compilerModel.HandleLabelAndReturnLine(line2, env);
        }
Beispiel #8
0
        public void TestHandleDirective_whenGoToIncorrectAddress_thenThrowException()
        {
            var compilerModel = new CompilerModel(null, null, null);
            var line          = ".org 10x00";
            var env           = new CompilerEnvironment();

            env.CurrentAddress = 10;

            compilerModel.HandleDirective(line, env);
        }
Beispiel #9
0
        public void TestHandleLabelAndReturnLine_whenThereIsNoLabel_thenReturnTheSameLine()
        {
            var compilerModel = new CompilerModel(null, null, null);
            var line          = "test";
            var env           = new CompilerEnvironment();

            var result = compilerModel.HandleLabelAndReturnLine(line, env);

            Assert.AreSame(result, line);
            Assert.AreEqual(env.GetLabelsCount(), 0);
        }
Beispiel #10
0
        public void TestHandleDirective_whenSetStackSegment_thenSegmentChanged()
        {
            var compilerModel = new CompilerModel(null, null, null);
            var line          = ".S2";
            var env           = new CompilerEnvironment();

            env.DefaultStackSegment = 1;

            compilerModel.HandleDirective(line, env);

            Assert.AreEqual(env.DefaultStackSegment, 2);
        }
Beispiel #11
0
        public void TestHandleDirective_whenGoToAddress_thenAddressChanged()
        {
            var compilerModel = new CompilerModel(null, null, null);
            var line          = ".org 100";
            var env           = new CompilerEnvironment();

            env.CurrentAddress = 10;

            compilerModel.HandleDirective(line, env);

            Assert.AreEqual(env.CurrentAddress, 100);
        }
Beispiel #12
0
        public void RamCommandsTest()
        {
            var inputs = new List <string> {
                "NOT", "ADD", "SUB", "MUL", "DIV", "AND", "OR", "XOR", "CMP", "RD", "WR", "INC", "DEC", "ADC", "SUBB", "XCH"
            };

            var args = new List <string[]> {
                new [] { "q" },
                new [] { "1" },
                new [] { "2" },
                new [] { "3" },
                new [] { "4" },
                new [] { "5" },
                new [] { "6" },
                new [] { "7" },
                new [] { "#8" },
                new [] { "#9" },
                new [] { "#10" },
                new [] { "#11" },
                new [] { "#0xc" },
                new [] { "#13" },
                new [] { "#14" },
                new [] { "#0b1111" }
            };

            var outputs = new List <string> {
                "0101111000000110",
                "1000000010000110",
                "0100000001000110",
                "1100000011000110",
                "0010000000100110",
                "1010000010100110",
                "0110000001100110",
                "1110000011100110",
                "0001000000011110",
                "1001000010011110",
                "0101000001011110",
                "1101000011011110",
                "0011000000111110",
                "1011000010111110",
                "0111000001111110",
                "1111000011111110"
            };

            var env = new CompilerEnvironment();

            env.AddVariable("q", 122);

            Test(inputs, args, outputs, env);
        }
Beispiel #13
0
        public void TestHandleLabelAndReturnLine_whenThereIsLabel_thenReturnLineWithoutLabelAndAddLabelToEnv()
        {
            var compilerModel = new CompilerModel(null, null, null);
            var line          = "la2_-s:test";
            var env           = new CompilerEnvironment();
            int address       = 67;

            env.CurrentAddress = 67;

            var result = compilerModel.HandleLabelAndReturnLine(line, env);

            Assert.IsTrue(result.Equals("test"));
            Assert.AreEqual(env.GetLabelsCount(), 1);
            Assert.AreEqual(env.GetLabelAddress("la2_-s"), address);
        }
Beispiel #14
0
        public void JumpCommandsTest()
        {
            var inputs = new List <string> {
                "JNZ", "JNC", "JNS", "JNO", "JZ", "JC", "JS", "JO", "jmp", "call", "int"
            };

            var args = new List <string[]> {
                new [] { "5" },
                new [] { "label1" },
                new [] { "label2" },
                new [] { "6" },
                new [] { "7" },
                new [] { "0" },
                new [] { "12" },
                new [] { "18" },
                new [] { "0xFA" },
                new [] { "12" },
                new [] { "18" }
            };

            var outputs = new List <string> {
                "1010000000000100",
                "0011000000100100",
                "0110010101010100",
                "0110000000110100",
                "1110000000001100",
                "0000000000101100",
                "0011000000011100",
                "0100100000111100",

                "0101111100000010",
                "0011000000010010",
                "0100100000110010"
            };

            var env = new CompilerEnvironment();

            env.CurrentAddress = 12;
            env.AddAddressLabelToNewCommand("label1");
            env.DefaultCodeSegment = 2;
            env.CurrentAddress     = 166;
            env.AddAddressLabelToNewCommand("label2");
            env.DefaultCodeSegment = 0;

            Test(inputs, args, outputs, env);
        }
Beispiel #15
0
        public void TestHandleCommand_whenCommandWithoutArgs_thenArgumentsEmpty()
        {
            var env      = new CompilerEnvironment();
            var line     = "tEsT";
            var commands = new Dictionary <string, CommandProcessorFactory.CommandProcessor> {
                {
                    "test",
                    (args, innerEnv) => {
                        Assert.AreSame(innerEnv, env);
                        Assert.AreEqual(args.Length, 0);
                    }
                }
            };
            var compilerModel = new CompilerModel(null, null, commands);

            compilerModel.HandleCommand(line, env);
        }
Beispiel #16
0
        private void Test(List <string> inputs, List <string[]> args, List <string> outputs, CompilerEnvironment env = null)
        {
            var commands = CommandProcessorFactory.GetCommandProcessors();

            if (env == null)
            {
                env = new CompilerEnvironment();
            }
            for (int i = 0; i < inputs.Count; i++)
            {
                env.CurrentAddress = 0;
                commands[inputs[i].ToLower()](args[i], env);
                var memory = env.GetMemory();
                var str    = new string(memory[0].ToBinString().Reverse().ToArray()) + new string( memory[1].ToBinString().Reverse().ToArray());
                Assert.AreEqual(outputs[i], str, $"Command: {inputs[i]}");
            }
        }
Beispiel #17
0
        public void TestHandleCommand_whenCommandCorrect_thenArgumentsPassed()
        {
            var env      = new CompilerEnvironment();
            var line     = "tEsT arg1  , arg2 ";
            var commands = new Dictionary <string, CommandProcessorFactory.CommandProcessor> {
                {
                    "test",
                    (args, innerEnv) => {
                        Assert.AreSame(innerEnv, env);
                        Assert.AreEqual(args.Length, 2);
                        Assert.IsTrue(args[0].Equals("arg1"));
                        Assert.IsTrue(args[1].Equals("arg2"));
                    }
                }
            };
            var compilerModel = new CompilerModel(null, null, commands);

            compilerModel.HandleCommand(line, env);
        }
 /// <summary>
 /// Функция, вызывающаяся при заверщении компиляции.
 /// </summary>
 /// <param name="env">Окружение компилятора, сформировавшееся после компиляции.</param>
 public void CompilationComplete(CompilerEnvironment env)
 {
     _output.MemoryFormed(env.GetMemory());
     _form.AddLineToOutput("Компиляция завершена успешно!");
 }