Exemplo n.º 1
0
        /// <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)));
        }
Exemplo n.º 2
0
        private bool BreakValue(long value, GBCommand cmd)
        {
            if (value == BREAK)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 4
0
 ///<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>();
 }
Exemplo n.º 5
0
 public virtual long Inspect(ref GBCommand cmd, long linePointer, long accumulator)
 {
     return(0);
 }