示例#1
0
        public void TestParseList_Valid_Code_2_With_Labels()
        {
            List <string> asm = new List <string>
            {
                "MVI A,0x5",
                "JNZ LABEL",
                "NOP",
                "LABEL: OUT 0x3",
                "HLT"
            };

            List <string> expected_bin = new List <string>
            {
                "00111110",
                "00000101",
                "11000010",
                "00000110",
                "00000000",
                "00000000",
                "11010011",
                "00000011",
                "01110110"
            };

            List <string> compiled_bin = Assemble.Parse(asm);

            Assert.AreEqual(expected_bin.Count, compiled_bin.Count);

            for (int i = 0; i < compiled_bin.Count; i++)
            {
                Assert.AreEqual(expected_bin[i], compiled_bin[i]);
            }
        }
示例#2
0
        public void TestParseList_Valid_Code_1()
        {
            List <string> asm = new List <string>
            {
                "MVI A,0x5",
                "MOV B,A",
                "HLT"
            };

            List <string> expected_bin = new List <string>
            {
                "00111110",
                "00000101",
                "01000111",
                "01110110"
            };

            List <string> compiled_bin = Assemble.Parse(asm);

            Assert.AreEqual(expected_bin.Count, compiled_bin.Count);

            for (int i = 0; i < compiled_bin.Count; i++)
            {
                Assert.AreEqual(expected_bin[i], compiled_bin[i]);
            }
        }
示例#3
0
        public void TestParseList_Valid_Code_6()
        {
            List <string> asm = new List <string>
            {
                "HLT 0x0",
                "..."
            };
            List <string> expected_bin = new List <string>
            {
                "11110000",
                "00000000",
                "00000000",
                "00000000",
                "00000000",
                "00000000",
                "00000000",
                "00000000",
                "00000000",
                "00000000",
                "00000000",
                "00000000",
                "00000000",
                "00000000",
                "00000000",
                "00000000",
            };

            List <string> compiled_bin = Assemble.Parse(asm);

            for (int i = 0; i <= 15; i++)
            {
                Assert.AreEqual(expected_bin[i], compiled_bin[i]);
            }
        }
示例#4
0
        public IActionResult Post([FromBody] AssemblePacket assemblePacket)
        {
            try
            {
                if (assemblePacket.Emulator.Equals("SAP1"))
                {
                    return(Ok(Assemble.Parse(assemblePacket.CodeList, assemblePacket.SetName)));
                }
                else if (assemblePacket.Emulator.Equals("SAP2"))
                {
                    return(Ok(SAP2_Assembler.Assemble.Parse(assemblePacket.CodeList, assemblePacket.SetName)));
                }

                //Not a set we have trigger that catch block below
                throw new Exception();
            }
            catch (ParseException pe)
            {
                return(BadRequest(pe.Message + " " + pe.InnerException.Message));
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
            }
        }
示例#5
0
        public void Bike_Manufacture_ReturnTrue()
        {
            var produce          = new Produce();
            var assemble         = new Assemble();
            var bike             = new Bike(produce, assemble);
            var calculatedResult = bike.Manufacture();

            Assert.That(calculatedResult, Is.True);
        }
示例#6
0
        public void Car_Manufacture_ReturnsTrue()
        {
            var produce          = new Produce();
            var assemble         = new Assemble();
            var car              = new Car(produce, assemble);
            var calculatedResult = car.Manufacture();

            Assert.That(calculatedResult, Is.True);
        }
