1 | unit UFormMain;
|
---|
2 |
|
---|
3 | {$mode Delphi}{$H+}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, FileUtil, SynEdit, Forms, Controls, Graphics, Dialogs,
|
---|
9 | Menus, ActnList, ComCtrls, ExtCtrls, UTarget, Registry, URegistry,
|
---|
10 | LazFileUtils;
|
---|
11 |
|
---|
12 | type
|
---|
13 |
|
---|
14 | { TFormMain }
|
---|
15 |
|
---|
16 | TFormMain = class(TForm)
|
---|
17 | AViewLog: TAction;
|
---|
18 | AProgramShowExecutionPoint: TAction;
|
---|
19 | AShowSourcePosition: TAction;
|
---|
20 | AShowTargetPosition: TAction;
|
---|
21 | AProgramCompile: TAction;
|
---|
22 | AAbout: TAction;
|
---|
23 | ABreakpointToggle: TAction;
|
---|
24 | AViewCompilers: TAction;
|
---|
25 | AOptions: TAction;
|
---|
26 | AProgramStepOut: TAction;
|
---|
27 | AProgramRunToCursor: TAction;
|
---|
28 | AProgramStepOver: TAction;
|
---|
29 | AProgramStepInto: TAction;
|
---|
30 | AProgramPause: TAction;
|
---|
31 | AProgramStop: TAction;
|
---|
32 | AHelp: TAction;
|
---|
33 | AProgramRun: TAction;
|
---|
34 | AProjectNew: TAction;
|
---|
35 | AExit: TAction;
|
---|
36 | AProjectSaveAs: TAction;
|
---|
37 | AProjectClose: TAction;
|
---|
38 | AProjectSave: TAction;
|
---|
39 | AProjectOpen: TAction;
|
---|
40 | ActionList1: TActionList;
|
---|
41 | MainMenu1: TMainMenu;
|
---|
42 | MenuItem1: TMenuItem;
|
---|
43 | MenuItem10: TMenuItem;
|
---|
44 | MenuItem11: TMenuItem;
|
---|
45 | MenuItem12: TMenuItem;
|
---|
46 | MenuItem13: TMenuItem;
|
---|
47 | MenuItem14: TMenuItem;
|
---|
48 | MenuItem15: TMenuItem;
|
---|
49 | MenuItem16: TMenuItem;
|
---|
50 | MenuItem17: TMenuItem;
|
---|
51 | MenuItem18: TMenuItem;
|
---|
52 | MenuItem19: TMenuItem;
|
---|
53 | MenuItem2: TMenuItem;
|
---|
54 | MenuItem22: TMenuItem;
|
---|
55 | MenuItem24: TMenuItem;
|
---|
56 | MenuItem25: TMenuItem;
|
---|
57 | MenuItem27: TMenuItem;
|
---|
58 | MenuItem28: TMenuItem;
|
---|
59 | MenuItem30: TMenuItem;
|
---|
60 | MenuItem31: TMenuItem;
|
---|
61 | MenuItem32: TMenuItem;
|
---|
62 | MenuItem33: TMenuItem;
|
---|
63 | MenuItem34: TMenuItem;
|
---|
64 | MenuItem35: TMenuItem;
|
---|
65 | MenuItemOpenRecent: TMenuItem;
|
---|
66 | MenuItemTarget: TMenuItem;
|
---|
67 | MenuItem3: TMenuItem;
|
---|
68 | MenuItem4: TMenuItem;
|
---|
69 | MenuItem5: TMenuItem;
|
---|
70 | MenuItem6: TMenuItem;
|
---|
71 | MenuItem7: TMenuItem;
|
---|
72 | MenuItem8: TMenuItem;
|
---|
73 | MenuItem9: TMenuItem;
|
---|
74 | OpenDialog1: TOpenDialog;
|
---|
75 | PageControlMain: TPageControl;
|
---|
76 | PageControlRight: TPageControl;
|
---|
77 | PageControlBottom: TPageControl;
|
---|
78 | PanelLeft: TPanel;
|
---|
79 | PanelMemory: TPanel;
|
---|
80 | PanelCPU: TPanel;
|
---|
81 | PanelOutput: TPanel;
|
---|
82 | PanelInput: TPanel;
|
---|
83 | PopupMenuTargets: TPopupMenu;
|
---|
84 | PopupMenuRecentFiles: TPopupMenu;
|
---|
85 | SaveDialog1: TSaveDialog;
|
---|
86 | Splitter1: TSplitter;
|
---|
87 | Splitter2: TSplitter;
|
---|
88 | Splitter3: TSplitter;
|
---|
89 | Splitter4: TSplitter;
|
---|
90 | Splitter5: TSplitter;
|
---|
91 | StatusBarMain: TStatusBar;
|
---|
92 | TabSheetMessages: TTabSheet;
|
---|
93 | TabSheetDebug: TTabSheet;
|
---|
94 | TabSheetSource: TTabSheet;
|
---|
95 | TabSheetTarget: TTabSheet;
|
---|
96 | TimerRefresh: TTimer;
|
---|
97 | ToolBarMain: TToolBar;
|
---|
98 | ToolButton1: TToolButton;
|
---|
99 | ToolButton10: TToolButton;
|
---|
100 | ToolButton11: TToolButton;
|
---|
101 | ToolButton12: TToolButton;
|
---|
102 | ToolButton13: TToolButton;
|
---|
103 | ToolButton14: TToolButton;
|
---|
104 | ToolButton15: TToolButton;
|
---|
105 | ToolButtonTarget: TToolButton;
|
---|
106 | ToolButton2: TToolButton;
|
---|
107 | ToolButton3: TToolButton;
|
---|
108 | ToolButton4: TToolButton;
|
---|
109 | ToolButton5: TToolButton;
|
---|
110 | ToolButton6: TToolButton;
|
---|
111 | ToolButton7: TToolButton;
|
---|
112 | ToolButton8: TToolButton;
|
---|
113 | ToolButton9: TToolButton;
|
---|
114 | procedure AAboutExecute(Sender: TObject);
|
---|
115 | procedure ABreakpointToggleExecute(Sender: TObject);
|
---|
116 | procedure AExitExecute(Sender: TObject);
|
---|
117 | procedure AOptionsExecute(Sender: TObject);
|
---|
118 | procedure AProgramCompileExecute(Sender: TObject);
|
---|
119 | procedure AProgramPauseExecute(Sender: TObject);
|
---|
120 | procedure AProgramRunToCursorExecute(Sender: TObject);
|
---|
121 | procedure AProgramRunExecute(Sender: TObject);
|
---|
122 | procedure AProgramShowExecutionPointExecute(Sender: TObject);
|
---|
123 | procedure AProgramStepIntoExecute(Sender: TObject);
|
---|
124 | procedure AProgramStepOutExecute(Sender: TObject);
|
---|
125 | procedure AProgramStepOverExecute(Sender: TObject);
|
---|
126 | procedure AProgramStopExecute(Sender: TObject);
|
---|
127 | procedure AProjectCloseExecute(Sender: TObject);
|
---|
128 | procedure AProjectNewExecute(Sender: TObject);
|
---|
129 | procedure AProjectOpenExecute(Sender: TObject);
|
---|
130 | procedure AProjectSaveAsExecute(Sender: TObject);
|
---|
131 | procedure AProjectSaveExecute(Sender: TObject);
|
---|
132 | procedure AShowSourcePositionExecute(Sender: TObject);
|
---|
133 | procedure AShowTargetPositionExecute(Sender: TObject);
|
---|
134 | procedure AViewCompilersExecute(Sender: TObject);
|
---|
135 | procedure AViewInterpretterExecute(Sender: TObject);
|
---|
136 | procedure AViewLogExecute(Sender: TObject);
|
---|
137 | procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
---|
138 | procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
|
---|
139 | procedure FormCreate(Sender: TObject);
|
---|
140 | procedure FormDestroy(Sender: TObject);
|
---|
141 | procedure FormShow(Sender: TObject);
|
---|
142 | procedure TimerRefreshTimer(Sender: TObject);
|
---|
143 | private
|
---|
144 | procedure AProjectOpenRecentExecute(Sender: TObject);
|
---|
145 | procedure MenuItemTargetClick(Sender: TObject);
|
---|
146 | procedure ProjectOpen(FileName: string);
|
---|
147 | procedure UpdateToolBarHints;
|
---|
148 | procedure DockInit;
|
---|
149 | procedure LastOpenedListChange(Sender: TObject);
|
---|
150 | public
|
---|
151 | procedure MessagesChanged(Sender: TObject);
|
---|
152 | procedure TargetLogExecute(Lines: TStrings);
|
---|
153 | procedure TargetStateChanged(Sender: TObject);
|
---|
154 | procedure LoadFromRegistry(Context: TRegistryContext);
|
---|
155 | procedure SaveToRegistry(Context: TRegistryContext);
|
---|
156 | procedure UpdateInterface;
|
---|
157 | procedure UpdateStatusBar;
|
---|
158 | procedure UpdateTargetList;
|
---|
159 | end;
|
---|
160 |
|
---|
161 | var
|
---|
162 | FormMain: TFormMain;
|
---|
163 |
|
---|
164 |
|
---|
165 | implementation
|
---|
166 |
|
---|
167 | {$R *.lfm}
|
---|
168 |
|
---|
169 | uses
|
---|
170 | UCore, UFormCPU, UFormOptions, UFormMessages, UFormTargets, UFormOutput, UFormInput,
|
---|
171 | UFormMemory, UFormSourceCode, UFormTargetCode, UTargetInterpretter, UFormLog,
|
---|
172 | UBFTarget, UFormAbout;
|
---|
173 |
|
---|
174 | resourcestring
|
---|
175 | SProgramStarted = 'Program started';
|
---|
176 | SProgramStopped = 'Program stopped';
|
---|
177 | SNewProject = 'New project';
|
---|
178 | SCompileStart = 'Compiling...';
|
---|
179 | SDone = 'Done';
|
---|
180 | SChanged = 'Changed';
|
---|
181 | SUnsavedChanges = 'Unsaved changes';
|
---|
182 | SDoYouWantToSaveProject = 'There are unsaved changes in project. Do you want to save them?';
|
---|
183 | SCloseProjectFirst = 'Project need to be closed before it can be openned';
|
---|
184 | SError = 'Error';
|
---|
185 |
|
---|
186 | { TFormMain }
|
---|
187 |
|
---|
188 | procedure TFormMain.FormShow(Sender: TObject);
|
---|
189 | begin
|
---|
190 | Core.Init;
|
---|
191 | LoadFromRegistry(Core.ApplicationInfo.GetRegistryContext);
|
---|
192 | PageControlMain.TabIndex := 0;
|
---|
193 | try
|
---|
194 | if Core.OpenProjectOnStart and (Core.LastOpenedList.Items.Count > 0) then
|
---|
195 | ProjectOpen(Core.LastOpenedList.Items[0])
|
---|
196 | else AProjectNew.Execute;
|
---|
197 | finally
|
---|
198 | LastOpenedListChange(nil);
|
---|
199 | UpdateInterface;
|
---|
200 | UpdateToolBarHints;
|
---|
201 | UpdateTargetList;
|
---|
202 | DockInit;
|
---|
203 | Core.PersistentForm1.Load(Self, True);
|
---|
204 | Core.ThemeManager.UseTheme(Self);
|
---|
205 | FormSourceCode.UpdateTheme;
|
---|
206 | end;
|
---|
207 | end;
|
---|
208 |
|
---|
209 | procedure TFormMain.TimerRefreshTimer(Sender: TObject);
|
---|
210 | begin
|
---|
211 | FormCPU.Reload;
|
---|
212 | FormOutput.Reload;
|
---|
213 | FormMemory.Reload;
|
---|
214 | end;
|
---|
215 |
|
---|
216 | procedure TFormMain.TargetLogExecute(Lines: TStrings);
|
---|
217 | begin
|
---|
218 | FormLog.Memo1.Lines.AddStrings(Lines);
|
---|
219 | end;
|
---|
220 |
|
---|
221 | procedure TFormMain.TargetStateChanged(Sender: TObject);
|
---|
222 | begin
|
---|
223 | UpdateInterface;
|
---|
224 | if Core.CurrentTarget.State = rsPaused then
|
---|
225 | AProgramShowExecutionPoint.Execute;
|
---|
226 | if Core.CurrentTarget.State = rsStopped then
|
---|
227 | Core.CurrentTarget.Messages.AddMessage(SProgramStopped);
|
---|
228 | end;
|
---|
229 |
|
---|
230 | procedure TFormMain.MessagesChanged(Sender: TObject);
|
---|
231 | begin
|
---|
232 | FormMessages.Reload;
|
---|
233 | end;
|
---|
234 |
|
---|
235 | procedure TFormMain.MenuItemTargetClick(Sender: TObject);
|
---|
236 | var
|
---|
237 | I: Integer;
|
---|
238 | begin
|
---|
239 | if Sender is TMenuItem then
|
---|
240 | with TMenuItem(Sender) do begin
|
---|
241 | Core.CurrentTarget := TTarget(Core.Targets[MenuIndex]);
|
---|
242 | Checked := True;
|
---|
243 | for I := 0 to Parent.Count - 1 do
|
---|
244 | if Parent.Items[I].MenuIndex <> MenuIndex then Parent.Items[I].Checked := False;
|
---|
245 | end;
|
---|
246 | end;
|
---|
247 |
|
---|
248 | procedure TFormMain.ProjectOpen(FileName: string);
|
---|
249 | begin
|
---|
250 | if Core.Project.Openned then
|
---|
251 | raise Exception.Create(SCloseProjectFirst);
|
---|
252 | FormSourceCode.SynEdit1.Lines.LoadFromFile(FileName);
|
---|
253 | Core.LastOpenedList.AddItem(FileName);
|
---|
254 | Core.Project.FileName := FileName;
|
---|
255 | Core.Project.Openned := True;
|
---|
256 | Core.CurrentTarget.Compiled := False;
|
---|
257 | UpdateInterface;
|
---|
258 | end;
|
---|
259 |
|
---|
260 | procedure TFormMain.UpdateToolBarHints;
|
---|
261 | var
|
---|
262 | I: Integer;
|
---|
263 | begin
|
---|
264 | for I := 0 to ToolBarMain.ControlCount - 1 do
|
---|
265 | ToolBarMain.Controls[I].Hint := ToolBarMain.Controls[I].Caption;
|
---|
266 | end;
|
---|
267 |
|
---|
268 | procedure TFormMain.DockInit;
|
---|
269 | begin
|
---|
270 | FormSourceCode.ManualDock(TabSheetSource, nil, alClient);
|
---|
271 | FormSourceCode.Align := alClient;
|
---|
272 | FormSourceCode.Show;
|
---|
273 | FormTargetCode.ManualDock(TabSheetTarget, nil, alClient);
|
---|
274 | FormTargetCode.Align := alClient;
|
---|
275 | FormTargetCode.Show;
|
---|
276 | FormCPU.ManualDock(PanelCPU, nil, alClient);
|
---|
277 | FormCPU.Align := alClient;
|
---|
278 | FormCPU.Show;
|
---|
279 | FormInput.ManualDock(PanelInput, nil, alClient);
|
---|
280 | FormInput.Align := alClient;
|
---|
281 | FormInput.Show;
|
---|
282 | FormOutput.ManualDock(PanelOutput, nil, alClient);
|
---|
283 | FormOutput.Align := alClient;
|
---|
284 | FormOutput.Show;
|
---|
285 | FormMemory.ManualDock(PanelMemory, nil, alClient);
|
---|
286 | FormMemory.Align := alClient;
|
---|
287 | FormMemory.Show;
|
---|
288 | FormMessages.ManualDock(TabSheetMessages, nil, alClient);
|
---|
289 | FormMessages.Align := alClient;
|
---|
290 | FormMessages.Show;
|
---|
291 | PageControlRight.Width := FormMain.Width div 3;
|
---|
292 | PageControlBottom.Height := FormMain.Height div 5;
|
---|
293 | end;
|
---|
294 |
|
---|
295 | procedure TFormMain.LastOpenedListChange(Sender: TObject);
|
---|
296 | begin
|
---|
297 | Core.LastOpenedList.LoadToMenuItem(MenuItemOpenRecent, AProjectOpenRecentExecute);
|
---|
298 | Core.LastOpenedList.LoadToMenuItem(PopupMenuRecentFiles.Items, AProjectOpenRecentExecute);
|
---|
299 | end;
|
---|
300 |
|
---|
301 | procedure TFormMain.LoadFromRegistry(Context: TRegistryContext);
|
---|
302 | var
|
---|
303 | TargetName: string;
|
---|
304 | begin
|
---|
305 | with TRegistryEx.Create do
|
---|
306 | try
|
---|
307 | CurrentContext := Context;
|
---|
308 | TargetName := ReadStringWithDefault('TargetName', 'Interpretter');
|
---|
309 | Core.CurrentTarget := Core.Targets.FindByName(TargetName);
|
---|
310 | if not Assigned(Core.CurrentTarget) then
|
---|
311 | Core.CurrentTarget := TTarget(Core.Targets[0]);
|
---|
312 | Core.Optimizations.AddSub := ReadBoolWithDefault('OptimizationAddSubEnabled', True);
|
---|
313 | Core.Optimizations.Merge := ReadBoolWithDefault('OptimizationMerge', True);
|
---|
314 | Core.Optimizations.CopyMultiply := ReadBoolWithDefault('OptimizationCopyMultiplyEnabled', True);
|
---|
315 | Core.Optimizations.RelativeIndexes := ReadBoolWithDefault('OptimizationRelativeIndexesEnabled', True);
|
---|
316 | finally
|
---|
317 | Free;
|
---|
318 | end;
|
---|
319 | end;
|
---|
320 |
|
---|
321 | procedure TFormMain.SaveToRegistry(Context: TRegistryContext);
|
---|
322 | begin
|
---|
323 | with TRegistryEx.Create do
|
---|
324 | try
|
---|
325 | CurrentContext := Context;
|
---|
326 | WriteString('TargetName', Core.CurrentTarget.Name);
|
---|
327 | WriteBool('OptimizationAddSubEnabled', Core.Optimizations.AddSub);
|
---|
328 | WriteBool('OptimizationMerge', Core.Optimizations.Merge);
|
---|
329 | WriteBool('OptimizationCopyMultiplyEnabled', Core.Optimizations.CopyMultiply);
|
---|
330 | WriteBool('OptimizationRelativeIndexesEnabled', Core.Optimizations.RelativeIndexes);
|
---|
331 | finally
|
---|
332 | Free;
|
---|
333 | end;
|
---|
334 | end;
|
---|
335 |
|
---|
336 | procedure TFormMain.UpdateInterface;
|
---|
337 | var
|
---|
338 | Title: string;
|
---|
339 | begin
|
---|
340 | Title := '';
|
---|
341 | if Core.Project.FileName <> '' then Title := Core.Project.FileName;
|
---|
342 | if Core.Project.Modified then Title := Title + ' (' + SChanged + ')';
|
---|
343 | Title:= Title + ' - ' + Core.ApplicationInfo.AppName;
|
---|
344 | Caption := Title;
|
---|
345 | AProjectSave.Enabled := Core.Project.Modified;
|
---|
346 | FormSourceCode.SynEdit1.Enabled := Core.Project.Openned;
|
---|
347 | AProjectClose.Enabled := Core.Project.Openned;
|
---|
348 | AProjectSaveAs.Enabled := Core.Project.Openned;
|
---|
349 | AProgramRun.Enabled := (tcRun in Core.CurrentTarget.Capabilities) and
|
---|
350 | Core.Project.Openned and (Core.CurrentTarget.State = rsStopped) or (Core.CurrentTarget.State = rsPaused);
|
---|
351 | AProgramPause.Enabled := (tcPause in Core.CurrentTarget.Capabilities) and
|
---|
352 | Core.Project.Openned and (Core.CurrentTarget.State = rsRunning);
|
---|
353 | AProgramStop.Enabled := (tcStop in Core.CurrentTarget.Capabilities) and
|
---|
354 | Core.Project.Openned and (Core.CurrentTarget.State <> rsStopped);
|
---|
355 | AProgramCompile.Enabled := (tcCompile in Core.CurrentTarget.Capabilities) and
|
---|
356 | Core.Project.Openned;
|
---|
357 | AProgramStepInto.Enabled := (tcStepInto in Core.CurrentTarget.Capabilities) and
|
---|
358 | Core.Project.Openned and ((Core.CurrentTarget.State = rsPaused) or (Core.CurrentTarget.State = rsStopped));
|
---|
359 | AProgramStepOut.Enabled := (tcStepOut in Core.CurrentTarget.Capabilities) and
|
---|
360 | Core.Project.Openned and (Core.CurrentTarget.State = rsPaused);
|
---|
361 | AProgramRunToCursor.Enabled := (tcRunToCursor in Core.CurrentTarget.Capabilities) and
|
---|
362 | Core.Project.Openned and ((Core.CurrentTarget.State = rsPaused) or (Core.CurrentTarget.State = rsStopped));
|
---|
363 | AProgramStepOver.Enabled := (tcStepOver in Core.CurrentTarget.Capabilities) and
|
---|
364 | Core.Project.Openned and ((Core.CurrentTarget.State = rsPaused) or (Core.CurrentTarget.State = rsStopped));
|
---|
365 | AProgramShowExecutionPoint.Enabled := (tcPause in Core.CurrentTarget.Capabilities) and
|
---|
366 | Core.Project.Openned and (Core.CurrentTarget.State = rsPaused);
|
---|
367 | AShowSourcePosition.Enabled := Core.CurrentTarget.Compiled;
|
---|
368 | AShowTargetPosition.Enabled := Core.CurrentTarget.Compiled;
|
---|
369 | UpdateStatusBar;
|
---|
370 | end;
|
---|
371 |
|
---|
372 | procedure TFormMain.UpdateStatusBar;
|
---|
373 | begin
|
---|
374 | StatusBarMain.Panels[0].Text := IntToStr(FormSourceCode.SynEdit1.CaretXY.X) +
|
---|
375 | ', ' + IntToStr(FormSourceCode.SynEdit1.CaretXY.Y);
|
---|
376 | end;
|
---|
377 |
|
---|
378 | procedure TFormMain.UpdateTargetList;
|
---|
379 | var
|
---|
380 | I: Integer;
|
---|
381 | begin
|
---|
382 | Core.Targets.LoadToMenuItem(MenuItemTarget, MenuItemTargetClick, Core.CurrentTarget);
|
---|
383 | Core.Targets.LoadToMenuItem(PopupMenuTargets.Items, MenuItemTargetClick, Core.CurrentTarget);
|
---|
384 |
|
---|
385 | // Update toolbutton
|
---|
386 | I := Core.Targets.IndexOf(Core.CurrentTarget);
|
---|
387 | if I <> -1 then
|
---|
388 | with TTarget(Core.Targets[I]) do begin
|
---|
389 | ToolButtonTarget.ImageIndex := ImageIndex;
|
---|
390 | ToolButtonTarget.Caption := Name;
|
---|
391 | ToolButtonTarget.OnClick := MenuItemTargetClick();
|
---|
392 | end;
|
---|
393 | end;
|
---|
394 |
|
---|
395 | procedure TFormMain.FormCreate(Sender: TObject);
|
---|
396 | begin
|
---|
397 | UpdateTargetList;
|
---|
398 | Core.LastOpenedList.OnChange := LastOpenedListChange;
|
---|
399 | end;
|
---|
400 |
|
---|
401 | procedure TFormMain.FormDestroy(Sender: TObject);
|
---|
402 | begin
|
---|
403 | SaveToRegistry(Core.ApplicationInfo.GetRegistryContext);
|
---|
404 | end;
|
---|
405 |
|
---|
406 | procedure TFormMain.AProgramRunExecute(Sender: TObject);
|
---|
407 | begin
|
---|
408 | if Core.CurrentTarget is TTargetInterpretter then
|
---|
409 | TTargetInterpretter(Core.CurrentTarget).Input := FormInput.MemoInput.Lines.Text;
|
---|
410 | if not Core.CurrentTarget.Compiled then AProgramCompile.Execute;
|
---|
411 | Core.CurrentTarget.Run;
|
---|
412 | Core.CurrentTarget.Messages.AddMessage(SProgramStarted);
|
---|
413 | end;
|
---|
414 |
|
---|
415 | procedure TFormMain.AShowSourcePositionExecute(Sender: TObject);
|
---|
416 | var
|
---|
417 | DebugStep: TDebugStep;
|
---|
418 | begin
|
---|
419 | DebugStep := Core.CurrentTarget.DebugSteps.SearchByTargetPos(FormTargetCode.MemoTarget.SelStart);
|
---|
420 | if Assigned(DebugStep) then begin
|
---|
421 | FormSourceCode.SynEdit1.SelStart := DebugStep.SourcePosition;
|
---|
422 | PageControlMain.TabIndex := 0;
|
---|
423 | end;
|
---|
424 | end;
|
---|
425 |
|
---|
426 | procedure TFormMain.AShowTargetPositionExecute(Sender: TObject);
|
---|
427 | var
|
---|
428 | DebugStep: TDebugStep;
|
---|
429 | begin
|
---|
430 | DebugStep := Core.CurrentTarget.DebugSteps.SearchBySourcePos(FormSourceCode.SynEdit1.SelStart);
|
---|
431 | if Assigned(DebugStep) then begin
|
---|
432 | FormTargetCode.MemoTarget.SelStart := DebugStep.TargetPosition;
|
---|
433 | PageControlMain.TabIndex := 1;
|
---|
434 | end;
|
---|
435 | end;
|
---|
436 |
|
---|
437 | procedure TFormMain.AViewCompilersExecute(Sender: TObject);
|
---|
438 | begin
|
---|
439 | if not Assigned(FormTargets) then FormTargets := TFormTargets.Create(Self);
|
---|
440 | FormTargets.Show;
|
---|
441 | end;
|
---|
442 |
|
---|
443 | procedure TFormMain.AViewInterpretterExecute(Sender: TObject);
|
---|
444 | begin
|
---|
445 | FormCPU.Show;
|
---|
446 | end;
|
---|
447 |
|
---|
448 | procedure TFormMain.AViewLogExecute(Sender: TObject);
|
---|
449 | begin
|
---|
450 | if not Assigned(FormLog) then FormLog := TFormLog.Create(Self);
|
---|
451 | FormLog.Show;
|
---|
452 | end;
|
---|
453 |
|
---|
454 | procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
---|
455 | begin
|
---|
456 | Core.PersistentForm1.Save(Self);
|
---|
457 | end;
|
---|
458 |
|
---|
459 | procedure TFormMain.FormCloseQuery(Sender: TObject; var CanClose: boolean);
|
---|
460 | begin
|
---|
461 | if Core.Project.Modified then begin
|
---|
462 | AProjectClose.Execute;
|
---|
463 | if Core.Project.Openned then CanClose := False;
|
---|
464 | end;
|
---|
465 | end;
|
---|
466 |
|
---|
467 | procedure TFormMain.AExitExecute(Sender: TObject);
|
---|
468 | begin
|
---|
469 | Close;
|
---|
470 | end;
|
---|
471 |
|
---|
472 | procedure TFormMain.AOptionsExecute(Sender: TObject);
|
---|
473 | begin
|
---|
474 | FormOptions := TFormOptions.Create(nil);
|
---|
475 | try
|
---|
476 | FormOptions.Load;
|
---|
477 | if FormOptions.ShowModal = mrOK then begin
|
---|
478 | FormOptions.Save;
|
---|
479 | if Assigned(Core.CurrentTarget) then begin
|
---|
480 | Core.CurrentTarget.OptimizationLevel := Core.OptimizationLevel;
|
---|
481 | if Core.CurrentTarget is TBFTarget then begin
|
---|
482 | TBFTarget(Core.CurrentTarget).CellSize := Core.CellSize;
|
---|
483 | TBFTarget(Core.CurrentTarget).MemorySize := Core.MemorySize;
|
---|
484 | end;
|
---|
485 | end;
|
---|
486 | Core.ThemeManager.UseTheme(Self);
|
---|
487 | FormSourceCode.UpdateTheme;
|
---|
488 | end;
|
---|
489 | finally
|
---|
490 | FormOptions.Free;
|
---|
491 | end;
|
---|
492 | end;
|
---|
493 |
|
---|
494 | procedure TFormMain.AProgramCompileExecute(Sender: TObject);
|
---|
495 | begin
|
---|
496 | with Core.CurrentTarget do
|
---|
497 | try
|
---|
498 | AProgramStop.Execute;
|
---|
499 | SourceCode := FormSourceCode.SynEdit1.Text;
|
---|
500 | ProjectFileName := Core.Project.FileName;
|
---|
501 | ProgramName := ExtractFileNameOnly(Core.Project.FileName);
|
---|
502 | if Core.CurrentTarget is TBFTarget then
|
---|
503 | TBFTarget(Core.CurrentTarget).Optimizations := Core.Optimizations;
|
---|
504 | Core.CurrentTarget.Messages.AddMessage(SCompileStart);
|
---|
505 | Application.ProcessMessages;
|
---|
506 | Compile;
|
---|
507 | Core.CurrentTarget.Messages.AppendMessage(SDone);
|
---|
508 | FormTargetCode.MemoTarget.Text := TargetCode;
|
---|
509 | UpdateInterface;
|
---|
510 | except
|
---|
511 | on E: Exception do
|
---|
512 | MessageDlg(SError, E.Message, mtError, [mbOk], 0);
|
---|
513 | end;
|
---|
514 | end;
|
---|
515 |
|
---|
516 | procedure TFormMain.ABreakpointToggleExecute(Sender: TObject);
|
---|
517 | var
|
---|
518 | DebugStep: TDebugStep;
|
---|
519 | BreakPoint: TBreakPoint;
|
---|
520 | begin
|
---|
521 | DebugStep := Core.CurrentTarget.DebugSteps.SearchBySourcePos(FormSourceCode.SynEdit1.SelStart);
|
---|
522 | if Assigned(DebugStep) then begin
|
---|
523 | BreakPoint := Core.CurrentTarget.BreakPoints.SearchByTargetPos(DebugStep.TargetPosition);
|
---|
524 | if Assigned(BreakPoint) then
|
---|
525 | Core.CurrentTarget.BreakPoints.Delete(Core.CurrentTarget.BreakPoints.IndexOf(BreakPoint))
|
---|
526 | else Core.CurrentTarget.BreakPoints.AddItem(DebugStep.TargetPosition);
|
---|
527 | end;
|
---|
528 | end;
|
---|
529 |
|
---|
530 | procedure TFormMain.AAboutExecute(Sender: TObject);
|
---|
531 | begin
|
---|
532 | FormAbout := TFormAbout.Create(nil);
|
---|
533 | try
|
---|
534 | FormAbout.ApplicationInfo := Core.ApplicationInfo;
|
---|
535 | FormAbout.CoolTranslator := Core.CoolTranslator1;
|
---|
536 | Core.ScaleDPI1.ScaleControl(FormAbout, Core.ScaleDPI1.DesignDPI);
|
---|
537 | FormAbout.ShowModal;
|
---|
538 | finally
|
---|
539 | FreeAndNil(FormAbout);
|
---|
540 | end;
|
---|
541 | end;
|
---|
542 |
|
---|
543 | procedure TFormMain.AProgramPauseExecute(Sender: TObject);
|
---|
544 | begin
|
---|
545 | Core.CurrentTarget.Pause;
|
---|
546 | end;
|
---|
547 |
|
---|
548 | procedure TFormMain.AProgramRunToCursorExecute(Sender: TObject);
|
---|
549 | var
|
---|
550 | DebugStep: TDebugStep;
|
---|
551 | begin
|
---|
552 | if Core.CurrentTarget.State = rsStopped then begin
|
---|
553 | if not Core.CurrentTarget.Compiled then AProgramCompile.Execute;
|
---|
554 | DebugStep := Core.CurrentTarget.DebugSteps.SearchBySourcePos(FormSourceCode.SynEdit1.SelStart);
|
---|
555 | Core.CurrentTarget.BreakPoints.SetSystem(DebugStep.TargetPosition);
|
---|
556 | AProgramRun.Execute;
|
---|
557 | end else begin
|
---|
558 | DebugStep := Core.CurrentTarget.DebugSteps.SearchBySourcePos(FormSourceCode.SynEdit1.SelStart);
|
---|
559 | Core.CurrentTarget.RunToCursor(DebugStep.TargetPosition);
|
---|
560 | end;
|
---|
561 | end;
|
---|
562 |
|
---|
563 | procedure TFormMain.AProgramShowExecutionPointExecute(Sender: TObject);
|
---|
564 | var
|
---|
565 | DebugStep: TDebugStep;
|
---|
566 | begin
|
---|
567 | DebugStep := Core.CurrentTarget.DebugSteps.SearchByTargetPos(Core.CurrentTarget.ExecutionPosition);
|
---|
568 | FormSourceCode.SynEdit1.SelStart := DebugStep.SourcePosition;
|
---|
569 | FormTargetCode.MemoTarget.SelStart := DebugStep.TargetPosition;
|
---|
570 | if PageControlMain.TabIndex = 0 then FormSourceCode.SynEdit1.SetFocus;
|
---|
571 | if PageControlMain.TabIndex = 1 then FormTargetCode.MemoTarget.SetFocus;
|
---|
572 | end;
|
---|
573 |
|
---|
574 | procedure TFormMain.AProgramStepIntoExecute(Sender: TObject);
|
---|
575 | begin
|
---|
576 | if Core.CurrentTarget.State = rsStopped then begin
|
---|
577 | if not Core.CurrentTarget.Compiled then AProgramCompile.Execute;
|
---|
578 | Core.CurrentTarget.BreakPoints.SetSystem(TDebugStep(Core.CurrentTarget.DebugSteps.First).TargetPosition);
|
---|
579 | AProgramRun.Execute;
|
---|
580 | end else Core.CurrentTarget.StepInto;
|
---|
581 | end;
|
---|
582 |
|
---|
583 | procedure TFormMain.AProgramStepOutExecute(Sender: TObject);
|
---|
584 | begin
|
---|
585 | Core.CurrentTarget.StepOut;
|
---|
586 | end;
|
---|
587 |
|
---|
588 | procedure TFormMain.AProgramStepOverExecute(Sender: TObject);
|
---|
589 | begin
|
---|
590 | if Core.CurrentTarget.State = rsStopped then begin
|
---|
591 | if not Core.CurrentTarget.Compiled then AProgramCompile.Execute;
|
---|
592 | Core.CurrentTarget.BreakPoints.SetSystem(TDebugStep(Core.CurrentTarget.DebugSteps.First).TargetPosition);
|
---|
593 | AProgramRun.Execute;
|
---|
594 | end else Core.CurrentTarget.StepOver;
|
---|
595 | end;
|
---|
596 |
|
---|
597 | procedure TFormMain.AProgramStopExecute(Sender: TObject);
|
---|
598 | begin
|
---|
599 | Core.CurrentTarget.Stop;
|
---|
600 | end;
|
---|
601 |
|
---|
602 | procedure TFormMain.AProjectCloseExecute(Sender: TObject);
|
---|
603 | var
|
---|
604 | DialogResult: TModalResult;
|
---|
605 | begin
|
---|
606 | DialogResult := mrNo;
|
---|
607 | if Core.Project.Modified then begin
|
---|
608 | DialogResult := MessageDlg(SUnsavedChanges, SDoYouWantToSaveProject, mtConfirmation, [mbYes, mbNo, mbCancel], 0);
|
---|
609 | if DialogResult = mrYes then begin
|
---|
610 | AProjectSave.Execute;
|
---|
611 | end;
|
---|
612 | end;
|
---|
613 | if (DialogResult = mrNo) or (DialogResult = mrYes) then begin
|
---|
614 | AProgramStop.Execute;
|
---|
615 | Core.Project.Openned := False;
|
---|
616 | FormSourceCode.SynEdit1.Clear;
|
---|
617 | UpdateInterface;
|
---|
618 | end;
|
---|
619 | end;
|
---|
620 |
|
---|
621 | procedure TFormMain.AProjectNewExecute(Sender: TObject);
|
---|
622 | begin
|
---|
623 | AProjectClose.Execute;
|
---|
624 | if Core.Project.Openned then Exit;
|
---|
625 | Core.Project.FileName := 'Examples' + DirectorySeparator + SNewProject + '.b';
|
---|
626 | FormSourceCode.SynEdit1.Clear;
|
---|
627 | Core.Project.Openned := True;
|
---|
628 | Core.CurrentTarget.Compiled := False;
|
---|
629 | UpdateInterface;
|
---|
630 | end;
|
---|
631 |
|
---|
632 | procedure TFormMain.AProjectOpenRecentExecute(Sender: TObject);
|
---|
633 | begin
|
---|
634 | AProjectClose.Execute;
|
---|
635 | if Core.Project.Openned then Exit;
|
---|
636 | ProjectOpen(Core.LastOpenedList.Items[TMenuItem(Sender).MenuIndex]);
|
---|
637 | end;
|
---|
638 |
|
---|
639 | procedure TFormMain.AProjectOpenExecute(Sender: TObject);
|
---|
640 | begin
|
---|
641 | if Core.LastOpenedList.Items.Count > 0 then
|
---|
642 | OpenDialog1.FileName := Core.LastOpenedList.Items[0]
|
---|
643 | else OpenDialog1.FileName := ExtractFileDir(Application.ExeName) + DirectorySeparator + 'Examples';
|
---|
644 | OpenDialog1.InitialDir := ExtractFileDir(OpenDialog1.FileName);
|
---|
645 | if OpenDialog1.Execute then begin
|
---|
646 | AProjectClose.Execute;
|
---|
647 | if Core.Project.Openned then Exit;
|
---|
648 | ProjectOpen(OpenDialog1.FileName);
|
---|
649 | end;
|
---|
650 | end;
|
---|
651 |
|
---|
652 | procedure TFormMain.AProjectSaveAsExecute(Sender: TObject);
|
---|
653 | begin
|
---|
654 | SaveDialog1.FileName := Core.Project.FileName;
|
---|
655 | if SaveDialog1.Execute then begin
|
---|
656 | FormSourceCode.SynEdit1.Lines.SaveToFile(SaveDialog1.FileName);
|
---|
657 | Core.Project.FileName := SaveDialog1.FileName;
|
---|
658 | Core.LastOpenedList.AddItem(SaveDialog1.FileName);
|
---|
659 | Core.Project.Modified := False;
|
---|
660 | UpdateInterface;
|
---|
661 | end;
|
---|
662 | end;
|
---|
663 |
|
---|
664 | procedure TFormMain.AProjectSaveExecute(Sender: TObject);
|
---|
665 | begin
|
---|
666 | if Core.Project.Modified and FileExistsUTF8(Core.Project.FileName) then begin
|
---|
667 | FormSourceCode.SynEdit1.Lines.SaveToFile(Core.Project.FileName);
|
---|
668 | Core.Project.Modified := False;
|
---|
669 | UpdateInterface;
|
---|
670 | end else AProjectSaveAs.Execute;
|
---|
671 | end;
|
---|
672 |
|
---|
673 | end.
|
---|
674 |
|
---|