Changeset 13 for trunk/UBrainFuck.pas


Ignore:
Timestamp:
Feb 11, 2012, 5:53:25 PM (13 years ago)
Author:
chronos
Message:
  • Added: Options form.
  • Modified: Interpretter now accept source code as string again.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UBrainFuck.pas

    r12 r13  
    4848    FThread: TBrainFuckInterpretterThread;
    4949    FStepCount: Integer;
     50    function GetSource: string;
     51    procedure SetSource(AValue: string);
    5052    procedure SetState(AValue: TRunState);
    5153    procedure Write(Value: Byte);
     
    5557    procedure PrepareJumpTable;
    5658  public
    57     Source: array of Char;
     59    FSource: array of Char;
    5860    SourceJump: array of Integer;
    5961    SourcePosition: Integer;
     62    SourceBreakpoint: array of Boolean;
    6063    Memory: array of Byte;
    6164    MemoryPosition: Integer;
     
    7376    property OnChangeState: TNotifyEvent read FOnChangeState write FOnChangeState;
    7477    property StepCount: Integer read FStepCount;
     78    property Source: string read GetSource write SetSource;
    7579  end;
    7680
     
    9094begin
    9195  repeat
    92     while (Parent.SourcePosition < Length(Parent.Source)) and (Parent.State <> rsStopped) do begin
     96    while (Parent.SourcePosition < Length(Parent.FSource)) and (Parent.State <> rsStopped) do begin
    9397      Parent.SingleStep;
    9498      while Parent.State = rsPaused do begin
     
    114118end;
    115119
     120function TBrainFuckInterpretter.GetSource: string;
     121var
     122  I: Integer;
     123begin
     124  SetLength(Result, Length(FSource));
     125  //Move(Pointer(Result)^, Pointer(FSource)^, Length(Result));
     126  for I := 0 to Length(FSource) - 1 do
     127    Result[I + 1] := FSource[I];
     128end;
     129
     130procedure TBrainFuckInterpretter.SetSource(AValue: string);
     131var
     132  I: Integer;
     133begin
     134  SetLength(FSource, Length(AValue));
     135  //Move(Pointer(AValue)^, Pointer(FSource)^, Length(AValue));
     136  for I := 0 to Length(FSource) - 1 do
     137    FSource[I] := AValue[I + 1];
     138end;
     139
    116140function TBrainFuckInterpretter.Read: Byte;
    117141begin
     
    125149function TBrainFuckInterpretter.ReadCode: Char;
    126150begin
    127   Result := Source[SourcePosition];
     151  Result := FSource[SourcePosition];
    128152end;
    129153
     
    148172  I: Integer;
    149173begin
    150   SetLength(SourceJump, Length(Source));
    151   FillChar(Pointer(SourceJump)^, Length(SourceJump), 0);
     174  SetLength(SourceJump, Length(FSource));
     175  //FillChar(Pointer(SourceJump)^, Length(SourceJump), 0);
     176  for I := 0 to Length(FSource) - 1 do
     177    SourceJump[I] := 0;
    152178  SetLength(Loop, 0);
    153   for I := 0 to Length(Source) - 1 do begin
    154     case Source[I] of
     179  for I := 0 to Length(FSource) - 1 do begin
     180    case FSource[I] of
    155181      '[': begin
    156182        SetLength(Loop, Length(Loop) + 1);
     
    170196
    171197procedure TBrainFuckInterpretter.Reset;
     198var
     199  I: Integer;
    172200begin
    173201  PrepareJumpTable;
     
    176204  Output := '';
    177205  MemoryPosition := 0;
    178   FillChar(Pointer(Memory)^, Length(Memory), 0);
     206  //FillChar(Pointer(Memory)^, Length(Memory), 0);
     207  for I := 0 to Length(Memory) - 1 do
     208    Memory[I] := 0;
    179209  FStepCount := 0;
    180210end;
Note: See TracChangeset for help on using the changeset viewer.