示例#7
0
        void OpenFile(string file, FileTabPanel docView = null)
        {
            //如果已经打开则忽略
            var view = this.m_documentViews.FirstOrDefault(x => x.FileName == file);

            if (view != null)
            {
                view.Activate();
                return;
            }
            if (this.m_documentViews.Count(x => x.FileName == file) > 0)
            {
                return;
            }

            var editorContext = Assemble.CreateEditor(file);

            if (editorContext == null)
            {
                MessageBox.Show(string.Format("不能打开文件", file));
                return;
            }

            editorContext.EditorContainer.Editor.Dock = DockStyle.Fill;
            if (!File.Exists(file))
            {
                MessageBox.Show(string.Format("不能打开文件", file));
                return;
            }

            var text = File.ReadAllText(file);

            editorContext.EditorContainer.Text = text;
            var model = editorContext.Model;

            var page = docView == null ? new FileTabPanel() : docView;

            page.Name     = (Path.GetFileName(file));
            page.TabText  = page.Text = page.Name;
            page.FileName = file;

            //page.Name = model.File;
            page.Tag         = model.FileId;
            page.ToolTipText = model.File;
            page.Controls.Add(editorContext.EditorContainer.Editor);
            page.Tag = editorContext.Model.FileId;
            page.Show(this.m_documentViewContainer, DockState.Document);

            editorContext.Model.Changed += new Core.Infrastructure.Model.OnChanged(Model_Changed);
            editorContext.Model.Saved   += new OnSaved(Model_Saved);
            //this.tabControl.TabPages.Add(page);
            //this.tabControl.SelectedTab = page;
            GlobalService.EditorContextManager.CurrentContext = editorContext;
            this.AddView(page);
            //GlobalService.ModelManager.Regist(editorContext.Model);
        }
示例#8
0
 public FrmAssemble(Assemble assemble, Action callBack) : this(callBack)
 {
     this.oldAssemble  = assemble;
     guna2TxtHote.Text = assemble.Hote;
     guna2DateTimePickerDatePremiereRencontre.Text = assemble.DateAssemble.ToString();
     guna2DateTimePickerHeureAssemble.Text         = assemble.HeureAssemble.ToString();
     guna2ComboBoxTypeAssemble.Text = assemble.TypeAssemble.ToString();
     guna2TxtSanctionRetard.Text    = assemble.SanctionRetard.ToString();
     guna2TxtSanctionAbsence.Text   = assemble.SanctionAbsence.ToString();
 }
示例#9
0
        public static Assembly LoadAssembly <T>()
        {
#if !WINRT
            Assembly assembly = typeof(T).Assembly;
#else
            Assemble assembly = typeof(T).GetTypeInfo().Assembly;
#endif

            return(assembly);
        }
示例#10
0
        public void Add(Assemble assemble)
        {
            var index = assembles.IndexOf(assemble);

            if (index >= 0)
            {
                throw new DuplicateNameException("This assembly hote already exists !");
            }
            assembles.Add(assemble);
            Save();
        }
示例#11
0
    public Vector3 GetTargetPoint(Assemble input)
    {
        int length = NPCList.Count;
        int index  = NPCList.IndexOf(input);

        if (length == 1)
        {
            return(assemblyPoint.position);
        }
        else
        {
            return(assemblyPoint.position + offsetRadius * new Vector3(Mathf.Cos(2 * Mathf.PI / length * index), Mathf.Sin(2 * Mathf.PI / length * index)));
        }
    }
示例#12
0
        public void TestParseList_Valid_Code_5()
        {
            List <string> asm = new List <string>
            {
                "LDA 0xD",
                "ADD 0xE",
                "ADD 0xF",
                "OUT 0x0",
                "OUT 0x0",
                "OUT 0x0",
                "OUT 0x0",
                "OUT 0x0",
                "OUT 0x0",
                "OUT 0x0",
                "OUT 0x0",
                "HLT 0x0",
                "HLT 0x0",
                "...",
                "0x2 0x8",
                "0x0 0xF",
                "0x0 0xD"
            };
            List <string> expected_bin = new List <string>
            {
                "00001101",
                "00011110",
                "00011111",
                "11100000",
                "11100000",
                "11100000",
                "11100000",
                "11100000",
                "11100000",
                "11100000",
                "11100000",
                "11110000",
                "11110000",
                "00101000",
                "00001111",
                "00001101",
            };

            List <string> compiled_bin = Assemble.Parse(asm);

            for (int i = 0; i <= 15; i++)
            {
                Assert.AreEqual(expected_bin[i], compiled_bin[i]);
            }
        }
示例#13
0
        public void Set(Assemble oldAssemble, Assemble newAssemble)
        {
            var oldIndex = assembles.IndexOf(oldAssemble);
            var newIndex = assembles.IndexOf(newAssemble);

            if (oldIndex < 0)
            {
                throw new KeyNotFoundException("The assembly doesn't exists !");
            }
            if (newIndex >= 0 && oldIndex != newIndex)
            {
                throw new DuplicateNameException("This assembly hote already exists !");
            }
            assembles[oldIndex] = newAssemble;
            Save();
        }
