Ignore:
Timestamp:
Jul 26, 2012, 3:11:08 PM (12 years ago)
Author:
chronos
Message:
  • Modified: Optimization functions moved to shared place in TTarget.
  • Modified: Text source is loaded to program source array of brainfuck commands for better processing.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Target/UTargetInterpretter.pas

    r48 r52  
    2222    procedure Execute; override;
    2323  end;
    24 
    25   TBrainFuckCommand = (cmNoOperation, cmInc, cmDec, cmPointerInc, cmPointerDec,
    26     cmOutput, cmInput, cmLoopStart, cmLoopEnd, cmDebug);
    2724
    2825  TCommandHandler = procedure of object;
     
    5552    function GetExecutionPosition: Integer; override;
    5653  public
    57     FProgram: array of TBrainFuckCommand;
    5854    FProgramBreakpoints: array of Boolean;
    5955    SourceJump: array of Integer;
    60     SourcePosition: Integer;
    6156    SourceBreakpoint: array of Boolean;
    6257    Memory: array of Integer;
     
    109104  with Parent do
    110105  repeat
    111     while (SourcePosition < Length(FProgram)) and (State <> rsStopped) do begin
     106    while (FProgramIndex < Length(FProgram)) and (State <> rsStopped) do begin
    112107      if State = rsRunning then begin
    113         if FProgramBreakpoints[SourcePosition] then begin
    114           BreakPoint := BreakPoints.SearchByTargetPos(SourcePosition);
     108        if FProgramBreakpoints[FProgramIndex] then begin
     109          BreakPoint := BreakPoints.SearchByTargetPos(FProgramIndex);
    115110          if BreakPoint.System then BreakPoints.Delete(BreakPoints.IndexOf(BreakPoint));
    116111          SetStateSafe(rsPaused);
    117112        end else begin
    118           FCommandTable[FProgram[SourcePosition]];
    119           Inc(SourcePosition);
     113          FCommandTable[FProgram[FProgramIndex]];
     114          Inc(FProgramIndex);
    120115          Inc(FStepCount);
    121116        end;
     
    155150begin
    156151  SetLength(Memory, AValue);
    157 end;
    158 
    159 procedure TTargetInterpretter.Compile;
    160 var
    161   I: Integer;
    162   Pos: Integer;
    163 begin
    164   inherited;
    165   DebugSteps.Clear;
    166   SetLength(FProgram, Length(FSourceCode));
    167   Pos := 0;
    168   for I := 1 to Length(FSourceCode) do begin
    169     case FSourceCode[I] of
    170       '+': begin
    171         FProgram[Pos] := cmInc;
    172         DebugSteps.AddStep(I - 1, Pos, soNormal);
    173       end;
    174       '-': begin
    175         FProgram[Pos] := cmDec;
    176         DebugSteps.AddStep(I - 1, Pos, soNormal);
    177       end;
    178       '>': begin
    179         FProgram[Pos] := cmPointerInc;
    180         DebugSteps.AddStep(I - 1, Pos, soNormal);
    181       end;
    182       '<': begin
    183         FProgram[Pos] := cmPointerDec;
    184         DebugSteps.AddStep(I - 1, Pos, soNormal);
    185       end;
    186       ',': begin
    187         FProgram[Pos] := cmInput;
    188         DebugSteps.AddStep(I - 1, Pos, soNormal);
    189       end;
    190       '.': begin
    191         FProgram[Pos] := cmOutput;
    192         DebugSteps.AddStep(I - 1, Pos, soNormal);
    193       end;
    194       '[': begin
    195         FProgram[Pos] := cmLoopStart;
    196         DebugSteps.AddStep(I - 1, Pos, soStepIn);
    197       end;
    198       ']': begin
    199         FProgram[Pos] := cmLoopEnd;
    200         DebugSteps.AddStep(I - 1, Pos, soStepOut);
    201       end
    202       else Dec(Pos);
    203     end;
    204     Inc(Pos);
    205   end;
    206   SetLength(FProgram, Pos);
    207152end;
    208153
     
    293238begin
    294239  if Memory[MemoryPosition] = 0 then
    295     SourcePosition := SourceJump[SourcePosition];
     240    FProgramIndex := SourceJump[FProgramIndex];
    296241end;
    297242
     
    299244begin
    300245  if Memory[MemoryPosition] > 0 then
    301     SourcePosition := SourceJump[SourcePosition] - 1;
     246    FProgramIndex := SourceJump[FProgramIndex] - 1;
    302247end;
    303248
     
    308253  inherited;
    309254  PrepareJumpTable;
    310   SourcePosition := 0;
     255  FProgramIndex := 0;
    311256  InputPosition := 1;
    312257  Output := '';
     
    320265end;
    321266
     267procedure TTargetInterpretter.Compile;
     268begin
     269  inherited;
     270end;
     271
    322272procedure TTargetInterpretter.PrepareBreakPoints;
    323273var
     
    343293function TTargetInterpretter.GetExecutionPosition: Integer;
    344294begin
    345   Result := SourcePosition;
     295  Result := FProgramIndex;
    346296end;
    347297
     
    379329begin
    380330  if State = rsPaused then begin
    381     Step := DebugSteps.SearchByTargetPos(SourcePosition);
     331    Step := DebugSteps.SearchByTargetPos(FProgramIndex);
    382332    if Step.Operation = soStepOut then begin
    383333      BreakPoints.SetSystem(Step.TargetPosition + 1);
     
    401351begin
    402352  if State = rsPaused then begin
    403     Step := DebugSteps.SearchByTargetPos(SourcePosition);
     353    Step := DebugSteps.SearchByTargetPos(FProgramIndex);
    404354    if Step.Operation = soStepOut then begin
    405355      BreakPoints.SetSystem(Step.TargetPosition + 1);
     
    422372begin
    423373  if State = rsPaused then begin
    424     Step := DebugSteps.SearchByTargetPos(SourcePosition);
     374    Step := DebugSteps.SearchByTargetPos(FProgramIndex);
    425375    StepIndex := DebugSteps.IndexOf(Step);
    426376    Nesting := 1;
Note: See TracChangeset for help on using the changeset viewer.