示例#1
0
        public override void OnExecuteCycle()
        {
            try
            {
                if (ProgramPtr >= Program.Lines.Count)
                {
                    throw new PTMException("Program pointer past end of program");
                }

                ProgramLine line = Program.Lines[ProgramPtr];

                if (IsExecutable(line))
                {
                    Commands.Execute(line);
                    Cycle++;
                }

                ProgramPtr++;
            }
            catch (PTMException ptmex)
            {
                Error(ptmex.Message);
                throw;
            }
            catch (Exception ex)
            {
                Error(ex.Message);
                throw new PTMException(ex.Message);
            }
        }
示例#2
0
 public Commands(Machine machine)
 {
     Machine     = machine;
     CurrentLine = machine.Program.Lines[0];
     Cmd         = new Dictionary <string, Action <CommandParams> >();
     Vars        = machine.Vars;
     Init();
 }
示例#3
0
        public void Execute(ProgramLine line)
        {
            CurrentLine = line;
            string command = line.Command;

            if (!Cmd.ContainsKey(command))
            {
                throw new PTMException($"Unrecognized command: {command}");
            }

            Cmd[command](new CommandParams(Vars, line.Params));
        }
示例#4
0
        public Machine(Program program)
        {
            Program = program;
            ProgramLine firstProgramLine = Program.Lines[0];

            Commands = new Commands(this);

            try
            {
                if (firstProgramLine.Command == "WINDOW.INIT")
                {
                    InitWindow(firstProgramLine.Params);
                }
                else
                {
                    throw new PTMException("WINDOW.INIT expected");
                }
            }
            catch (Exception ex)
            {
                Error(ex.Message);
                throw new PTMException(ex.Message);
            }
        }
示例#5
0
 private bool IsExecutable(ProgramLine line)
 {
     return(!Program.IsLabel(line.Command));
 }