Changeset 30 for trunk/Target/UTargetInterpretter.pas
- Timestamp:
- Feb 18, 2012, 7:49:17 PM (13 years ago)
- Location:
- trunk/Target
- Files:
-
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Target/UTargetInterpretter.pas
r29 r30 1 unit U BrainFuck;1 unit UTargetInterpretter; 2 2 3 3 {$mode Delphi}{$H+} … … 9 9 10 10 type 11 T BrainFuckInterpretter = class;11 TTargetInterpretter = class; 12 12 13 13 14 14 TRunState = (rsStopped, rsPaused, rsRunning); 15 15 16 { T BrainFuckInterpretterThread }17 18 T BrainFuckInterpretterThread = class(TThread)19 Parent: T BrainFuckInterpretter;16 { TTargetInterpretterThread } 17 18 TTargetInterpretterThread = class(TThread) 19 Parent: TTargetInterpretter; 20 20 procedure Execute; override; 21 21 end; … … 26 26 TCommandHandler = procedure of object; 27 27 28 { T BrainFuckInterpretter }29 30 T BrainFuckInterpretter = class28 { TTargetInterpretter } 29 30 TTargetInterpretter = class 31 31 private 32 32 FCellSize: Integer; … … 34 34 FState: TRunState; 35 35 FThreadState: Boolean; 36 FThread: T BrainFuckInterpretterThread;36 FThread: TTargetInterpretterThread; 37 37 FStepCount: Integer; 38 38 FCommandTable: array[TBrainFuckCommand] of TCommandHandler; … … 88 88 SMemoryCellOutOfRange = 'Memory cell %s value out of range'; 89 89 90 { T BrainFuckInterpretterThread }91 92 procedure T BrainFuckInterpretterThread.Execute;90 { TTargetInterpretterThread } 91 92 procedure TTargetInterpretterThread.Execute; 93 93 begin 94 94 repeat … … 103 103 end; 104 104 105 { T BrainFuckInterpretter }106 107 procedure T BrainFuckInterpretter.SetState(AValue: TRunState);105 { TTargetInterpretter } 106 107 procedure TTargetInterpretter.SetState(AValue: TRunState); 108 108 begin 109 109 if FState = AValue then Exit; … … 112 112 end; 113 113 114 function T BrainFuckInterpretter.GetMemorySize: Integer;114 function TTargetInterpretter.GetMemorySize: Integer; 115 115 begin 116 116 Result := Length(Memory); 117 117 end; 118 118 119 procedure T BrainFuckInterpretter.SetMemorySize(AValue: Integer);119 procedure TTargetInterpretter.SetMemorySize(AValue: Integer); 120 120 begin 121 121 SetLength(Memory, AValue); 122 122 end; 123 123 124 procedure T BrainFuckInterpretter.SetSource(AValue: string);124 procedure TTargetInterpretter.SetSource(AValue: string); 125 125 var 126 126 I: Integer; … … 146 146 end; 147 147 148 procedure T BrainFuckInterpretter.SetThread(State: Boolean);148 procedure TTargetInterpretter.SetThread(State: Boolean); 149 149 begin 150 150 if FThreadState = State then Exit; 151 151 FThreadState := State; 152 152 if State then begin 153 FThread := T BrainFuckInterpretterThread.Create(True);153 FThread := TTargetInterpretterThread.Create(True); 154 154 FThread.Parent := Self; 155 155 FThread.FreeOnTerminate := False; … … 160 160 end; 161 161 162 procedure T BrainFuckInterpretter.PrepareJumpTable;162 procedure TTargetInterpretter.PrepareJumpTable; 163 163 var 164 164 Loop: array of Integer; … … 188 188 end; 189 189 190 procedure T BrainFuckInterpretter.CommandInc;190 procedure TTargetInterpretter.CommandInc; 191 191 begin 192 192 Memory[MemoryPosition] := ((Memory[MemoryPosition] + 1) mod CellSize); 193 193 end; 194 194 195 procedure T BrainFuckInterpretter.CommandDec;195 procedure TTargetInterpretter.CommandDec; 196 196 begin 197 197 Memory[MemoryPosition] := ((Memory[MemoryPosition] - 1) mod CellSize); 198 198 end; 199 199 200 procedure T BrainFuckInterpretter.CommandPointerInc;200 procedure TTargetInterpretter.CommandPointerInc; 201 201 begin 202 202 if MemoryPosition < MemorySize then Inc(MemoryPosition) … … 204 204 end; 205 205 206 procedure T BrainFuckInterpretter.CommandPointerDec;206 procedure TTargetInterpretter.CommandPointerDec; 207 207 begin 208 208 if MemoryPosition > 0 then Dec(MemoryPosition) … … 210 210 end; 211 211 212 procedure T BrainFuckInterpretter.CommandInput;212 procedure TTargetInterpretter.CommandInput; 213 213 begin 214 214 while (InputPosition > Length(Input)) and (FState <> rsStopped) do begin … … 221 221 end; 222 222 223 procedure T BrainFuckInterpretter.CommandOutput;223 procedure TTargetInterpretter.CommandOutput; 224 224 begin 225 225 if OutputPosition > Length(Output) then … … 229 229 end; 230 230 231 procedure T BrainFuckInterpretter.CommandLoopStart;231 procedure TTargetInterpretter.CommandLoopStart; 232 232 begin 233 233 if Memory[MemoryPosition] = 0 then … … 235 235 end; 236 236 237 procedure T BrainFuckInterpretter.CommandLoopEnd;237 procedure TTargetInterpretter.CommandLoopEnd; 238 238 begin 239 239 if Memory[MemoryPosition] > 0 then … … 241 241 end; 242 242 243 procedure T BrainFuckInterpretter.Reset;243 procedure TTargetInterpretter.Reset; 244 244 var 245 245 I: Integer; … … 257 257 end; 258 258 259 procedure T BrainFuckInterpretter.SingleStep;259 procedure TTargetInterpretter.SingleStep; 260 260 begin 261 261 FCommandTable[FSource[SourcePosition]]; … … 264 264 end; 265 265 266 procedure T BrainFuckInterpretter.Run;266 procedure TTargetInterpretter.Run; 267 267 begin 268 268 SetState(rsRunning); … … 272 272 end; 273 273 274 procedure T BrainFuckInterpretter.Pause;274 procedure TTargetInterpretter.Pause; 275 275 begin 276 276 if State = rsRunning then SetState(rsPaused); 277 277 end; 278 278 279 procedure T BrainFuckInterpretter.Stop;279 procedure TTargetInterpretter.Stop; 280 280 begin 281 281 SetState(rsStopped); 282 282 end; 283 283 284 constructor T BrainFuckInterpretter.Create;284 constructor TTargetInterpretter.Create; 285 285 begin 286 286 MemorySize := 30000; … … 296 296 end; 297 297 298 destructor T BrainFuckInterpretter.Destroy;298 destructor TTargetInterpretter.Destroy; 299 299 begin 300 300 FState := rsStopped;
Note:
See TracChangeset
for help on using the changeset viewer.