Changeset 14952 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Views/PushDebuggerView.cs
- Timestamp:
- 05/10/17 11:23:05 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Views/PushDebuggerView.cs
r14914 r14952 18 18 19 19 private PooledPushInterpreter interpreter; 20 private PooledPushInterpreter interpreter2; // used to determine noops21 20 private PushInterpreterPool pool; 22 21 23 private const string GroupBoxTextStringFormat = "{0}[{1}]"; 22 private const string GROUP_BOX_TEXT_STRING_FORMAT = "{0}[{1}]"; 23 private const string EXEC_COUNT_LABEL_FORMAT = "{0}/{1} max. expressions evaluated"; 24 24 25 25 public event EventHandler<IPushInterpreter> OnReset; … … 32 32 ~PushDebuggerView() { 33 33 interpreter.Dispose(); 34 interpreter2.Dispose();35 34 } 36 35 … … 52 51 if (interpreter != null) { 53 52 interpreter.Dispose(); 54 interpreter2.Dispose();55 53 } 56 54 57 55 interpreter = pool.Create(Content.Random); 58 interpreter2 = pool.Create(Content.Random);59 60 56 61 57 InitDebugLists(Content.Config); … … 66 62 } 67 63 64 private void UpdateExecCountLabel() { 65 execCountLabel.Text = string.Format( 66 EXEC_COUNT_LABEL_FORMAT, 67 interpreter.ExecCounter, 68 Content.Config.EvalPushLimit); 69 } 70 68 71 private void InitEvents() { 69 72 runButton.Click += RunButtonClick; … … 78 81 79 82 interpreter.Resume(); 80 81 ResetDebugging(); 83 UpdateStep(); 84 } 85 86 private void StepButtonClick(object sender, EventArgs e) { 87 if (interpreter == null || stepWidthBox.Value <= 0) 88 return; 89 90 var count = Math.Min(stepWidthBox.Value, interpreter.ExecStack.Count); 91 92 for (var i = 0; i < count; i++) { 93 SkipNoops(); 94 95 // run next none noop expression 96 interpreter.Step(); 97 } 98 99 // skip trailing noops so next expression is a none noop in debugger 100 SkipNoops(); 101 102 stepWidthBox.Maximum = Math.Max(1, interpreter.ExecStack.Count); 103 UpdateStep(); 104 } 105 106 private void UpdateStep() { 82 107 UpdateExecList(); 83 108 UpdateDebugLists(); 109 UpdateExecCountLabel(); 84 110 CheckIfButtonsCanBeEnabled(); 85 111 } 86 112 87 private void StepButtonClick(object sender, EventArgs e) { 88 if (interpreter == null || stepWidthBox.Value <= 0) 89 return; 90 91 var count = Math.Min(stepWidthBox.Value, interpreter.ExecStack.Count); 92 93 if (!interpreter.CanStep) 94 return; 95 96 // skip leading noops 97 if (interpreter2.ExecCounter == (Content.Program.IsProgram ? 1 : 0) && 98 skipNoopsCheckBox.Checked && 99 SkipNoops()) { 100 count = 0; // no entries left, cause all were noops 101 } 102 103 for (var i = 0; i < count; i++) { 104 if (skipNoopsCheckBox.Checked) { 113 private void SkipNoops() { 114 // skip noops 115 if (skipNoopsCheckBox.Checked) { 116 while (interpreter.CanStep && interpreter.ExecStack.Top.IsNoop(interpreter)) { 105 117 interpreter.Step(); 106 107 if (SkipNoops())108 break;109 } else {110 interpreter.Step();111 interpreter2.Step();112 118 } 113 119 } 114 115 stepWidthBox.Maximum = Math.Max(1, interpreter.ExecStack.Count);116 117 UpdateExecList();118 UpdateDebugLists();119 CheckIfButtonsCanBeEnabled();120 }121 122 private bool SkipNoops() {123 var skipCount = 0;124 bool isNoop;125 126 do {127 skipCount++;128 isNoop = !interpreter2.Step();129 } while (interpreter2.CanStep && isNoop);130 131 if (isNoop) {132 interpreter.Step(skipCount);133 } else if (skipCount > 1) {134 interpreter.Step(skipCount - 1);135 }136 137 return isNoop;138 120 } 139 121 … … 162 144 if (interpreter != null) { 163 145 interpreter.Reset(); 164 interpreter2.Reset();165 146 } 166 147 167 148 if (OnReset != null) { 168 149 OnReset(this, interpreter); 169 OnReset(this, interpreter2);170 150 } 171 151 172 152 interpreter.Run(Content.Program, true); 173 interpreter2.Run(Content.Program, true);174 153 175 154 stepWidthBox.Maximum = interpreter.ExecStack.Count; 176 177 UpdateDebugLists(); 178 UpdateExecList(); 179 CheckIfButtonsCanBeEnabled(); 155 UpdateStep(); 180 156 } 181 157 … … 194 170 195 171 execList.Items.AddRange(expressions); 196 execGroupBox.Text = string.Format(G roupBoxTextStringFormat, Enum.GetName(typeof(StackTypes), StackTypes.Exec), interpreter.ExecStack.Count);172 execGroupBox.Text = string.Format(GROUP_BOX_TEXT_STRING_FORMAT, Enum.GetName(typeof(StackTypes), StackTypes.Exec), interpreter.ExecStack.Count); 197 173 } 198 174 … … 224 200 225 201 var list = new ListBox { 226 Dock = DockStyle.Fill, 227 DrawMode = DrawMode.OwnerDrawFixed 202 Dock = DockStyle.Fill 228 203 }; 229 204 … … 232 207 if (stackEntryType == typeof(double) || 233 208 stackEntryType == typeof(long)) { 209 list.DrawMode = DrawMode.OwnerDrawFixed; 234 210 list.DrawItem += (sender, e) => { 235 211 if (e.Index <= -1) return; … … 271 247 272 248 foreach (var pair in debugControlDict) { 273 var stack = interpreter.Stacks[pair.Key];274 249 var name = Enum.GetName(typeof(StackTypes), pair.Key); 275 276 pair.Value.Items.AddRange(stack.AsObjects().Reverse().ToArray()); 277 ((GroupBox)pair.Value.Parent).Text = string.Format(GroupBoxTextStringFormat, name, pair.Value.Items.Count); 250 var items = InterpreterStackStringifier.StringifyStack(interpreter, pair.Key).ToArray(); 251 252 pair.Value.Items.AddRange(items); 253 ((GroupBox)pair.Value.Parent).Text = string.Format(GROUP_BOX_TEXT_STRING_FORMAT, name, pair.Value.Items.Count); 278 254 } 279 255 }
Note: See TracChangeset
for help on using the changeset viewer.