Changeset 128
- Timestamp:
- Jan 17, 2022, 4:53:31 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormMain.pas
r126 r128 334 334 var 335 335 Title: string; 336 CanDebug: Boolean; 336 337 begin 337 338 Title := ''; … … 352 353 AProgramCompile.Enabled := (tcCompile in Core.CurrentTarget.Capabilities) and 353 354 Core.Project.Openned; 354 AProgramStepInto.Enabled := (tcStepInto in Core.CurrentTarget.Capabilities) and 355 Core.Project.Openned and ((Core.CurrentTarget.State = rsPaused) or (Core.CurrentTarget.State = rsStopped)); 356 AProgramStepOut.Enabled := (tcStepOut in Core.CurrentTarget.Capabilities) and 357 Core.Project.Openned and (Core.CurrentTarget.State = rsPaused); 358 AProgramRunToCursor.Enabled := (tcRunToCursor in Core.CurrentTarget.Capabilities) and 359 Core.Project.Openned and ((Core.CurrentTarget.State = rsPaused) or (Core.CurrentTarget.State = rsStopped)); 360 AProgramStepOver.Enabled := (tcStepOver in Core.CurrentTarget.Capabilities) and 361 Core.Project.Openned and ((Core.CurrentTarget.State = rsPaused) or (Core.CurrentTarget.State = rsStopped)); 362 AProgramShowExecutionPoint.Enabled := (tcPause in Core.CurrentTarget.Capabilities) and 363 Core.Project.Openned and (Core.CurrentTarget.State = rsPaused); 355 CanDebug := Core.DebugEnabled and Core.Project.Openned and 356 ((Core.CurrentTarget.State = rsPaused) or (Core.CurrentTarget.State = rsStopped)); 357 AProgramStepInto.Enabled := CanDebug and (tcStepInto in Core.CurrentTarget.Capabilities); 358 AProgramStepOut.Enabled := CanDebug and (tcStepOut in Core.CurrentTarget.Capabilities); 359 AProgramRunToCursor.Enabled := CanDebug and (tcRunToCursor in Core.CurrentTarget.Capabilities); 360 AProgramStepOver.Enabled := CanDebug and (tcStepOver in Core.CurrentTarget.Capabilities); 361 AProgramShowExecutionPoint.Enabled := CanDebug and (tcPause in Core.CurrentTarget.Capabilities); 364 362 AShowSourcePosition.Enabled := Core.CurrentTarget.Compiled; 365 363 AShowTargetPosition.Enabled := Core.CurrentTarget.Compiled; … … 568 566 if Core.CurrentTarget.State = rsStopped then begin 569 567 if not Core.CurrentTarget.Compiled then AProgramCompile.Execute; 570 Core.CurrentTarget.BreakPoints.SetSystem( TDebugStep(Core.CurrentTarget.DebugSteps.First).ProgramPosition);568 Core.CurrentTarget.BreakPoints.SetSystem(Core.CurrentTarget.DebugSteps.First.ProgramPosition); 571 569 AProgramRun.Execute; 572 570 end else Core.CurrentTarget.StepInto; -
trunk/Forms/UFormOptions.lfm
r126 r128 39 39 Top = 10 40 40 Width = 711 41 ActivePage = TabSheet Build41 ActivePage = TabSheetGeneral 42 42 Anchors = [akTop, akLeft, akRight, akBottom] 43 43 ParentFont = False 44 TabIndex = 144 TabIndex = 0 45 45 TabOrder = 2 46 46 object TabSheetGeneral: TTabSheet … … 78 78 TabOrder = 0 79 79 end 80 object CheckBox 1: TCheckBox80 object CheckBoxReopenLastFile: TCheckBox 81 81 Left = 10 82 82 Height = 32 … … 279 279 TabOrder = 7 280 280 end 281 object CheckBoxDebugEnabled: TCheckBox 282 Left = 392 283 Height = 30 284 Top = 12 285 Width = 120 286 Caption = 'Debugging' 287 ParentFont = False 288 TabOrder = 8 289 end 281 290 end 282 291 end -
trunk/Forms/UFormOptions.lrj
r126 r128 5 5 {"hash":231000124,"name":"tformoptions.tabsheetgeneral.caption","sourcebytes":[71,101,110,101,114,97,108],"value":"General"}, 6 6 {"hash":52873082,"name":"tformoptions.label3.caption","sourcebytes":[73,110,116,101,114,102,97,99,101,32,108,97,110,103,117,97,103,101,58],"value":"Interface language:"}, 7 {"hash":100189188,"name":"tformoptions.checkbox 1.caption","sourcebytes":[82,101,111,112,101,110,100,32,108,97,115,116,32,111,112,101,110,101,100,32,112,114,111,106,101,99,116],"value":"Reopend last opened project"},7 {"hash":100189188,"name":"tformoptions.checkboxreopenlastfile.caption","sourcebytes":[82,101,111,112,101,110,100,32,108,97,115,116,32,111,112,101,110,101,100,32,112,114,111,106,101,99,116],"value":"Reopend last opened project"}, 8 8 {"hash":37628553,"name":"tformoptions.checkboxdpiauto.caption","sourcebytes":[65,117,116,111,109,97,116,105,99,32,68,80,73],"value":"Automatic DPI"}, 9 9 {"hash":300234,"name":"tformoptions.labeldpi.caption","sourcebytes":[68,80,73,58],"value":"DPI:"}, … … 18 18 {"hash":243182762,"name":"tformoptions.label2.caption","sourcebytes":[67,101,108,108,32,115,105,122,101,58],"value":"Cell size:"}, 19 19 {"hash":239490586,"name":"tformoptions.label1.caption","sourcebytes":[77,101,109,111,114,121,32,115,105,122,101,58],"value":"Memory size:"}, 20 {"hash":208144671,"name":"tformoptions.checkboxoptimizesetzero.caption","sourcebytes":[83,101,116,32,122,101,114,111],"value":"Set zero"} 20 {"hash":208144671,"name":"tformoptions.checkboxoptimizesetzero.caption","sourcebytes":[83,101,116,32,122,101,114,111],"value":"Set zero"}, 21 {"hash":163419895,"name":"tformoptions.checkboxdebugenabled.caption","sourcebytes":[68,101,98,117,103,103,105,110,103],"value":"Debugging"} 21 22 ]} -
trunk/Forms/UFormOptions.pas
r126 r128 16 16 ButtonOk: TButton; 17 17 ButtonCancel: TButton; 18 CheckBox 1: TCheckBox;18 CheckBoxReopenLastFile: TCheckBox; 19 19 CheckBoxDPIAuto: TCheckBox; 20 20 CheckBoxOptimizeAddSub: TCheckBox; 21 CheckBoxDebugEnabled: TCheckBox; 21 22 CheckBoxOptimizeCopyMultiply: TCheckBox; 22 23 CheckBoxOptimizeSetZero: TCheckBox; … … 96 97 ComboBoxTheme.ItemIndex := ComboBoxTheme.Items.IndexOfObject(Core.ThemeManager.Theme); 97 98 if ComboBoxTheme.ItemIndex = -1 then ComboBoxTheme.ItemIndex := 0; 98 CheckBox 1.Checked := Core.OpenProjectOnStart;99 CheckBoxReopenLastFile.Checked := Core.OpenProjectOnStart; 99 100 CheckBoxOptimizeAddSub.Checked := Core.Optimizations.AddSub; 100 101 CheckBoxOptimizeSetZero.Checked := Core.Optimizations.SetZero; … … 108 109 SpinEditCellSize.Value := Core.CellSize; 109 110 SpinEditMemorySize.Value := Core.MemorySize; 111 CheckBoxDebugEnabled.Checked := Core.DebugEnabled; 112 if Core.OptionsFormTabIndex < PageControl1.PageCount then 113 PageControl1.TabIndex := Core.OptionsFormTabIndex 114 else PageControl1.TabIndex := 0; 110 115 UpdateInterface; 111 116 end; … … 117 122 if ComboBoxTheme.ItemIndex <> -1 then 118 123 Core.ThemeManager.Theme := TTheme(ComboBoxTheme.Items.Objects[ComboBoxTheme.ItemIndex]); 119 Core.OpenProjectOnStart := CheckBox 1.Checked;124 Core.OpenProjectOnStart := CheckBoxReopenLastFile.Checked; 120 125 Core.ScaleDPI1.DPI := Point(SpinEditDPIX.Value, SpinEditDPIY.Value); 121 126 Core.ScaleDPI1.AutoDetect := CheckBoxDPIAuto.Checked; … … 128 133 Core.Optimizations.RelativeIndexes := CheckBoxOptimizeRelativeIndexes.Checked; 129 134 Core.Optimizations.CopyMultiply := CheckBoxOptimizeCopyMultiply.Checked; 135 Core.DebugEnabled := CheckBoxDebugEnabled.Checked; 136 Core.OptionsFormTabIndex := PageControl1.TabIndex; 130 137 end; 131 138 -
trunk/Forms/UFormSourceCode.lfm
r115 r128 10 10 OnCreate = FormCreate 11 11 OnDestroy = FormDestroy 12 LCLVersion = '2. 0.2.0'12 LCLVersion = '2.2.0.4' 13 13 inline SynEditSource: TSynEdit 14 14 Left = 0 15 Height = 49115 Height = 589 16 16 Top = 0 17 Width = 56017 Width = 672 18 18 Align = alClient 19 19 Font.Height = -16 … … 517 517 object PopupMenuSource: TPopupMenu 518 518 Images = Core.ImageListMain 519 left = 154520 top = 154519 Left = 154 520 Top = 154 521 521 object MenuItem23: TMenuItem 522 522 Action = FormMain.ABreakpointToggle … … 591 591 object ActionList1: TActionList 592 592 Images = Core.ImageListMain 593 left = 154594 top = 67593 Left = 154 594 Top = 67 595 595 object AGenerateNumber: TAction 596 596 Caption = 'Generate number' … … 645 645 DefaultFilter = 'Soubory Java (*.java)|*.java' 646 646 Enabled = False 647 left = 486648 top = 316647 Left = 486 648 Top = 316 649 649 end 650 650 end -
trunk/Forms/UFormSourceCode.pas
r109 r128 7 7 uses 8 8 Classes, SysUtils, FileUtil, SynEdit, SynHighlighterIni, Forms, Controls, 9 Graphics, Dialogs, StdCtrls,Menus, ActnList, strutils,9 Graphics, Dialogs, Menus, ActnList, strutils, 10 10 SynEditHighlighter, SynHighlighterAny, SynHighlighterJava, UBFHighlighter; 11 11 … … 132 132 end; 133 133 SynEditSource.Text := NewSource; 134 MemoSourceChange(nil); 134 135 end; 135 136 … … 165 166 SetLength(Source, Pos - 1); 166 167 SynEditSource.Text := Source; 168 MemoSourceChange(nil); 167 169 end; 168 170 -
trunk/Forms/UFormTargetCode.pas
r107 r128 9 9 SynHighlighterCpp, SynHighlighterPHP, SynHighlighterJava, 10 10 SynHighlighterPython, SynHighlighterJScript, Forms, Controls, Graphics, 11 Dialogs, StdCtrls,Menus, ActnList, strutils;11 Dialogs, Menus, ActnList, strutils; 12 12 13 13 type -
trunk/Languages/LazFuck.cs.po
r127 r128 263 263 msgstr "Volby" 264 264 265 #: tformoptions.checkbox 1.caption266 msgid " Reopend last opened project"267 msgstr " OtevÅÃt naposledy otevÅenÃœ projekt"265 #: tformoptions.checkboxdebugenabled.caption 266 msgid "Debugging" 267 msgstr "LadÄnÃ" 268 268 269 269 #: tformoptions.checkboxdpiauto.caption … … 290 290 msgid "Set zero" 291 291 msgstr "Nastavenà nuly" 292 293 #: tformoptions.checkboxreopenlastfile.caption 294 msgctxt "tformoptions.checkboxreopenlastfile.caption" 295 msgid "Reopend last opened project" 296 msgstr "OtevÅÃt naposledy otevÅenÃœ projekt" 292 297 293 298 #: tformoptions.label1.caption -
trunk/Languages/LazFuck.pot
r127 r128 253 253 msgstr "" 254 254 255 #: tformoptions.checkbox 1.caption256 msgid " Reopend last opened project"255 #: tformoptions.checkboxdebugenabled.caption 256 msgid "Debugging" 257 257 msgstr "" 258 258 … … 279 279 #: tformoptions.checkboxoptimizesetzero.caption 280 280 msgid "Set zero" 281 msgstr "" 282 283 #: tformoptions.checkboxreopenlastfile.caption 284 msgctxt "tformoptions.checkboxreopenlastfile.caption" 285 msgid "Reopend last opened project" 281 286 msgstr "" 282 287 -
trunk/LazFuck.lpi
r122 r128 61 61 </Options> 62 62 </Linking> 63 <Other> 64 <CompilerMessages> 65 <IgnoredMessages idx6058="True" idx3124="True" idx3123="True"/> 66 </CompilerMessages> 67 </Other> 63 68 </CompilerOptions> 64 69 </Item2> … … 284 289 <Other> 285 290 <CompilerMessages> 286 <IgnoredMessages idx 5024="True"/>291 <IgnoredMessages idx6058="True" idx5024="True" idx3124="True" idx3123="True"/> 287 292 </CompilerMessages> 288 293 <CustomOptions Value="-dDEBUG"/> -
trunk/Target/UTargetInterpretter.pas
r126 r128 46 46 procedure CommandMultiply; 47 47 procedure PrepareBreakPoints; 48 procedure CheckMemoryBounds(Address: Integer); 48 49 protected 49 50 procedure SetState(AValue: TRunState); override; 50 function GetTargetCode: string; override;51 procedure EmitTargetCode; 51 52 function GetExecutionPosition: Integer; override; 52 53 public … … 82 83 SProgramLowerLimit = 'Program run over lower limit'; 83 84 SProgramUpperLimit = 'Program run over upper limit'; 84 SJumpTableIn sistent = 'Jump table is inconsistent';85 SJumpTableInconsistent = 'Jump table is inconsistent'; 85 86 SJumpTableCollision = 'Jump table collision'; 86 87 SProgramNotRunning = 'Program not running'; … … 179 180 end; 180 181 end; 181 if Length(Loop) > 0 then raise Exception.Create(SJumpTableIn sistent);182 if Length(Loop) > 0 then raise Exception.Create(SJumpTableInconsistent); 182 183 end; 183 184 … … 242 243 procedure TTargetInterpretter.CommandPointerInc; 243 244 begin 244 if MemoryPosition < MemorySize then Inc(MemoryPosition, FProgram[FProgramIndex].Parameter) 245 if MemoryPosition < MemorySize then 246 Inc(MemoryPosition, FProgram[FProgramIndex].Parameter) 245 247 else raise Exception.Create(SProgramUpperLimit); 246 248 end; … … 248 250 procedure TTargetInterpretter.CommandPointerDec; 249 251 begin 250 if MemoryPosition > 0 then Dec(MemoryPosition, FProgram[FProgramIndex].Parameter) 252 if MemoryPosition > 0 then 253 Dec(MemoryPosition, FProgram[FProgramIndex].Parameter) 251 254 else raise Exception.Create(SProgramLowerLimit); 252 255 end; … … 257 260 begin 258 261 Addr := MemoryPosition + FProgram[FProgramIndex].RelIndex; 262 CheckMemoryBounds(Addr); 259 263 Memory[Addr] := FProgram[FProgramIndex].Parameter mod CellSize; 260 264 MemoryMaxUsedAddr := Max(Addr, MemoryMaxUsedAddr); … … 267 271 begin 268 272 Addr := MemoryPosition + FProgram[FProgramIndex].RelIndex; 273 CheckMemoryBounds(Addr); 269 274 Memory[Addr] := (Memory[Addr] + Memory[MemoryPosition] * 270 275 FProgram[FProgramIndex].Parameter) mod CellSize; … … 297 302 begin 298 303 inherited; 304 EmitTargetCode; 299 305 end; 300 306 … … 311 317 end; 312 318 313 function TTargetInterpretter.GetTargetCode: string; 319 procedure TTargetInterpretter.CheckMemoryBounds(Address: Integer); 320 begin 321 if Address < 0 then raise Exception.Create(SProgramLowerLimit); 322 if Address >= MemorySize then raise Exception.Create(SProgramUpperLimit); 323 end; 324 325 procedure TTargetInterpretter.EmitTargetCode; 314 326 var 315 327 I: Integer; 316 begin 317 Result := ''; 328 Code: string; 329 TargetIndex: Integer; 330 Step: TDebugStep; 331 begin 332 TargetIndex := 0; 333 FTargetCode := ''; 318 334 for I := 0 to FProgram.Count - 1 do begin 319 Result := Result + GetOperationText(FProgram[I]); 335 Code := GetOperationText(FProgram[I]); 336 FTargetCode := FTargetCode + Code; 337 if DebugEnabled then begin 338 Step := DebugSteps.SearchByProgramPos(I); 339 if Assigned(Step) then begin 340 Step.TargetPosition := TargetIndex; 341 end;// else 342 // raise Exception.Create(Format('Program index %d missing debug step.', [I])); 343 end; 344 Inc(TargetIndex, Length(Code)); 320 345 end; 321 346 end; -
trunk/UBFTarget.pas
r126 r128 37 37 Index: Integer; 38 38 procedure Assign(Source: TProgram); 39 procedure Write(Operation: TMachineOperation); 40 function Read: TMachineOperation; 39 41 property Count: Integer read GetCount write SetCount; 40 42 property Items[Index: Integer]: TMachineOperation read GetItem write SetItem; default; … … 117 119 end; 118 120 121 procedure TProgram.Write(Operation: TMachineOperation); 122 begin 123 Operations[Index] := Operation; 124 Inc(Index); 125 end; 126 127 function TProgram.Read: TMachineOperation; 128 begin 129 Result := Operations[Index]; 130 Inc(Index); 131 end; 132 119 133 { TMachineOperation } 120 134 … … 158 172 var 159 173 NewProgram: TProgram; 160 NewTargetIndex: Integer; 161 FirstIndex: Integer; 162 begin 163 NewTargetIndex := 0; 174 InitialProgramIndex: Integer; 175 InitialNewProgramIndex: Integer; 176 begin 164 177 NewProgram := TProgram.Create; 165 178 NewProgram.Count := FProgram.Count; … … 167 180 FProgramIndex := 0; 168 181 while FProgramIndex < FProgram.Count do begin 169 FirstIndex := FProgramIndex; 182 InitialProgramIndex := FProgramIndex; 183 InitialNewProgramIndex := NewProgram.Index; 170 184 case FProgram[FProgramIndex].Command of 171 185 cmPointerInc: begin 172 NewProgram [NewProgram.Index] :=TMachineOperation.Create(cmPointerInc,173 CheckOccurenceSumParam(cmPointerInc)) ;186 NewProgram.Write(TMachineOperation.Create(cmPointerInc, 187 CheckOccurenceSumParam(cmPointerInc))); 174 188 end; 175 189 cmPointerDec: begin 176 NewProgram [NewProgram.Index] :=TMachineOperation.Create(cmPointerDec,177 CheckOccurenceSumParam(cmPointerDec)) ;190 NewProgram.Write(TMachineOperation.Create(cmPointerDec, 191 CheckOccurenceSumParam(cmPointerDec))); 178 192 end; 179 193 cmInc: begin 180 NewProgram [NewProgram.Index] :=TMachineOperation.Create(cmInc,181 CheckOccurenceSumParam(cmInc)) ;194 NewProgram.Write(TMachineOperation.Create(cmInc, 195 CheckOccurenceSumParam(cmInc))); 182 196 end; 183 197 cmDec: begin 184 NewProgram [NewProgram.Index] :=TMachineOperation.Create(cmDec,185 CheckOccurenceSumParam(cmDec)) ;186 end; 187 else NewProgram [NewProgram.Index] := FProgram[FProgramIndex];198 NewProgram.Write(TMachineOperation.Create(cmDec, 199 CheckOccurenceSumParam(cmDec))); 200 end; 201 else NewProgram.Write(FProgram[FProgramIndex]); 188 202 end; 189 DebugSteps.UpdateTargetPos( FirstIndex, FProgramIndex, NewProgram.Index, NewTargetIndex);190 Inc(NewTargetIndex, Length(GetOperationText(NewProgram[NewProgram.Index])));203 DebugSteps.UpdateTargetPos(InitialProgramIndex, FProgramIndex, InitialNewProgramIndex, 204 NewProgram.Index); 191 205 Inc(FProgramIndex); 192 Inc(NewProgram.Index);193 206 end; 194 207 … … 202 215 var 203 216 NewProgram: TProgram; 204 FirstIndex: Integer; 205 NewTargetIndex: Integer; 206 begin 207 NewTargetIndex := 0; 217 InitialProgramIndex: Integer; 218 InitialNewProgramIndex: Integer; 219 begin 208 220 NewProgram := TProgram.Create; 209 221 NewProgram.Count := FProgram.Count; … … 211 223 FProgramIndex := 0; 212 224 while FProgramIndex < FProgram.Count do begin 213 FirstIndex := FProgramIndex; 225 InitialProgramIndex := FProgramIndex; 226 InitialNewProgramIndex := NewProgram.Index; 214 227 case FProgram[FProgramIndex].Command of 215 228 cmLoopStart: begin 216 229 if CheckLoopSetZero then begin 217 NewProgram [NewProgram.Index] := TMachineOperation.Create(cmSet, 0, 0);230 NewProgram.Write(TMachineOperation.Create(cmSet, 0, 0)); 218 231 Inc(FProgramIndex, 2); 219 232 end else begin 220 NewProgram [NewProgram.Index] := FProgram[FProgramIndex];221 end; 222 end; 223 else NewProgram [NewProgram.Index] := FProgram[FProgramIndex];233 NewProgram.Write(FProgram[FProgramIndex]); 234 end; 235 end; 236 else NewProgram.Write(FProgram[FProgramIndex]); 224 237 end; 225 DebugSteps.UpdateTargetPos( FirstIndex, FProgramIndex, NewProgram.Index, NewTargetIndex);226 Inc(NewTargetIndex, Length(GetOperationText(NewProgram[NewProgram.Index])));238 DebugSteps.UpdateTargetPos(InitialProgramIndex, FProgramIndex, InitialNewProgramIndex, 239 NewProgram.Index); 227 240 Inc(FProgramIndex); 228 Inc(NewProgram.Index);229 241 end; 230 242 NewProgram.Count := NewProgram.Index; … … 239 251 NewProgram: TProgram; 240 252 PreviousCommand: TMachineCommand; 241 FirstIndex: Integer; 242 NewTargetIndex: Integer; 243 begin 244 NewTargetIndex := 0; 253 InitialProgramIndex: Integer; 254 InitialNewProgramIndex: Integer; 255 begin 245 256 NewProgram := TProgram.Create; 246 257 NewProgram.Count := FProgram.Count; … … 249 260 FProgramIndex := 0; 250 261 while FProgramIndex < FProgram.Count do begin 251 FirstIndex := FProgramIndex; 262 InitialProgramIndex := FProgramIndex; 263 InitialNewProgramIndex := NewProgram.Index; 252 264 case FProgram[FProgramIndex].Command of 253 265 cmPointerInc: begin … … 267 279 else NewProgram.Operations[NewProgram.Index - 1].Command := cmPointerInc; 268 280 end; 269 if NewProgram.Operations[NewProgram.Index - 1].Parameter = 0 then Dec(NewProgram.Index);270 Dec(NewProgram.Index);271 end else begin 272 NewProgram [NewProgram.Index] :=TMachineOperation.Create(cmPointerInc,273 FProgram[FProgramIndex].Parameter) ;281 if NewProgram.Operations[NewProgram.Index - 1].Parameter = 0 then 282 Dec(NewProgram.Index); 283 end else begin 284 NewProgram.Write(TMachineOperation.Create(cmPointerInc, 285 FProgram[FProgramIndex].Parameter)); 274 286 end; 275 287 end; … … 289 301 else NewProgram.Operations[NewProgram.Index - 1].Command := cmPointerInc; 290 302 end; 291 if NewProgram[NewProgram.Index - 1].Parameter = 0 then Dec(NewProgram.Index);292 Dec(NewProgram.Index);293 end else begin 294 NewProgram [NewProgram.Index] :=TMachineOperation.Create(cmPointerDec,295 FProgram[FProgramIndex].Parameter) ;303 if NewProgram[NewProgram.Index - 1].Parameter = 0 then 304 Dec(NewProgram.Index); 305 end else begin 306 NewProgram.Write(TMachineOperation.Create(cmPointerDec, 307 FProgram[FProgramIndex].Parameter)); 296 308 end; 297 309 end; … … 311 323 else NewProgram.Operations[NewProgram.Index - 1].Command := cmInc; 312 324 end; 313 if NewProgram[NewProgram.Index - 1].Parameter = 0 then Dec(NewProgram.Index);314 Dec(NewProgram.Index);315 end else begin 316 NewProgram [NewProgram.Index] :=TMachineOperation.Create(cmInc,317 FProgram[FProgramIndex].Parameter) ;325 if NewProgram[NewProgram.Index - 1].Parameter = 0 then 326 Dec(NewProgram.Index); 327 end else begin 328 NewProgram.Write(TMachineOperation.Create(cmInc, 329 FProgram[FProgramIndex].Parameter)); 318 330 end; 319 331 end; … … 333 345 else NewProgram.Operations[NewProgram.Index - 1].Command := cmInc; 334 346 end; 335 if NewProgram[NewProgram.Index - 1].Parameter = 0 then Dec(NewProgram.Index);336 Dec(NewProgram.Index);337 end else begin 338 NewProgram [NewProgram.Index] :=TMachineOperation.Create(cmDec,339 FProgram[FProgramIndex].Parameter) ;347 if NewProgram[NewProgram.Index - 1].Parameter = 0 then 348 Dec(NewProgram.Index); 349 end else begin 350 NewProgram.Write(TMachineOperation.Create(cmDec, 351 FProgram[FProgramIndex].Parameter)); 340 352 end; 341 353 end; … … 344 356 // Set overrides value of previous commands 345 357 Dec(NewProgram.Index); 346 NewProgram [NewProgram.Index] :=TMachineOperation.Create(cmSet,347 FProgram[FProgramIndex].Parameter) ;348 end else begin 349 NewProgram [NewProgram.Index] := FProgram[FProgramIndex];350 end; 351 end; 352 else NewProgram [NewProgram.Index] := FProgram[FProgramIndex];358 NewProgram.Write(TMachineOperation.Create(cmSet, 359 FProgram[FProgramIndex].Parameter)); 360 end else begin 361 NewProgram.Write(FProgram[FProgramIndex]); 362 end; 363 end; 364 else NewProgram.Write(FProgram[FProgramIndex]); 353 365 end; 354 366 PreviousCommand := FProgram[FProgramIndex].Command; 355 DebugSteps.UpdateTargetPos( FirstIndex, FProgramIndex, NewProgram.Index, NewTargetIndex);356 Inc(NewTargetIndex, Length(GetOperationText(NewProgram[NewProgram.Index])));367 DebugSteps.UpdateTargetPos(InitialProgramIndex, FProgramIndex, InitialNewProgramIndex, 368 NewProgram.Index); 357 369 Inc(FProgramIndex); 358 Inc(NewProgram.Index);359 370 end; 360 371 … … 375 386 NewProgram: TProgram; 376 387 RelIndex: Integer; 377 FirstIndex: Integer; 378 NewTargetIndex: Integer; 379 begin 380 NewTargetIndex := 0; 388 InitialProgramIndex: Integer; 389 InitialNewProgramIndex: Integer; 390 begin 381 391 NewProgram := TProgram.Create; 382 392 NewProgram.Count := FProgram.Count; … … 385 395 FProgramIndex := 0; 386 396 while FProgramIndex < FProgram.Count do begin 387 FirstIndex := FProgramIndex; 397 InitialProgramIndex := FProgramIndex; 398 InitialNewProgramIndex := NewProgram.Index; 388 399 case FProgram[FProgramIndex].Command of 389 400 cmPointerInc: begin 390 401 RelIndex := RelIndex + FProgram[FProgramIndex].Parameter; 391 Dec(NewProgram.Index);392 402 end; 393 403 cmPointerDec: begin 394 404 RelIndex := RelIndex - FProgram[FProgramIndex].Parameter; 395 Dec(NewProgram.Index);396 405 end; 397 406 cmInc, cmDec, cmInput, cmOutput, cmSet: begin 398 NewProgram [NewProgram.Index] := FProgram[FProgramIndex];399 NewProgram.Operations[NewProgram.Index ].RelIndex :=400 NewProgram[NewProgram.Index ].RelIndex + RelIndex;407 NewProgram.Write(FProgram[FProgramIndex]); 408 NewProgram.Operations[NewProgram.Index - 1].RelIndex := 409 NewProgram[NewProgram.Index - 1].RelIndex + RelIndex; 401 410 end; 402 411 cmLoopStart, cmLoopEnd: begin 403 412 if RelIndex > 0 then begin 404 NewProgram[NewProgram.Index] := TMachineOperation.Create(cmPointerInc, 405 RelIndex, 0); 406 Inc(NewProgram.Index); 413 NewProgram.Write(TMachineOperation.Create(cmPointerInc, 414 RelIndex, 0)); 407 415 RelIndex := 0; 408 416 end else 409 417 if RelIndex < 0 then begin 410 NewProgram[NewProgram.Index] := TMachineOperation.Create(cmPointerDec, 411 Abs(RelIndex), 0); 412 Inc(NewProgram.Index); 418 NewProgram.Write(TMachineOperation.Create(cmPointerDec, 419 Abs(RelIndex), 0)); 413 420 RelIndex := 0; 414 421 end; 415 NewProgram [NewProgram.Index] := FProgram[FProgramIndex];422 NewProgram.Write(FProgram[FProgramIndex]); 416 423 end; 417 424 else raise Exception.Create(Format(SUnsupportedCommand, [FProgram[FProgramIndex].Command])); 418 425 end; 419 DebugSteps.UpdateTargetPos( FirstIndex, FProgramIndex, NewProgram.Index, NewTargetIndex);420 Inc(NewTargetIndex, Length(GetOperationText(NewProgram[NewProgram.Index])));426 DebugSteps.UpdateTargetPos(InitialProgramIndex, FProgramIndex, InitialNewProgramIndex, 427 NewProgram.Index); 421 428 Inc(FProgramIndex); 422 Inc(NewProgram.Index);423 429 end; 424 430 … … 472 478 ProcessingLoop: Boolean; 473 479 PointerChange: Integer; 474 NumberOfBaseDecrement: Integer; 475 FirstIndex: Integer; 476 NewTextIndex: Integer; 477 NoNewCode: Boolean; 480 InitialProgramIndex: Integer; 481 InitialNewProgramIndex: Integer; 478 482 begin 479 483 NewProgram := TProgram.Create; 480 484 NewProgram.Count := FProgram.Count; 481 485 482 NumberOfBaseDecrement := 0;483 486 ProcessingLoop := False; 484 487 FProgramIndex := 0; 485 NewTextIndex := 0;486 488 PointerChange := 0; 487 489 while FProgramIndex < FProgram.Count do begin 488 FirstIndex := FProgramIndex;489 NoNewCode := False;490 InitialProgramIndex := FProgramIndex; 491 InitialNewProgramIndex := NewProgram.Index; 490 492 case FProgram[FProgramIndex].Command of 491 493 cmPointerInc: begin 492 494 Inc(PointerChange, FProgram[FProgramIndex].Parameter); 493 NewProgram [NewProgram.Index] := FProgram[FProgramIndex];495 NewProgram.Write(FProgram[FProgramIndex]); 494 496 end; 495 497 cmPointerDec: begin 496 498 Dec(PointerChange, FProgram[FProgramIndex].Parameter); 497 NewProgram [NewProgram.Index] := FProgram[FProgramIndex];499 NewProgram.Write(FProgram[FProgramIndex]); 498 500 end; 499 501 cmInc: begin 500 502 if not ProcessingLoop then begin 501 NewProgram [NewProgram.Index] := FProgram[FProgramIndex];503 NewProgram.Write(FProgram[FProgramIndex]); 502 504 end else begin 503 505 if ((FProgram[FProgramIndex].RelIndex + PointerChange) <> 0) then begin 504 NewProgram [NewProgram.Index] := FProgram[FProgramIndex];505 NewProgram.Operations[NewProgram.Index ].Command := cmMultiply;506 end else NoNewCode := True;506 NewProgram.Write(FProgram[FProgramIndex]); 507 NewProgram.Operations[NewProgram.Index - 1].Command := cmMultiply; 508 end; 507 509 end; 508 510 end; 509 511 cmDec: begin 510 512 if not ProcessingLoop then begin 511 if (PointerChange = 0) and (FProgram[FProgramIndex].RelIndex = 0) and 512 (FProgram[FProgramIndex].Parameter = 1) then 513 Inc(NumberOfBaseDecrement); 514 NewProgram[NewProgram.Index] := FProgram[FProgramIndex]; 513 NewProgram.Write(FProgram[FProgramIndex]); 515 514 end else begin 516 515 if ((FProgram[FProgramIndex].RelIndex + PointerChange) <> 0) then begin 517 NewProgram[NewProgram.Index] := FProgram[FProgramIndex]; 518 NewProgram.Operations[NewProgram.Index].Command := cmMultiply; 519 NewProgram.Operations[NewProgram.Index].Parameter := -FProgram[FProgramIndex].Parameter; 520 end else NoNewCode := True; 521 end; 522 end; 523 cmInput, cmOutput: begin 524 NewProgram[NewProgram.Index] := FProgram[FProgramIndex]; 525 Inc(NumberOfBaseDecrement, 2); 526 end; 527 cmSet: begin 528 NewProgram[NewProgram.Index] := FProgram[FProgramIndex]; 529 Inc(NumberOfBaseDecrement, 2); 516 NewProgram.Write(FProgram[FProgramIndex]); 517 NewProgram.Operations[NewProgram.Index - 1].Command := cmMultiply; 518 NewProgram.Operations[NewProgram.Index - 1].Parameter := -FProgram[FProgramIndex].Parameter; 519 end; 520 end; 521 end; 522 cmInput, cmOutput, cmSet: begin 523 NewProgram.Write(FProgram[FProgramIndex]); 530 524 end; 531 525 cmLoopStart: begin … … 534 528 PointerChange := 0; 535 529 ProcessingLoop := True; 536 NoNewCode := True;537 530 end else 538 NewProgram [NewProgram.Index] := FProgram[FProgramIndex];539 end else begin 540 NoNewCode := True;531 NewProgram.Write(FProgram[FProgramIndex]); 532 end else begin 533 raise Exception.Create('Another loop start not allowed inside loop'); 541 534 end; 542 535 end; 543 536 cmLoopEnd: begin 544 537 if not ProcessingLoop then begin 545 NewProgram [NewProgram.Index] := FProgram[FProgramIndex];538 NewProgram.Write(FProgram[FProgramIndex]); 546 539 end else begin 547 540 // Finally set decrementing cell to zero 548 NewProgram [NewProgram.Index] := TMachineOperation.Create(cmSet, 0, 0);541 NewProgram.Write(TMachineOperation.Create(cmSet, 0, 0)); 549 542 ProcessingLoop := False; 550 543 end; … … 552 545 else raise Exception.Create(Format(SUnsupportedCommand, [FProgram[FProgramIndex].Command])); 553 546 end; 554 if NoNewCode then DebugSteps.UpdateTargetPos(FirstIndex, FProgramIndex, -1, NewTextIndex) 555 else begin 556 DebugSteps.UpdateTargetPos(FirstIndex, FProgramIndex, NewProgram.Index, NewTextIndex); 557 Inc(NewTextIndex, Length(GetOperationText(NewProgram[NewProgram.Index]))); 558 end; 547 548 DebugSteps.UpdateTargetPos(InitialProgramIndex, FProgramIndex, 549 InitialNewProgramIndex, NewProgram.Index); 559 550 Inc(FProgramIndex); 560 if not NoNewCode then Inc(NewProgram.Index);561 551 end; 562 552 … … 581 571 var 582 572 I: Integer; 573 LastIndex: Integer; 583 574 begin 584 575 inherited; 585 576 DebugSteps.Clear; 586 577 FProgram.Count := Length(FSourceCode); 587 FProgramIndex := 0; 578 FProgram.Index := 0; 579 LastIndex := 0; 588 580 for I := 1 to Length(FSourceCode) do begin 589 581 case FSourceCode[I] of 590 '+': begin 591 FProgram[FProgramIndex] := TMachineOperation.Create(cmInc, 1, 0); 592 DebugSteps.AddStep(I - 1, FProgramIndex, soNormal); 593 end; 594 '-': begin 595 FProgram[FProgramIndex] := TMachineOperation.Create(cmDec, 1, 0); 596 DebugSteps.AddStep(I - 1, FProgramIndex, soNormal); 597 end; 598 '>': begin 599 FProgram[FProgramIndex] := TMachineOperation.Create(cmPointerInc, 1, 0); 600 DebugSteps.AddStep(I - 1, FProgramIndex, soNormal); 601 end; 602 '<': begin 603 FProgram[FProgramIndex] := TMachineOperation.Create(cmPointerDec, 1, 0); 604 DebugSteps.AddStep(I - 1, FProgramIndex, soNormal); 605 end; 606 ',': begin 607 FProgram[FProgramIndex] := TMachineOperation.Create(cmInput, 0, 0); 608 DebugSteps.AddStep(I - 1, FProgramIndex, soNormal); 609 end; 610 '.': begin 611 FProgram[FProgramIndex] := TMachineOperation.Create(cmOutput, 0, 0); 612 DebugSteps.AddStep(I - 1, FProgramIndex, soNormal); 613 end; 614 '[': begin 615 FProgram[FProgramIndex] := TMachineOperation.Create(cmLoopStart, 0, 0); 616 DebugSteps.AddStep(I - 1, FProgramIndex, soStepIn); 617 end; 618 ']': begin 619 FProgram[FProgramIndex] := TMachineOperation.Create(cmLoopEnd, 0 ,0); 620 DebugSteps.AddStep(I - 1, FProgramIndex, soStepOut); 621 end 622 else Dec(FProgramIndex); 582 '+': FProgram.Write(TMachineOperation.Create(cmInc, 1)); 583 '-': FProgram.Write(TMachineOperation.Create(cmDec, 1)); 584 '>': FProgram.Write(TMachineOperation.Create(cmPointerInc, 1)); 585 '<': FProgram.Write(TMachineOperation.Create(cmPointerDec, 1)); 586 ',': FProgram.Write(TMachineOperation.Create(cmInput, 0)); 587 '.': FProgram.Write(TMachineOperation.Create(cmOutput, 0)); 588 '[': FProgram.Write(TMachineOperation.Create(cmLoopStart, 0)); 589 ']': FProgram.Write(TMachineOperation.Create(cmLoopEnd, 0)); 623 590 end; 624 Inc(FProgramIndex); 625 end; 626 FProgram.Count := FProgramIndex; 591 if DebugEnabled and (FProgram.Index <> LastIndex) then 592 DebugSteps.AddStep(I - 1, FProgram.Index - 1, soNormal); 593 LastIndex := FProgram.Index; 594 end; 595 FProgramIndex := FProgram.Index; 596 FProgram.Count := FProgram.Index; 627 597 end; 628 598 -
trunk/UCore.pas
r125 r128 38 38 CellSize: Integer; 39 39 MemorySize: Integer; 40 DebugEnabled: Boolean; 41 OptionsFormTabIndex: Integer; 40 42 Optimizations: TOptimizations; 41 43 procedure Init; … … 120 122 MemorySize := ReadIntegerWithDefault('MemorySize', 30000); 121 123 CellSize := ReadIntegerWithDefault('CellSize', 256); 124 DebugEnabled := ReadBoolWithDefault('DebugEnabled', True); 125 OptionsFormTabIndex := ReadIntegerWithDefault('OptionsFormTabIndex', 0); 122 126 ThemeManager.Theme := ThemeManager.Themes.FindByName(ReadStringWithDefault('Theme', 'System')); 123 127 finally … … 143 147 WriteInteger('MemorySize', MemorySize); 144 148 WriteInteger('CellSize', CellSize); 149 WriteBool('DebugEnabled', DebugEnabled); 150 WriteInteger('OptionsFormTabIndex', OptionsFormTabIndex); 145 151 if Assigned(Translator.Language) and (Translator.Language.Code <> '') then 146 152 WriteString('LanguageCode', Translator.Language.Code) -
trunk/UTarget.pas
r126 r128 35 35 function SearchIndexByProgramPos(Pos: Integer): Integer; 36 36 procedure AddStep(SourcePos, TargetPos: Integer; Operation: TStepOperation); 37 procedure UpdateTargetPos(OldProgramFrom, OldProgramTo, NewProgram, NewTarget: Integer); 37 procedure UpdateTargetPos(OldProgramFrom, OldProgramTo, NewProgramFrom, 38 NewProgramTo: Integer; NewTarget: Integer = 0); 38 39 end; 39 40 … … 108 109 BreakPoints: TBreakPointList; 109 110 DebugSteps: TDebugStepList; 111 DebugEnabled: Boolean; 110 112 Messages: TMessageList; 111 113 constructor Create; virtual; … … 280 282 end; 281 283 282 procedure TDebugStepList.UpdateTargetPos(OldProgramFrom, OldProgramTo, NewProgram, NewTarget: Integer); 284 procedure TDebugStepList.UpdateTargetPos(OldProgramFrom, OldProgramTo, NewProgramFrom, 285 NewProgramTo: Integer; NewTarget: Integer = 0); 283 286 var 284 287 I: Integer; … … 288 291 First := SearchIndexByProgramPos(OldProgramFrom); 289 292 Last := SearchIndexByProgramPos(OldProgramTo); 290 for I := Last downto First + 1 do Delete(I); 291 if NewProgram = -1 then begin 292 Delete(First); 293 end else begin 294 if (First >= 0) and (First < Count) then begin 295 Items[First].ProgramPosition := NewProgram; 293 if (First <> -1) and (Last <> -1) then begin 294 if First > Last then 295 raise Exception.Create('First index higher than last index'); 296 if (First < 0) or (First >= Count) then 297 raise Exception.Create('First index out of range'); 298 if (Last < 0) or (Last >= Count) then 299 raise Exception.Create('Last index out of range'); 300 for I := Last downto First + 1 do Delete(I); 301 302 if NewProgramTo - NewProgramFrom = 0 then begin 303 Delete(First); 304 end else 305 if NewProgramTo > NewProgramFrom then begin 306 Items[First].ProgramPosition := NewProgramFrom; 296 307 Items[First].TargetPosition := NewTarget; 297 end else begin 298 // Index not found, possible new command? 299 end; 308 end else 309 raise Exception.Create('Old program index higher than new'); 300 310 end; 301 311 end;
Note:
See TracChangeset
for help on using the changeset viewer.