Changeset 114 for trunk/UBFTarget.pas
- Timestamp:
- May 18, 2019, 12:13:44 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UBFTarget.pas
r112 r114 44 44 FProgram: array of TMachineOperation; 45 45 FProgramIndex: Integer; 46 function GetOperationText(Operation: TMachineOperation): string; virtual; 46 47 procedure LoadProgram; override; 47 48 public … … 55 56 end; 56 57 58 const 59 BrainFuckCommandText: array[TMachineCommand] of Char = ( 60 ' ', '+', '-', '>', '<', '.', ',', '[', ']', '@', '=', '*'); 61 57 62 58 63 implementation … … 98 103 NewProgram: array of TMachineOperation; 99 104 NewProgramIndex: Integer; 105 NewTargetPos: Integer; 106 FirstIndex: Integer; 100 107 begin 101 108 NewProgramIndex := 0; 109 NewTargetPos := 0; 102 110 SetLength(NewProgram, Length(FProgram)); 103 111 104 112 FProgramIndex := 0; 105 113 while (FProgramIndex < Length(FProgram)) do begin 114 FirstIndex := FProgramIndex; 106 115 case FProgram[FProgramIndex].Command of 107 116 cmPointerInc: begin … … 123 132 else NewProgram[NewProgramIndex] := FProgram[FProgramIndex]; 124 133 end; 125 DebugSteps.UpdateTargetPos(FProgramIndex, NewProgramIndex); 134 DebugSteps.UpdateTargetPos(FirstIndex, FProgramIndex, NewProgramIndex, NewTargetPos); 135 Inc(NewTargetPos, Length(GetOperationText(NewProgram[NewProgramIndex]))); 126 136 Inc(FProgramIndex); 127 137 Inc(NewProgramIndex); … … 139 149 NewProgramIndex: Integer; 140 150 PreviousCommand: TMachineCommand; 151 FirstIndex: Integer; 152 NewTextIndex: Integer; 141 153 begin 142 154 // Merge together cmInc, cmDec, cmSet … … 147 159 148 160 FProgramIndex := 0; 161 NewTextIndex := 0; 149 162 while (FProgramIndex < Length(FProgram)) do begin 163 FirstIndex := FProgramIndex; 150 164 case FProgram[FProgramIndex].Command of 151 165 cmPointerInc: begin … … 258 272 end; 259 273 PreviousCommand := FProgram[FProgramIndex].Command; 260 DebugSteps.UpdateTargetPos(FProgramIndex, NewProgramIndex); 274 DebugSteps.UpdateTargetPos(FirstIndex, FProgramIndex, NewProgramIndex, NewTextIndex); 275 Inc(NewTextIndex, Length(GetOperationText(NewProgram[NewProgramIndex]))); 261 276 Inc(FProgramIndex); 262 277 Inc(NewProgramIndex); … … 281 296 NewProgramIndex: Integer; 282 297 RelIndex: Integer; 298 FirstIndex: Integer; 299 NewTextIndex: Integer; 283 300 begin 284 301 NewProgramIndex := 0; … … 287 304 RelIndex := 0; 288 305 FProgramIndex := 0; 306 NewTextIndex := 0; 289 307 while (FProgramIndex < Length(FProgram)) do begin 308 FirstIndex := FProgramIndex; 290 309 case FProgram[FProgramIndex].Command of 291 310 cmPointerInc: begin … … 319 338 else raise Exception.Create(Format('Unsupported command %d', [FProgram[FProgramIndex].Command])); 320 339 end; 321 DebugSteps.UpdateTargetPos(FProgramIndex, NewProgramIndex); 340 DebugSteps.UpdateTargetPos(FirstIndex, FProgramIndex, NewProgramIndex, NewTextIndex); 341 Inc(NewTextIndex, Length(GetOperationText(NewProgram[NewProgramIndex]))); 322 342 Inc(FProgramIndex); 323 343 Inc(NewProgramIndex); … … 340 360 LoopStartIndex: Integer; 341 361 LoopStartIndexNew: Integer; 362 FirstIndex: Integer; 363 NewTextIndex: Integer; 342 364 begin 343 365 NewProgramIndex := 0; … … 347 369 ProcessLoop := False; 348 370 FProgramIndex := 0; 371 NewTextIndex := 0; 349 372 PointerChange := 0; 350 373 while (FProgramIndex < Length(FProgram)) do begin 374 FirstIndex := FProgramIndex; 351 375 case FProgram[FProgramIndex].Command of 352 376 cmPointerInc: begin … … 418 442 else raise Exception.Create(Format('Unsupported command %d', [FProgram[FProgramIndex].Command])); 419 443 end; 420 DebugSteps.UpdateTargetPos(FProgramIndex, NewProgramIndex); 444 DebugSteps.UpdateTargetPos(FirstIndex, FProgramIndex, NewProgramIndex, NewTextIndex); 445 Inc(NewTextIndex, Length(GetOperationText(NewProgram[NewProgramIndex]))); 421 446 Inc(FProgramIndex); 422 447 Inc(NewProgramIndex); … … 428 453 Move(Pointer(NewProgram)^, Pointer(FProgram)^, SizeOf(TMachineOperation) * 429 454 Length(NewProgram)); 455 end; 456 457 function TBFTarget.GetOperationText(Operation: TMachineOperation): string; 458 begin 459 Result := BrainFuckCommandText[Operation.Command]; 460 if Operation.Command in [cmInc, cmDec, cmPointerInc, cmPointerDec, 461 cmSet, cmMultipy] then begin 462 if Operation.Parameter <> 1 then 463 Result := Result + IntToStr(Operation.Parameter); 464 end; 465 if Operation.RelIndex <> 0 then 466 Result := Result + 'R' + IntToStr(Operation.RelIndex); 430 467 end; 431 468
Note:
See TracChangeset
for help on using the changeset viewer.