Changeset 96 for trunk/UBFTarget.pas
- Timestamp:
- Aug 2, 2018, 10:41:11 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UBFTarget.pas
r91 r96 12 12 TMachineCommand = (cmNoOperation, cmInc, cmDec, cmPointerInc, cmPointerDec, 13 13 cmOutput, cmInput, cmLoopStart, cmLoopEnd, cmDebug, cmSet, cmMultipy); 14 15 { TMachineOperation } 14 16 15 17 TMachineOperation = record … … 17 19 Parameter: Integer; 18 20 RelIndex: Integer; 21 function Create(Command: TMachineCommand; Parameter, RelIndex: Integer): TMachineOperation; 19 22 end; 20 23 … … 55 58 implementation 56 59 60 { TMachineOperation } 61 62 function TMachineOperation.Create(Command: TMachineCommand; Parameter, 63 RelIndex: Integer): TMachineOperation; 64 begin 65 Result.Command := Command; 66 Result.Parameter := Parameter; 67 Result.RelIndex := RelIndex; 68 end; 69 57 70 function TBFTarget.CheckClear: Boolean; 58 71 begin … … 108 121 NewProgram[NewProgramIndex].Parameter := CheckOccurenceSumParam(cmDec); 109 122 end; 110 else begin 111 NewProgram[NewProgramIndex].Command := FProgram[FProgramIndex].Command; 112 NewProgram[NewProgramIndex].Parameter := FProgram[FProgramIndex].Parameter; 113 end; 123 else NewProgram[NewProgramIndex] := FProgram[FProgramIndex]; 114 124 end; 115 125 DebugSteps.UpdateTargetPos(FProgramIndex, NewProgramIndex); … … 234 244 NewProgram[NewProgramIndex].Parameter := FProgram[FProgramIndex].Parameter; 235 245 end else begin 236 NewProgram[NewProgramIndex].Command := cmSet; 237 NewProgram[NewProgramIndex].Parameter := FProgram[FProgramIndex].Parameter; 246 NewProgram[NewProgramIndex] := FProgram[FProgramIndex]; 238 247 end; 239 248 end; 240 249 cmLoopStart: begin 241 250 if CheckClear then begin 242 NewProgram[NewProgramIndex].Command := cmSet; 243 NewProgram[NewProgramIndex].Parameter := 0; 251 NewProgram[NewProgramIndex] := TMachineOperation.Create(cmSet, 0, 0); 244 252 Inc(FProgramIndex, 2); 245 253 end else begin 246 NewProgram[NewProgramIndex].Command := FProgram[FProgramIndex].Command; 247 NewProgram[NewProgramIndex].Parameter := FProgram[FProgramIndex].Parameter; 248 end; 249 end; 250 else begin 251 NewProgram[NewProgramIndex].Command := FProgram[FProgramIndex].Command; 252 NewProgram[NewProgramIndex].Parameter := FProgram[FProgramIndex].Parameter; 253 end; 254 NewProgram[NewProgramIndex] := FProgram[FProgramIndex]; 255 end; 256 end; 257 else NewProgram[NewProgramIndex] := FProgram[FProgramIndex]; 254 258 end; 255 259 PreviousCommand := FProgram[FProgramIndex].Command; … … 294 298 end; 295 299 cmInc, cmDec, cmInput, cmOutput, cmSet: begin 296 NewProgram[NewProgramIndex] .Command := FProgram[FProgramIndex].Command;297 NewProgram[NewProgramIndex]. Parameter := FProgram[FProgramIndex].Parameter;298 NewProgram[NewProgramIndex].RelIndex :=RelIndex;300 NewProgram[NewProgramIndex] := FProgram[FProgramIndex]; 301 NewProgram[NewProgramIndex].RelIndex := 302 NewProgram[NewProgramIndex].RelIndex + RelIndex; 299 303 end; 300 304 cmLoopStart, cmLoopEnd: begin 301 305 if RelIndex > 0 then begin 302 NewProgram[NewProgramIndex].Command := cmPointerInc; 303 NewProgram[NewProgramIndex].Parameter := RelIndex; 304 NewProgram[NewProgramIndex].RelIndex := 0; 306 NewProgram[NewProgramIndex] := TMachineOperation.Create(cmPointerInc, 307 RelIndex, 0); 305 308 Inc(NewProgramIndex); 306 309 RelIndex := 0; 307 310 end else 308 311 if RelIndex < 0 then begin 309 NewProgram[NewProgramIndex].Command := cmPointerDec; 310 NewProgram[NewProgramIndex].Parameter := Abs(RelIndex); 311 NewProgram[NewProgramIndex].RelIndex := 0; 312 NewProgram[NewProgramIndex] := TMachineOperation.Create(cmPointerDec, 313 Abs(RelIndex), 0); 312 314 Inc(NewProgramIndex); 313 315 RelIndex := 0; 314 316 end; 315 NewProgram[NewProgramIndex].Command := FProgram[FProgramIndex].Command; 316 NewProgram[NewProgramIndex].Parameter := FProgram[FProgramIndex].Parameter; 317 NewProgram[NewProgramIndex].RelIndex := 0; 318 end; 317 NewProgram[NewProgramIndex] := FProgram[FProgramIndex]; 318 end; 319 else raise Exception.Create(Format('Unsupported command %d', [FProgram[FProgramIndex].Command])); 319 320 end; 320 321 DebugSteps.UpdateTargetPos(FProgramIndex, NewProgramIndex); … … 351 352 cmPointerInc: begin 352 353 PointerChange := PointerChange + FProgram[FProgramIndex].Parameter; 353 NewProgram[NewProgramIndex].Command := FProgram[FProgramIndex].Command; 354 NewProgram[NewProgramIndex].Parameter := FProgram[FProgramIndex].Parameter; 355 NewProgram[NewProgramIndex].RelIndex := FProgram[FProgramIndex].RelIndex; 354 NewProgram[NewProgramIndex] := FProgram[FProgramIndex]; 356 355 end; 357 356 cmPointerDec: begin 358 357 PointerChange := PointerChange - FProgram[FProgramIndex].Parameter; 359 NewProgram[NewProgramIndex].Command := FProgram[FProgramIndex].Command; 360 NewProgram[NewProgramIndex].Parameter := FProgram[FProgramIndex].Parameter; 361 NewProgram[NewProgramIndex].RelIndex := FProgram[FProgramIndex].RelIndex; 358 NewProgram[NewProgramIndex] := FProgram[FProgramIndex]; 362 359 end; 363 360 cmInc: begin 364 361 if not ProcessLoop then begin 365 NewProgram[NewProgramIndex].Command := FProgram[FProgramIndex].Command; 366 NewProgram[NewProgramIndex].Parameter := FProgram[FProgramIndex].Parameter; 367 NewProgram[NewProgramIndex].RelIndex := FProgram[FProgramIndex].RelIndex; 362 NewProgram[NewProgramIndex] := FProgram[FProgramIndex]; 368 363 end else begin 369 364 if ((FProgram[FProgramIndex].RelIndex + PointerChange) <> 0) then begin 365 NewProgram[NewProgramIndex] := FProgram[FProgramIndex]; 370 366 NewProgram[NewProgramIndex].Command := cmMultipy; 371 NewProgram[NewProgramIndex].Parameter := FProgram[FProgramIndex].Parameter;372 NewProgram[NewProgramIndex].RelIndex := FProgram[FProgramIndex].RelIndex;373 367 end else Dec(NewProgramIndex); 374 368 end; … … 379 373 (FProgram[FProgramIndex].Parameter = 1) then 380 374 Inc(NumberOfBaseDecrement); 381 NewProgram[NewProgramIndex].Command := FProgram[FProgramIndex].Command; 382 NewProgram[NewProgramIndex].Parameter := FProgram[FProgramIndex].Parameter; 383 NewProgram[NewProgramIndex].RelIndex := FProgram[FProgramIndex].RelIndex; 375 NewProgram[NewProgramIndex] := FProgram[FProgramIndex]; 384 376 end else begin 385 377 if ((FProgram[FProgramIndex].RelIndex + PointerChange) <> 0) then begin 378 NewProgram[NewProgramIndex] := FProgram[FProgramIndex]; 386 379 NewProgram[NewProgramIndex].Command := cmMultipy; 387 380 NewProgram[NewProgramIndex].Parameter := -FProgram[FProgramIndex].Parameter; 388 NewProgram[NewProgramIndex].RelIndex := FProgram[FProgramIndex].RelIndex;389 381 end else Dec(NewProgramIndex); 390 382 end; 391 383 end; 392 384 cmInput, cmOutput: begin 393 NewProgram[NewProgramIndex].Command := FProgram[FProgramIndex].Command; 394 NewProgram[NewProgramIndex].Parameter := FProgram[FProgramIndex].Parameter; 395 NewProgram[NewProgramIndex].RelIndex := FProgram[FProgramIndex].RelIndex; 385 NewProgram[NewProgramIndex] := FProgram[FProgramIndex]; 396 386 Inc(NumberOfBaseDecrement, 2); 397 387 end; 398 388 cmSet: begin 399 NewProgram[NewProgramIndex].Command := FProgram[FProgramIndex].Command; 400 NewProgram[NewProgramIndex].Parameter := FProgram[FProgramIndex].Parameter; 401 NewProgram[NewProgramIndex].RelIndex := FProgram[FProgramIndex].RelIndex; 389 NewProgram[NewProgramIndex] := FProgram[FProgramIndex]; 402 390 Inc(NumberOfBaseDecrement, 2); 403 391 end; … … 408 396 LoopStartIndex := FProgramIndex; 409 397 LoopStartIndexNew := NewProgramIndex; 410 NewProgram[NewProgramIndex].Command := FProgram[FProgramIndex].Command; 411 NewProgram[NewProgramIndex].Parameter := FProgram[FProgramIndex].Parameter; 412 NewProgram[NewProgramIndex].RelIndex := FProgram[FProgramIndex].RelIndex; 398 NewProgram[NewProgramIndex] := FProgram[FProgramIndex]; 413 399 end else begin 414 400 Dec(NewProgramIndex); … … 422 408 ProcessLoop := True; 423 409 end else begin 424 NewProgram[NewProgramIndex].Command := FProgram[FProgramIndex].Command; 425 NewProgram[NewProgramIndex].Parameter := FProgram[FProgramIndex].Parameter; 426 NewProgram[NewProgramIndex].RelIndex := FProgram[FProgramIndex].RelIndex; 410 NewProgram[NewProgramIndex] := FProgram[FProgramIndex]; 427 411 end; 428 412 end else begin 429 NewProgram[NewProgramIndex].Command := cmSet; 430 NewProgram[NewProgramIndex].Parameter := 0; 431 NewProgram[NewProgramIndex].RelIndex := 0; 413 NewProgram[NewProgramIndex] := TMachineOperation.Create(cmSet, 0, 0); 432 414 ProcessLoop := False; 433 415 NumberOfBaseDecrement := 0; 434 416 end; 435 417 end; 418 else raise Exception.Create(Format('Unsupported command %d', [FProgram[FProgramIndex].Command])); 436 419 end; 437 420 DebugSteps.UpdateTargetPos(FProgramIndex, NewProgramIndex); … … 458 441 case FSourceCode[I] of 459 442 '+': begin 460 FProgram[FProgramIndex].Command := cmInc; 461 FProgram[FProgramIndex].Parameter := 1; 462 FProgram[FProgramIndex].RelIndex := 0; 443 FProgram[FProgramIndex] := TMachineOperation.Create(cmInc, 1, 0); 463 444 DebugSteps.AddStep(I - 1, FProgramIndex, soNormal); 464 445 end; 465 446 '-': begin 466 FProgram[FProgramIndex].Command := cmDec; 467 FProgram[FProgramIndex].Parameter := 1; 468 FProgram[FProgramIndex].RelIndex := 0; 447 FProgram[FProgramIndex] := TMachineOperation.Create(cmDec, 1, 0); 469 448 DebugSteps.AddStep(I - 1, FProgramIndex, soNormal); 470 449 end; 471 450 '>': begin 472 FProgram[FProgramIndex].Command := cmPointerInc; 473 FProgram[FProgramIndex].Parameter := 1; 474 FProgram[FProgramIndex].RelIndex := 0; 451 FProgram[FProgramIndex] := TMachineOperation.Create(cmPointerInc, 1, 0); 475 452 DebugSteps.AddStep(I - 1, FProgramIndex, soNormal); 476 453 end; 477 454 '<': begin 478 FProgram[FProgramIndex].Command := cmPointerDec; 479 FProgram[FProgramIndex].Parameter := 1; 480 FProgram[FProgramIndex].RelIndex := 0; 455 FProgram[FProgramIndex] := TMachineOperation.Create(cmPointerDec, 1, 0); 481 456 DebugSteps.AddStep(I - 1, FProgramIndex, soNormal); 482 457 end; 483 458 ',': begin 484 FProgram[FProgramIndex].Command := cmInput; 485 FProgram[FProgramIndex].Parameter := 0; 486 FProgram[FProgramIndex].RelIndex := 0; 459 FProgram[FProgramIndex] := TMachineOperation.Create(cmInput, 0, 0); 487 460 DebugSteps.AddStep(I - 1, FProgramIndex, soNormal); 488 461 end; 489 462 '.': begin 490 FProgram[FProgramIndex].Command := cmOutput; 491 FProgram[FProgramIndex].Parameter := 0; 492 FProgram[FProgramIndex].RelIndex := 0; 463 FProgram[FProgramIndex] := TMachineOperation.Create(cmOutput, 0, 0); 493 464 DebugSteps.AddStep(I - 1, FProgramIndex, soNormal); 494 465 end; 495 466 '[': begin 496 FProgram[FProgramIndex].Command := cmLoopStart; 497 FProgram[FProgramIndex].Parameter := 0; 498 FProgram[FProgramIndex].RelIndex := 0; 467 FProgram[FProgramIndex] := TMachineOperation.Create(cmLoopStart, 0, 0); 499 468 DebugSteps.AddStep(I - 1, FProgramIndex, soStepIn); 500 469 end; 501 470 ']': begin 502 FProgram[FProgramIndex].Command := cmLoopEnd; 503 FProgram[FProgramIndex].Parameter := 0; 504 FProgram[FProgramIndex].RelIndex := 0; 471 FProgram[FProgramIndex] := TMachineOperation.Create(cmLoopEnd, 0 ,0); 505 472 DebugSteps.AddStep(I - 1, FProgramIndex, soStepOut); 506 473 end
Note:
See TracChangeset
for help on using the changeset viewer.