Changeset 28 for trunk/Compiler
- Timestamp:
- Feb 13, 2012, 12:26:12 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 4 4 backup 5 5 LazFuckIDE 6 compiled
-
- Property svn:ignore
-
trunk/Compiler/UCompiler.pas
r25 r28 6 6 7 7 uses 8 Classes, SysUtils, StrUtils, Registry, URegistry, SpecializedList; 8 Classes, SysUtils, StrUtils, Registry, URegistry, SpecializedList, 9 FileUtil, Process; 9 10 10 11 type … … 26 27 SourceExtension: string; 27 28 CompiledExtension: string; 29 ProjectFileName: string; 28 30 constructor Create; virtual; 29 31 procedure OptimizeSource; 30 32 procedure Compile; virtual; 33 procedure CompileToFile; virtual; 34 procedure Run; virtual; 31 35 end; 32 36 … … 39 43 40 44 45 resourcestring 46 SCompilerNotFound = 'Compiler "%s" not found'; 47 SCompiledFileNotFound = 'Program compiled file "%s" not found'; 48 49 41 50 implementation 51 42 52 43 53 { TCompilerList } … … 99 109 end; 100 110 111 procedure TBrainFuckCompiler.CompileToFile; 112 var 113 Process: TProcess; 114 CompiledFile: string; 115 begin 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])); 137 end; 138 139 procedure TBrainFuckCompiler.Run; 140 var 141 CompiledFile: string; 142 Process: TProcess; 143 begin 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])); 156 end; 157 101 158 102 159 -
trunk/Compiler/UCompilerC.pas
r27 r28 6 6 7 7 uses 8 Classes, SysUtils, UCompiler;8 Classes, SysUtils, FileUtil, UCompiler, Process; 9 9 10 10 type … … 15 15 constructor Create; override; 16 16 procedure Compile; override; 17 procedure CompileToFile; override; 18 procedure Run; override; 17 19 end; 18 20 … … 28 30 CompiledExtension := '.exe'; 29 31 {$IFDEF Windows} 30 CompilerPath := ' C:\Program Files\Dev-Cpp\mingw32-gcc.exe';32 CompilerPath := 'c:\Program Files\MinGW\bin\gcc.exe -o %1:s'; 31 33 {$ENDIF} 32 34 {$IFDEF Linux} … … 59 61 AddLine('{'); 60 62 Inc(Indent); 61 AddLine('char [30000] Memory;');63 AddLine('char Memory[30000];'); 62 64 AddLine('int Pos;'); 63 65 AddLine('char ReadChar;'); … … 83 85 AddLine('Memory[Pos] = Memory[Pos] - ' + IntToStr(Sum) + ';'); 84 86 end; 85 '.': AddLine('putc (Memory[Pos]);');86 ',': AddLine(' getc(Memory[Pos]);');87 '.': AddLine('putchar(Memory[Pos]);'); 88 ',': AddLine('Memory[Pos] = getchar();'); 87 89 '[': begin 88 AddLine('while(Memory[Pos] <>0)');90 AddLine('while(Memory[Pos] != 0)'); 89 91 AddLine('{'); 90 92 Inc(Indent); … … 102 104 end; 103 105 106 procedure TBrainFuckCompilerC.CompileToFile; 107 var 108 Process: TProcess; 109 CompiledFile: string; 110 begin 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])); 133 end; 134 135 procedure TBrainFuckCompilerC.Run; 136 begin 137 inherited Run; 138 end; 139 104 140 end. 105 141 -
trunk/Compiler/UCompilerPHP.pas
r26 r28 15 15 constructor Create; override; 16 16 procedure Compile; override; 17 procedure Run; override; 17 18 end; 18 19 … … 92 93 end; 93 94 95 procedure TBrainFuckCompilerPHP.Run; 96 begin 97 inherited Run; 98 end; 99 94 100 end. 95 101
Note:
See TracChangeset
for help on using the changeset viewer.