示例#14
0
        public void TestParseList_Invalid_Code_2()
        {
            List <string> asm = new List <string>
            {
                "...",
                "jjj 0xF"
            };

            try
            {
                // This should fail and throw an execption, if it doesn't it will fail
                _ = Assemble.Parse(asm);
                Assert.Fail();
            }
            catch (ParseException)
            {
                Assert.IsTrue(true);
            }
        }
示例#15
0
        public void Test_Non_16_Ben_Eater()
        {
            List <string> asm = new List <string>
            {
                "LDI 0xA",
                "ADD 0xA",
                "HLT 0x0",
            };

            try
            {
                Assemble.Parse(asm, "BenEater");
                Assert.Fail();
            }
            catch (Exception)
            {
                Assert.IsTrue(true);
            }
        }
示例#16
0
        public void Test_Non_16_Malvino()
        {
            List <string> asm = new List <string>
            {
                "LDA 0xA",
                "ADD 0xA",
                "HLT 0x0",
            };

            try
            {
                Assemble.Parse(asm, "Malvino");
                Assert.Fail();
            }
            catch (Exception)
            {
                Assert.IsTrue(true);
            }
        }
示例#17
0
        public void Test_MalvinoCodes_1()
        {
            List <string> asm = new List <string>
            {
                "LDA 0xF",
                "OUT 0x0",
                "HLT 0x0",
                "...    ",
                "0xA 0xA"
            };

            try
            {
                Assemble.Parse(asm, "Malvino");
            }
            catch (Exception e)
            {
                Assert.Fail(e.ToString());
            }
        }
示例#18
0
        public void TestParseList_Valid_Code_With_Label_Decl_Forgotten()
        {
            List <string> asm = new List <string>
            {
                "MVI A,0x5",
                "JNZ LABEL",
                "NOP",
                "OUT 0x3",
                "HLT"
            };

            try
            {
                _ = Assemble.Parse(asm);
                Assert.Fail();
            }
            catch (ParseException)
            {
                Assert.IsTrue(true);
            }
        }
示例#19
0
        public void Test_MalvinoCodes_2()
        {
            List <string> asm = new List <string>
            {
                "LDA 0xF",
                "STA 0xE",
                "OUT 0x0",
                "HLT 0x0",
                "...    ",
                "0x0 0x0",
                "0xA 0xA"
            };

            try
            {
                Assemble.Parse(asm, "Malvino");
                Assert.Fail();
            }
            catch (Exception)
            {
            }
        }
