Changeset 8 for trunk/UBrainFuck.pas


Ignore:
Timestamp:
Feb 9, 2012, 3:48:16 PM (12 years ago)
Author:
chronos
Message:
  • Modified: Some optimalization of interpretter.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UBrainFuck.pas

    r7 r8  
    7676begin
    7777  repeat
    78     while Parent.SourcePosition < Length(Parent.Source) do begin
     78    while (Parent.SourcePosition < Length(Parent.Source)) and (Parent.State <> rsStopped) do begin
    7979      Parent.SingleStep;
    8080      while Parent.State = rsPaused do begin
     
    8383    end;
    8484    Parent.SetState(rsStopped);
    85   until Terminated;
     85  until Terminated or (Parent.State = rsStopped);
    8686end;
    8787
     
    101101
    102102function TBrainFuckInterpretter.Read: Byte;
    103 var
    104   Character: string;
    105103begin
    106104  while InputPosition >= Length(Input) do begin
    107105    Sleep(1);
    108     Application.ProcessMessages;
    109   end;
    110   Character := Copy(Input, InputPosition, 1);
    111   Result := Ord(Character[1]);
     106  end;
     107  Result := Ord(Input[InputPosition + 1]);
    112108  Inc(InputPosition);
    113109end;
    114110
    115111function TBrainFuckInterpretter.ReadCode: Char;
    116 var
    117   Code: string;
    118 begin
    119   Code := Copy(Source, SourcePosition + 1, 1);
    120   Result := Code[1];
     112begin
     113  Result := Source[SourcePosition + 1]
    121114end;
    122115
     
    156149begin
    157150  case ReadCode of
    158     '>': Inc(MemoryPosition);
     151    '>': if MemoryPosition < Length(Memory) then Inc(MemoryPosition)
     152      else raise Exception.Create(SProgramUpperLimit);
    159153    '<': if MemoryPosition > 0 then Dec(MemoryPosition)
    160154      else raise Exception.Create(SProgramLowerLimit);
     
    199193  SetState(rsRunning);
    200194  Reset;
     195  SetThread(False);
    201196  SetThread(True);
    202197end;
Note: See TracChangeset for help on using the changeset viewer.