Changeset 14
- Timestamp:
- Feb 11, 2012, 6:27:10 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LazFuckIDE.lpi
r13 r14 32 32 </local> 33 33 </RunParams> 34 <RequiredPackages Count=" 2">34 <RequiredPackages Count="4"> 35 35 <Item1> 36 <PackageName Value=" SynEdit"/>36 <PackageName Value="TemplateGenerics"/> 37 37 </Item1> 38 38 <Item2> 39 <PackageName Value="Common"/> 40 </Item2> 41 <Item3> 42 <PackageName Value="SynEdit"/> 43 </Item3> 44 <Item4> 39 45 <PackageName Value="LCL"/> 40 </Item 2>46 </Item4> 41 47 </RequiredPackages> 42 48 <Units Count="7"> -
trunk/LazFuckIDE.lpr
r13 r14 10 10 Interfaces, // this includes the LCL widgetset 11 11 Forms, UMainForm, UBrainFuck, UInterpreterForm, UApplicationInfo, 12 UCompiledForm, UOptionsForm 12 UCompiledForm, UOptionsForm, Common, TemplateGenerics 13 13 { you can add units after this }; 14 14 -
trunk/UBrainFuck.pas
r13 r14 43 43 TBrainFuckInterpretter = class 44 44 private 45 FCellSize: Integer; 45 46 FOnChangeState: TNotifyEvent; 46 47 FState: TRunState; … … 48 49 FThread: TBrainFuckInterpretterThread; 49 50 FStepCount: Integer; 51 function GetMemorySize: Integer; 50 52 function GetSource: string; 53 procedure SetMemorySize(AValue: Integer); 51 54 procedure SetSource(AValue: string); 52 55 procedure SetState(AValue: TRunState); 53 56 procedure Write(Value: Byte); 54 57 function Read: Byte; 58 function TryRead(Output: Byte): Boolean; 55 59 function ReadCode: Char; 56 60 procedure SetThread(State: Boolean); … … 61 65 SourcePosition: Integer; 62 66 SourceBreakpoint: array of Boolean; 63 Memory: array of Byte;67 Memory: array of Integer; 64 68 MemoryPosition: Integer; 65 69 Output: string; … … 77 81 property StepCount: Integer read FStepCount; 78 82 property Source: string read GetSource write SetSource; 83 property MemorySize: Integer read GetMemorySize write SetMemorySize; 84 property CellSize: Integer read FCellSize write FCellSize; 79 85 end; 80 86 … … 88 94 SJumpTableInsistent = 'Jump table is inconsistent'; 89 95 SJumpTableColision = 'Jump table colision'; 96 SMemoryCellOutOfRange = 'Memory cell %s value out of range'; 90 97 91 98 { TBrainFuckInterpretterThread } … … 128 135 end; 129 136 137 function TBrainFuckInterpretter.GetMemorySize: Integer; 138 begin 139 Result := Length(Memory); 140 end; 141 142 procedure TBrainFuckInterpretter.SetMemorySize(AValue: Integer); 143 begin 144 SetLength(Memory, AValue); 145 end; 146 130 147 procedure TBrainFuckInterpretter.SetSource(AValue: string); 131 148 var … … 140 157 function TBrainFuckInterpretter.Read: Byte; 141 158 begin 142 while InputPosition >= Length(Input) do begin159 while (InputPosition >= Length(Input)) and (FState <> rsStopped) do begin 143 160 Sleep(1); 144 161 end; 145 Result := Ord(Input[InputPosition + 1]); 146 Inc(InputPosition); 162 if InputPosition < Length(Input) then begin 163 Result := Ord(Input[InputPosition + 1]); 164 Inc(InputPosition); 165 end else Result := 0; 166 end; 167 168 function TBrainFuckInterpretter.TryRead(Output: Byte): Boolean; 169 begin 170 if InputPosition >= Length(Input) then Result := False 171 else begin 172 Output := Ord(Input[InputPosition + 1]); 173 Inc(InputPosition); 174 Result := True; 175 end; 147 176 end; 148 177 … … 217 246 begin 218 247 case ReadCode of 219 '>': if MemoryPosition < Length(Memory)then Inc(MemoryPosition)248 '>': if MemoryPosition < MemorySize then Inc(MemoryPosition) 220 249 else raise Exception.Create(SProgramUpperLimit); 221 250 '<': if MemoryPosition > 0 then Dec(MemoryPosition) 222 251 else raise Exception.Create(SProgramLowerLimit); 223 '+': Memory[MemoryPosition] := Memory[MemoryPosition] + 1;224 '-': Memory[MemoryPosition] := Memory[MemoryPosition] - 1;252 '+': Memory[MemoryPosition] := ((Memory[MemoryPosition] + 1) mod CellSize); 253 '-': Memory[MemoryPosition] := ((Memory[MemoryPosition] - 1) mod CellSize); 225 254 '.': Write(Memory[MemoryPosition]); 226 255 ',': Memory[MemoryPosition] := Read; … … 282 311 constructor TBrainFuckInterpretter.Create; 283 312 begin 284 SetLength(Memory, 32000); 313 MemorySize := 30000; 314 CellSize := 256; 285 315 end; 286 316 287 317 destructor TBrainFuckInterpretter.Destroy; 288 318 begin 319 FState := rsStopped; 289 320 SetThread(False); 290 321 inherited Destroy; -
trunk/UMainForm.pas
r13 r14 7 7 uses 8 8 Classes, SysUtils, FileUtil, SynEdit, Forms, Controls, Graphics, Dialogs, 9 Menus, ActnList, StdCtrls, ComCtrls, UBrainFuck ;9 Menus, ActnList, StdCtrls, ComCtrls, UBrainFuck, SpecializedList; 10 10 11 11 type … … 107 107 BrainFuckCompiler: TBrainFuckCompiler; 108 108 BrainFuckInterpreter: TBrainFuckInterpretter; 109 BreakPoints: TListInteger; 109 110 procedure UpdateInterface; 110 111 procedure UpdateStatusBar; … … 185 186 procedure TMainForm.FormCreate(Sender: TObject); 186 187 begin 188 BreakPoints := TListInteger.Create; 187 189 BrainFuckInterpreter := TBrainFuckInterpretter.Create; 188 190 BrainFuckInterpreter.OnChangeState := BrainFuckInterpreterChangeState; … … 194 196 BrainFuckCompiler.Free; 195 197 BrainFuckInterpreter.Free; 198 BreakPoints.Free; 196 199 end; 197 200 … … 226 229 procedure TMainForm.AOptionsExecute(Sender: TObject); 227 230 begin 231 OptionsForm.LoadFromInterpretter(BrainFuckInterpreter); 228 232 if OptionsForm.ShowModal = mrOK then begin 229 233 OptionsForm.SaveToInterpretter(BrainFuckInterpreter); 230 234 end; 231 235 end; -
trunk/UOptionsForm.lfm
r13 r14 40 40 Height = 27 41 41 Top = 6 42 Width = 128 42 Width = 130 43 MaxValue = 65535 43 44 TabOrder = 2 44 45 end 46 object Label2: TLabel 47 Left = 8 48 Height = 18 49 Top = 40 50 Width = 60 51 Caption = 'Cell size:' 52 ParentColor = False 53 end 54 object SpinEditCellSize: TSpinEdit 55 Left = 136 56 Height = 27 57 Top = 40 58 Width = 130 59 MaxValue = 65535 60 TabOrder = 3 61 end 45 62 end -
trunk/UOptionsForm.pas
r13 r14 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, 9 Spin ;9 Spin, UBrainFuck; 10 10 11 11 type … … 17 17 ButtonCancel: TButton; 18 18 Label1: TLabel; 19 Label2: TLabel; 20 SpinEditCellSize: TSpinEdit; 19 21 SpinEditMemorySize: TSpinEdit; 20 22 private 21 23 { private declarations } 22 24 public 23 { public declarations } 25 procedure LoadFromInterpretter(Interpretter: TBrainFuckInterpretter); 26 procedure SaveToInterpretter(Interpretter: TBrainFuckInterpretter); 24 27 end; 25 28 … … 31 34 {$R *.lfm} 32 35 36 { TOptionsForm } 37 38 procedure TOptionsForm.LoadFromInterpretter(Interpretter: TBrainFuckInterpretter 39 ); 40 begin 41 SpinEditCellSize.Value := Interpretter.CellSize; 42 SpinEditMemorySize.Value := Interpretter.MemorySize; 43 end; 44 45 procedure TOptionsForm.SaveToInterpretter(Interpretter: TBrainFuckInterpretter); 46 begin 47 Interpretter.CellSize := SpinEditCellSize.Value; 48 Interpretter.MemorySize := SpinEditMemorySize.Value; 49 end; 50 33 51 end. 34 52
Note:
See TracChangeset
for help on using the changeset viewer.