Changeset 12
- Timestamp:
- Feb 11, 2012, 4:32:27 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 3 3 LazFuckIDE.lps 4 4 backup 5 LazFuckIDE
-
- Property svn:ignore
-
trunk/LazFuckIDE.lpi
r9 r12 7 7 <SessionStorage Value="InProjectDir"/> 8 8 <MainUnit Value="0"/> 9 <Title Value="LazFuck "/>9 <Title Value="LazFuck IDE"/> 10 10 <ResourceType Value="res"/> 11 11 <UseXPManifest Value="True"/> … … 29 29 <local> 30 30 <FormatVersion Value="1"/> 31 <LaunchingApplication PathPlusParams="\usr\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/> 31 32 </local> 32 33 </RunParams> … … 88 89 <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> 89 90 </SearchPaths> 91 <CodeGeneration> 92 <Checks> 93 <IOChecks Value="True"/> 94 <RangeChecks Value="True"/> 95 <OverflowChecks Value="True"/> 96 <StackChecks Value="True"/> 97 </Checks> 98 <VerifyObjMethodCallValidity Value="True"/> 99 </CodeGeneration> 90 100 <Linking> 91 101 <Options> -
trunk/LazFuckIDE.lpr
r9 r12 4 4 5 5 uses 6 {$IFDEF UNIX} {$IFDEF UseCThreads}6 {$IFDEF UNIX}//{$IFDEF UseCThreads} 7 7 cthreads, 8 {$ENDIF}{$ENDIF} 8 //{$ENDIF} 9 {$ENDIF} 9 10 Interfaces, // this includes the LCL widgetset 10 11 Forms, UMainForm, UBrainFuck, UInterpreterForm, UApplicationInfo, … … 15 16 16 17 begin 17 Application.Title:='LazFuck ';18 Application.Title:='LazFuck IDE'; 18 19 RequireDerivedFormResource := True; 19 20 Application.Initialize; -
trunk/UBrainFuck.pas
r10 r12 12 12 13 13 TCompilerTarget = (ctDelphi); 14 TCompilerOptimization = (coNone, coNormal); 15 14 16 { TBrainFuckCompiler } 15 17 … … 23 25 Output: string; 24 26 Target: TCompilerTarget; 27 Optimization: TCompilerOptimization; 28 procedure OptimizeSource; 25 29 procedure Compile; 26 30 end; … … 43 47 FThreadState: Boolean; 44 48 FThread: TBrainFuckInterpretterThread; 49 FStepCount: Integer; 45 50 procedure SetState(AValue: TRunState); 46 51 procedure Write(Value: Byte); … … 48 53 function ReadCode: Char; 49 54 procedure SetThread(State: Boolean); 55 procedure PrepareJumpTable; 50 56 public 51 Source: string; 57 Source: array of Char; 58 SourceJump: array of Integer; 52 59 SourcePosition: Integer; 53 60 Memory: array of Byte; 54 61 MemoryPosition: Integer; 55 Loop: array of Integer;56 LoopCurrent: Integer;57 62 Output: string; 58 63 Input: string; 59 64 InputPosition: Integer; 60 StepCount: Integer;61 65 procedure Reset; 62 66 procedure SingleStep; … … 68 72 property State: TRunState read FState; 69 73 property OnChangeState: TNotifyEvent read FOnChangeState write FOnChangeState; 74 property StepCount: Integer read FStepCount; 70 75 end; 71 76 … … 77 82 SProgramUpperLimit = 'Program run over upper limit'; 78 83 SReadInputError = 'Read input error'; 84 SJumpTableInsistent = 'Jump table is inconsistent'; 85 SJumpTableColision = 'Jump table colision'; 79 86 80 87 { TBrainFuckInterpretterThread } … … 118 125 function TBrainFuckInterpretter.ReadCode: Char; 119 126 begin 120 Result := Source[SourcePosition + 1]127 Result := Source[SourcePosition]; 121 128 end; 122 129 … … 135 142 end; 136 143 144 procedure TBrainFuckInterpretter.PrepareJumpTable; 145 var 146 Loop: array of Integer; 147 LoopCurrent: Integer; 148 I: Integer; 149 begin 150 SetLength(SourceJump, Length(Source)); 151 FillChar(Pointer(SourceJump)^, Length(SourceJump), 0); 152 SetLength(Loop, 0); 153 for I := 0 to Length(Source) - 1 do begin 154 case Source[I] of 155 '[': begin 156 SetLength(Loop, Length(Loop) + 1); 157 Loop[High(Loop)] := I; 158 end; 159 ']': begin 160 if SourceJump[I] > 0 then raise Exception.Create(SJumpTableColision); 161 SourceJump[I] := Loop[High(Loop)]; 162 if SourceJump[Loop[High(Loop)]] > 0 then raise Exception.Create(SJumpTableColision); 163 SourceJump[Loop[High(Loop)]] := I; 164 SetLength(Loop, Length(Loop) - 1); 165 end; 166 end; 167 end; 168 if Length(Loop) > 0 then raise Exception.Create(SJumpTableInsistent); 169 end; 170 137 171 procedure TBrainFuckInterpretter.Reset; 138 var 139 I: Integer; 140 begin 172 begin 173 PrepareJumpTable; 141 174 SourcePosition := 0; 142 175 InputPosition := 0; 143 176 Output := ''; 144 177 MemoryPosition := 0; 145 for I := 0 to Length(Memory) - 1 do 146 Memory[I] := 0; 147 SetLength(Loop, 0); 148 StepCount := 0; 178 FillChar(Pointer(Memory)^, Length(Memory), 0); 179 FStepCount := 0; 149 180 end; 150 181 … … 152 183 var 153 184 CodeText: string; 154 Code: Char;155 185 C: Integer; 186 NewPos: Integer; 156 187 begin 157 188 case ReadCode of … … 166 197 '[': begin 167 198 if Memory[MemoryPosition] = 0 then begin 168 C := 1; 199 SourcePosition := SourceJump[SourcePosition]; 200 (*C := 1; 169 201 Inc(SourcePosition); 170 202 while C > 0 do begin … … 175 207 Inc(SourcePosition); 176 208 end; 177 Dec(SourcePosition); 209 Dec(SourcePosition);*) 210 //if NewPos <> SourcePosition then raise Exception.Create('Wrong pos: ' + IntToStr(SourcePosition) + ' ' + IntToStr(NewPos)); 178 211 end; 179 212 end; 180 213 ']': begin 181 214 if Memory[MemoryPosition] > 0 then begin 182 C := 1; 215 SourcePosition := SourceJump[SourcePosition] - 1; 216 (*C := 1; 183 217 Dec(SourcePosition); 184 218 while C > 0 do begin … … 189 223 Dec(SourcePosition); 190 224 end; 225 if NewPos <> SourcePosition then raise Exception.Create('Wrong pos: ' + IntToStr(SourcePosition) + ' ' + IntToStr(NewPos)); 226 *) 191 227 end; 192 228 end; 193 229 end; 194 230 Inc(SourcePosition); 195 Inc( StepCount);231 Inc(FStepCount); 196 232 end; 197 233 … … 230 266 begin 231 267 Output := Output + DupeString(' ', Indent) + Text + LineEnding; 268 end; 269 270 procedure TBrainFuckCompiler.OptimizeSource; 271 begin 272 // Remove redundand code 273 232 274 end; 233 275 -
trunk/UInterpreterForm.lfm
r11 r12 43 43 object Label1: TLabel 44 44 Left = 8 45 Height = 1 445 Height = 18 46 46 Top = 8 47 Width = 3 147 Width = 38 48 48 Caption = 'Input:' 49 49 ParentColor = False … … 71 71 object Label2: TLabel 72 72 Left = 8 73 Height = 1 473 Height = 18 74 74 Top = 6 75 Width = 3975 Width = 49 76 76 Caption = 'Output:' 77 77 ParentColor = False … … 109 109 object Label3: TLabel 110 110 Left = 1 111 Height = 1 4111 Height = 18 112 112 Top = 8 113 Width = 82113 Width = 110 114 114 Caption = 'Program pointer:' 115 115 ParentColor = False … … 117 117 object LabelProgramPointer: TLabel 118 118 Left = 112 119 Height = 1 4119 Height = 18 120 120 Top = 8 121 Width = 1 0121 Width = 13 122 122 Caption = ' ' 123 123 ParentColor = False … … 125 125 object Label5: TLabel 126 126 Left = 1 127 Height = 1 4127 Height = 18 128 128 Top = 24 129 Width = 80129 Width = 108 130 130 Caption = 'Memory pointer:' 131 131 ParentColor = False … … 133 133 object LabelMemoryPointer: TLabel 134 134 Left = 112 135 Height = 1 4135 Height = 18 136 136 Top = 24 137 Width = 1 0137 Width = 13 138 138 Caption = ' ' 139 139 ParentColor = False … … 141 141 object Label4: TLabel 142 142 Left = 1 143 Height = 1 4143 Height = 18 144 144 Top = 42 145 Width = 67145 Width = 87 146 146 Caption = 'Step counter:' 147 147 ParentColor = False … … 149 149 object LabelStepCounter: TLabel 150 150 Left = 112 151 Height = 1 4151 Height = 18 152 152 Top = 42 153 Width = 1 0153 Width = 13 154 154 Caption = ' ' 155 155 ParentColor = False … … 168 168 item 169 169 Caption = 'Data' 170 Width = 3 00170 Width = 330 171 171 end> 172 172 Font.Height = -11 … … 181 181 object Label6: TLabel 182 182 Left = 8 183 Height = 1 4183 Height = 18 184 184 Top = 104 185 Width = 43185 Width = 57 186 186 Caption = 'Memory:' 187 187 ParentColor = False … … 211 211 Action = MainForm.AProgramStop 212 212 end 213 object ToolButton4: TToolButton 214 Left = 70 215 Top = 2 216 Action = MainForm.AInterpretterRunToCursor 217 end 218 object ToolButton5: TToolButton 219 Left = 93 220 Top = 2 221 Action = MainForm.AInterpretterStepInto 222 end 223 object ToolButton6: TToolButton 224 Left = 116 225 Top = 2 226 Action = MainForm.AInterpretterStepOut 227 end 228 object ToolButton7: TToolButton 229 Left = 139 230 Top = 2 231 Action = MainForm.AInterpretterStopOver 232 end 213 233 end 214 234 object Timer1: TTimer -
trunk/UInterpreterForm.pas
r6 r12 40 40 ToolButton2: TToolButton; 41 41 ToolButton3: TToolButton; 42 ToolButton4: TToolButton; 43 ToolButton5: TToolButton; 44 ToolButton6: TToolButton; 45 ToolButton7: TToolButton; 42 46 procedure ListViewMemoryData(Sender: TObject; Item: TListItem); 43 47 procedure MemoInputKeyPress(Sender: TObject; var Key: char); -
trunk/UMainForm.lfm
r11 r12 1 1 object MainForm: TMainForm 2 Left = 2 582 Left = 286 3 3 Height = 465 4 Top = 1 214 Top = 140 5 5 Width = 643 6 6 Caption = 'LazFuck' 7 ClientHeight = 44 67 ClientHeight = 440 8 8 ClientWidth = 643 9 9 Menu = MainMenu1 … … 13 13 OnShow = FormShow 14 14 LCLVersion = '0.9.31' 15 WindowState = wsMaximized 15 16 object MemoSource: TMemo 16 17 Left = 0 17 Height = 3 7018 Height = 363 18 19 Top = 56 19 20 Width = 643 … … 22 23 Font.Name = 'Courier New' 23 24 OnChange = MemoSourceChange 25 OnKeyDown = MemoSourceKeyDown 26 OnKeyPress = MemoSourceKeyPress 27 OnKeyUp = MemoSourceKeyUp 28 OnMouseDown = MemoSourceMouseDown 24 29 ParentFont = False 25 30 ScrollBars = ssAutoBoth … … 28 33 object StatusBar1: TStatusBar 29 34 Left = 0 30 Height = 2 031 Top = 4 2635 Height = 21 36 Top = 419 32 37 Width = 643 33 Panels = <> 38 Panels = < 39 item 40 Width = 70 41 end 42 item 43 Width = 70 44 end 45 item 46 Width = 80 47 end> 48 SimplePanel = False 34 49 end 35 50 object ToolBar1: TToolBar … … 630 645 Caption = 'Compiled' 631 646 OnExecute = AViewCompiledExecute 647 end 648 object AInterpretterStepInto: TAction 649 Caption = 'Step into' 650 end 651 object AInterpretterStopOver: TAction 652 Caption = 'Step over' 653 end 654 object AInterpretterRunToCursor: TAction 655 Caption = 'Run to cursor' 656 end 657 object AInterpretterStepOut: TAction 658 Caption = 'Step out' 659 end 660 object ABreakpointSet: TAction 661 Caption = 'Breakpoint set' 662 end 663 object ABreakpointUnset: TAction 664 Caption = 'Unset breakpoint' 632 665 end 633 666 end -
trunk/UMainForm.pas
r11 r12 16 16 ACompile: TAction; 17 17 AAbout: TAction; 18 ABreakpointSet: TAction; 19 ABreakpointUnset: TAction; 20 AInterpretterStepOut: TAction; 21 AInterpretterRunToCursor: TAction; 22 AInterpretterStopOver: TAction; 23 AInterpretterStepInto: TAction; 18 24 AViewCompiled: TAction; 19 25 AViewInterpretter: TAction; … … 83 89 procedure FormShow(Sender: TObject); 84 90 procedure MemoSourceChange(Sender: TObject); 91 procedure MemoSourceKeyDown(Sender: TObject; var Key: Word; 92 Shift: TShiftState); 93 procedure MemoSourceKeyPress(Sender: TObject; var Key: char); 94 procedure MemoSourceKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState 95 ); 96 procedure MemoSourceMouseDown(Sender: TObject; Button: TMouseButton; 97 Shift: TShiftState; X, Y: Integer); 85 98 private 86 99 procedure BrainFuckInterpreterChangeState(Sender: TObject); … … 91 104 BrainFuckInterpreter: TBrainFuckInterpretter; 92 105 procedure UpdateInterface; 106 procedure UpdateStatusBar; 93 107 end; 94 108 … … 114 128 Modified := True; 115 129 UpdateInterface; 130 end; 131 132 procedure TMainForm.MemoSourceKeyDown(Sender: TObject; var Key: Word; 133 Shift: TShiftState); 134 begin 135 end; 136 137 procedure TMainForm.MemoSourceKeyPress(Sender: TObject; var Key: char); 138 begin 139 end; 140 141 procedure TMainForm.MemoSourceKeyUp(Sender: TObject; var Key: Word; 142 Shift: TShiftState); 143 begin 144 UpdateStatusBar; 145 end; 146 147 procedure TMainForm.MemoSourceMouseDown(Sender: TObject; Button: TMouseButton; 148 Shift: TShiftState; X, Y: Integer); 149 begin 150 UpdateStatusBar; 116 151 end; 117 152 … … 136 171 AProgramStop.Enabled := (ProjectFileName <> '') and (BrainFuckInterpreter.State <> rsStopped); 137 172 ACompile.Enabled := ProjectFileName <> ''; 173 UpdateStatusBar; 174 end; 175 176 procedure TMainForm.UpdateStatusBar; 177 begin 178 StatusBar1.Panels[0].Text := IntToStr(MemoSource.CaretPos.X) + ', ' + IntToStr(MemoSource.CaretPos.Y); 138 179 end; 139 180 … … 152 193 153 194 procedure TMainForm.AProgramRunExecute(Sender: TObject); 195 var 196 SourceText: string; 154 197 begin 155 198 InterpreterForm.Show; 156 199 BrainFuckInterpreter.Input := InterpreterForm.MemoInput.Lines.Text; 157 BrainFuckInterpreter.Source := MemoSource.Lines.Text; 200 SourceText := MemoSource.Lines.Text; 201 SetLength(BrainFuckInterpreter.Source, Length(SourceText)); 202 Move(Pointer(SourceText)^, Pointer(BrainFuckInterpreter.Source)^, Length(SourceText)); 158 203 BrainFuckInterpreter.Run; 159 204 end;
Note:
See TracChangeset
for help on using the changeset viewer.