示例#20
0
        public IActionResult StartEmulation([FromBody] SAP2CodePacket sap2CodePacket)
        {
            EmulationSessionMap session = null;

            try
            {
                session = _sap1EmuContext.EmulationSessionMaps
                          .Single(esm => esm.EmulationID == sap2CodePacket.EmulationID);
            }
            catch (InvalidOperationException)
            {
                return(BadRequest(sap2CodePacket.EmulationID));
            }


            if (session.StatusId != (int)StatusType.Pending)
            {
                string message = string.Empty;
                switch ((StatusType)session.StatusId)
                {
                case StatusType.Ok:
                    message = "Emulation Complete: Please use 'GET: /session/{id}/recall' instead";
                    break;

                case StatusType.SQLError:
                case StatusType.ParsingError:
                case StatusType.EmulationError:
                case StatusType.SystemError:
                    message = "Emulation Errored: Please create new session";
                    break;

                case StatusType.InProgress:
                    message = "Emulation In Progress: Please use 'POST: /{id}/resume' instead";
                    break;

                default:
                    message = "Unknown Host Error";
                    break;
                }

                return(BadRequest(
                           new
                {
                    EmulationID = sap2CodePacket.EmulationID,
                    Status = StatusFactory.GetStatus((StatusType)session.StatusId),
                    Message = message
                }
                           ));
            }


            // This will save the plain code
            try
            {
                _sap1EmuContext.CodeSubmissions.Add(
                    new CodeSubmission()
                {
                    EmulationID = session.EmulationID,
                    Code        = sap2CodePacket.Code
                }
                    );
                _sap1EmuContext.SaveChanges();
            }
            catch (Exception e)
            {
                _sap1EmuContext.ErrorLog.Add(
                    new ErrorLog
                {
                    EmulationID = session.EmulationID,
                    ErrorMsg    = "NON-FATAL SQL ERROR:\t" + e.Message + (e.InnerException != null ? "\t" + e.InnerException.Message : "")
                }
                    );
                //session.SessionEnd = DateTime.UtcNow;
                session.StatusId = (int)StatusType.SQLError;

                _sap1EmuContext.SaveChanges();
            }


            SAP2BinaryPacket sap2BinaryPacket;

            // Assemble
            try
            {
                sap2BinaryPacket = new SAP2BinaryPacket()
                {
                    EmulationID = sap2CodePacket.EmulationID,
                    Code        = Assemble.Parse((List <string>)sap2CodePacket.Code),
                    SetName     = sap2CodePacket.SetName
                };
            }
            catch (ParseException pe)
            {
                session.StatusId   = (int)StatusType.ParsingError;
                session.SessionEnd = DateTime.UtcNow;

                string errorMsg = pe.Message + (pe.InnerException != null ? "\n" + pe.InnerException.Message : "");
                _sap1EmuContext.ErrorLog.Add(
                    new ErrorLog
                {
                    EmulationID = session.EmulationID,
                    ErrorMsg    = errorMsg
                }
                    );

                _sap1EmuContext.SaveChanges();
                return(BadRequest(
                           new
                {
                    EmulationID = sap2CodePacket.EmulationID,
                    Status = StatusFactory.GetStatus((StatusType)session.StatusId),
                    Message = errorMsg
                }
                           ));
            }


            // Save Binary
            try
            {
                _sap1EmuContext.CodeSubmissionsBinary.Add(
                    new CodeSubmission()
                {
                    EmulationID = session.EmulationID,
                    Code        = sap2BinaryPacket.Code
                }
                    );
                _sap1EmuContext.SaveChanges();
            }
            catch (Exception e)
            {
                _sap1EmuContext.ErrorLog.Add(
                    new ErrorLog
                {
                    EmulationID = session.EmulationID,
                    ErrorMsg    = "NON-FATAL SQL ERROR:\t" + e.Message + (e.InnerException != null ? "\t" + e.InnerException.Message : "")
                }
                    );

                session.SessionEnd = DateTime.UtcNow;
                session.StatusId   = (int)StatusType.SystemError;

                _sap1EmuContext.SaveChanges();
            }


            // Run Emulator
            try
            {
                RAMProgram rmp = new RAMProgram((List <string>)sap2BinaryPacket.Code);

                EngineProc engine = new EngineProc();
                engine.Init(rmp, _decoder, sap2BinaryPacket.SetName);
                engine.Run();

                session.StatusId   = (int)StatusType.Ok;
                session.SessionEnd = DateTime.UtcNow;
                _sap1EmuContext.SaveChanges();

                return(Ok(engine.FrameStack()));
            }
            catch (EngineRuntimeException ere)
            {
                session.StatusId   = (int)StatusType.EmulationError;
                session.SessionEnd = DateTime.UtcNow;

                string errorMsg = ere.Message + (ere.InnerException != null ? "\n" + ere.InnerException.Message : "");
                _sap1EmuContext.ErrorLog.Add(
                    new ErrorLog
                {
                    EmulationID = session.EmulationID,
                    ErrorMsg    = errorMsg
                }
                    );
                _sap1EmuContext.SaveChanges();
                return(BadRequest(
                           new
                {
                    EmulationID = sap2CodePacket.EmulationID,
                    Status = StatusFactory.GetStatus((StatusType)session.StatusId),
                    Message = errorMsg
                }
                           ));
            }
        }
示例#21
0
 public void ButtonClicked()
 {
     DispMsg.dispMessage(gameObject.name);
     Assemble.SetComponent(gameObject.name);
 }
