コード例 #1
0
ファイル: Executor.cs プロジェクト: jdraines/aoc2020
        /// <summary>
        /// The Run method executes the code and allows for an injected inspector
        /// to perform inspection operations and return a break code if desired.
        ///
        /// Inspectors inspect each line of code. While the inspector cannot alter
        /// the linePointer or accumulator values, it can alter the single command
        /// that it inspects, enabling some debugging.
        /// </summary>
        public long Run(IInspector inspector = null, bool WriteOut = true)
        {
            if (inspector != null)
            {
                Inspector = inspector;
            }

            while (linePointer <= Code.Length)
            {
                GBCommand Cmd        = ParseLine(Code[linePointer - 1]);
                long      inspection = inspector.Inspect(ref Cmd, linePointer, Accumulator);
                if (BreakValue(inspection, Cmd))
                {
                    return(Break(Cmd, WriteOut));
                }

                long execution = Command[Cmd.Name].Run(Cmd.Value, ref linePointer, ref Accumulator);
                History.Add(Cmd);
                if (BreakValue(execution, Cmd))
                {
                    return(Break(Cmd, WriteOut));
                }
            }
            return(Break(new GBCommand("COMPLETE", 0)));
        }
コード例 #2
0
ファイル: Executor.cs プロジェクト: jdraines/aoc2020
        private bool BreakValue(long value, GBCommand cmd)
        {
            if (value == BREAK)
            {
                return(true);
            }

            return(false);
        }
コード例 #3
0
ファイル: Executor.cs プロジェクト: jdraines/aoc2020
 private long Break(GBCommand cmd, bool WriteOut = true)
 {
     ExitCommand = cmd;
     if (WriteOut)
     {
         string msg = $"Breaking execution at line {linePointer}, command {cmd.ToString()}, with state Accumulator={Accumulator}";
         Console.WriteLine(msg);
     }
     return(0);
 }
コード例 #4
0
ファイル: Executor.cs プロジェクト: jdraines/aoc2020
 ///<summary>
 /// The Reset method allows one to reset the instance to an initialized state.
 /// </summary>
 public void Reset(string[] code = null, long accInit = 0, long lineInit = 1)
 {
     if (code is null)
     {
         Code = code;
     }
     Accumulator = accInit;
     linePointer = lineInit;
     ExitCommand = new GBCommand("INITIALIZE", 0);
     History     = new List <GBCommand>();
 }
コード例 #5
0
ファイル: Inspector.cs プロジェクト: jdraines/aoc2020
 public virtual long Inspect(ref GBCommand cmd, long linePointer, long accumulator)
 {
     return(0);
 }