- Timestamp:
- Feb 9, 2012, 3:22:38 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 10 added
- 1 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UBrainFuck.pas
r5 r6 18 18 end; 19 19 20 TRunState = (rsStopped, rsPaused, rsRunning); 21 20 22 { TBrainFuckInterpreter } 21 23 22 24 TBrainFuckInterpreter = class 23 25 private 26 FOnChangeState: TNotifyEvent; 27 FState: TRunState; 28 procedure SetState(AValue: TRunState); 24 29 procedure Write(Value: Byte); 25 30 function Read: Byte; … … 39 44 procedure SingleStep; 40 45 procedure Run; 46 procedure Pause; 47 procedure Stop; 41 48 constructor Create; 42 49 destructor Destroy; override; 50 property State: TRunState read FState; 51 property OnChangeState: TNotifyEvent read FOnChangeState write FOnChangeState; 43 52 end; 44 53 … … 58 67 end; 59 68 69 procedure TBrainFuckInterpreter.SetState(AValue: TRunState); 70 begin 71 if FState = AValue then Exit; 72 FState := AValue; 73 if Assigned(FOnChangeState) then FOnChangeState(Self); 74 end; 75 60 76 function TBrainFuckInterpreter.Read: Byte; 61 77 var 62 78 Character: string; 63 79 begin 64 if InputPosition < Length(Input) then begin 65 Character := Copy(Input, InputPosition, 1); 66 Result := Ord(Character[1]); 67 Inc(InputPosition); 68 end else 69 raise Exception.Create(SReadInputError); 80 while InputPosition >= Length(Input) do begin 81 Sleep(1); 82 Application.ProcessMessages; 83 end; 84 Character := Copy(Input, InputPosition, 1); 85 Result := Ord(Character[1]); 86 Inc(InputPosition); 70 87 end; 71 88 … … 140 157 procedure TBrainFuckInterpreter.Run; 141 158 begin 159 SetState(rsRunning); 142 160 Reset; 143 161 while SourcePosition < Length(Source) do begin 144 162 SingleStep; 145 163 Application.ProcessMessages; 146 end; 164 while State = rsPaused do begin 165 Sleep(1); 166 Application.ProcessMessages; 167 end; 168 end; 169 SetState(rsStopped); 170 end; 171 172 procedure TBrainFuckInterpreter.Pause; 173 begin 174 if State = rsRunning then SetState(rsPaused); 175 end; 176 177 procedure TBrainFuckInterpreter.Stop; 178 begin 179 SetState(rsStopped); 147 180 end; 148 181 -
trunk/UInterpreterForm.lfm
r5 r6 1 1 object InterpreterForm: TInterpreterForm 2 Left = 2 422 Left = 262 3 3 Height = 509 4 Top = 1 164 Top = 127 5 5 Width = 762 6 6 Caption = 'Runtime' … … 10 10 object Panel3: TPanel 11 11 Left = 0 12 Height = 50913 Top = 012 Height = 483 13 Top = 26 14 14 Width = 323 15 15 Align = alLeft 16 16 BevelOuter = bvNone 17 ClientHeight = 50917 ClientHeight = 483 18 18 ClientWidth = 323 19 19 TabOrder = 0 … … 34 34 Width = 309 35 35 Anchors = [akTop, akLeft, akRight, akBottom] 36 OnKeyPress = MemoInputKeyPress 37 ScrollBars = ssAutoBoth 36 38 TabOrder = 0 37 39 end … … 56 58 object Panel2: TPanel 57 59 Left = 0 58 Height = 2 6260 Height = 236 59 61 Top = 247 60 62 Width = 323 61 63 Align = alClient 62 64 BevelOuter = bvNone 63 ClientHeight = 2 6265 ClientHeight = 236 64 66 ClientWidth = 323 65 67 TabOrder = 2 … … 74 76 object MemoOutput: TMemo 75 77 Left = 8 76 Height = 2 3778 Height = 211 77 79 Top = 22 78 80 Width = 309 79 81 Anchors = [akTop, akLeft, akRight, akBottom] 82 ScrollBars = ssAutoBoth 80 83 TabOrder = 0 81 84 end … … 84 87 object Splitter2: TSplitter 85 88 Left = 323 86 Height = 50987 Top = 089 Height = 483 90 Top = 26 88 91 Width = 5 89 92 end 90 93 object Panel4: TPanel 91 94 Left = 328 92 Height = 50993 Top = 095 Height = 483 96 Top = 26 94 97 Width = 434 95 98 Align = alClient 96 99 BevelOuter = bvNone 97 ClientHeight = 509100 ClientHeight = 483 98 101 ClientWidth = 434 99 102 TabOrder = 2 … … 148 151 object ListViewMemory: TListView 149 152 Left = 8 150 Height = 3 84153 Height = 358 151 154 Top = 120 152 155 Width = 422 … … 179 182 end 180 183 end 184 object ToolBar1: TToolBar 185 Left = 0 186 Height = 26 187 Top = 0 188 Width = 762 189 Caption = 'ToolBar1' 190 Images = MainForm.ImageList1 191 TabOrder = 3 192 object ToolButton1: TToolButton 193 Left = 1 194 Top = 2 195 Action = MainForm.AProgramRun 196 end 197 object ToolButton2: TToolButton 198 Left = 24 199 Top = 2 200 Action = MainForm.AProgramPause 201 end 202 object ToolButton3: TToolButton 203 Left = 47 204 Top = 2 205 Action = MainForm.AProgramStop 206 end 207 end 181 208 object Timer1: TTimer 182 209 Interval = 500 -
trunk/UInterpreterForm.pas
r5 r6 36 36 Splitter2: TSplitter; 37 37 Timer1: TTimer; 38 ToolBar1: TToolBar; 39 ToolButton1: TToolButton; 40 ToolButton2: TToolButton; 41 ToolButton3: TToolButton; 38 42 procedure ListViewMemoryData(Sender: TObject; Item: TListItem); 43 procedure MemoInputKeyPress(Sender: TObject; var Key: char); 39 44 procedure Timer1Timer(Sender: TObject); 40 45 private … … 42 47 public 43 48 procedure RefreshListViewMemory; 49 procedure UpadateInterface; 44 50 end; 45 51 … … 71 77 end; 72 78 79 procedure TInterpreterForm.UpadateInterface; 80 begin 81 MainForm.UpdateInterface; 82 end; 83 73 84 procedure TInterpreterForm.ListViewMemoryData(Sender: TObject; Item: TListItem); 74 85 var … … 86 97 end; 87 98 99 procedure TInterpreterForm.MemoInputKeyPress(Sender: TObject; var Key: char); 100 begin 101 with MainForm.BrainFuckInterpreter do Input := Input + Key; 102 end; 103 88 104 end. 89 105 -
trunk/UMainForm.lfm
r5 r6 68 68 Left = 103 69 69 Top = 2 70 Action = A Run70 Action = AProgramRun 71 71 end 72 72 object ToolButton7: TToolButton … … 369 369 } 370 370 end 371 object MenuItem17: TMenuItem 372 Caption = '-' 373 end 371 374 object MenuItem12: TMenuItem 372 Action = A Run375 Action = AProgramRun 373 376 Bitmap.Data = { 374 377 36040000424D3604000000000000360000002800000010000000100000000100 … … 407 410 0000000000000000000000000000000000000000000000000000 408 411 } 412 end 413 object MenuItem15: TMenuItem 414 Action = AProgramPause 415 end 416 object MenuItem16: TMenuItem 417 Action = AProgramStop 409 418 end 410 419 end … … 499 508 ImageIndex = 8 500 509 end 501 object A Run: TAction510 object AProgramRun: TAction 502 511 Caption = 'Run' 503 512 ImageIndex = 1 504 OnExecute = A RunExecute513 OnExecute = AProgramRunExecute 505 514 end 506 515 object AAbout: TAction … … 510 519 Caption = 'Help' 511 520 ImageIndex = 6 521 end 522 object AProgramPause: TAction 523 Caption = 'Pause' 524 ImageIndex = 11 525 OnExecute = AProgramPauseExecute 526 end 527 object AProgramStop: TAction 528 Caption = 'Stop' 529 ImageIndex = 10 530 OnExecute = AProgramStopExecute 512 531 end 513 532 end … … 516 535 top = 96 517 536 Bitmap = { 518 4C690 A0000001000000010000000000000000000000000000000000000000000537 4C690C0000001000000010000000000000000000000000000000000000000000 519 538 0000000000000000000000000000000000000000000000000000000000000000 520 539 000000000000000000000000000000000000000000FF000000FF000000FF0000 … … 836 855 00FF000000FF0000000000000000000000000000000000000000000000000000 837 856 0000000000000000000000000000000000000000000000000000000000000000 857 0000000000000000000000000000000000000000000000000000000000000000 858 0000000000000000000000000000000000000000000000000000000000000000 859 0000000000000000000000000000000000000000000000000000000000000000 860 0000000000000000000000000000000000000000000000000000000000000000 861 0000000000000000000000000000000000000000000000000000000000000000 862 0000000000000000000000000000000000000000000000000000000000000000 863 0000000000000000000000000000000000000000000000000000000000000000 864 0000000000000000000000000000000000000000000000000000000000000000 865 0000000000000000000000000000000000000000000000000000000000000000 866 FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000 867 0000000000000000000000000000000000000000000000000000000000000000 868 FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000 869 0000000000000000000000000000000000000000000000000000000000000000 870 FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000 871 0000000000000000000000000000000000000000000000000000000000000000 872 FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000 873 0000000000000000000000000000000000000000000000000000000000000000 874 FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000 875 0000000000000000000000000000000000000000000000000000000000000000 876 FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000 877 0000000000000000000000000000000000000000000000000000000000000000 878 FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000 879 0000000000000000000000000000000000000000000000000000000000000000 880 FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000 881 0000000000000000000000000000000000000000000000000000000000000000 882 0000000000000000000000000000000000000000000000000000000000000000 883 0000000000000000000000000000000000000000000000000000000000000000 884 0000000000000000000000000000000000000000000000000000000000000000 885 0000000000000000000000000000000000000000000000000000000000000000 886 0000000000000000000000000000000000000000000000000000000000000000 887 0000000000000000000000000000000000000000000000000000000000000000 888 0000000000000000000000000000000000000000000000000000000000000000 889 0000000000000000000000000000000000000000000000000000000000000000 890 0000000000000000000000000000000000000000000000000000000000000000 891 0000000000000000000000000000000000000000000000000000000000000000 892 0000000000000000000000000000000000000000000000000000000000000000 893 0000000000000000000000000000000000000000000000000000DE9077BFDA8A 894 70FFD88367FFD57C61FF0000000000000000DE9077BFDA8A70FFD88367FFD57C 895 61FF000000000000000000000000000000000000000000000000D9866CBFEBB0 896 9DFFF0BBABFFD27457FF0000000000000000D9866CBFEBB09DFFF0BBABFFD274 897 57FF000000000000000000000000000000000000000000000000D57C61BFE8A7 898 93FFEDB6A3FFCD6849FF0000000000000000D57C61BFE8A793FFEDB6A3FFCD68 899 49FF000000000000000000000000000000000000000000000000D27457BFE5A1 900 8BFFEBAF9AFFC95E3EFF0000000000000000D27457BFE5A18BFFEBAF9AFFC95E 901 3EFF000000000000000000000000000000000000000000000000CD6849BFE198 902 81FFE8A793FFC45432FF0000000000000000CD6849BFE19881FFE8A793FFC454 903 32FF000000000000000000000000000000000000000000000000C86A4DBFE7A5 904 90FFE5A18BFFBF4A27FF0000000000000000C86A4DBFE7A590FFE5A18BFFBF4A 905 27FF000000000000000000000000000000000000000000000000B95435BFE299 906 84FFE29A85FFB5401DFF0000000000000000B95435BFE29984FFE29A85FFB540 907 1DFF000000000000000000000000000000000000000000000000BF4A27C0D985 908 6BFFDF957EFFAA3A18FF0000000000000000BF4A27C0D9856BFFDF957EFFAA3A 909 18FF000000000000000000000000000000000000000000000000B5401DBFD57C 910 61FFDE9077FF993414FF0000000000000000B5401DBFD57C61FFDE9077FF9934 911 14FF000000000000000000000000000000000000000000000000AA3A18BFD375 912 58FFDC8B71FF8A2C0FFF0000000000000000AA3A18BFD37558FFDC8B71FF8A2C 913 0FFF000000000000000000000000000000000000000000000000993414BFCF6F 914 50FFDA886DFF7F270BFF0000000000000000993414BFCF6F50FFDA886DFF7F27 915 0BFF0000000000000000000000000000000000000000000000008A2C0FBF842A 916 0EFF7C260BFF7A250AFF00000000000000008A2C0FBF842A0EFF7C260BFF7A25 917 0AFF000000000000000000000000000000000000000000000000000000000000 918 0000000000000000000000000000000000000000000000000000000000000000 919 0000000000000000000000000000000000000000000000000000000000000000 920 0000000000000000000000000000000000000000000000000000000000000000 838 921 0000000000000000000000000000 839 922 } -
trunk/UMainForm.pas
r5 r6 16 16 ACompile: TAction; 17 17 AAbout: TAction; 18 AProgramPause: TAction; 19 AProgramStop: TAction; 18 20 AHelp: TAction; 19 A Run: TAction;21 AProgramRun: TAction; 20 22 AProjectNew: TAction; 21 23 AExit: TAction; … … 34 36 MenuItem13: TMenuItem; 35 37 MenuItem14: TMenuItem; 38 MenuItem15: TMenuItem; 39 MenuItem16: TMenuItem; 40 MenuItem17: TMenuItem; 36 41 MenuItem2: TMenuItem; 37 42 MenuItem3: TMenuItem; … … 55 60 ToolButton7: TToolButton; 56 61 procedure AExitExecute(Sender: TObject); 62 procedure AProgramPauseExecute(Sender: TObject); 63 procedure AProgramStopExecute(Sender: TObject); 57 64 procedure AProjectCloseExecute(Sender: TObject); 58 65 procedure AProjectNewExecute(Sender: TObject); … … 60 67 procedure AProjectSaveAsExecute(Sender: TObject); 61 68 procedure AProjectSaveExecute(Sender: TObject); 62 procedure A RunExecute(Sender: TObject);69 procedure AProgramRunExecute(Sender: TObject); 63 70 procedure FormCloseQuery(Sender: TObject; var CanClose: boolean); 64 71 procedure FormCreate(Sender: TObject); … … 67 74 procedure MemoSourceChange(Sender: TObject); 68 75 private 69 { private declarations }76 procedure BrainFuckInterpreterChangeState(Sender: TObject); 70 77 public 71 78 Modified: Boolean; … … 95 102 begin 96 103 Modified := True; 104 UpdateInterface; 105 end; 106 107 procedure TMainForm.BrainFuckInterpreterChangeState(Sender: TObject); 108 begin 97 109 UpdateInterface; 98 110 end; … … 109 121 MemoSource.Enabled := ProjectFileName <> ''; 110 122 AProjectClose.Enabled := ProjectFileName <> ''; 111 ARun.Enabled := ProjectFileName <> ''; 123 AProgramRun.Enabled := (ProjectFileName <> '') and (BrainFuckInterpreter.State = rsStopped); 124 AProgramPause.Enabled := (ProjectFileName <> '') and (BrainFuckInterpreter.State = rsRunning); 125 AProgramStop.Enabled := (ProjectFileName <> '') and (BrainFuckInterpreter.State <> rsStopped); 112 126 ACompile.Enabled := ProjectFileName <> ''; 113 127 end; … … 116 130 begin 117 131 BrainFuckInterpreter := TBrainFuckInterpreter.Create; 132 BrainFuckInterpreter.OnChangeState := BrainFuckInterpreterChangeState; 118 133 end; 119 134 … … 123 138 end; 124 139 125 procedure TMainForm.A RunExecute(Sender: TObject);140 procedure TMainForm.AProgramRunExecute(Sender: TObject); 126 141 begin 127 142 InterpreterForm.Show; … … 138 153 begin 139 154 Close; 155 end; 156 157 procedure TMainForm.AProgramPauseExecute(Sender: TObject); 158 begin 159 MainForm.BrainFuckInterpreter.Pause 160 end; 161 162 procedure TMainForm.AProgramStopExecute(Sender: TObject); 163 begin 164 MainForm.BrainFuckInterpreter.Stop; 140 165 end; 141 166
Note:
See TracChangeset
for help on using the changeset viewer.