示例#22
0
        /// <summary>
        /// Returns a list of business candidates based on search key.
        /// </summary>
        /// <param name="searchKey">search key eg. microsoft</param>
        /// <returns>Returns a list of candidates.</returns>
        public List <Candidate> SearchBusinessCandidates(string searchKey)
        {
            List <Candidate> candidates = new List <Candidate>();

            try
            {
                //Build the API  request to be send.
                _Request             = WebRequest.Create(new Uri(String.Format("{0}{1}", _DnBBasicURL, StatementBuilder.FindCompany(searchKey))));
                _Request.Method      = "GET";
                _Request.ContentType = "application/json; charset=UTF-8";
                _Request.Headers.Add("Authorization", _Token);
                //Call the API and get a response.
                HttpWebResponse response = (HttpWebResponse)_Request.GetResponse();
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    using (var streamReader = new StreamReader(response.GetResponseStream()))
                    {
                        //Get Json
                        string json = streamReader.ReadToEnd();
                        //Deserialized Json
                        var foundCompany = JsonConvert.DeserializeObject <DnB.NET.JsonModels.SearchMatch.SearchMatchResponse>(json);
                        if (foundCompany == null)
                        {
                            _ErrorMessage = "No results found";
                            return(null);
                        }

                        if (foundCompany.MatchResponse.TransactionResult.ResultText.Equals("Success"))
                        {
                            List <Candidate> results = Assemble.Build(foundCompany.MatchResponse.MatchResponseDetail.MatchCandidate);
                            if (results == null || results.Count <= 0)
                            {
                                _ErrorMessage = "No results found. Couldn't Build Object from JSON.";
                                return(null);
                            }

                            candidates = results;
                        }
                        else
                        {
                            _ErrorMessage = "API Call Success. Couldn't read data.";
                            return(null);
                        }
                    }
                }
                response.Close();
            }
            catch (WebException wex)
            {
                HttpWebResponse resp = (HttpWebResponse)wex.Response;
                if (resp.StatusCode == HttpStatusCode.NotFound)
                {
                    _ErrorMessage = "Entity not found";
                    return(null);
                }
                else
                {
                    using (var streamReader = new StreamReader(resp.GetResponseStream()))
                    {
                        var errAPI = JsonConvert.DeserializeObject <DnB.NET.JsonModels.JsonError.ErrorAPICall>(streamReader.ReadToEnd());
                        _ErrorMessage = String.Format("API CALL ERROR: {0} - {1}", errAPI.MatchResponse.TransactionResult.ResultText, errAPI.MatchResponse.TransactionResult.ResultMessage[0].ResultDescription);
                    }
                    return(null);
                }
            }
            catch (JsonSerializationException jex)
            {
                _ErrorMessage = "Json De-serialization exception.";
                return(null);
            }
            catch (Exception ex)
            {
                _ErrorMessage = ex.Message;
                return(null);
            }

            return(candidates);
        }
示例#23
0
 public void Remove(Assemble assemble)
 {
     assembles.Remove(assemble);//base sur Assemble.Equals redefini
     Save();
 }
示例#24
0
 public void DeleteAssemble(Assemble assemble)
 {
     assembleRepo.Remove(assemble);
 }
示例#25
0
 public void EditAssemble(Assemble oldAssemble, Assemble newAssemble)
 {
     assembleRepo.Set(oldAssemble, newAssemble);
 }
