Changeset 35 for trunk/Target/UTargetInterpretter.pas
- Timestamp:
- Feb 19, 2012, 12:03:21 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Target/UTargetInterpretter.pas
r33 r35 45 45 procedure CommandLoopStart; 46 46 procedure CommandLoopEnd; 47 procedure SingleStep;48 47 procedure Reset; 48 procedure PrepareBreakPoints; 49 49 protected 50 50 function GetTargetCode: string; override; 51 function GetExecutionPosition: Integer; override; 51 52 public 52 53 FProgram: array of TBrainFuckCommand; 54 FProgramBreakpoints: array of Boolean; 53 55 SourceJump: array of Integer; 54 56 SourcePosition: Integer; … … 64 66 procedure Pause; override; 65 67 procedure Stop; override; 68 procedure StepInto; override; 69 procedure StepOver; override; 70 procedure StepOut; override; 71 procedure RunToCursor(Pos: Integer); override; 66 72 constructor Create; override; 67 73 destructor Destroy; override; … … 92 98 procedure TTargetInterpretterThread.Execute; 93 99 begin 100 with Parent do 94 101 repeat 95 while (Parent.SourcePosition < Length(Parent.FProgram)) and (Parent.State <> rsStopped) do begin 96 Parent.SingleStep; 97 while Parent.State = rsPaused do begin 98 Sleep(1); 99 end; 102 while (SourcePosition < Length(FProgram)) and (State <> rsStopped) do begin 103 if State = rsRunning then begin 104 if FProgramBreakpoints[SourcePosition] then begin 105 FProgramBreakpoints[SourcePosition] := False; 106 SetState(rsPaused); 107 end else begin 108 FCommandTable[FProgram[SourcePosition]]; 109 Inc(SourcePosition); 110 Inc(FStepCount); 111 end; 112 end else 113 if State = rsPaused then Sleep(1); 100 114 end; 101 Parent.SetState(rsStopped);102 until Terminated or ( Parent.State = rsStopped);115 SetState(rsStopped); 116 until Terminated or (State = rsStopped); 103 117 end; 104 118 … … 127 141 Pos: Integer; 128 142 begin 143 inherited; 129 144 DebugSteps.Clear; 130 145 SetLength(FProgram, Length(FSourceCode)); … … 282 297 end; 283 298 299 procedure TTargetInterpretter.PrepareBreakPoints; 300 var 301 I: Integer; 302 begin 303 SetLength(FProgramBreakpoints, Length(FProgram)); 304 for I := 0 to High(FProgramBreakpoints) do 305 FProgramBreakpoints[I] := False; 306 for I := 0 to BreakPoints.Count - 1 do 307 FProgramBreakpoints[BreakPoints[I]] := True; 308 end; 309 284 310 function TTargetInterpretter.GetTargetCode: string; 285 311 var … … 291 317 end; 292 318 293 procedure TTargetInterpretter.SingleStep; 294 begin 295 FCommandTable[FProgram[SourcePosition]]; 296 Inc(SourcePosition); 297 Inc(FStepCount); 319 function TTargetInterpretter.GetExecutionPosition: Integer; 320 begin 321 Result := SourcePosition; 298 322 end; 299 323 … … 302 326 SetState(rsRunning); 303 327 Reset; 328 PrepareBreakPoints; 304 329 SetThread(False); 305 330 SetThread(True); … … 314 339 begin 315 340 SetState(rsStopped); 341 end; 342 343 procedure TTargetInterpretter.StepInto; 344 var 345 Step: TDebugStep; 346 begin 347 Step := DebugSteps.SearchByTargetPos(SourcePosition); 348 FProgramBreakpoints[Step.TargetPosition + 1] := True; 349 end; 350 351 procedure TTargetInterpretter.StepOver; 352 var 353 Step: TDebugStep; 354 begin 355 end; 356 357 procedure TTargetInterpretter.StepOut; 358 begin 359 inherited StepOut; 360 end; 361 362 procedure TTargetInterpretter.RunToCursor(Pos: Integer); 363 begin 364 FProgramBreakpoints[Pos] := True; 316 365 end; 317 366
Note:
See TracChangeset
for help on using the changeset viewer.