Changeset 52 for trunk/Target/UTargetInterpretter.pas
- Timestamp:
- Jul 26, 2012, 3:11:08 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Target/UTargetInterpretter.pas
r48 r52 22 22 procedure Execute; override; 23 23 end; 24 25 TBrainFuckCommand = (cmNoOperation, cmInc, cmDec, cmPointerInc, cmPointerDec,26 cmOutput, cmInput, cmLoopStart, cmLoopEnd, cmDebug);27 24 28 25 TCommandHandler = procedure of object; … … 55 52 function GetExecutionPosition: Integer; override; 56 53 public 57 FProgram: array of TBrainFuckCommand;58 54 FProgramBreakpoints: array of Boolean; 59 55 SourceJump: array of Integer; 60 SourcePosition: Integer;61 56 SourceBreakpoint: array of Boolean; 62 57 Memory: array of Integer; … … 109 104 with Parent do 110 105 repeat 111 while ( SourcePosition< Length(FProgram)) and (State <> rsStopped) do begin106 while (FProgramIndex < Length(FProgram)) and (State <> rsStopped) do begin 112 107 if State = rsRunning then begin 113 if FProgramBreakpoints[ SourcePosition] then begin114 BreakPoint := BreakPoints.SearchByTargetPos( SourcePosition);108 if FProgramBreakpoints[FProgramIndex] then begin 109 BreakPoint := BreakPoints.SearchByTargetPos(FProgramIndex); 115 110 if BreakPoint.System then BreakPoints.Delete(BreakPoints.IndexOf(BreakPoint)); 116 111 SetStateSafe(rsPaused); 117 112 end else begin 118 FCommandTable[FProgram[ SourcePosition]];119 Inc( SourcePosition);113 FCommandTable[FProgram[FProgramIndex]]; 114 Inc(FProgramIndex); 120 115 Inc(FStepCount); 121 116 end; … … 155 150 begin 156 151 SetLength(Memory, AValue); 157 end;158 159 procedure TTargetInterpretter.Compile;160 var161 I: Integer;162 Pos: Integer;163 begin164 inherited;165 DebugSteps.Clear;166 SetLength(FProgram, Length(FSourceCode));167 Pos := 0;168 for I := 1 to Length(FSourceCode) do begin169 case FSourceCode[I] of170 '+': begin171 FProgram[Pos] := cmInc;172 DebugSteps.AddStep(I - 1, Pos, soNormal);173 end;174 '-': begin175 FProgram[Pos] := cmDec;176 DebugSteps.AddStep(I - 1, Pos, soNormal);177 end;178 '>': begin179 FProgram[Pos] := cmPointerInc;180 DebugSteps.AddStep(I - 1, Pos, soNormal);181 end;182 '<': begin183 FProgram[Pos] := cmPointerDec;184 DebugSteps.AddStep(I - 1, Pos, soNormal);185 end;186 ',': begin187 FProgram[Pos] := cmInput;188 DebugSteps.AddStep(I - 1, Pos, soNormal);189 end;190 '.': begin191 FProgram[Pos] := cmOutput;192 DebugSteps.AddStep(I - 1, Pos, soNormal);193 end;194 '[': begin195 FProgram[Pos] := cmLoopStart;196 DebugSteps.AddStep(I - 1, Pos, soStepIn);197 end;198 ']': begin199 FProgram[Pos] := cmLoopEnd;200 DebugSteps.AddStep(I - 1, Pos, soStepOut);201 end202 else Dec(Pos);203 end;204 Inc(Pos);205 end;206 SetLength(FProgram, Pos);207 152 end; 208 153 … … 293 238 begin 294 239 if Memory[MemoryPosition] = 0 then 295 SourcePosition := SourceJump[SourcePosition];240 FProgramIndex := SourceJump[FProgramIndex]; 296 241 end; 297 242 … … 299 244 begin 300 245 if Memory[MemoryPosition] > 0 then 301 SourcePosition := SourceJump[SourcePosition] - 1;246 FProgramIndex := SourceJump[FProgramIndex] - 1; 302 247 end; 303 248 … … 308 253 inherited; 309 254 PrepareJumpTable; 310 SourcePosition:= 0;255 FProgramIndex := 0; 311 256 InputPosition := 1; 312 257 Output := ''; … … 320 265 end; 321 266 267 procedure TTargetInterpretter.Compile; 268 begin 269 inherited; 270 end; 271 322 272 procedure TTargetInterpretter.PrepareBreakPoints; 323 273 var … … 343 293 function TTargetInterpretter.GetExecutionPosition: Integer; 344 294 begin 345 Result := SourcePosition;295 Result := FProgramIndex; 346 296 end; 347 297 … … 379 329 begin 380 330 if State = rsPaused then begin 381 Step := DebugSteps.SearchByTargetPos( SourcePosition);331 Step := DebugSteps.SearchByTargetPos(FProgramIndex); 382 332 if Step.Operation = soStepOut then begin 383 333 BreakPoints.SetSystem(Step.TargetPosition + 1); … … 401 351 begin 402 352 if State = rsPaused then begin 403 Step := DebugSteps.SearchByTargetPos( SourcePosition);353 Step := DebugSteps.SearchByTargetPos(FProgramIndex); 404 354 if Step.Operation = soStepOut then begin 405 355 BreakPoints.SetSystem(Step.TargetPosition + 1); … … 422 372 begin 423 373 if State = rsPaused then begin 424 Step := DebugSteps.SearchByTargetPos( SourcePosition);374 Step := DebugSteps.SearchByTargetPos(FProgramIndex); 425 375 StepIndex := DebugSteps.IndexOf(Step); 426 376 Nesting := 1;
Note:
See TracChangeset
for help on using the changeset viewer.