static void Main(params string[] args)
 {
     if (args.Length != 1 ||  !File.Exists(args[0]))
         return;
     ByterProject project = new ByterProject();
     project.LoadFiles(args[0]);
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     OutputForm outf = new OutputForm();
     DebugForm debug = new DebugForm(project, project.MainMethod, outf);
     debug.IsMain = true;
     Application.Run(debug);
 }
Beispiel #2
0
        static void Main(params string[] args)
        {
            if (args.Length != 1 || !File.Exists(args[0]))
            {
                return;
            }
            ByterProject project = new ByterProject();

            project.LoadFiles(args[0]);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            OutputForm outf  = new OutputForm();
            DebugForm  debug = new DebugForm(project, project.MainMethod, outf);

            debug.IsMain = true;
            Application.Run(debug);
        }
 public DebugForm(ByterProject project, string methodName, OutputForm output)
 {
     if (project == null || methodName == null || output == null)
         throw new ArgumentNullException("Cannot create debug form for empty procedure.");
     InitializeComponent();
     Project = project;
     CodeTable = new char[16, 16];
     Array.Copy(Project.Sources[methodName], CodeTable, 256);
     Output = output;
     CurrentPosition = new Point(0, 0);
     IsMain = false;
     CurrentDirection = Direction.Right;
     Child = Parent = null;
     dataGridView1.RowCount = 16;
     dataGridView1.ColumnCount = 16;
     RefreshTable();
     for (int i = 0; i < 16; i++)
         dataGridView1.Columns[i].Width = dataGridView1.Rows[i].Height;
     Text += " — " + methodName;
 }
 private int MakeStep(char[,] codeTable, ref Point position, ref Direction direction, bool goInto)
 {
     switch (codeTable[position.Y, position.X])
     {
         case '>': codeTable[position.Y, position.X] = '<'; position.X++; direction = Direction.Right; break;
         case '<': codeTable[position.Y, position.X] = '>'; position.X--; direction = Direction.Left; break;
         case 'V': codeTable[position.Y, position.X] = 'A'; position.Y++; direction = Direction.Down; break;
         case 'A': codeTable[position.Y, position.X] = 'V'; position.Y--; direction = Direction.Up; break;
         case '0':
             switch (direction)
             {
                 case Direction.Up: position.Y++; direction = Direction.Down; break;
                 case Direction.Right: position.X--; direction = Direction.Left; break;
                 case Direction.Down: position.Y--; direction = Direction.Up; break;
                 case Direction.Left: position.X++; direction = Direction.Right; break;
             }
             break;
         case '}': Print(position); position.X++; direction = Direction.Right; break;
         case '{': Print(position); position.X--; direction = Direction.Left; break;
         case '+': Print(position); position.Y--; direction = Direction.Up; break;
         case '-': Print(position); position.Y++; direction = Direction.Down; break;
         case '$': Print(position); position = new Point(0, 0); break;
         case '#': return 1;
         default:
             if (Project.Sources.ContainsKey(codeTable[position.Y, position.X].ToString()))
             {
                 if (goInto)
                 {
                     this.statusLabel.Text = "Waiting";
                     this.StepBtn.Enabled = this.StepIntoBtn.Enabled = this.StepOutBtn.Enabled = false;
                     Child = new DebugForm(Project, codeTable[position.Y, position.X].ToString(), Output);
                     Child.Parent = this;
                     Child.Show();
                 }
                 else
                 {
                     this.statusLabel.Text = "Waiting";
                     this.StepBtn.Enabled = this.StepIntoBtn.Enabled = this.StepOutBtn.Enabled = false;
                     RunToEnd(Project.Sources[codeTable[position.Y, position.X].ToString()], new Point(0, 0), Direction.Right);
                     this.StepBtn.Enabled = this.StepIntoBtn.Enabled = this.StepOutBtn.Enabled = true;
                     statusLabel.Text = "Step-by-step running";
                 }
             }
             else
                 MessageBox.Show("Unknown symbol");
             switch (direction)
             {
                 case Direction.Right: position.X++; break;
                 case Direction.Left: position.X--; break;
                 case Direction.Up: position.Y--; break;
                 case Direction.Down: position.Y++; break;
             }
             break;
     }
     if (position.X < 0) position.X += 16;
     if (position.X >= 16) position.X -= 16;
     if (position.Y < 0) position.Y += 16;
     if (position.Y >= 16) position.Y -= 16;
     return 0;
 }
Beispiel #5
0
        private int MakeStep(char[,] codeTable, ref Point position, ref Direction direction, bool goInto)
        {
            switch (codeTable[position.Y, position.X])
            {
            case '>': codeTable[position.Y, position.X] = '<'; position.X++; direction = Direction.Right; break;

            case '<': codeTable[position.Y, position.X] = '>'; position.X--; direction = Direction.Left; break;

            case 'V': codeTable[position.Y, position.X] = 'A'; position.Y++; direction = Direction.Down; break;

            case 'A': codeTable[position.Y, position.X] = 'V'; position.Y--; direction = Direction.Up; break;

            case '0':
                switch (direction)
                {
                case Direction.Up: position.Y++; direction = Direction.Down; break;

                case Direction.Right: position.X--; direction = Direction.Left; break;

                case Direction.Down: position.Y--; direction = Direction.Up; break;

                case Direction.Left: position.X++; direction = Direction.Right; break;
                }
                break;

            case '}': Print(position); position.X++; direction = Direction.Right; break;

            case '{': Print(position); position.X--; direction = Direction.Left; break;

            case '+': Print(position); position.Y--; direction = Direction.Up; break;

            case '-': Print(position); position.Y++; direction = Direction.Down; break;

            case '$': Print(position); position = new Point(0, 0); break;

            case '#': return(1);

            default:
                if (Project.Sources.ContainsKey(codeTable[position.Y, position.X].ToString()))
                {
                    if (goInto)
                    {
                        this.statusLabel.Text = "Waiting";
                        this.StepBtn.Enabled  = this.StepIntoBtn.Enabled = this.StepOutBtn.Enabled = false;
                        Child        = new DebugForm(Project, codeTable[position.Y, position.X].ToString(), Output);
                        Child.Parent = this;
                        Child.Show();
                    }
                    else
                    {
                        this.statusLabel.Text = "Waiting";
                        this.StepBtn.Enabled  = this.StepIntoBtn.Enabled = this.StepOutBtn.Enabled = false;
                        RunToEnd(Project.Sources[codeTable[position.Y, position.X].ToString()], new Point(0, 0), Direction.Right);
                        this.StepBtn.Enabled = this.StepIntoBtn.Enabled = this.StepOutBtn.Enabled = true;
                        statusLabel.Text     = "Step-by-step running";
                    }
                }
                else
                {
                    MessageBox.Show("Unknown symbol");
                }
                switch (direction)
                {
                case Direction.Right: position.X++; break;

                case Direction.Left: position.X--; break;

                case Direction.Up: position.Y--; break;

                case Direction.Down: position.Y++; break;
                }
                break;
            }
            if (position.X < 0)
            {
                position.X += 16;
            }
            if (position.X >= 16)
            {
                position.X -= 16;
            }
            if (position.Y < 0)
            {
                position.Y += 16;
            }
            if (position.Y >= 16)
            {
                position.Y -= 16;
            }
            return(0);
        }