Changeset 35 for trunk


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.
Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UMainForm.lfm

    r34 r35  
    590590        Action = AProgramRunToCursor
    591591      end
     592      object MenuItem31: TMenuItem
     593        Action = AProgramShowExecutionPoint
     594      end
    592595    end
    593596    object MenuItem24: TMenuItem
     
    821824      Caption = 'Step into'
    822825      ImageIndex = 15
     826      OnExecute = AProgramStepIntoExecute
    823827      ShortCut = 118
    824828    end
     
    827831      Caption = 'Step over'
    828832      ImageIndex = 17
     833      OnExecute = AProgramStepOverExecute
    829834      ShortCut = 119
    830835    end
     
    833838      Caption = 'Run to cursor'
    834839      ImageIndex = 14
     840      OnExecute = AProgramRunToCursorExecute
    835841      ShortCut = 115
    836842    end
     
    839845      Caption = 'Step out'
    840846      ImageIndex = 16
     847      OnExecute = AProgramStepOutExecute
    841848      ShortCut = 8311
    842849    end
     
    876883      Caption = 'Show position in target'
    877884      OnExecute = AShowTargetPositionExecute
     885      ShortCut = 16393
    878886    end
    879887    object AShowSourcePosition: TAction
    880888      Caption = 'Show position in source'
    881889      OnExecute = AShowSourcePositionExecute
     890      ShortCut = 16393
     891    end
     892    object AProgramShowExecutionPoint: TAction
     893      Category = 'Program'
     894      Caption = 'Show execution point'
     895      OnExecute = AProgramShowExecutionPointExecute
    882896    end
    883897  end
  • trunk/Forms/UMainForm.lrt

    r34 r35  
    3636TMAINFORM.ASHOWTARGETPOSITION.CAPTION=Show position in target
    3737TMAINFORM.ASHOWSOURCEPOSITION.CAPTION=Show position in source
     38TMAINFORM.APROGRAMSHOWEXECUTIONPOINT.CAPTION=Show execution point
  • trunk/Forms/UMainForm.pas

    r34 r35  
    1818
    1919  TMainForm = class(TForm)
     20    AProgramShowExecutionPoint: TAction;
    2021    AShowSourcePosition: TAction;
    2122    AShowTargetPosition: TAction;
     
    7273    MenuItem29: TMenuItem;
    7374    MenuItem30: TMenuItem;
     75    MenuItem31: TMenuItem;
    7476    MenuItem32: TMenuItem;
    7577    MenuItem33: TMenuItem;
     
    111113    ToolButton9: TToolButton;
    112114    procedure ABreakpointToggleExecute(Sender: TObject);
    113     procedure AProgramCompileExecute(Sender: TObject);
    114115    procedure AExitExecute(Sender: TObject);
    115116    procedure AFormatSourceExecute(Sender: TObject);
    116117    procedure AGenerateNumberExecute(Sender: TObject);
    117118    procedure AOptionsExecute(Sender: TObject);
     119    procedure AProgramCompileExecute(Sender: TObject);
    118120    procedure AProgramPauseExecute(Sender: TObject);
     121    procedure AProgramRunToCursorExecute(Sender: TObject);
     122    procedure AProgramShowExecutionPointExecute(Sender: TObject);
     123    procedure AProgramStepIntoExecute(Sender: TObject);
     124    procedure AProgramStepOutExecute(Sender: TObject);
     125    procedure AProgramStepOverExecute(Sender: TObject);
    119126    procedure AProgramStopExecute(Sender: TObject);
    120127    procedure AProjectCloseExecute(Sender: TObject);
     
    144151    FCurrentTarget: TTarget;
    145152    procedure AProjectOpenRecentExecute(Sender: TObject);
    146     procedure BrainFuckInterpreterChangeState(Sender: TObject);
     153    procedure TargetStateChanged(Sender: TObject);
    147154    procedure MenuItemTargetClick(Sender: TObject);
    148155    procedure ProjectOpen(FileName: string);
     
    218225end;
    219226
    220 procedure TMainForm.BrainFuckInterpreterChangeState(Sender: TObject);
    221 begin
     227procedure TMainForm.TargetStateChanged(Sender: TObject);
     228var
     229  DebugStep: TDebugStep;
     230begin
     231  if CurrentTarget.State = rsPaused then
     232    AProgramShowExecutionPoint.Execute;
    222233  UpdateInterface;
    223234end;
     
    253264  for I := 0 to Targets.Count - 1 do
    254265    TTarget(Targets[I]).OnChangeState := nil;
    255   FCurrentTarget.OnChangeState := BrainFuckInterpreterChangeState;
     266  FCurrentTarget.OnChangeState := TargetStateChanged;
    256267  UpdateInterface;
    257268end;
     
    309320  AProjectClose.Enabled := ProjectFileName <> '';
    310321  AProgramRun.Enabled := (tcRun in CurrentTarget.Capabilities) and
    311     (ProjectFileName <> '') and (CurrentTarget.State = rsStopped);
     322    (ProjectFileName <> '') and (CurrentTarget.State = rsStopped) or (CurrentTarget.State = rsPaused);
    312323  AProgramPause.Enabled := (tcPause in CurrentTarget.Capabilities) and
    313324    (ProjectFileName <> '') and (CurrentTarget.State = rsRunning);
    314325  AProgramStop.Enabled := (tcStop in CurrentTarget.Capabilities) and
    315326    (ProjectFileName <> '') and (CurrentTarget.State <> rsStopped);
    316   AProgramCompile.Enabled := (tcCompile in CurrentTarget.Capabilities) and (ProjectFileName <> '');
    317   AProgramStepInto.Enabled := (tcStepInto in CurrentTarget.Capabilities) and (ProjectFileName <> '');
    318   AProgramStepOut.Enabled := (tcStepOut in CurrentTarget.Capabilities) and (ProjectFileName <> '');
    319   AProgramRunToCursor.Enabled := (tcRunToCursor in CurrentTarget.Capabilities) and (ProjectFileName <> '');
    320   AProgramStepOver.Enabled := (tcStepOver in CurrentTarget.Capabilities) and (ProjectFileName <> '');
     327  AProgramCompile.Enabled := (tcCompile in CurrentTarget.Capabilities);
     328  AProgramStepInto.Enabled := (tcStepInto in CurrentTarget.Capabilities) and
     329    (ProjectFileName <> '') and (CurrentTarget.State = rsPaused);
     330  AProgramStepOut.Enabled := (tcStepOut in CurrentTarget.Capabilities) and
     331    (ProjectFileName <> '') and (CurrentTarget.State = rsPaused);
     332  AProgramRunToCursor.Enabled := (tcRunToCursor in CurrentTarget.Capabilities) and
     333    (ProjectFileName <> '') and (CurrentTarget.State = rsPaused);
     334  AProgramStepOver.Enabled := (tcStepOver in CurrentTarget.Capabilities) and
     335    (ProjectFileName <> '') and (CurrentTarget.State = rsPaused);
     336  AProgramShowExecutionPoint.Enabled := (tcPause in CurrentTarget.Capabilities) and
     337    (ProjectFileName <> '') and (CurrentTarget.State = rsPaused);
     338  AShowSourcePosition.Enabled := CurrentTarget.Compiled;
     339  AShowTargetPosition.Enabled := CurrentTarget.Compiled;
    321340  UpdateStatusBar;
    322341  UpdateTargetList;
     
    373392    TTargetInterpretter(CurrentTarget).Input := InterpreterForm.MemoInput.Lines.Text;
    374393  CurrentTarget.SourceCode := MemoSource.Text;
    375   if not CurrentTarget.Compiled then CurrentTarget.Compile;
     394  if not CurrentTarget.Compiled then AProgramCompile.Execute;
    376395  CurrentTarget.Run;
    377396end;
     
    381400  DebugStep: TDebugStep;
    382401begin
    383   DebugStep := CurrentTarget.DebugSteps.SearchByTargetPos(MemoSource.SelStart);
    384   MemoTarget.SelStart := DebugStep.SourcePosition;
    385   PageControl1.TabIndex := 0;
     402  DebugStep := CurrentTarget.DebugSteps.SearchByTargetPos(MemoTarget.SelStart);
     403  if Assigned(DebugStep) then begin
     404    MemoSource.SelStart := DebugStep.SourcePosition;
     405    PageControl1.TabIndex := 0;
     406  end;
    386407end;
    387408
     
    391412begin
    392413  DebugStep := CurrentTarget.DebugSteps.SearchBySourcePos(MemoSource.SelStart);
    393   MemoTarget.SelStart := DebugStep.TargetPosition;
    394   PageControl1.TabIndex := 1;
     414  if Assigned(DebugStep) then begin
     415    MemoTarget.SelStart := DebugStep.TargetPosition;
     416    PageControl1.TabIndex := 1;
     417  end;
    395418end;
    396419
     
    487510begin
    488511  with CurrentTarget do begin
     512    Stop;
    489513    Optimization := coNormal;
    490514    SourceCode := MemoSource.Text;
     
    492516    Compile;
    493517    MemoTarget.Text := TargetCode;
     518    UpdateInterface;
    494519  end;
    495520end;
     
    503528begin
    504529  CurrentTarget.Pause
     530end;
     531
     532procedure TMainForm.AProgramRunToCursorExecute(Sender: TObject);
     533var
     534  DebugStep: TDebugStep;
     535begin
     536  DebugStep := CurrentTarget.DebugSteps.SearchBySourcePos(MemoSource.SelStart);
     537  CurrentTarget.RunToCursor(DebugStep.TargetPosition);
     538end;
     539
     540procedure TMainForm.AProgramShowExecutionPointExecute(Sender: TObject);
     541var
     542  DebugStep: TDebugStep;
     543begin
     544  DebugStep := CurrentTarget.DebugSteps.SearchByTargetPos(CurrentTarget.ExecutionPosition);
     545  MemoSource.SelStart := DebugStep.SourcePosition;
     546  MemoTarget.SelStart := DebugStep.TargetPosition;
     547end;
     548
     549procedure TMainForm.AProgramStepIntoExecute(Sender: TObject);
     550begin
     551  CurrentTarget.StepInto;
     552end;
     553
     554procedure TMainForm.AProgramStepOutExecute(Sender: TObject);
     555begin
     556  CurrentTarget.StepOut;
     557end;
     558
     559procedure TMainForm.AProgramStepOverExecute(Sender: TObject);
     560begin
     561  CurrentTarget.StepOver;
    505562end;
    506563
  • trunk/Languages/LazFuckIDE.cs.po

    r34 r35  
    137137msgstr "Spustit po ukazatel"
    138138
     139#: tmainform.aprogramshowexecutionpoint.caption
     140msgid "Show execution point"
     141msgstr ""
     142
    139143#: tmainform.aprogramstepinto.caption
    140144msgctxt "tmainform.aprogramstepinto.caption"
  • trunk/Languages/LazFuckIDE.po

    r34 r35  
    128128msgstr ""
    129129
     130#: tmainform.aprogramshowexecutionpoint.caption
     131msgid "Show execution point"
     132msgstr ""
     133
    130134#: tmainform.aprogramstepinto.caption
    131135msgctxt "TMAINFORM.APROGRAMSTEPINTO.CAPTION"
  • trunk/Target/UTarget.pas

    r34 r35  
    4949    procedure AddLine(Text: string);
    5050    function LongFileName(FileName: string): string;
     51    function GetExecutionPosition: Integer; virtual;
    5152  public
    5253    Name: string;
     
    5859    ProjectFileName: string;
    5960    Capabilities: TTargetCapabilities;
    60     BreakPointers: TListInteger;
     61    BreakPoints: TListInteger;
    6162    DebugSteps: TDebugStepList;
    6263    constructor Create; virtual;
     
    7172    procedure StepInto; virtual;
    7273    procedure StepOut; virtual;
    73     procedure RunToCursor; virtual;
     74    procedure RunToCursor(Pos: Integer); virtual;
    7475    procedure LoadFromRegistry(Root: HKEY; Key: string); virtual;
    7576    procedure SaveToRegistry(Root: HKEY; Key: string); virtual;
     
    7980    property TargetCode: string read GetTargetCode;
    8081    property Compiled: Boolean read FCompiled write FCompiled;
     82    property ExecutionPosition: Integer read GetExecutionPosition;
    8183  end;
    8284
     
    184186begin
    185187  Result := FTargetCode;
     188end;
     189
     190function TTarget.GetExecutionPosition: Integer;
     191begin
     192
    186193end;
    187194
     
    211218  inherited;
    212219  Optimization := coNormal;
    213   BreakPointers := TListInteger.Create;
     220  BreakPoints := TListInteger.Create;
    214221  DebugSteps := TDebugStepList.Create;
    215222end;
     
    218225begin
    219226  DebugSteps.Free;;
    220   BreakPointers.Free;
     227  BreakPoints.Free;
    221228  inherited Destroy;
    222229end;
     
    303310end;
    304311
    305 procedure TTarget.RunToCursor;
     312procedure TTarget.RunToCursor(Pos: Integer);
    306313begin
    307314
  • trunk/Target/UTargetC.pas

    r34 r35  
    5757
    5858begin
     59  inherited;
    5960  Indent := 0;
    6061  FTargetCode := '';
  • trunk/Target/UTargetDelphi.pas

    r34 r35  
    5252
    5353begin
     54  inherited;
    5455  Indent := 0;
    5556  FTargetCode := '';
  • 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
  • trunk/Target/UTargetPHP.pas

    r34 r35  
    5555
    5656begin
     57  inherited;
    5758  Indent := 0;
    5859  FTargetCode := '';
Note: See TracChangeset for help on using the changeset viewer.