Changeset 52 for trunk/Target/UTargetDelphi.pas
- Timestamp:
- Jul 26, 2012, 3:11:08 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Target/UTargetDelphi.pas
r48 r52 39 39 procedure TTargetDelphi.Compile; 40 40 var 41 I: Integer;42 41 Sum: Integer; 43 44 function CheckOccurence(C: Char): Integer;45 begin46 Result := 1;47 if Optimization = coNormal then48 while ((I + 1) <= Length(FSourceCode)) and (FSourceCode[I + 1] = C) do begin49 Inc(Result);50 Inc(I)51 end;52 end;53 54 function CheckClear: Boolean;55 begin56 Result := (FSourceCode[I] = '[') and (Length(FSourceCode) >= I + 2) and57 (FSourceCode[I + 1] = '-') and (FSourceCode[I + 2] = ']');58 end;59 60 42 begin 61 43 inherited; … … 74 56 Inc(Indent); 75 57 AddLine('Pos := 0;'); 76 I := 1;77 while ( I <= Length(FSourceCode)) do begin78 case F SourceCode[I] of79 '>': begin80 Sum := CheckOccurence( '>');58 FProgramIndex := 0; 59 while (FProgramIndex < Length(FProgram)) do begin 60 case FProgram[FProgramIndex] of 61 cmPointerInc: begin 62 Sum := CheckOccurence(cmPointerInc); 81 63 AddLine('Inc(Pos, ' + IntToStr(Sum) + ');'); 82 64 end; 83 '<': begin84 Sum := CheckOccurence( '<');65 cmPointerDec: begin 66 Sum := CheckOccurence(cmPointerDec); 85 67 AddLine('Dec(Pos, ' + IntToStr(Sum) + ');'); 86 68 end; 87 '+': begin88 Sum := CheckOccurence( '+');69 cmInc: begin 70 Sum := CheckOccurence(cmInc); 89 71 AddLine('Memory[Pos] := Memory[Pos] + ' + IntToStr(Sum) + ';'); 90 72 end; 91 '-': begin92 Sum := CheckOccurence( '-');73 cmDec: begin 74 Sum := CheckOccurence(cmDec); 93 75 AddLine('Memory[Pos] := Memory[Pos] - ' + IntToStr(Sum) + ';'); 94 76 end; 95 '.': AddLine('Write(Chr(Memory[Pos]));');96 ',': AddLine('Read(ReadChar); Memory[Pos] := Ord(ReadChar);');97 '[': begin77 cmOutput: AddLine('Write(Chr(Memory[Pos]));'); 78 cmInput: AddLine('Read(ReadChar); Memory[Pos] := Ord(ReadChar);'); 79 cmLoopStart: begin 98 80 if CheckClear then begin 99 81 AddLine('Memory[Pos] := 0;'); 100 Inc( I, 2);82 Inc(FProgramIndex, 2); 101 83 end else begin 102 84 AddLine('while Memory[Pos] <> 0 do begin'); … … 104 86 end; 105 87 end; 106 ']': begin88 cmLoopEnd: begin 107 89 Dec(Indent); 108 90 AddLine('end;'); 109 91 end; 110 92 end; 111 Inc( I);93 Inc(FProgramIndex); 112 94 end; 113 95 Dec(Indent);
Note:
See TracChangeset
for help on using the changeset viewer.