Changeset 86 for trunk/Target/UTargetPython.pas
- Timestamp:
- Aug 29, 2017, 5:12:18 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Target/UTargetPython.pas
r82 r86 14 14 TTargetPython = class(TBFTarget) 15 15 private 16 function GetMemoryCell: string; 16 17 public 17 18 constructor Create; override; … … 42 43 ExecutorPath := '/usr/bin/python'; 43 44 {$ENDIF} 45 end; 46 47 function TTargetPython.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 + ']'; 44 55 end; 45 56 … … 97 108 cmPointerInc: AddLine('position += ' + IntToStr(FProgram[FProgramIndex].Parameter)); 98 109 cmPointerDec: AddLine('position -= ' + IntToStr(FProgram[FProgramIndex].Parameter)); 99 cmInc: AddLine( 'memory[position]+= ' + IntToStr(FProgram[FProgramIndex].Parameter));100 cmDec: AddLine( 'memory[position]-= ' + IntToStr(FProgram[FProgramIndex].Parameter));110 cmInc: AddLine(GetMemoryCell + ' += ' + IntToStr(FProgram[FProgramIndex].Parameter)); 111 cmDec: AddLine(GetMemoryCell + ' -= ' + IntToStr(FProgram[FProgramIndex].Parameter)); 101 112 cmOutput: begin 102 AddLine('sys.stdout.write(chr( memory[position]))');113 AddLine('sys.stdout.write(chr(' + GetMemoryCell + '))'); 103 114 AddLine('sys.stdout.flush()'); 104 115 end; 105 cmInput: AddLine('memory[position] = ord(getchar())'); 106 cmSet: AddLine('memory[position] = ' + IntToStr(FProgram[FProgramIndex].Parameter)); 116 cmInput: AddLine(GetMemoryCell + ' = ord(getchar())'); 117 cmSet: AddLine(GetMemoryCell + ' = ' + IntToStr(FProgram[FProgramIndex].Parameter)); 118 cmMultipy: AddLine(GetMemoryCell + ' = ' + GetMemoryCell + ' + memory[position] * ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';'); 107 119 cmLoopStart: begin 108 AddLine('while( memory[position]!= 0):');120 AddLine('while(' + GetMemoryCell + ' != 0):'); 109 121 Inc(Indent); 110 122 end;
Note:
See TracChangeset
for help on using the changeset viewer.