- Timestamp:
- Feb 9, 2012, 3:37:38 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 1 1 lib 2 2 LazFuckIDE.exe 3 LazFuckIDE.lps
-
- Property svn:ignore
-
trunk/UBrainFuck.pas
r6 r7 9 9 10 10 type 11 TBrainFuckInterpretter = class; 11 12 12 13 { TBrainFuck } … … 20 21 TRunState = (rsStopped, rsPaused, rsRunning); 21 22 22 { TBrainFuckInterpreter } 23 24 TBrainFuckInterpreter = class 23 { TBrainFuckInterpretterThread } 24 25 TBrainFuckInterpretterThread = class(TThread) 26 Parent: TBrainFuckInterpretter; 27 procedure Execute; override; 28 end; 29 30 { TBrainFuckInterpretter } 31 32 TBrainFuckInterpretter = class 25 33 private 26 34 FOnChangeState: TNotifyEvent; 27 35 FState: TRunState; 36 FThreadState: Boolean; 37 FThread: TBrainFuckInterpretterThread; 28 38 procedure SetState(AValue: TRunState); 29 39 procedure Write(Value: Byte); 30 40 function Read: Byte; 31 41 function ReadCode: Char; 42 procedure SetThread(State: Boolean); 32 43 public 33 44 Source: string; … … 60 71 SReadInputError = 'Read input error'; 61 72 62 { TBrainFuckInterpreter } 63 64 procedure TBrainFuckInterpreter.Write(Value: Byte); 73 { TBrainFuckInterpretterThread } 74 75 procedure TBrainFuckInterpretterThread.Execute; 76 begin 77 repeat 78 while Parent.SourcePosition < Length(Parent.Source) do begin 79 Parent.SingleStep; 80 while Parent.State = rsPaused do begin 81 Sleep(1); 82 end; 83 end; 84 Parent.SetState(rsStopped); 85 until Terminated; 86 end; 87 88 { TBrainFuckInterpretter } 89 90 procedure TBrainFuckInterpretter.Write(Value: Byte); 65 91 begin 66 92 Output := Output + Char(Value); 67 93 end; 68 94 69 procedure TBrainFuckInterpret er.SetState(AValue: TRunState);95 procedure TBrainFuckInterpretter.SetState(AValue: TRunState); 70 96 begin 71 97 if FState = AValue then Exit; … … 74 100 end; 75 101 76 function TBrainFuckInterpret er.Read: Byte;102 function TBrainFuckInterpretter.Read: Byte; 77 103 var 78 104 Character: string; … … 87 113 end; 88 114 89 function TBrainFuckInterpret er.ReadCode: Char;115 function TBrainFuckInterpretter.ReadCode: Char; 90 116 var 91 117 Code: string; … … 95 121 end; 96 122 97 procedure TBrainFuckInterpreter.Reset; 123 procedure TBrainFuckInterpretter.SetThread(State: Boolean); 124 begin 125 if FThreadState = State then Exit; 126 FThreadState := State; 127 if State then begin 128 FThread := TBrainFuckInterpretterThread.Create(True); 129 FThread.Parent := Self; 130 FThread.FreeOnTerminate := False; 131 FThread.Start; 132 end else begin 133 FThread.Free; 134 end; 135 end; 136 137 procedure TBrainFuckInterpretter.Reset; 98 138 var 99 139 I: Integer; … … 109 149 end; 110 150 111 procedure TBrainFuckInterpret er.SingleStep;151 procedure TBrainFuckInterpretter.SingleStep; 112 152 var 113 153 CodeText: string; … … 155 195 end; 156 196 157 procedure TBrainFuckInterpret er.Run;197 procedure TBrainFuckInterpretter.Run; 158 198 begin 159 199 SetState(rsRunning); 160 200 Reset; 161 while SourcePosition < Length(Source) do begin 162 SingleStep; 163 Application.ProcessMessages; 164 while State = rsPaused do begin 165 Sleep(1); 166 Application.ProcessMessages; 167 end; 168 end; 201 SetThread(True); 202 end; 203 204 procedure TBrainFuckInterpretter.Pause; 205 begin 206 if State = rsRunning then SetState(rsPaused); 207 end; 208 209 procedure TBrainFuckInterpretter.Stop; 210 begin 169 211 SetState(rsStopped); 170 212 end; 171 213 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); 180 end; 181 182 constructor TBrainFuckInterpreter.Create; 214 constructor TBrainFuckInterpretter.Create; 183 215 begin 184 216 SetLength(Memory, 32000); 185 217 end; 186 218 187 destructor TBrainFuckInterpreter.Destroy; 188 begin 219 destructor TBrainFuckInterpretter.Destroy; 220 begin 221 SetThread(False); 189 222 inherited Destroy; 190 223 end; -
trunk/UMainForm.pas
r6 r7 78 78 Modified: Boolean; 79 79 ProjectFileName: string; 80 BrainFuckInterpreter: TBrainFuckInterpret er;80 BrainFuckInterpreter: TBrainFuckInterpretter; 81 81 procedure UpdateInterface; 82 82 end; … … 129 129 procedure TMainForm.FormCreate(Sender: TObject); 130 130 begin 131 BrainFuckInterpreter := TBrainFuckInterpret er.Create;131 BrainFuckInterpreter := TBrainFuckInterpretter.Create; 132 132 BrainFuckInterpreter.OnChangeState := BrainFuckInterpreterChangeState; 133 133 end;
Note:
See TracChangeset
for help on using the changeset viewer.