示例#26
0
        public ActionResult Post([FromBody] EmulatorPacket emulatorPacket)
        {
            EntityEntry <EmulationSessionMap> session;

            try
            {
                session = _sap1EmuContext.Add <EmulationSessionMap>(new EmulationSessionMap
                {
                    EmulationID      = Guid.NewGuid(),
                    ConnectionID     = null,
                    SessionStart     = DateTime.UtcNow,
                    EmulatorId       = _emulatorId,
                    StatusId         = StatusFactory.GetStatus(StatusType.Pending).Id,
                    InstructionSetId = _instructionSets[emulatorPacket.SetName]
                });
                _sap1EmuContext.CodeSubmissions.Add(new CodeSubmission()
                {
                    EmulationID = session.Entity.EmulationID,
                    Code        = emulatorPacket.CodeList,
                });
                _sap1EmuContext.SaveChanges();
            }
            catch (KeyNotFoundException)
            {
                return(BadRequest(
                           // TODO: Set Type to supported_sets url
                           new ProblemDetails()
                {
                    Status = StatusCodes.Status400BadRequest,
                    Type = "",
                    Title = "Invalid SetName...",
                    Detail = $"The Instruction Set `{emulatorPacket.SetName}` does not exist.",
                    Instance = HttpContext.Request.Path
                }
                           ));
            }


            try
            {
                List <string> compiled_binary = Assemble.Parse(emulatorPacket.CodeList, emulatorPacket.SetName);
                RAMProgram    rmp             = new RAMProgram(compiled_binary);

                EngineProc engine = new EngineProc();
                engine.Init(rmp, _decoder, emulatorPacket.SetName);
                engine.Run();

                session.Entity.SessionEnd = DateTime.UtcNow;
                session.Entity.StatusId   = StatusFactory.GetStatus(StatusType.Ok).Id;

                _sap1EmuContext.SaveChanges();
                return(Ok(engine.FrameStack()));
            }
            catch (ParseException pe)
            {
                session.Entity.SessionEnd = DateTime.UtcNow;
                session.Entity.StatusId   = StatusFactory.GetStatus(StatusType.ParsingError).Id;


                if (pe.InnerException != null)
                {
                    string msg = (pe.Message + " " + pe.InnerException.Message);
                    _sap1EmuContext.ErrorLog.Add(new ErrorLog()
                    {
                        EmulationID = session.Entity.EmulationID,
                        ErrorMsg    = msg
                    });

                    _sap1EmuContext.SaveChanges();
                    return(BadRequest(msg));
                }
                else
                {
                    _sap1EmuContext.ErrorLog.Add(new ErrorLog()
                    {
                        EmulationID = session.Entity.EmulationID,
                        ErrorMsg    = pe.Message
                    });

                    _sap1EmuContext.SaveChanges();
                    return(BadRequest(pe.Message));
                }
            }
            catch (EngineRuntimeException ere)
            {
                session.Entity.SessionEnd = DateTime.UtcNow;
                session.Entity.StatusId   = StatusFactory.GetStatus(StatusType.EmulationError).Id;

                if (ere.InnerException != null)
                {
                    string msg = (ere.Message + " " + ere.InnerException.Message);
                    _sap1EmuContext.ErrorLog.Add(new ErrorLog()
                    {
                        EmulationID = session.Entity.EmulationID,
                        ErrorMsg    = msg
                    });

                    _sap1EmuContext.SaveChanges();
                    return(BadRequest(ere.Message + " " + ere.InnerException.Message));
                }
                else
                {
                    _sap1EmuContext.ErrorLog.Add(new ErrorLog()
                    {
                        EmulationID = session.Entity.EmulationID,
                        ErrorMsg    = ere.Message
                    });

                    _sap1EmuContext.SaveChanges();
                    return(BadRequest(ere.Message));
                }
            }
            catch (Exception e)
            {
                session.Entity.SessionEnd = DateTime.UtcNow;
                session.Entity.StatusId   = StatusFactory.GetStatus(StatusType.SystemError).Id;

                _sap1EmuContext.ErrorLog.Add(new ErrorLog()
                {
                    EmulationID = session.Entity.EmulationID,
                    ErrorMsg    = e.Message
                });

                _sap1EmuContext.SaveChanges();
                return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
            }
        }
示例#27
0
        private void guna2GradientCreer_Click(object sender, EventArgs e)
        {
            try
            {
                // checkForm();

                Assemble newAssemble = new Assemble
                                       (
                    guna2TxtHote.Text,
                    DateTime.Parse(guna2DateTimePickerDatePremiereRencontre.Text),
                    DateTime.Parse(guna2DateTimePickerHeureAssemble.Text),
                    guna2ComboBoxTypeAssemble.Text,
                    guna2TxtSanctionRetard.Text,
                    guna2TxtSanctionAbsence.Text
                                       );

                AssembleBLO assembleBLO = new AssembleBLO(ConfigurationManager.AppSettings["DbFolder"]);

                if (this.oldAssemble == null)
                {
                    assembleBLO.CreateAssemble(newAssemble);
                }
                else
                {
                    assembleBLO.EditAssemble(oldAssemble, newAssemble);
                }

                MessageBox.Show
                (
                    "Assembler creer !",
                    "Confirmation",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information
                );

                if (callBack != null)
                {
                    callBack();
                }

                if (oldAssemble != null)
                {
                    Close();
                }

                guna2TxtHote.Clear();

                guna2TxtSanctionRetard.Clear();

                guna2TxtSanctionAbsence.Focus();
            }
            catch (TypingException ex)
            {
                MessageBox.Show
                (
                    ex.Message,
                    "Typing error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning
                );
            }
            catch (DuplicateNameException ex)
            {
                MessageBox.Show
                (
                    ex.Message,
                    "Duplicate error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning
                );
            }
            catch (KeyNotFoundException ex)
            {
                MessageBox.Show
                (
                    ex.Message,
                    "Not found error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning
                );
            }
            catch (Exception ex)
            {
                ex.WriteToFile();
                MessageBox.Show
                (
                    "An error occurred! Please try again later.",
                    "Erreur",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                );
            }
        }
