Changeset 32 for trunk/Forms


Ignore:
Timestamp:
Feb 18, 2012, 8:44:10 PM (13 years ago)
Author:
chronos
Message:
  • Modified: Target specific options is maintained by target class in registry.
  • Modified: Integer index TargetIndex replaced by object reference CurrentTarget.
Location:
trunk/Forms
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UInterpretterForm.pas

    r24 r32  
    6464
    6565uses
    66   UMainForm;
     66  UMainForm, UTargetInterpretter;
    6767
    6868{$R *.lfm}
     
    7575procedure TInterpreterForm.Timer1Timer(Sender: TObject);
    7676begin
    77   LabelProgramPointer.Caption := IntToStr(MainForm.BrainFuckInterpreter.SourcePosition);
    78   LabelMemoryPointer.Caption := IntToStr(MainForm.BrainFuckInterpreter.MemoryPosition);
    79   LabelStepCounter.Caption := IntToStr(MainForm.BrainFuckInterpreter.StepCount);
    80   LabelStepSpeed.Caption := IntToStr(MainForm.BrainFuckInterpreter.StepCount - LastStepCounter) + SStepsPerSecond;
    81   LastStepCounter := MainForm.BrainFuckInterpreter.StepCount;
     77  if MainForm.CurrentTarget is TTargetInterpretter then
     78  with TTargetInterpretter(MainForm.CurrentTarget) do begin
     79    LabelProgramPointer.Caption := IntToStr(SourcePosition);
     80    LabelMemoryPointer.Caption := IntToStr(MemoryPosition);
     81    LabelStepCounter.Caption := IntToStr(StepCount);
     82    LabelStepSpeed.Caption := IntToStr(StepCount - LastStepCounter) + SStepsPerSecond;
     83    LastStepCounter := StepCount;
     84    MemoOutput.Lines.Text := Output;
     85  end;
    8286  RefreshListViewMemory;
    83   MemoOutput.Lines.Text := MainForm.BrainFuckInterpreter.Output;
    8487end;
    8588
    8689procedure TInterpreterForm.RefreshListViewMemory;
    8790begin
    88   ListViewMemory.Items.Count := Trunc(Length(MainForm.BrainFuckInterpreter.Memory) / RowSize);
    89   ListViewMemory.Refresh;
     91  if MainForm.CurrentTarget is TTargetInterpretter then
     92  with TTargetInterpretter(MainForm.CurrentTarget) do begin
     93    ListViewMemory.Items.Count := Trunc(Length(Memory) / RowSize);
     94    ListViewMemory.Refresh;
     95  end;
    9096end;
    9197
     
    100106  I: Integer;
    101107begin
    102   with MainForm.BrainFuckInterpreter do
     108  if MainForm.CurrentTarget is TTargetInterpretter then
     109  with TTargetInterpretter(MainForm.CurrentTarget) do
    103110  if (Item.Index >= 0) and (Item.Index < Trunc(Length(Memory) / RowSize)) then begin
    104111    Item.Caption := IntToHex(Item.Index * RowSize, 8);
     
    122129procedure TInterpreterForm.MemoInputKeyPress(Sender: TObject; var Key: char);
    123130begin
    124   with MainForm.BrainFuckInterpreter do Input := Input + Key;
     131  if MainForm.CurrentTarget is TTargetInterpretter then
     132  with TTargetInterpretter(MainForm.CurrentTarget) do
     133    Input := Input + Key;
    125134end;
    126135
  • trunk/Forms/UMainForm.lfm

    r30 r32  
    9292      Left = 126
    9393      Top = 2
    94       Action = ACompile
     94      Action = AProgramCompile
    9595    end
    9696    object ToolButton8: TToolButton
     
    394394      Caption = 'Program'
    395395      object MenuItem11: TMenuItem
    396         Action = ACompile
     396        Action = AProgramCompile
    397397        Bitmap.Data = {
    398398          36040000424D3604000000000000360000002800000010000000100000000100
     
    562562      end
    563563      object MenuItem33: TMenuItem
    564         Action = AProgramStopOver
     564        Action = AProgramStepOver
    565565      end
    566566      object MenuItem34: TMenuItem
     
    761761      ShortCut = 32883
    762762    end
    763     object ACompile: TAction
     763    object AProgramCompile: TAction
    764764      Category = 'Program'
    765765      Caption = 'Compile'
    766766      ImageIndex = 8
    767       OnExecute = ACompileExecute
     767      OnExecute = AProgramCompileExecute
    768768      ShortCut = 16504
    769769    end
     
    814814      ShortCut = 118
    815815    end
    816     object AProgramStopOver: TAction
     816    object AProgramStepOver: TAction
    817817      Category = 'Program'
    818818      Caption = 'Step over'
  • trunk/Forms/UMainForm.lrt

    r30 r32  
    1919TMAINFORM.APROJECTNEW.CAPTION=New
    2020TMAINFORM.AEXIT.CAPTION=Exit
    21 TMAINFORM.ACOMPILE.CAPTION=Compile
     21TMAINFORM.APROGRAMCOMPILE.CAPTION=Compile
    2222TMAINFORM.ACOMPILEANDRUN.CAPTION=Compile and run
    2323TMAINFORM.APROGRAMRUN.CAPTION=Run
     
    2929TMAINFORM.AVIEWCOMPILED.CAPTION=Compiled
    3030TMAINFORM.APROGRAMSTEPINTO.CAPTION=Step into
    31 TMAINFORM.APROGRAMSTOPOVER.CAPTION=Step over
     31TMAINFORM.APROGRAMSTEPOVER.CAPTION=Step over
    3232TMAINFORM.APROGRAMRUNTOCURSOR.CAPTION=Run to cursor
    3333TMAINFORM.APROGRAMSTEPOUT.CAPTION=Step out
  • trunk/Forms/UMainForm.pas

    r31 r32  
    1818
    1919  TMainForm = class(TForm)
    20     ACompile: TAction;
     20    AProgramCompile: TAction;
    2121    AAbout: TAction;
    2222    ABreakpointToggle: TAction;
     
    2929    AProgramStepOut: TAction;
    3030    AProgramRunToCursor: TAction;
    31     AProgramStopOver: TAction;
     31    AProgramStepOver: TAction;
    3232    AProgramStepInto: TAction;
    3333    AViewCompiled: TAction;
     
    108108    procedure ABreakpointToggleExecute(Sender: TObject);
    109109    procedure ACompileAndRunExecute(Sender: TObject);
    110     procedure ACompileExecute(Sender: TObject);
     110    procedure AProgramCompileExecute(Sender: TObject);
    111111    procedure AExitExecute(Sender: TObject);
    112112    procedure AFormatSourceExecute(Sender: TObject);
     
    138138      Shift: TShiftState; X, Y: Integer);
    139139  private
     140    FCurrentTarget: TTarget;
    140141    procedure AProjectOpenRecentExecute(Sender: TObject);
    141142    procedure BrainFuckInterpreterChangeState(Sender: TObject);
    142143    procedure MenuItemTargetClick(Sender: TObject);
    143144    procedure ProjectOpen(FileName: string);
     145    procedure SetCurrentTarget(AValue: TTarget);
    144146  public
    145147    Modified: Boolean;
    146     CompilerIndex: Integer;
    147148    ProjectFileName: string;
    148     BrainFuckCompiler: TTarget;
    149     BrainFuckInterpreter: TTargetInterpretter;
    150149    BreakPoints: TListInteger;
    151150    Targets: TTargetList;
     
    157156    procedure UpdateStatusBar;
    158157    procedure UpdateTargetList;
     158    property CurrentTarget: TTarget read FCurrentTarget write SetCurrentTarget;
    159159  end;
    160160
     
    222222begin
    223223  with TMenuItem(Sender) do begin
    224     CompilerIndex := MenuIndex;
     224    CurrentTarget := TTarget(Targets[MenuIndex]);
    225225    Checked := True;
    226226    for I := 0 to Parent.Count - 1 do
    227       if Parent.Items[I].MenuIndex <> MenuIndex then Parent.Items[I].Checked := False
     227      if Parent.Items[I].MenuIndex <> MenuIndex then Parent.Items[I].Checked := False;
    228228  end;
    229229end;
     
    238238end;
    239239
     240procedure TMainForm.SetCurrentTarget(AValue: TTarget);
     241var
     242  I: Integer;
     243begin
     244  if FCurrentTarget = AValue then Exit;
     245  FCurrentTarget := AValue;
     246  for I := 0 to Targets.Count - 1 do
     247    TTarget(Targets[I]).OnChangeState := nil;
     248  FCurrentTarget.OnChangeState := BrainFuckInterpreterChangeState;
     249end;
     250
    240251procedure TMainForm.LoadFromRegistry(Root: HKEY; Key: string);
     252var
     253  TargetName: string;
    241254begin
    242255  with TRegistryEx.Create do
     
    245258    OpenKey(Key, True);
    246259    OpenProjectOnStart := ReadBoolWithDefault('OpenProjectOnStart', True);
    247     BrainFuckInterpreter.CellSize := ReadIntegerWithDefault('CellSize', 256);
    248     BrainFuckInterpreter.MemorySize := ReadIntegerWithDefault('MemorySize', 30000);
    249260    if ValueExists('LanguageCode') then
    250261      CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode(ReadStringWithDefault('LanguageCode', ''))
    251262      else CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode('');
    252     CompilerIndex := ReadIntegerWithDefault('SelectedCompiler', 0);
     263    TargetName := ReadStringWithDefault('TargetName', 'Interpretter');
     264    CurrentTarget := Targets.FindByName(TargetName);
     265    if not Assigned(CurrentTarget) then CurrentTarget := TTarget(Targets[0]);
    253266  finally
    254267    Free;
     
    267280    OpenKey(Key, True);
    268281    WriteBool('OpenProjectOnStart', OpenProjectOnStart);
    269     WriteInteger('CellSize', BrainFuckInterpreter.CellSize);
    270     WriteInteger('MemorySize', BrainFuckInterpreter.MemorySize);
    271282    if Assigned(CoolTranslator1.Language) and (CoolTranslator1.Language.Code <> '') then
    272283      WriteString('LanguageCode', CoolTranslator1.Language.Code)
    273284      else DeleteValue('LanguageCode');
    274     WriteInteger('SelectedCompiler', CompilerIndex);
     285    WriteString('TargetName', CurrentTarget.Name);
    275286  finally
    276287    Free;
     
    289300  MemoSource.Enabled := ProjectFileName <> '';
    290301  AProjectClose.Enabled := ProjectFileName <> '';
    291   AProgramRun.Enabled := (ProjectFileName <> '') and (BrainFuckInterpreter.State = rsStopped);
    292   AProgramPause.Enabled := (ProjectFileName <> '') and (BrainFuckInterpreter.State = rsRunning);
    293   AProgramStop.Enabled := (ProjectFileName <> '') and (BrainFuckInterpreter.State <> rsStopped);
    294   ACompile.Enabled := ProjectFileName <> '';
     302  AProgramRun.Enabled := (tcRun in CurrentTarget.Capabilities) and
     303    (ProjectFileName <> '') and (CurrentTarget.State = rsStopped);
     304  AProgramPause.Enabled := (tcPause in CurrentTarget.Capabilities) and
     305    (ProjectFileName <> '') and (CurrentTarget.State = rsRunning);
     306  AProgramStop.Enabled := (tcStop in CurrentTarget.Capabilities) and
     307    (ProjectFileName <> '') and (CurrentTarget.State <> rsStopped);
     308  AProgramCompile.Enabled := (tcCompile in CurrentTarget.Capabilities) and (ProjectFileName <> '');
     309  AProgramStepInto.Enabled := (tcStepInto in CurrentTarget.Capabilities) and (ProjectFileName <> '');
     310  AProgramStepOut.Enabled := (tcStepOut in CurrentTarget.Capabilities) and (ProjectFileName <> '');
     311  AProgramRunToCursor.Enabled := (tcRunToCursor in CurrentTarget.Capabilities) and (ProjectFileName <> '');
     312  AProgramStepOver.Enabled := (tcStepOver in CurrentTarget.Capabilities) and (ProjectFileName <> '');
    295313  UpdateStatusBar;
    296314  UpdateTargetList;
     
    312330    NewMenuItem.Caption := TTarget(Targets[I]).Name;
    313331    NewMenuItem.OnClick := MenuItemTargetClick;
    314     if I = CompilerIndex then NewMenuItem.Checked := True;
     332    if TTarget(Targets[I]) = CurrentTarget then NewMenuItem.Checked := True;
    315333    MenuItemTarget.Add(NewMenuItem);
    316334  end;
     
    320338begin
    321339  BreakPoints := TListInteger.Create;
    322   BrainFuckInterpreter := TTargetInterpretter.Create;
    323   BrainFuckInterpreter.OnChangeState := BrainFuckInterpreterChangeState;
    324   BrainFuckCompiler := TTarget.Create;
    325340  Targets := TTargetList.Create;
    326341  Targets.Add(TTargetInterpretter.Create);
     
    340355  LastOpenedList.Free;
    341356  Targets.Free;
    342   BrainFuckCompiler.Free;
    343   BrainFuckInterpreter.Free;
    344357  BreakPoints.Free;
    345358end;
     
    349362  InterpreterForm.LastStepCounter := 0;
    350363  InterpreterForm.Show;
    351   BrainFuckInterpreter.Input := InterpreterForm.MemoInput.Lines.Text;
    352   BrainFuckInterpreter.Source := MemoSource.Text;
    353   BrainFuckInterpreter.Run;
     364  if CurrentTarget is TTargetInterpretter then
     365    TTargetInterpretter(CurrentTarget).Input := InterpreterForm.MemoInput.Lines.Text;
     366  CurrentTarget.Source := MemoSource.Text;
     367  CurrentTarget.Run;
    354368end;
    355369
     
    442456procedure TMainForm.AOptionsExecute(Sender: TObject);
    443457begin
    444   OptionsForm.LoadFromInterpretter(BrainFuckInterpreter);
     458  //OptionsForm.LoadFromInterpretter(CurrentTarget);
    445459  if OptionsForm.ShowModal = mrOK then begin
    446     OptionsForm.SaveToInterpretter(BrainFuckInterpreter);
    447   end;
    448 end;
    449 
    450 procedure TMainForm.ACompileExecute(Sender: TObject);
    451 begin
    452   with TTarget(Targets[CompilerIndex]) do begin
     460    //OptionsForm.SaveToInterpretter(CurrentTarget);
     461  end;
     462end;
     463
     464procedure TMainForm.AProgramCompileExecute(Sender: TObject);
     465begin
     466  with CurrentTarget do begin
    453467    Optimization := coNormal;
    454468    Source := MemoSource.Text;
     
    467481procedure TMainForm.ACompileAndRunExecute(Sender: TObject);
    468482begin
    469   with TTarget(Targets[CompilerIndex]) do begin
     483  with CurrentTarget do begin
    470484    Optimization := coNormal;
    471485    Source := MemoSource.Text;
     
    480494procedure TMainForm.AProgramPauseExecute(Sender: TObject);
    481495begin
    482   MainForm.BrainFuckInterpreter.Pause
     496  CurrentTarget.Pause
    483497end;
    484498
    485499procedure TMainForm.AProgramStopExecute(Sender: TObject);
    486500begin
    487   MainForm.BrainFuckInterpreter.Stop;
     501  CurrentTarget.Stop;
    488502end;
    489503
Note: See TracChangeset for help on using the changeset viewer.