Ignore:
Timestamp:
Feb 19, 2012, 12:03:21 AM (13 years ago)
Author:
chronos
Message:
  • Added: Function to show execution point in code if program is paused.
  • Added: Some partial stepping implementation.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Target/UTargetInterpretter.pas

    r33 r35  
    4545    procedure CommandLoopStart;
    4646    procedure CommandLoopEnd;
    47     procedure SingleStep;
    4847    procedure Reset;
     48    procedure PrepareBreakPoints;
    4949  protected
    5050    function GetTargetCode: string; override;
     51    function GetExecutionPosition: Integer; override;
    5152  public
    5253    FProgram: array of TBrainFuckCommand;
     54    FProgramBreakpoints: array of Boolean;
    5355    SourceJump: array of Integer;
    5456    SourcePosition: Integer;
     
    6466    procedure Pause; override;
    6567    procedure Stop; override;
     68    procedure StepInto; override;
     69    procedure StepOver; override;
     70    procedure StepOut; override;
     71    procedure RunToCursor(Pos: Integer); override;
    6672    constructor Create; override;
    6773    destructor Destroy; override;
     
    9298procedure TTargetInterpretterThread.Execute;
    9399begin
     100  with Parent do
    94101  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);
    100114    end;
    101     Parent.SetState(rsStopped);
    102   until Terminated or (Parent.State = rsStopped);
     115    SetState(rsStopped);
     116  until Terminated or (State = rsStopped);
    103117end;
    104118
     
    127141  Pos: Integer;
    128142begin
     143  inherited;
    129144  DebugSteps.Clear;
    130145  SetLength(FProgram, Length(FSourceCode));
     
    282297end;
    283298
     299procedure TTargetInterpretter.PrepareBreakPoints;
     300var
     301  I: Integer;
     302begin
     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;
     308end;
     309
    284310function TTargetInterpretter.GetTargetCode: string;
    285311var
     
    291317end;
    292318
    293 procedure TTargetInterpretter.SingleStep;
    294 begin
    295   FCommandTable[FProgram[SourcePosition]];
    296   Inc(SourcePosition);
    297   Inc(FStepCount);
     319function TTargetInterpretter.GetExecutionPosition: Integer;
     320begin
     321  Result := SourcePosition;
    298322end;
    299323
     
    302326  SetState(rsRunning);
    303327  Reset;
     328  PrepareBreakPoints;
    304329  SetThread(False);
    305330  SetThread(True);
     
    314339begin
    315340  SetState(rsStopped);
     341end;
     342
     343procedure TTargetInterpretter.StepInto;
     344var
     345  Step: TDebugStep;
     346begin
     347  Step := DebugSteps.SearchByTargetPos(SourcePosition);
     348  FProgramBreakpoints[Step.TargetPosition + 1] := True;
     349end;
     350
     351procedure TTargetInterpretter.StepOver;
     352var
     353  Step: TDebugStep;
     354begin
     355end;
     356
     357procedure TTargetInterpretter.StepOut;
     358begin
     359  inherited StepOut;
     360end;
     361
     362procedure TTargetInterpretter.RunToCursor(Pos: Integer);
     363begin
     364  FProgramBreakpoints[Pos] := True;
    316365end;
    317366
Note: See TracChangeset for help on using the changeset viewer.