Changeset 86 for trunk/Target/UTargetC.pas
- Timestamp:
- Aug 29, 2017, 5:12:18 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Target/UTargetC.pas
r72 r86 15 15 TTargetC = class(TBFTarget) 16 16 private 17 function GetMemoryCell: string; 17 18 public 18 19 constructor Create; override; … … 46 47 end; 47 48 49 function TTargetC.GetMemoryCell: string; 50 begin 51 Result := 'Memory[Pos'; 52 if FProgram[FProgramIndex].RelIndex > 0 then 53 Result := Result + ' + ' + IntToStr(FProgram[FProgramIndex].RelIndex) 54 else if FProgram[FProgramIndex].RelIndex < 0 then 55 Result := Result + ' - ' + IntToStr(Abs(FProgram[FProgramIndex].RelIndex)); 56 Result := Result + ']'; 57 end; 58 48 59 procedure TTargetC.Compile; 49 60 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] = Memory[Pos] + ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';'); 70 cmDec: AddLine('Memory[Pos] = Memory[Pos] - ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';'); 71 cmOutput: AddLine('putchar(Memory[Pos]);'); 72 cmInput: AddLine('Memory[Pos] = getchar();'); 73 cmSet: AddLine('Memory[Pos] = ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';'); 80 cmInc: AddLine(GetMemoryCell + ' = ' + GetMemoryCell + ' + ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';'); 81 cmDec: AddLine(GetMemoryCell + ' = ' + GetMemoryCell + ' - ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';'); 82 cmOutput: AddLine('putchar(' + GetMemoryCell + ');'); 83 cmInput: AddLine(GetMemoryCell + ' = getchar();'); 84 cmSet: AddLine(GetMemoryCell + ' = ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';'); 85 cmMultipy: AddLine(GetMemoryCell + ' = ' + GetMemoryCell + ' + 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.