Changeset 52 for trunk/Target/UTargetC.pas
- Timestamp:
- Jul 26, 2012, 3:11:08 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Target/UTargetC.pas
r48 r52 35 35 Capabilities := [tcCompile, tcRun]; 36 36 {$IFDEF Windows} 37 CompilerPath := 'c:\Program Files\MinGW\bin\gcc.exe -o %1:s';37 CompilerPath := 'c:\Program Files\MinGW\bin\gcc.exe'; 38 38 {$ENDIF} 39 39 {$IFDEF Linux} … … 44 44 procedure TTargetC.Compile; 45 45 var 46 I: Integer;47 46 Sum: Integer; 48 49 function CheckOccurence(C: Char): Integer;50 begin51 Result := 1;52 if Optimization = coNormal then53 while ((I + 1) <= Length(FSourceCode)) and (FSourceCode[I + 1] = C) do begin54 Inc(Result);55 Inc(I)56 end;57 end;58 59 47 begin 60 48 inherited; … … 72 60 AddLine(''); 73 61 AddLine('Pos = 0;'); 74 I := 1;75 while ( I <= Length(FSourceCode)) do begin76 case F SourceCode[I] of77 '>': begin78 Sum := CheckOccurence( '>');62 FProgramIndex := 0; 63 while (FProgramIndex < Length(FProgram)) do begin 64 case FProgram[FProgramIndex] of 65 cmPointerInc: begin 66 Sum := CheckOccurence(cmPointerInc); 79 67 AddLine('Pos = Pos + ' + IntToStr(Sum) + ';'); 80 68 end; 81 '<': begin82 Sum := CheckOccurence( '<');69 cmPointerDec: begin 70 Sum := CheckOccurence(cmPointerDec); 83 71 AddLine('Pos = Pos - ' + IntToStr(Sum) + ';'); 84 72 end; 85 '+': begin86 Sum := CheckOccurence( '+');73 cmInc: begin 74 Sum := CheckOccurence(cmInc); 87 75 AddLine('Memory[Pos] = Memory[Pos] + ' + IntToStr(Sum) + ';'); 88 76 end; 89 '-': begin90 Sum := CheckOccurence( '-');77 cmDec: begin 78 Sum := CheckOccurence(cmDec); 91 79 AddLine('Memory[Pos] = Memory[Pos] - ' + IntToStr(Sum) + ';'); 92 80 end; 93 '.': AddLine('putchar(Memory[Pos]);'); 94 ',': AddLine('Memory[Pos] = getchar();'); 95 '[': begin 96 AddLine('while(Memory[Pos] != 0)'); 97 AddLine('{'); 98 Inc(Indent); 81 cmOutput: AddLine('putchar(Memory[Pos]);'); 82 cmInput: AddLine('Memory[Pos] = getchar();'); 83 cmLoopStart: begin 84 if CheckClear then begin 85 AddLine('Memory[Pos] = 0;'); 86 Inc(FProgramIndex, 2); 87 end else begin 88 AddLine('while(Memory[Pos] != 0)'); 89 AddLine('{'); 90 Inc(Indent); 91 end; 99 92 end; 100 ']': begin93 cmLoopEnd: begin 101 94 Dec(Indent); 102 95 AddLine('}'); 103 96 end; 104 97 end; 105 Inc( I);98 Inc(FProgramIndex); 106 99 end; 107 100 AddLine('return 0;');
Note:
See TracChangeset
for help on using the changeset viewer.