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); } }
public Commands(Machine machine) { Machine = machine; CurrentLine = machine.Program.Lines[0]; Cmd = new Dictionary <string, Action <CommandParams> >(); Vars = machine.Vars; Init(); }
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)); }
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); } }
private bool IsExecutable(ProgramLine line) { return(!Program.IsLabel(line.Command)); }