/// <summary> /// Fetches and executes the next <see cref="Instruction"/>. /// </summary> public void Step() { var instruction = Fetch(); try { Decode(instruction); Execute(instruction); Tick?.Invoke(this, new EventArgs()); if (instruction == Instruction.HALT) { Halt?.Invoke(this, new EventArgs()); } if (instruction == Instruction.RESET) { Reset?.Invoke(this, new ResetEventArgs(instruction, null)); } } catch (Exception e) { continueExecution = false; Initialize(); Reset?.Invoke(this, new ResetEventArgs(instruction, e)); // FUTURE: don't throw exception? throw; } }
private Halt CreateModel(HaltBindingModel model, Halt halt) { halt.Name = model.Name; halt.Address = model.Address; halt.OperatorID = model.OperatorID; return halt; }
private static int FeedbackSet(long[] input, IntCodeProgram[] amplifiers, List <int> phaseSettingSequence) { for (int i = 0; i < amplifiers.Length; i++) { amplifiers[i] = new IntCodeProgram(input, phaseSettingSequence[i]); } amplifiers[0].Input.Enqueue(0); Queue <IntCodeProgram> amplifiersQueue = new Queue <IntCodeProgram>(amplifiers); Queue <long> nextInput = new Queue <long>(); while (amplifiersQueue.Count > 0) { IntCodeProgram amp = amplifiersQueue.Dequeue(); OutputToInput(nextInput, amp.Input); Halt haltType = amp.Run(); OutputToInput(amp.Output, nextInput); if (haltType == Halt.NeedInput) { amplifiersQueue.Enqueue(amp); } } return((int)nextInput.Single()); }
public MIPS Visitor(Halt instance, IFunctionCil function, GenerateToCil cil) { return(new MIPS() { Functions = new List <string>() { "eret" } }); }
public static TimeSpan?GetAbfahrt <T>(this Halt <T> halt) where T : Zug { var result = halt.AbfahrtPlan; if (halt is HaltDispo dispoHalt) { result = dispoHalt.AbfahrtIst ?? dispoHalt.AbfahrtSoll ?? halt.AbfahrtPlan; } return(result); }
public void Announce(Event ev, object payload = null) { Assert(ev != null, "Machine cannot announce a null event"); if (ev is PHalt) { ev = new Halt(); } var oneArgConstructor = ev.GetType().GetConstructors().First(x => x.GetParameters().Length > 0); var @event = (Event)oneArgConstructor.Invoke(new[] { payload }); AnnounceInternal(@event); }
private void Initialize() { // startup state Address.IsEnabled = true; BusAcknowledge.Write(DigitalLevel.High); Halt.Write(DigitalLevel.High); IoRequest.Write(DigitalLevel.High); MemoryRequest.Write(DigitalLevel.High); MachineCycle1.Write(DigitalLevel.High); Refresh.Write(DigitalLevel.High); Read.Write(DigitalLevel.High); Write.Write(DigitalLevel.High); }
public static DateTime?GetAnkunftPath <T>(this Halt <T> halt, bool preferPrognosis) where T : Zug { var result = halt.AnkunftPlan; if (halt is HaltDispo dispoHalt) { result = preferPrognosis ? dispoHalt.AnkunftPrognose ?? dispoHalt.AnkunftSoll : dispoHalt.AnkunftSoll; } return(result.ToDateTime()); }
public void Run() { long opCode; while (true) { opCode = Read(); if (opCode % DecoderConstants.NumberOfCodeValues == 99) { Halt?.Invoke(this, EventArgs.Empty); break; } Decode(_opCodeHandlers[opCode % 100], opCode); } }
public void Delete(HaltBindingModel model) { using (var context = new TourFirmDatabase()) { Halt element = context.Halts.FirstOrDefault(rec => rec.ID == model.ID); if (element != null) { context.Halts.Remove(element); context.SaveChanges(); } else { throw new Exception("Элемент не найден"); } } }
/// <summary> /// Scrapes data from the NUFORC web portal, deserializes it into Report objects /// Multithreaded, takes a lot of CPU and memory to run, and is more or less a DDOS if done wrong /// Ensure parameters are properly set before starting /// </summary> /// <returns></returns> public IEnumerable <Report> GetReports(ISet <int> currentIds) { IsRunning = true; Halt = false; var newReports = new HashSet <Report>(); var web = new HtmlWeb(); var homeDoc = web.Load(BaseUrl + "webreports.html"); // from front page, go to "by state" var stateIndexLink = BaseUrl + homeDoc.QuerySelector(Selectors.indexSelector).Attributes["href"].Value; var stateIndexDoc = web.Load(stateIndexLink); // number of pending requests to the NUFORC site, decrements once the web page is received int requestsInFlight = 0; // get list of links to state pages var stateLinkNodes = stateIndexDoc.QuerySelectorAll(Selectors.tableLinkSelector); // Main loop, forks threads to independently open and close pages as they load do { foreach (var s in stateLinkNodes) { web = new HtmlWeb(); var stateLink = BaseUrl + "webreports/" + s.Attributes["href"].Value; // throttle requests when too many are in flight while (requestsInFlight > MaxInFlight) { Thread.Sleep(ThrottleTimeout); } requestsInFlight++; // spin off threads for each state web.LoadFromWebAsync(stateLink).ContinueWith((state_task) => { try { state_task.Wait(); } catch { return; } requestsInFlight--; if (!state_task.IsCompletedSuccessfully) { return; } var stateDoc = state_task.Result; // get list of links to individual reports (same selector) var reportLinkNodes = stateDoc.QuerySelectorAll(Selectors.tableLinkSelector); foreach (var r in reportLinkNodes) { // add another short lived web client! var webTemp = new HtmlWeb(); var reportLink = BaseUrl + "webreports/" + r.Attributes["href"].Value; // extract ID from url, use that as the ID bool parseResult = int.TryParse(reportLink.Substring(reportLink.LastIndexOf('/') + 2).Replace(".html", ""), out int reportId); // check against duplicates and failed lookups if (!parseResult || currentIds.Contains(reportId)) { continue; } // throttle requests when to many are in flight while (requestsInFlight >= MaxInFlight) { Thread.Sleep(ThrottleTimeout); } requestsInFlight++; // spin off *another* thread to load the report pages webTemp.LoadFromWebAsync(reportLink).ContinueWith((report_task) => { try { report_task.Wait(); } catch { return; } finally { requestsInFlight--; } // bail out if the request failed if (!report_task.IsCompletedSuccessfully) { return; } var reportDoc = report_task.Result; // get the details and description of the report var reportTable = reportDoc.QuerySelectorAll("tr td"); // report wasn't found, got a different page if (reportTable.Count < 2) { return; } var details = reportTable[0].InnerHtml; var description = reportTable[1]; // bail out if we've hit the max batch in any thread if (Halt.Equals(true) || (BatchSize != -1 && newReports.Count > BatchSize)) { Halt = true; return; } // for this row: the left most portion is the date, the rightmost is the time, the middle is usually useless var reportDateTimes = Regex.Match(details, RegularExpressions.dateReported).Value.Split(' '); // there is newReports.Add(new Report() { ReportId = reportId, DateOccurred = DateTime.Parse(Regex.Match(details, RegularExpressions.dateOccured).Value), DateSubmitted = DateTime.Parse(reportDateTimes[0] + reportDateTimes[reportDateTimes.Length - 1]), DatePosted = DateTime.Parse(Regex.Match(details, RegularExpressions.datePosted).Value), Location = Regex.Match(details, RegularExpressions.location).Value, Shape = ShapeUtility.ShapeAliases(Regex.Match(details, RegularExpressions.shape).Value), Duration = Regex.Match(details, RegularExpressions.duration).Value, Description = description.InnerText }); Console.WriteLine(newReports.Count); }); if (Halt.Equals(true)) { break; } } }); if (Halt.Equals(true)) { break; } } } while (requestsInFlight > 0 || Halt.Equals(false)); // reset initial conditions Halt = false; IsRunning = false; return(newReports); }
public override void OnHalt(MachineId machineId, int inboxSize) { base.OnHalt(machineId, inboxSize); Halt?.Invoke(machineId, inboxSize); }
protected HaltTests() { TestedInstruction = new Halt(); }
private void UpdateHalt() { if (dataGridView2.SelectedRows.Count == 0) return; string haltId = (string)dataGridView2.SelectedRows[0].Cells["HaltId"].Value; h = activeRoute.GetHaltById(haltId); }
protected virtual void OnHalt(EventArgs e) { Halt?.Invoke(this, e); }