Changeset 86 for trunk/Target/UTargetFPC.pas
- Timestamp:
- Aug 29, 2017, 5:12:18 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Target/UTargetFPC.pas
r66 r86 14 14 TTargetFPC = class(TBFTarget) 15 15 private 16 function GetMemoryCell: string; 16 17 public 17 18 constructor Create; override; … … 43 44 end; 44 45 46 function TTargetFPC.GetMemoryCell: string; 47 begin 48 Result := 'Memory[Pos'; 49 if FProgram[FProgramIndex].RelIndex > 0 then 50 Result := Result + ' + ' + IntToStr(FProgram[FProgramIndex].RelIndex) 51 else if FProgram[FProgramIndex].RelIndex < 0 then 52 Result := Result + ' - ' + IntToStr(Abs(FProgram[FProgramIndex].RelIndex)); 53 Result := Result + ']'; 54 end; 55 45 56 procedure TTargetFPC.Compile; 46 57 begin … … 50 61 51 62 AddLine('program ' + ProgramName + ';'); 52 AddLine('');53 63 AddLine('var'); 54 64 AddLine(' Memory: array[0..30000] of Byte;'); … … 63 73 cmPointerInc: AddLine('Inc(Pos, ' + IntToStr(FProgram[FProgramIndex].Parameter) + ');'); 64 74 cmPointerDec: AddLine('Dec(Pos, ' + IntToStr(FProgram[FProgramIndex].Parameter) + ');'); 65 cmInc: AddLine('Memory[Pos] := Memory[Pos] + ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';'); 66 cmDec: AddLine('Memory[Pos] := Memory[Pos] - ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';'); 67 cmSet: AddLine('Memory[Pos] := ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';'); 68 cmOutput: AddLine('Write(Chr(Memory[Pos]));'); 69 cmInput: AddLine('Read(ReadChar); Memory[Pos] := Ord(ReadChar);'); 75 cmInc: AddLine(GetMemoryCell + ' := ' + GetMemoryCell + ' + ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';'); 76 cmDec: AddLine(GetMemoryCell + ' := ' + GetMemoryCell + ' - ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';'); 77 cmSet: AddLine(GetMemoryCell + ' := ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';'); 78 cmMultipy: AddLine(GetMemoryCell + ' := ' + GetMemoryCell + ' + Memory[Pos] * ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';'); 79 cmOutput: AddLine('Write(Chr(' + GetMemoryCell + '));'); 80 cmInput: AddLine('Read(ReadChar); ' + GetMemoryCell + ' := Ord(ReadChar);'); 70 81 cmLoopStart: begin 71 AddLine('while Memory[Pos]<> 0 do begin');82 AddLine('while ' + GetMemoryCell + ' <> 0 do begin'); 72 83 Inc(Indent); 73 84 end;
Note:
See TracChangeset
for help on using the changeset viewer.