Ignore:
Timestamp:
Feb 13, 2012, 9:47:18 AM (12 years ago)
Author:
chronos
Message:
  • Added: List of supported compiler targets.
  • Added: Action to compile and run project.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UMainForm.pas

    r24 r25  
    88  Classes, SysUtils, FileUtil, SynEdit, Forms, Controls, Graphics, Dialogs,
    99  Menus, ActnList, StdCtrls, ComCtrls, UBrainFuck, UCoolTranslator, StrUtils,
    10   SpecializedList, UCompiler, Registry, URegistry, ULastOpenedList;
     10  SpecializedList, UCompiler, Registry, URegistry, ULastOpenedList, Process;
    1111
    1212const
     
    2121    AAbout: TAction;
    2222    ABreakpointToggle: TAction;
     23    ACompileAndRun: TAction;
     24    AViewCompilers: TAction;
    2325    AGenerateNumber: TAction;
    2426    AShrinkSource: TAction;
     
    6870    MenuItem28: TMenuItem;
    6971    MenuItem29: TMenuItem;
     72    MenuItem30: TMenuItem;
     73    MenuItem31: TMenuItem;
    7074    MenuItemOpenRecent: TMenuItem;
    7175    MenuItemTarget: TMenuItem;
     
    9599    ToolButton9: TToolButton;
    96100    procedure ABreakpointToggleExecute(Sender: TObject);
     101    procedure ACompileAndRunExecute(Sender: TObject);
    97102    procedure ACompileExecute(Sender: TObject);
    98103    procedure AExitExecute(Sender: TObject);
     
    110115    procedure AShrinkSourceExecute(Sender: TObject);
    111116    procedure AViewCompiledExecute(Sender: TObject);
     117    procedure AViewCompilersExecute(Sender: TObject);
    112118    procedure AViewInterpretterExecute(Sender: TObject);
    113119    procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
     
    135141    BrainFuckInterpreter: TBrainFuckInterpretter;
    136142    BreakPoints: TListInteger;
    137     Compilers: TListObject; // TListObject<TCompiler>
     143    Compilers: TCompilerList;
    138144    LastOpenedList: TLastOpenedList;
    139145    OpenProjectOnStart: Boolean;
     
    142148    procedure UpdateInterface;
    143149    procedure UpdateStatusBar;
    144     procedure UpdateTergetList;
     150    procedure UpdateTargetList;
    145151  end;
    146152
     
    154160uses
    155161  UInterpretterForm, UApplicationInfo, UCompiledForm, UOptionsForm,
    156   UCompilerDelphi, UCompilerPHP;
     162  UCompilerDelphi, UCompilerPHP, UCompilersForm;
    157163
    158164resourcestring
    159165  SEnterNumber = 'Enter number';
    160166  SNumberGeneration = 'Number generation';
     167  SProgramExited = 'Program exited';
     168  SCompilerNotFound = 'Compiler "%s" not found';
     169  SCompiledFileNotFound = 'Program compiled file "%s" not found';
    161170
    162171{ TMainForm }
     
    167176    ProjectOpen(LastOpenedList[0])
    168177    else AProjectNew.Execute;
     178  UpdateInterface;
    169179end;
    170180
     
    234244      CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode(ReadStringWithDefault('LanguageCode', ''))
    235245      else CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode('');
     246    CompilerIndex := ReadIntegerWithDefault('SelectedCompiler', 0);
    236247  finally
    237248    Free;
    238249  end;
    239250  LastOpenedList.LoadFromRegistry(Root, Key);
     251  Compilers.LoadFromRegistry(Root, Key);
    240252end;
    241253
    242254procedure TMainForm.SaveToRegistry(Root: HKEY; Key: string);
    243255begin
     256  Compilers.SaveToRegistry(Root, Key);
    244257  LastOpenedList.SaveToRegistry(Root, Key);
    245258  with TRegistryEx.Create do
     
    253266      WriteString('LanguageCode', CoolTranslator1.Language.Code)
    254267      else DeleteValue('LanguageCode');
     268    WriteInteger('SelectedCompiler', CompilerIndex);
    255269  finally
    256270    Free;
     
    274288  ACompile.Enabled := ProjectFileName <> '';
    275289  UpdateStatusBar;
     290  UpdateTargetList;
    276291end;
    277292
     
    281296end;
    282297
    283 procedure TMainForm.UpdateTergetList;
     298procedure TMainForm.UpdateTargetList;
    284299var
    285300  I: Integer;
     
    302317  BrainFuckInterpreter.OnChangeState := BrainFuckInterpreterChangeState;
    303318  BrainFuckCompiler := TBrainFuckCompiler.Create;
    304   Compilers := TListObject.Create;
     319  Compilers := TCompilerList.Create;
    305320  Compilers.Add(TBrainFuckCompilerDelphi.Create);
    306321  Compilers.Add(TBrainFuckCompilerPHP.Create);
    307   UpdateTergetList;
     322  UpdateTargetList;
    308323  LastOpenedList := TLastOpenedList.Create;
    309324  LastOpenedList.MenuItem := MenuItemOpenRecent;
     
    352367begin
    353368  CompiledForm.Show;
     369end;
     370
     371procedure TMainForm.AViewCompilersExecute(Sender: TObject);
     372begin
     373  FormCompilers.Show;
    354374end;
    355375
     
    437457end;
    438458
     459procedure TMainForm.ACompileAndRunExecute(Sender: TObject);
     460var
     461  Process: TProcess;
     462  CompiledFile: string;
     463begin
     464  with TBrainFuckCompiler(Compilers[CompilerIndex]) do begin
     465    Optimization := coNormal;
     466    Source := MemoSource.Text;
     467    ProgramName := ExtractFileNameOnly(ProjectFileName);
     468    Compile;
     469    CompiledFile := ExtractFilePath(ProjectFileName) +
     470      'compiled' + DirectorySeparator + Name + DirectorySeparator +
     471      ExtractFileNameOnly(ProjectFileName) + SourceExtension;
     472    ForceDirectoriesUTF8(ExtractFilePath(CompiledFile));
     473    with TStringList.Create do
     474    try
     475      Text := Output;
     476      SaveToFile(CompiledFile);
     477    finally
     478      Free;
     479    end;
     480    if FileExistsUTF8(CompilerPath) then
     481    try
     482      Process := TProcess.Create(nil);
     483      Process.CommandLine := '"' + CompilerPath + '" "' + CompiledFile + '"';
     484      Process.Options := [poWaitOnExit];
     485      Process.Execute;
     486    finally
     487      Process.Free;
     488    end else raise Exception.Create(Format(SCompilerNotFound, [CompilerPath]));
     489
     490    if CompiledExtension <> '' then begin
     491      CompiledFile := ExtractFilePath(CompiledFile) + ExtractFileNameOnly(CompiledFile) + CompiledExtension;
     492      if FileExistsUTF8(CompiledFile) then
     493      try
     494        Process := TProcess.Create(nil);
     495        Process.CommandLine := '"' + CompiledFile + '"';
     496        Process.Options := [poWaitOnExit];
     497        Process.Execute;
     498      finally
     499        Process.Free;
     500      end else raise Exception.Create(Format(SCompiledFileNotFound, [CompiledFile]));
     501    end;
     502  end;
     503end;
     504
    439505procedure TMainForm.AProgramPauseExecute(Sender: TObject);
    440506begin
Note: See TracChangeset for help on using the changeset viewer.