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

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        44backup
        55LazFuckIDE
         6compiled
  • 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
Note: See TracChangeset for help on using the changeset viewer.