Changeset 86 for trunk/Target/UTargetPHP.pas
- Timestamp:
- Aug 29, 2017, 5:12:18 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Target/UTargetPHP.pas
r72 r86 14 14 TTargetPHP = class(TBFTarget) 15 15 private 16 function GetMemoryCell: string; 16 17 public 17 18 constructor Create; override; … … 44 45 end; 45 46 47 function TTargetPHP.GetMemoryCell: string; 48 begin 49 Result := '$Memory[$Position'; 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 TTargetPHP.Compile; 47 58 begin … … 59 70 cmPointerInc: AddLine('$Position = $Position + ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';'); 60 71 cmPointerDec: AddLine('$Position = $Position - ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';'); 61 cmInc: AddLine('$Memory[$Position] = chr(ord($Memory[$Position]) + ' + IntToStr(FProgram[FProgramIndex].Parameter) + ');'); 62 cmDec: AddLine('$Memory[$Position] = chr(ord($Memory[$Position]) - ' + IntToStr(FProgram[FProgramIndex].Parameter) + ');'); 63 cmOutput: AddLine('echo($Memory[$Position]);'); 64 cmInput: AddLine('$Memory[$Position] = fgetc(STDIN);'); 65 cmSet: AddLine('$Memory[$Position] = chr(' + IntToStr(FProgram[FProgramIndex].Parameter) + ');'); 72 cmInc: AddLine(GetMemoryCell + ' = chr(ord(' + GetMemoryCell + ') + ' + 73 IntToStr(FProgram[FProgramIndex].Parameter) + ');'); 74 cmDec: AddLine(GetMemoryCell + ' = chr(ord(' + GetMemoryCell + ') - ' + 75 IntToStr(FProgram[FProgramIndex].Parameter) + ');'); 76 cmOutput: AddLine('echo(' + GetMemoryCell + ');'); 77 cmInput: AddLine(GetMemoryCell + ' = fgetc(STDIN);'); 78 cmSet: AddLine(GetMemoryCell + ' = chr(' + IntToStr(FProgram[FProgramIndex].Parameter) + ');'); 79 cmMultipy: AddLine(GetMemoryCell + ' = chr(ord(' + GetMemoryCell + ') + ord($Memory[$Position]) * ' + IntToStr(FProgram[FProgramIndex].Parameter) + ');'); 66 80 cmLoopStart: begin 67 AddLine('while( $Memory[$Position]!= "\0") {');81 AddLine('while(' + GetMemoryCell + ' != "\0") {'); 68 82 Inc(Indent); 69 83 end;
Note:
See TracChangeset
for help on using the changeset viewer.