Changeset 13 for trunk/UBrainFuck.pas
- Timestamp:
- Feb 11, 2012, 5:53:25 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UBrainFuck.pas
r12 r13 48 48 FThread: TBrainFuckInterpretterThread; 49 49 FStepCount: Integer; 50 function GetSource: string; 51 procedure SetSource(AValue: string); 50 52 procedure SetState(AValue: TRunState); 51 53 procedure Write(Value: Byte); … … 55 57 procedure PrepareJumpTable; 56 58 public 57 Source: array of Char;59 FSource: array of Char; 58 60 SourceJump: array of Integer; 59 61 SourcePosition: Integer; 62 SourceBreakpoint: array of Boolean; 60 63 Memory: array of Byte; 61 64 MemoryPosition: Integer; … … 73 76 property OnChangeState: TNotifyEvent read FOnChangeState write FOnChangeState; 74 77 property StepCount: Integer read FStepCount; 78 property Source: string read GetSource write SetSource; 75 79 end; 76 80 … … 90 94 begin 91 95 repeat 92 while (Parent.SourcePosition < Length(Parent. Source)) and (Parent.State <> rsStopped) do begin96 while (Parent.SourcePosition < Length(Parent.FSource)) and (Parent.State <> rsStopped) do begin 93 97 Parent.SingleStep; 94 98 while Parent.State = rsPaused do begin … … 114 118 end; 115 119 120 function TBrainFuckInterpretter.GetSource: string; 121 var 122 I: Integer; 123 begin 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]; 128 end; 129 130 procedure TBrainFuckInterpretter.SetSource(AValue: string); 131 var 132 I: Integer; 133 begin 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]; 138 end; 139 116 140 function TBrainFuckInterpretter.Read: Byte; 117 141 begin … … 125 149 function TBrainFuckInterpretter.ReadCode: Char; 126 150 begin 127 Result := Source[SourcePosition];151 Result := FSource[SourcePosition]; 128 152 end; 129 153 … … 148 172 I: Integer; 149 173 begin 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; 152 178 SetLength(Loop, 0); 153 for I := 0 to Length( Source) - 1 do begin154 case Source[I] of179 for I := 0 to Length(FSource) - 1 do begin 180 case FSource[I] of 155 181 '[': begin 156 182 SetLength(Loop, Length(Loop) + 1); … … 170 196 171 197 procedure TBrainFuckInterpretter.Reset; 198 var 199 I: Integer; 172 200 begin 173 201 PrepareJumpTable; … … 176 204 Output := ''; 177 205 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; 179 209 FStepCount := 0; 180 210 end;
Note:
See TracChangeset
for help on using the changeset viewer.