Changeset 28 for trunk


Ignore:
Timestamp:
Feb 13, 2012, 12:26:12 PM (12 years ago)
Author:
chronos
Message:
  • Fixed: Compile and run C project using MinGW gcc.
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        44backup
        55LazFuckIDE
         6compiled
  • trunk/Compiler/UCompiler.pas

    r25 r28  
    66
    77uses
    8   Classes, SysUtils, StrUtils, Registry, URegistry, SpecializedList;
     8  Classes, SysUtils, StrUtils, Registry, URegistry, SpecializedList,
     9  FileUtil, Process;
    910
    1011type
     
    2627    SourceExtension: string;
    2728    CompiledExtension: string;
     29    ProjectFileName: string;
    2830    constructor Create; virtual;
    2931    procedure OptimizeSource;
    3032    procedure Compile; virtual;
     33    procedure CompileToFile; virtual;
     34    procedure Run; virtual;
    3135  end;
    3236
     
    3943
    4044
     45resourcestring
     46  SCompilerNotFound = 'Compiler "%s" not found';
     47  SCompiledFileNotFound = 'Program compiled file "%s" not found';
     48
     49
    4150implementation
     51
    4252
    4353{ TCompilerList }
     
    99109end;
    100110
     111procedure TBrainFuckCompiler.CompileToFile;
     112var
     113  Process: TProcess;
     114  CompiledFile: string;
     115begin
     116  CompiledFile := ExtractFilePath(ProjectFileName) +
     117    'compiled' + DirectorySeparator + Name + DirectorySeparator +
     118    ExtractFileNameOnly(ProjectFileName) + SourceExtension;
     119  ForceDirectoriesUTF8(ExtractFilePath(CompiledFile));
     120  with TStringList.Create do
     121  try
     122    Text := Output;
     123    SaveToFile(CompiledFile);
     124  finally
     125    Free;
     126  end;
     127  if FileExistsUTF8(CompilerPath) then
     128  try
     129    Process := TProcess.Create(nil);
     130    Process.CurrentDirectory := ExtractFilePath(CompilerPath);
     131    Process.CommandLine := '"' + CompilerPath + '" "' + CompiledFile + '"';
     132    Process.Options := [poWaitOnExit];
     133    Process.Execute;
     134  finally
     135    Process.Free;
     136  end else raise Exception.Create(Format(SCompilerNotFound, [CompilerPath]));
     137end;
     138
     139procedure TBrainFuckCompiler.Run;
     140var
     141  CompiledFile: string;
     142  Process: TProcess;
     143begin
     144  CompiledFile := ExtractFilePath(ProjectFileName) +
     145    'compiled' + DirectorySeparator + Name + DirectorySeparator +
     146    ExtractFileNameOnly(ProjectFileName) + CompiledExtension;
     147  if FileExistsUTF8(CompiledFile) then
     148  try
     149    Process := TProcess.Create(nil);
     150    Process.CommandLine := '"' + CompiledFile + '"';
     151    Process.Options := [poWaitOnExit];
     152    Process.Execute;
     153  finally
     154    Process.Free;
     155  end else raise Exception.Create(Format(SCompiledFileNotFound, [CompiledFile]));
     156end;
     157
    101158
    102159
  • trunk/Compiler/UCompilerC.pas

    r27 r28  
    66
    77uses
    8   Classes, SysUtils, UCompiler;
     8  Classes, SysUtils, FileUtil, UCompiler, Process;
    99
    1010type
     
    1515    constructor Create; override;
    1616    procedure Compile; override;
     17    procedure CompileToFile; override;
     18    procedure Run; override;
    1719  end;
    1820
     
    2830  CompiledExtension := '.exe';
    2931  {$IFDEF Windows}
    30   CompilerPath := 'C:\Program Files\Dev-Cpp\mingw32-gcc.exe';
     32  CompilerPath := 'c:\Program Files\MinGW\bin\gcc.exe -o %1:s';
    3133  {$ENDIF}
    3234  {$IFDEF Linux}
     
    5961  AddLine('{');
    6062  Inc(Indent);
    61   AddLine('char[30000] Memory;');
     63  AddLine('char Memory[30000];');
    6264  AddLine('int Pos;');
    6365  AddLine('char ReadChar;');
     
    8385        AddLine('Memory[Pos] = Memory[Pos] - ' + IntToStr(Sum) + ';');
    8486      end;
    85       '.': AddLine('putc(Memory[Pos]);');
    86       ',': AddLine('getc(Memory[Pos]);');
     87      '.': AddLine('putchar(Memory[Pos]);');
     88      ',': AddLine('Memory[Pos] = getchar();');
    8789      '[': begin
    88         AddLine('while(Memory[Pos] <> 0)');
     90        AddLine('while(Memory[Pos] != 0)');
    8991        AddLine('{');
    9092        Inc(Indent);
     
    102104end;
    103105
     106procedure TBrainFuckCompilerC.CompileToFile;
     107var
     108  Process: TProcess;
     109  CompiledFile: string;
     110begin
     111  CompiledFile := ExtractFilePath(ProjectFileName) +
     112    'compiled' + DirectorySeparator + Name + DirectorySeparator +
     113    ExtractFileNameOnly(ProjectFileName) + SourceExtension;
     114  ForceDirectoriesUTF8(ExtractFilePath(CompiledFile));
     115  with TStringList.Create do
     116  try
     117    Text := Output;
     118    SaveToFile(CompiledFile);
     119  finally
     120    Free;
     121  end;
     122  if FileExistsUTF8(CompilerPath) then
     123  try
     124    Process := TProcess.Create(nil);
     125    Process.CurrentDirectory := ExtractFilePath(CompilerPath);
     126    Process.CommandLine := '"' + CompilerPath + '" "' + CompiledFile + '" -o ' +
     127      ExtractFilePath(CompiledFile) + ExtractFileNameOnly(CompiledFile) + CompiledExtension;
     128    Process.Options := [poWaitOnExit];
     129    Process.Execute;
     130  finally
     131    Process.Free;
     132  end else raise Exception.Create(Format(SCompilerNotFound, [CompilerPath]));
     133end;
     134
     135procedure TBrainFuckCompilerC.Run;
     136begin
     137  inherited Run;
     138end;
     139
    104140end.
    105141
  • trunk/Compiler/UCompilerPHP.pas

    r26 r28  
    1515    constructor Create; override;
    1616    procedure Compile; override;
     17    procedure Run; override;
    1718  end;
    1819
     
    9293end;
    9394
     95procedure TBrainFuckCompilerPHP.Run;
     96begin
     97  inherited Run;
     98end;
     99
    94100end.
    95101
  • trunk/Forms/UMainForm.pas

    r27 r28  
    166166  SNumberGeneration = 'Number generation';
    167167  SProgramExited = 'Program exited';
    168   SCompilerNotFound = 'Compiler "%s" not found';
    169   SCompiledFileNotFound = 'Program compiled file "%s" not found';
    170168
    171169{ TMainForm }
     
    459457
    460458procedure TMainForm.ACompileAndRunExecute(Sender: TObject);
    461 var
    462   Process: TProcess;
    463   CompiledFile: string;
    464459begin
    465460  with TBrainFuckCompiler(Compilers[CompilerIndex]) do begin
     
    467462    Source := MemoSource.Text;
    468463    ProgramName := ExtractFileNameOnly(ProjectFileName);
     464    ProjectFileName := Self.ProjectFileName;
    469465    Compile;
    470     CompiledFile := ExtractFilePath(ProjectFileName) +
    471       'compiled' + DirectorySeparator + Name + DirectorySeparator +
    472       ExtractFileNameOnly(ProjectFileName) + SourceExtension;
    473     ForceDirectoriesUTF8(ExtractFilePath(CompiledFile));
    474     with TStringList.Create do
    475     try
    476       Text := Output;
    477       SaveToFile(CompiledFile);
    478     finally
    479       Free;
    480     end;
    481     if FileExistsUTF8(CompilerPath) then
    482     try
    483       Process := TProcess.Create(nil);
    484       Process.CommandLine := '"' + CompilerPath + '" "' + CompiledFile + '"';
    485       Process.Options := [poWaitOnExit];
    486       Process.Execute;
    487     finally
    488       Process.Free;
    489     end else raise Exception.Create(Format(SCompilerNotFound, [CompilerPath]));
    490 
    491     if CompiledExtension <> '' then begin
    492       CompiledFile := ExtractFilePath(CompiledFile) + ExtractFileNameOnly(CompiledFile) + CompiledExtension;
    493       if FileExistsUTF8(CompiledFile) then
    494       try
    495         Process := TProcess.Create(nil);
    496         Process.CommandLine := '"' + CompiledFile + '"';
    497         Process.Options := [poWaitOnExit];
    498         Process.Execute;
    499       finally
    500         Process.Free;
    501       end else raise Exception.Create(Format(SCompiledFileNotFound, [CompiledFile]));
    502     end;
     466    CompileToFile;
     467    if CompiledExtension <> '' then Run;
    503468  end;
    504469end;
  • trunk/Languages/LazFuckIDE.cs.po

    r25 r28  
    290290msgstr "Chyba čtení vstupu"
    291291
     292#: ucompiler.scompiledfilenotfound
     293msgctxt "ucompiler.scompiledfilenotfound"
     294msgid "Program compiled file \"%s\" not found"
     295msgstr ""
     296
     297#: ucompiler.scompilernotfound
     298msgctxt "ucompiler.scompilernotfound"
     299msgid "Compiler \"%s\" not found"
     300msgstr ""
     301
    292302#: ucompilersform.scompileroptions
    293303msgid "Compiler options"
     
    308318msgstr " kroků/s"
    309319
    310 #: umainform.scompiledfilenotfound
    311 msgid "Program compiled file \"%s\" not found"
    312 msgstr ""
    313 
    314 #: umainform.scompilernotfound
    315 msgid "Compiler \"%s\" not found"
    316 msgstr ""
    317 
    318320#: umainform.senternumber
    319321msgid "Enter number"
  • trunk/Languages/LazFuckIDE.po

    r25 r28  
    281281msgstr ""
    282282
     283#: ucompiler.scompiledfilenotfound
     284msgctxt "ucompiler.scompiledfilenotfound"
     285msgid "Program compiled file \"%s\" not found"
     286msgstr ""
     287
     288#: ucompiler.scompilernotfound
     289msgctxt "ucompiler.scompilernotfound"
     290msgid "Compiler \"%s\" not found"
     291msgstr ""
     292
    283293#: ucompilersform.scompileroptions
    284294msgid "Compiler options"
     
    299309msgstr ""
    300310
    301 #: umainform.scompiledfilenotfound
    302 msgid "Program compiled file \"%s\" not found"
    303 msgstr ""
    304 
    305 #: umainform.scompilernotfound
    306 msgid "Compiler \"%s\" not found"
    307 msgstr ""
    308 
    309311#: umainform.senternumber
    310312msgid "Enter number"
Note: See TracChangeset for help on using the changeset viewer.