Changeset 52 for trunk/Target/UTargetJava.pas
- Timestamp:
- Jul 26, 2012, 3:11:08 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Target/UTargetJava.pas
r48 r52 45 45 procedure TTargetJava.Compile; 46 46 var 47 I: Integer;48 47 Sum: Integer; 49 50 function CheckOccurence(C: Char): Integer;51 begin52 Result := 1;53 if Optimization = coNormal then54 while ((I + 1) <= Length(FSourceCode)) and (FSourceCode[I + 1] = C) do begin55 Inc(Result);56 Inc(I)57 end;58 end;59 60 48 begin 61 49 inherited; … … 75 63 AddLine('Memory = new char[30000];'); 76 64 AddLine('Pos = 0;'); 77 I := 1;78 while ( I <= Length(FSourceCode)) do begin79 case F SourceCode[I] of80 '>': begin81 Sum := CheckOccurence( '>');65 FProgramIndex := 0; 66 while (FProgramIndex < Length(FProgram)) do begin 67 case FProgram[FProgramIndex] of 68 cmPointerInc: begin 69 Sum := CheckOccurence(cmPointerInc); 82 70 AddLine('Pos = Pos + ' + IntToStr(Sum) + ';'); 83 71 end; 84 '<': begin85 Sum := CheckOccurence( '<');72 cmPointerDec: begin 73 Sum := CheckOccurence(cmPointerDec); 86 74 AddLine('Pos = Pos - ' + IntToStr(Sum) + ';'); 87 75 end; 88 '+': begin89 Sum := CheckOccurence( '+');76 cmInc: begin 77 Sum := CheckOccurence(cmInc); 90 78 AddLine('Memory[Pos] = (char)((int)Memory[Pos] + ' + IntToStr(Sum) + ');'); 91 79 end; 92 '-': begin93 Sum := CheckOccurence( '-');80 cmDec: begin 81 Sum := CheckOccurence(cmDec); 94 82 AddLine('Memory[Pos] = (char)((int)Memory[Pos] - ' + IntToStr(Sum) + ');'); 95 83 end; 96 '.': AddLine('System.out.print(Memory[Pos]);'); 97 ',': AddLine('Memory[Pos] = (char)System.in.read();'); 98 '[': begin 99 AddLine('while(Memory[Pos] != 0)'); 100 AddLine('{'); 101 Inc(Indent); 84 cmOutput: AddLine('System.out.print(Memory[Pos]);'); 85 cmInput: AddLine('Memory[Pos] = (char)System.in.read();'); 86 cmLoopStart: begin 87 if CheckClear then begin 88 AddLine('Memory[Pos] = 0;'); 89 Inc(FProgramIndex, 2); 90 end else begin 91 AddLine('while(Memory[Pos] != 0)'); 92 AddLine('{'); 93 Inc(Indent); 94 end; 102 95 end; 103 ']': begin96 cmLoopEnd: begin 104 97 Dec(Indent); 105 98 AddLine('}'); 106 99 end; 107 100 end; 108 Inc( I);101 Inc(FProgramIndex); 109 102 end; 110 103 Dec(Indent);
Note:
See TracChangeset
for help on using the changeset viewer.