Changeset 86 for trunk/Target/UTargetJava.pas
- Timestamp:
- Aug 29, 2017, 5:12:18 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Target/UTargetJava.pas
r72 r86 14 14 TTargetJava = class(TBFTarget) 15 15 private 16 function GetMemoryCell: string; 16 17 public 17 18 constructor Create; override; … … 44 45 end; 45 46 47 function TTargetJava.GetMemoryCell: string; 48 begin 49 Result := 'Memory[Pos'; 50 if FProgram[FProgramIndex].RelIndex > 0 then 51 Result := Result + ' + ' + IntToStr(FProgram[FProgramIndex].RelIndex) 52 else if FProgram[FProgramIndex].RelIndex < 0 then 53 Result := Result + ' - ' + IntToStr(Abs(FProgram[FProgramIndex].RelIndex)); 54 Result := Result + ']'; 55 end; 56 46 57 procedure TTargetJava.Compile; 47 58 begin … … 67 78 cmPointerInc: AddLine('Pos = Pos + ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';'); 68 79 cmPointerDec: AddLine('Pos = Pos - ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';'); 69 cmInc: AddLine('Memory[Pos] = (char)((int)Memory[Pos] + ' + IntToStr(FProgram[FProgramIndex].Parameter) + ');'); 70 cmDec: AddLine('Memory[Pos] = (char)((int)Memory[Pos] - ' + IntToStr(FProgram[FProgramIndex].Parameter) + ');'); 71 cmOutput: AddLine('System.out.print(Memory[Pos]);'); 72 cmInput: AddLine('Memory[Pos] = (char)System.in.read();'); 73 cmSet: AddLine('Memory[Pos] = ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';'); 80 cmInc: AddLine(GetMemoryCell + ' = (char)((int)' + GetMemoryCell + ' + ' + IntToStr(FProgram[FProgramIndex].Parameter) + ');'); 81 cmDec: AddLine(GetMemoryCell + ' = (char)((int)' + GetMemoryCell + ' - ' + IntToStr(FProgram[FProgramIndex].Parameter) + ');'); 82 cmOutput: AddLine('System.out.print(' + GetMemoryCell + ');'); 83 cmInput: AddLine(GetMemoryCell + ' = (char)System.in.read();'); 84 cmSet: AddLine(GetMemoryCell + ' = (char)' + IntToStr(FProgram[FProgramIndex].Parameter) + ';'); 85 cmMultipy: AddLine(GetMemoryCell + ' = (char)((int)' + GetMemoryCell + ' + (int)Memory[Pos] * ' + IntToStr(FProgram[FProgramIndex].Parameter) + ');'); 74 86 cmLoopStart: begin 75 AddLine('while( Memory[Pos]!= 0)');87 AddLine('while(' + GetMemoryCell + ' != 0)'); 76 88 AddLine('{'); 77 89 Inc(Indent);
Note:
See TracChangeset
for help on using the changeset viewer.