示例#28
0
 public void CreateAssemble(Assemble assemble)
 {
     assembleRepo.Add(assemble);
 }
示例#29
0
        public static void Main(string[] args)
        {
            IDecoder _decoder = new InstructionDecoder();

            _ = Parser.Default.ParseArguments <Options>(args)
                .WithParsed(o =>
            {
                List <string> source_file_contents = new List <string>();;
                FileType fileType = FileType.B;

                if (!string.IsNullOrEmpty(o.SourceFile))
                {
                    if (!File.Exists(o.SourceFile))
                    {
                        Console.Error.WriteLine($"SAP1EMU: error: {o.SourceFile}: No such file");
                        Console.Error.WriteLine($"SAP1EMU: fatal error: no input file");
                        Console.Error.WriteLine("emulation terminated");
                        CheckEnvAndExit();
                    }
                    else        // Check if file is valid
                    {
                        source_file_contents = new List <string>(File.ReadAllLines(o.SourceFile));
                        int loc = source_file_contents.Count;

                        if (o.SourceFile.Length >= 3)
                        {
                            string ftype = o.SourceFile.Substring(o.SourceFile.Length - 2, 2);
                            if (ftype == ".s")
                            {
                                fileType = FileType.S;
                            }
                            else if (ftype == ".b")
                            {
                                fileType = FileType.B;
                            }
                            else
                            {
                                Console.Error.WriteLine($"SAP1EMU: error: {o.SourceFile}: Invalid file extension: Must be <FileName>.s or <FileName>.b");
                                Console.Error.WriteLine($"SAP1EMU: fatal error: no valid input file");
                                Console.Error.WriteLine("emulation terminated.");
                                CheckEnvAndExit();
                            }
                        }

                        if (loc == 0)
                        {
                            Console.Error.WriteLine($"SAP1EMU: error: {o.SourceFile}: File is empty");
                            Console.Error.WriteLine($"SAP1EMU: fatal error: no valid input file");
                            Console.Error.WriteLine("emulation terminated");
                            CheckEnvAndExit();
                        }
                        if (loc > 16)
                        {
                            Console.Error.WriteLine($"SAP1EMU: error: {o.SourceFile}: invalid file: Contains more than 16 lines of code.");
                            Console.Error.WriteLine($"SAP1EMU: fatal error: no valid input file");
                            Console.Error.WriteLine("emulation terminated");
                            CheckEnvAndExit();
                        }
                    }
                    if (!string.IsNullOrEmpty(o.FOframe))
                    {
                        if (o.FOframe.ToLower() != "no-format" && o.FOframe.ToLower() != "std")
                        {
                            Console.Error.WriteLine($"SAP1EMU: warning: {o.SourceFile}: invalid format argument {o.FOframe}: Defaulting to \"std\".");
                            o.FOframe = "std";
                        }
                    }

                    if (o.InstructionSetName.ToLower() != "sap1emu" && o.InstructionSetName.ToLower() != "malvino" && o.InstructionSetName.ToLower() != "beneater")
                    {
                        Console.Error.WriteLine($"SAP1EMU: warning: {o.InstructionSetName}: invalid argument:  Defaulting to \"SAP1Emu\".");
                        o.InstructionSetName = "SAP1Emu";
                    }

                    List <string> compiled_binary = null;

                    if (fileType == FileType.S)
                    {
                        try
                        {
                            compiled_binary = Assemble.Parse(source_file_contents, o.InstructionSetName);
                        }
                        catch (ParseException pe)
                        {
                            //Console.SetOut(new StreamWriter(Console.OpenStandardOutput()));
                            //Console.SetError(new StreamWriter(Console.OpenStandardError()));

                            var tempColor = Console.ForegroundColor;
                            if (Console.BackgroundColor == ConsoleColor.Red)
                            {
                                Console.ForegroundColor = ConsoleColor.Cyan;
                            }
                            else
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                            }
                            Console.Error.WriteLine($"SAP1ASM: fatal error: " + pe.Message + " " + pe.InnerException.Message);
                            Console.ForegroundColor = tempColor;
                            Console.Error.WriteLine("assembly terminated");

                            Console.Error.Flush();

                            CheckEnvAndExit();
                        }
                    }
                    else
                    {
                        compiled_binary = source_file_contents;
                    }

                    RAMProgram rmp    = new RAMProgram(compiled_binary);
                    EngineProc engine = new EngineProc();

                    //StringBuilder sb_out = new StringBuilder();
                    //TextWriter writer_out = new StringWriter(sb_out);
                    //Console.SetOut(writer_out);

                    //StringBuilder sb_error = new StringBuilder();
                    //TextWriter writer_error = new StringWriter(sb_error);
                    //Console.SetError(writer_error);

                    engine.Init(rmp, _decoder, o.InstructionSetName);
                    try
                    {
                        engine.Run();
                    }
                    catch (EngineRuntimeException ere)
                    {
                        var tempColor = Console.ForegroundColor;
                        if (Console.BackgroundColor == ConsoleColor.Red)
                        {
                            Console.ForegroundColor = ConsoleColor.Cyan;
                        }
                        else
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                        }

                        //Console.SetOut(new StreamWriter(Console.OpenStandardOutput()));
                        //Console.SetError(new StreamWriter(Console.OpenStandardError()));

                        Console.Error.WriteLine($"SAP1EMU: fatal error: " + ere.Message);
                        Console.ForegroundColor = tempColor;
                        Console.Error.WriteLine("emulation terminated");

                        Console.Error.Flush();

                        CheckEnvAndExit();
                    }

                    string engine_output = "************************************************************\n"
                                           + "Final Output Register Value: " + engine.GetOutputReg()
                                           + "\n************************************************************\n\n";

                    List <Frame> FrameStack = engine.FrameStack();

                    if (o.fframe)
                    {
                        engine_output += "\n" + engine.FinalFrame();
                    }
                    else if (o.Fframe)
                    {
                        StringBuilder sb = new StringBuilder();
                        StringWriter fw  = new StringWriter(sb);

                        foreach (Frame frame in FrameStack)
                        {
                            fw.WriteLine(frame.ToString());
                        }
                        fw.Flush();

                        engine_output += "\n" + sb.ToString();
                    }
                    else if (o.FOframe != null)
                    {
                        engine_output = null;        // Clear the output

                        StringBuilder sb = new StringBuilder();
                        StringWriter fw  = new StringWriter(sb);

                        foreach (Frame frame in FrameStack)
                        {
                            if (frame.TState == 6)
                            {
                                if (o.FOframe.ToLower() == "std")
                                {
                                    fw.WriteLine(frame.OutputRegister());
                                }
                                else if (o.FOframe.ToLower() == "no-format")
                                {
                                    string temp = frame.OReg;
                                    if (string.IsNullOrEmpty(temp))
                                    {
                                        temp = "00000000";
                                    }
                                    fw.WriteLine(temp);
                                }
                            }
                        }
                        fw.Flush();

                        engine_output += sb.ToString();
                    }

                    var standardOutput = new StreamWriter(Console.OpenStandardOutput())
                    {
                        AutoFlush = true
                    };
                    Console.SetOut(standardOutput);

                    var standardError = new StreamWriter(Console.OpenStandardError())
                    {
                        AutoFlush = true
                    };
                    Console.SetError(standardError);

                    //string stdout = sb_out.ToString();
                    //string stderror = sb_error.ToString();

                    File.WriteAllText(o.OutputFile, engine_output);

                    // Start the Single Stepping Debug Session if Debug Flag is set

                    Debug_Proc(o, source_file_contents, FrameStack);
                    Console.Out.WriteLine("Debug Session Complete");

                    //foreach(Frame f in FrameStack)
                    //{
                    //    foreach(string s in f.RAM)
                    //    {
                    //        Console.Out.WriteLine(s);
                    //    }
                    //    Console.Out.WriteLine("\n");
                    //}
                }
            });
        }