Ignore:
Timestamp:
Feb 18, 2012, 7:49:17 PM (13 years ago)
Author:
chronos
Message:
  • Renamed: Compilers renamed to Targets. Interpretter will be one of possible targets.
Location:
trunk/Target
Files:
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/Target/UTargetInterpretter.pas

    r29 r30  
    1 unit UBrainFuck;
     1unit UTargetInterpretter;
    22
    33{$mode Delphi}{$H+}
     
    99
    1010type
    11   TBrainFuckInterpretter = class;
     11  TTargetInterpretter = class;
    1212
    1313
    1414  TRunState = (rsStopped, rsPaused, rsRunning);
    1515
    16   { TBrainFuckInterpretterThread }
    17 
    18   TBrainFuckInterpretterThread = class(TThread)
    19     Parent: TBrainFuckInterpretter;
     16  { TTargetInterpretterThread }
     17
     18  TTargetInterpretterThread = class(TThread)
     19    Parent: TTargetInterpretter;
    2020    procedure Execute; override;
    2121  end;
     
    2626  TCommandHandler = procedure of object;
    2727
    28   { TBrainFuckInterpretter }
    29 
    30   TBrainFuckInterpretter = class
     28  { TTargetInterpretter }
     29
     30  TTargetInterpretter = class
    3131  private
    3232    FCellSize: Integer;
     
    3434    FState: TRunState;
    3535    FThreadState: Boolean;
    36     FThread: TBrainFuckInterpretterThread;
     36    FThread: TTargetInterpretterThread;
    3737    FStepCount: Integer;
    3838    FCommandTable: array[TBrainFuckCommand] of TCommandHandler;
     
    8888  SMemoryCellOutOfRange = 'Memory cell %s value out of range';
    8989
    90 { TBrainFuckInterpretterThread }
    91 
    92 procedure TBrainFuckInterpretterThread.Execute;
     90{ TTargetInterpretterThread }
     91
     92procedure TTargetInterpretterThread.Execute;
    9393begin
    9494  repeat
     
    103103end;
    104104
    105 { TBrainFuckInterpretter }
    106 
    107 procedure TBrainFuckInterpretter.SetState(AValue: TRunState);
     105{ TTargetInterpretter }
     106
     107procedure TTargetInterpretter.SetState(AValue: TRunState);
    108108begin
    109109  if FState = AValue then Exit;
     
    112112end;
    113113
    114 function TBrainFuckInterpretter.GetMemorySize: Integer;
     114function TTargetInterpretter.GetMemorySize: Integer;
    115115begin
    116116  Result := Length(Memory);
    117117end;
    118118
    119 procedure TBrainFuckInterpretter.SetMemorySize(AValue: Integer);
     119procedure TTargetInterpretter.SetMemorySize(AValue: Integer);
    120120begin
    121121  SetLength(Memory, AValue);
    122122end;
    123123
    124 procedure TBrainFuckInterpretter.SetSource(AValue: string);
     124procedure TTargetInterpretter.SetSource(AValue: string);
    125125var
    126126  I: Integer;
     
    146146end;
    147147
    148 procedure TBrainFuckInterpretter.SetThread(State: Boolean);
     148procedure TTargetInterpretter.SetThread(State: Boolean);
    149149begin
    150150  if FThreadState = State then Exit;
    151151  FThreadState := State;
    152152  if State then begin
    153     FThread := TBrainFuckInterpretterThread.Create(True);
     153    FThread := TTargetInterpretterThread.Create(True);
    154154    FThread.Parent := Self;
    155155    FThread.FreeOnTerminate := False;
     
    160160end;
    161161
    162 procedure TBrainFuckInterpretter.PrepareJumpTable;
     162procedure TTargetInterpretter.PrepareJumpTable;
    163163var
    164164  Loop: array of Integer;
     
    188188end;
    189189
    190 procedure TBrainFuckInterpretter.CommandInc;
     190procedure TTargetInterpretter.CommandInc;
    191191begin
    192192  Memory[MemoryPosition] := ((Memory[MemoryPosition] + 1) mod CellSize);
    193193end;
    194194
    195 procedure TBrainFuckInterpretter.CommandDec;
     195procedure TTargetInterpretter.CommandDec;
    196196begin
    197197  Memory[MemoryPosition] := ((Memory[MemoryPosition] - 1) mod CellSize);
    198198end;
    199199
    200 procedure TBrainFuckInterpretter.CommandPointerInc;
     200procedure TTargetInterpretter.CommandPointerInc;
    201201begin
    202202  if MemoryPosition < MemorySize then Inc(MemoryPosition)
     
    204204end;
    205205
    206 procedure TBrainFuckInterpretter.CommandPointerDec;
     206procedure TTargetInterpretter.CommandPointerDec;
    207207begin
    208208  if MemoryPosition > 0 then Dec(MemoryPosition)
     
    210210end;
    211211
    212 procedure TBrainFuckInterpretter.CommandInput;
     212procedure TTargetInterpretter.CommandInput;
    213213begin
    214214  while (InputPosition > Length(Input)) and (FState <> rsStopped) do begin
     
    221221end;
    222222
    223 procedure TBrainFuckInterpretter.CommandOutput;
     223procedure TTargetInterpretter.CommandOutput;
    224224begin
    225225  if OutputPosition > Length(Output) then
     
    229229end;
    230230
    231 procedure TBrainFuckInterpretter.CommandLoopStart;
     231procedure TTargetInterpretter.CommandLoopStart;
    232232begin
    233233  if Memory[MemoryPosition] = 0 then
     
    235235end;
    236236
    237 procedure TBrainFuckInterpretter.CommandLoopEnd;
     237procedure TTargetInterpretter.CommandLoopEnd;
    238238begin
    239239  if Memory[MemoryPosition] > 0 then
     
    241241end;
    242242
    243 procedure TBrainFuckInterpretter.Reset;
     243procedure TTargetInterpretter.Reset;
    244244var
    245245  I: Integer;
     
    257257end;
    258258
    259 procedure TBrainFuckInterpretter.SingleStep;
     259procedure TTargetInterpretter.SingleStep;
    260260begin
    261261  FCommandTable[FSource[SourcePosition]];
     
    264264end;
    265265
    266 procedure TBrainFuckInterpretter.Run;
     266procedure TTargetInterpretter.Run;
    267267begin
    268268  SetState(rsRunning);
     
    272272end;
    273273
    274 procedure TBrainFuckInterpretter.Pause;
     274procedure TTargetInterpretter.Pause;
    275275begin
    276276  if State = rsRunning then SetState(rsPaused);
    277277end;
    278278
    279 procedure TBrainFuckInterpretter.Stop;
     279procedure TTargetInterpretter.Stop;
    280280begin
    281281  SetState(rsStopped);
    282282end;
    283283
    284 constructor TBrainFuckInterpretter.Create;
     284constructor TTargetInterpretter.Create;
    285285begin
    286286  MemorySize := 30000;
     
    296296end;
    297297
    298 destructor TBrainFuckInterpretter.Destroy;
     298destructor TTargetInterpretter.Destroy;
    299299begin
    300300  FState := rsStopped;
Note: See TracChangeset for help on using the changeset viewer.