Changeset 128


Ignore:
Timestamp:
Jan 17, 2022, 4:53:31 PM (3 years ago)
Author:
chronos
Message:
  • Added: Two more code examples.
  • Added: Allow to disable debugging support.
  • Added: Remember last opened tab in options form.
Location:
trunk
Files:
2 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormMain.pas

    r126 r128  
    334334var
    335335  Title: string;
     336  CanDebug: Boolean;
    336337begin
    337338  Title := '';
     
    352353  AProgramCompile.Enabled := (tcCompile in Core.CurrentTarget.Capabilities) and
    353354    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);
    364362  AShowSourcePosition.Enabled := Core.CurrentTarget.Compiled;
    365363  AShowTargetPosition.Enabled := Core.CurrentTarget.Compiled;
     
    568566  if Core.CurrentTarget.State = rsStopped then begin
    569567    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);
    571569    AProgramRun.Execute;
    572570  end else Core.CurrentTarget.StepInto;
  • trunk/Forms/UFormOptions.lfm

    r126 r128  
    3939    Top = 10
    4040    Width = 711
    41     ActivePage = TabSheetBuild
     41    ActivePage = TabSheetGeneral
    4242    Anchors = [akTop, akLeft, akRight, akBottom]
    4343    ParentFont = False
    44     TabIndex = 1
     44    TabIndex = 0
    4545    TabOrder = 2
    4646    object TabSheetGeneral: TTabSheet
     
    7878          TabOrder = 0
    7979        end
    80         object CheckBox1: TCheckBox
     80        object CheckBoxReopenLastFile: TCheckBox
    8181          Left = 10
    8282          Height = 32
     
    279279          TabOrder = 7
    280280        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
    281290      end
    282291    end
  • trunk/Forms/UFormOptions.lrj

    r126 r128  
    55{"hash":231000124,"name":"tformoptions.tabsheetgeneral.caption","sourcebytes":[71,101,110,101,114,97,108],"value":"General"},
    66{"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.checkbox1.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"},
    88{"hash":37628553,"name":"tformoptions.checkboxdpiauto.caption","sourcebytes":[65,117,116,111,109,97,116,105,99,32,68,80,73],"value":"Automatic DPI"},
    99{"hash":300234,"name":"tformoptions.labeldpi.caption","sourcebytes":[68,80,73,58],"value":"DPI:"},
     
    1818{"hash":243182762,"name":"tformoptions.label2.caption","sourcebytes":[67,101,108,108,32,115,105,122,101,58],"value":"Cell size:"},
    1919{"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"}
    2122]}
  • trunk/Forms/UFormOptions.pas

    r126 r128  
    1616    ButtonOk: TButton;
    1717    ButtonCancel: TButton;
    18     CheckBox1: TCheckBox;
     18    CheckBoxReopenLastFile: TCheckBox;
    1919    CheckBoxDPIAuto: TCheckBox;
    2020    CheckBoxOptimizeAddSub: TCheckBox;
     21    CheckBoxDebugEnabled: TCheckBox;
    2122    CheckBoxOptimizeCopyMultiply: TCheckBox;
    2223    CheckBoxOptimizeSetZero: TCheckBox;
     
    9697  ComboBoxTheme.ItemIndex := ComboBoxTheme.Items.IndexOfObject(Core.ThemeManager.Theme);
    9798  if ComboBoxTheme.ItemIndex = -1 then ComboBoxTheme.ItemIndex := 0;
    98   CheckBox1.Checked := Core.OpenProjectOnStart;
     99  CheckBoxReopenLastFile.Checked := Core.OpenProjectOnStart;
    99100  CheckBoxOptimizeAddSub.Checked := Core.Optimizations.AddSub;
    100101  CheckBoxOptimizeSetZero.Checked := Core.Optimizations.SetZero;
     
    108109  SpinEditCellSize.Value := Core.CellSize;
    109110  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;
    110115  UpdateInterface;
    111116end;
     
    117122  if ComboBoxTheme.ItemIndex <> -1 then
    118123    Core.ThemeManager.Theme := TTheme(ComboBoxTheme.Items.Objects[ComboBoxTheme.ItemIndex]);
    119   Core.OpenProjectOnStart := CheckBox1.Checked;
     124  Core.OpenProjectOnStart := CheckBoxReopenLastFile.Checked;
    120125  Core.ScaleDPI1.DPI := Point(SpinEditDPIX.Value, SpinEditDPIY.Value);
    121126  Core.ScaleDPI1.AutoDetect := CheckBoxDPIAuto.Checked;
     
    128133  Core.Optimizations.RelativeIndexes := CheckBoxOptimizeRelativeIndexes.Checked;
    129134  Core.Optimizations.CopyMultiply := CheckBoxOptimizeCopyMultiply.Checked;
     135  Core.DebugEnabled := CheckBoxDebugEnabled.Checked;
     136  Core.OptionsFormTabIndex := PageControl1.TabIndex;
    130137end;
    131138
  • trunk/Forms/UFormSourceCode.lfm

    r115 r128  
    1010  OnCreate = FormCreate
    1111  OnDestroy = FormDestroy
    12   LCLVersion = '2.0.2.0'
     12  LCLVersion = '2.2.0.4'
    1313  inline SynEditSource: TSynEdit
    1414    Left = 0
    15     Height = 491
     15    Height = 589
    1616    Top = 0
    17     Width = 560
     17    Width = 672
    1818    Align = alClient
    1919    Font.Height = -16
     
    517517  object PopupMenuSource: TPopupMenu
    518518    Images = Core.ImageListMain
    519     left = 154
    520     top = 154
     519    Left = 154
     520    Top = 154
    521521    object MenuItem23: TMenuItem
    522522      Action = FormMain.ABreakpointToggle
     
    591591  object ActionList1: TActionList
    592592    Images = Core.ImageListMain
    593     left = 154
    594     top = 67
     593    Left = 154
     594    Top = 67
    595595    object AGenerateNumber: TAction
    596596      Caption = 'Generate number'
     
    645645    DefaultFilter = 'Soubory Java (*.java)|*.java'
    646646    Enabled = False
    647     left = 486
    648     top = 316
     647    Left = 486
     648    Top = 316
    649649  end
    650650end
  • trunk/Forms/UFormSourceCode.pas

    r109 r128  
    77uses
    88  Classes, SysUtils, FileUtil, SynEdit, SynHighlighterIni, Forms, Controls,
    9   Graphics, Dialogs, StdCtrls, Menus, ActnList, strutils,
     9  Graphics, Dialogs, Menus, ActnList, strutils,
    1010  SynEditHighlighter, SynHighlighterAny, SynHighlighterJava, UBFHighlighter;
    1111
     
    132132  end;
    133133  SynEditSource.Text := NewSource;
     134  MemoSourceChange(nil);
    134135end;
    135136
     
    165166  SetLength(Source, Pos - 1);
    166167  SynEditSource.Text := Source;
     168  MemoSourceChange(nil);
    167169end;
    168170
  • trunk/Forms/UFormTargetCode.pas

    r107 r128  
    99  SynHighlighterCpp, SynHighlighterPHP, SynHighlighterJava,
    1010  SynHighlighterPython, SynHighlighterJScript, Forms, Controls, Graphics,
    11   Dialogs, StdCtrls, Menus, ActnList, strutils;
     11  Dialogs, Menus, ActnList, strutils;
    1212
    1313type
  • trunk/Languages/LazFuck.cs.po

    r127 r128  
    263263msgstr "Volby"
    264264
    265 #: tformoptions.checkbox1.caption
    266 msgid "Reopend last opened project"
    267 msgstr "Otevřít naposledy otevřenÃœ projekt"
     265#: tformoptions.checkboxdebugenabled.caption
     266msgid "Debugging"
     267msgstr "Ladění"
    268268
    269269#: tformoptions.checkboxdpiauto.caption
     
    290290msgid "Set zero"
    291291msgstr "Nastavení nuly"
     292
     293#: tformoptions.checkboxreopenlastfile.caption
     294msgctxt "tformoptions.checkboxreopenlastfile.caption"
     295msgid "Reopend last opened project"
     296msgstr "Otevřít naposledy otevřenÃœ projekt"
    292297
    293298#: tformoptions.label1.caption
  • trunk/Languages/LazFuck.pot

    r127 r128  
    253253msgstr ""
    254254
    255 #: tformoptions.checkbox1.caption
    256 msgid "Reopend last opened project"
     255#: tformoptions.checkboxdebugenabled.caption
     256msgid "Debugging"
    257257msgstr ""
    258258
     
    279279#: tformoptions.checkboxoptimizesetzero.caption
    280280msgid "Set zero"
     281msgstr ""
     282
     283#: tformoptions.checkboxreopenlastfile.caption
     284msgctxt "tformoptions.checkboxreopenlastfile.caption"
     285msgid "Reopend last opened project"
    281286msgstr ""
    282287
  • trunk/LazFuck.lpi

    r122 r128  
    6161            </Options>
    6262          </Linking>
     63          <Other>
     64            <CompilerMessages>
     65              <IgnoredMessages idx6058="True" idx3124="True" idx3123="True"/>
     66            </CompilerMessages>
     67          </Other>
    6368        </CompilerOptions>
    6469      </Item2>
     
    284289    <Other>
    285290      <CompilerMessages>
    286         <IgnoredMessages idx5024="True"/>
     291        <IgnoredMessages idx6058="True" idx5024="True" idx3124="True" idx3123="True"/>
    287292      </CompilerMessages>
    288293      <CustomOptions Value="-dDEBUG"/>
  • trunk/Target/UTargetInterpretter.pas

    r126 r128  
    4646    procedure CommandMultiply;
    4747    procedure PrepareBreakPoints;
     48    procedure CheckMemoryBounds(Address: Integer);
    4849  protected
    4950    procedure SetState(AValue: TRunState); override;
    50     function GetTargetCode: string; override;
     51    procedure EmitTargetCode;
    5152    function GetExecutionPosition: Integer; override;
    5253  public
     
    8283  SProgramLowerLimit = 'Program run over lower limit';
    8384  SProgramUpperLimit = 'Program run over upper limit';
    84   SJumpTableInsistent = 'Jump table is inconsistent';
     85  SJumpTableInconsistent = 'Jump table is inconsistent';
    8586  SJumpTableCollision = 'Jump table collision';
    8687  SProgramNotRunning = 'Program not running';
     
    179180    end;
    180181  end;
    181   if Length(Loop) > 0 then raise Exception.Create(SJumpTableInsistent);
     182  if Length(Loop) > 0 then raise Exception.Create(SJumpTableInconsistent);
    182183end;
    183184
     
    242243procedure TTargetInterpretter.CommandPointerInc;
    243244begin
    244   if MemoryPosition < MemorySize then Inc(MemoryPosition, FProgram[FProgramIndex].Parameter)
     245  if MemoryPosition < MemorySize then
     246    Inc(MemoryPosition, FProgram[FProgramIndex].Parameter)
    245247    else raise Exception.Create(SProgramUpperLimit);
    246248end;
     
    248250procedure TTargetInterpretter.CommandPointerDec;
    249251begin
    250   if MemoryPosition > 0 then Dec(MemoryPosition, FProgram[FProgramIndex].Parameter)
     252  if MemoryPosition > 0 then
     253    Dec(MemoryPosition, FProgram[FProgramIndex].Parameter)
    251254    else raise Exception.Create(SProgramLowerLimit);
    252255end;
     
    257260begin
    258261  Addr := MemoryPosition + FProgram[FProgramIndex].RelIndex;
     262  CheckMemoryBounds(Addr);
    259263  Memory[Addr] := FProgram[FProgramIndex].Parameter mod CellSize;
    260264  MemoryMaxUsedAddr := Max(Addr, MemoryMaxUsedAddr);
     
    267271begin
    268272  Addr := MemoryPosition + FProgram[FProgramIndex].RelIndex;
     273  CheckMemoryBounds(Addr);
    269274  Memory[Addr] := (Memory[Addr] + Memory[MemoryPosition] *
    270275    FProgram[FProgramIndex].Parameter) mod CellSize;
     
    297302begin
    298303  inherited;
     304  EmitTargetCode;
    299305end;
    300306
     
    311317end;
    312318
    313 function TTargetInterpretter.GetTargetCode: string;
     319procedure TTargetInterpretter.CheckMemoryBounds(Address: Integer);
     320begin
     321  if Address < 0 then raise Exception.Create(SProgramLowerLimit);
     322  if Address >= MemorySize then raise Exception.Create(SProgramUpperLimit);
     323end;
     324
     325procedure TTargetInterpretter.EmitTargetCode;
    314326var
    315327  I: Integer;
    316 begin
    317   Result := '';
     328  Code: string;
     329  TargetIndex: Integer;
     330  Step: TDebugStep;
     331begin
     332  TargetIndex := 0;
     333  FTargetCode := '';
    318334  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));
    320345  end;
    321346end;
  • trunk/UBFTarget.pas

    r126 r128  
    3737    Index: Integer;
    3838    procedure Assign(Source: TProgram);
     39    procedure Write(Operation: TMachineOperation);
     40    function Read: TMachineOperation;
    3941    property Count: Integer read GetCount write SetCount;
    4042    property Items[Index: Integer]: TMachineOperation read GetItem write SetItem; default;
     
    117119end;
    118120
     121procedure TProgram.Write(Operation: TMachineOperation);
     122begin
     123  Operations[Index] := Operation;
     124  Inc(Index);
     125end;
     126
     127function TProgram.Read: TMachineOperation;
     128begin
     129  Result := Operations[Index];
     130  Inc(Index);
     131end;
     132
    119133{ TMachineOperation }
    120134
     
    158172var
    159173  NewProgram: TProgram;
    160   NewTargetIndex: Integer;
    161   FirstIndex: Integer;
    162 begin
    163   NewTargetIndex := 0;
     174  InitialProgramIndex: Integer;
     175  InitialNewProgramIndex: Integer;
     176begin
    164177  NewProgram := TProgram.Create;
    165178  NewProgram.Count := FProgram.Count;
     
    167180  FProgramIndex := 0;
    168181  while FProgramIndex < FProgram.Count do begin
    169     FirstIndex := FProgramIndex;
     182    InitialProgramIndex := FProgramIndex;
     183    InitialNewProgramIndex := NewProgram.Index;
    170184    case FProgram[FProgramIndex].Command of
    171185      cmPointerInc: begin
    172         NewProgram[NewProgram.Index] := TMachineOperation.Create(cmPointerInc,
    173           CheckOccurenceSumParam(cmPointerInc));
     186        NewProgram.Write(TMachineOperation.Create(cmPointerInc,
     187          CheckOccurenceSumParam(cmPointerInc)));
    174188      end;
    175189      cmPointerDec: begin
    176         NewProgram[NewProgram.Index] := TMachineOperation.Create(cmPointerDec,
    177           CheckOccurenceSumParam(cmPointerDec));
     190        NewProgram.Write(TMachineOperation.Create(cmPointerDec,
     191          CheckOccurenceSumParam(cmPointerDec)));
    178192      end;
    179193      cmInc: begin
    180         NewProgram[NewProgram.Index] := TMachineOperation.Create(cmInc,
    181           CheckOccurenceSumParam(cmInc));
     194        NewProgram.Write(TMachineOperation.Create(cmInc,
     195          CheckOccurenceSumParam(cmInc)));
    182196      end;
    183197      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]);
    188202    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);
    191205    Inc(FProgramIndex);
    192     Inc(NewProgram.Index);
    193206  end;
    194207
     
    202215var
    203216  NewProgram: TProgram;
    204   FirstIndex: Integer;
    205   NewTargetIndex: Integer;
    206 begin
    207   NewTargetIndex := 0;
     217  InitialProgramIndex: Integer;
     218  InitialNewProgramIndex: Integer;
     219begin
    208220  NewProgram := TProgram.Create;
    209221  NewProgram.Count := FProgram.Count;
     
    211223  FProgramIndex := 0;
    212224  while FProgramIndex < FProgram.Count do begin
    213     FirstIndex := FProgramIndex;
     225    InitialProgramIndex := FProgramIndex;
     226    InitialNewProgramIndex := NewProgram.Index;
    214227    case FProgram[FProgramIndex].Command of
    215228      cmLoopStart: begin
    216229        if CheckLoopSetZero then begin
    217           NewProgram[NewProgram.Index] := TMachineOperation.Create(cmSet, 0, 0);
     230          NewProgram.Write(TMachineOperation.Create(cmSet, 0, 0));
    218231          Inc(FProgramIndex, 2);
    219232        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]);
    224237    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);
    227240    Inc(FProgramIndex);
    228     Inc(NewProgram.Index);
    229241  end;
    230242  NewProgram.Count := NewProgram.Index;
     
    239251  NewProgram: TProgram;
    240252  PreviousCommand: TMachineCommand;
    241   FirstIndex: Integer;
    242   NewTargetIndex: Integer;
    243 begin
    244   NewTargetIndex := 0;
     253  InitialProgramIndex: Integer;
     254  InitialNewProgramIndex: Integer;
     255begin
    245256  NewProgram := TProgram.Create;
    246257  NewProgram.Count := FProgram.Count;
     
    249260  FProgramIndex := 0;
    250261  while FProgramIndex < FProgram.Count do begin
    251     FirstIndex := FProgramIndex;
     262    InitialProgramIndex := FProgramIndex;
     263    InitialNewProgramIndex := NewProgram.Index;
    252264    case FProgram[FProgramIndex].Command of
    253265      cmPointerInc: begin
     
    267279              else NewProgram.Operations[NewProgram.Index - 1].Command := cmPointerInc;
    268280          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));
    274286        end;
    275287      end;
     
    289301              else NewProgram.Operations[NewProgram.Index - 1].Command := cmPointerInc;
    290302          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));
    296308        end;
    297309      end;
     
    311323              else NewProgram.Operations[NewProgram.Index - 1].Command := cmInc;
    312324          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));
    318330        end;
    319331      end;
     
    333345              else NewProgram.Operations[NewProgram.Index - 1].Command := cmInc;
    334346          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));
    340352        end;
    341353      end;
     
    344356          // Set overrides value of previous commands
    345357          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]);
    353365    end;
    354366    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);
    357369    Inc(FProgramIndex);
    358     Inc(NewProgram.Index);
    359370  end;
    360371
     
    375386  NewProgram: TProgram;
    376387  RelIndex: Integer;
    377   FirstIndex: Integer;
    378   NewTargetIndex: Integer;
    379 begin
    380   NewTargetIndex := 0;
     388  InitialProgramIndex: Integer;
     389  InitialNewProgramIndex: Integer;
     390begin
    381391  NewProgram := TProgram.Create;
    382392  NewProgram.Count := FProgram.Count;
     
    385395  FProgramIndex := 0;
    386396  while FProgramIndex < FProgram.Count do begin
    387     FirstIndex := FProgramIndex;
     397    InitialProgramIndex := FProgramIndex;
     398    InitialNewProgramIndex := NewProgram.Index;
    388399    case FProgram[FProgramIndex].Command of
    389400      cmPointerInc: begin
    390401        RelIndex := RelIndex + FProgram[FProgramIndex].Parameter;
    391         Dec(NewProgram.Index);
    392402      end;
    393403      cmPointerDec: begin
    394404        RelIndex := RelIndex - FProgram[FProgramIndex].Parameter;
    395         Dec(NewProgram.Index);
    396405      end;
    397406      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;
    401410      end;
    402411      cmLoopStart, cmLoopEnd: begin
    403412        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));
    407415          RelIndex := 0;
    408416        end else
    409417        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));
    413420          RelIndex := 0;
    414421        end;
    415         NewProgram[NewProgram.Index] := FProgram[FProgramIndex];
     422        NewProgram.Write(FProgram[FProgramIndex]);
    416423      end;
    417424      else raise Exception.Create(Format(SUnsupportedCommand, [FProgram[FProgramIndex].Command]));
    418425    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);
    421428    Inc(FProgramIndex);
    422     Inc(NewProgram.Index);
    423429  end;
    424430
     
    472478  ProcessingLoop: Boolean;
    473479  PointerChange: Integer;
    474   NumberOfBaseDecrement: Integer;
    475   FirstIndex: Integer;
    476   NewTextIndex: Integer;
    477   NoNewCode: Boolean;
     480  InitialProgramIndex: Integer;
     481  InitialNewProgramIndex: Integer;
    478482begin
    479483  NewProgram := TProgram.Create;
    480484  NewProgram.Count := FProgram.Count;
    481485
    482   NumberOfBaseDecrement := 0;
    483486  ProcessingLoop := False;
    484487  FProgramIndex := 0;
    485   NewTextIndex := 0;
    486488  PointerChange := 0;
    487489  while FProgramIndex < FProgram.Count do begin
    488     FirstIndex := FProgramIndex;
    489     NoNewCode := False;
     490    InitialProgramIndex := FProgramIndex;
     491    InitialNewProgramIndex := NewProgram.Index;
    490492    case FProgram[FProgramIndex].Command of
    491493      cmPointerInc: begin
    492494        Inc(PointerChange, FProgram[FProgramIndex].Parameter);
    493         NewProgram[NewProgram.Index] := FProgram[FProgramIndex];
     495        NewProgram.Write(FProgram[FProgramIndex]);
    494496      end;
    495497      cmPointerDec: begin
    496498        Dec(PointerChange, FProgram[FProgramIndex].Parameter);
    497         NewProgram[NewProgram.Index] := FProgram[FProgramIndex];
     499        NewProgram.Write(FProgram[FProgramIndex]);
    498500      end;
    499501      cmInc: begin
    500502        if not ProcessingLoop then begin
    501           NewProgram[NewProgram.Index] := FProgram[FProgramIndex];
     503          NewProgram.Write(FProgram[FProgramIndex]);
    502504        end else begin
    503505          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;
    507509        end;
    508510      end;
    509511      cmDec: begin
    510512        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]);
    515514        end else begin
    516515          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]);
    530524      end;
    531525      cmLoopStart: begin
     
    534528            PointerChange := 0;
    535529            ProcessingLoop := True;
    536             NoNewCode := True;
    537530          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');
    541534        end;
    542535      end;
    543536      cmLoopEnd: begin
    544537        if not ProcessingLoop then begin
    545           NewProgram[NewProgram.Index] := FProgram[FProgramIndex];
     538          NewProgram.Write(FProgram[FProgramIndex]);
    546539        end else begin
    547540          // Finally set decrementing cell to zero
    548           NewProgram[NewProgram.Index] := TMachineOperation.Create(cmSet, 0, 0);
     541          NewProgram.Write(TMachineOperation.Create(cmSet, 0, 0));
    549542          ProcessingLoop := False;
    550543        end;
     
    552545      else raise Exception.Create(Format(SUnsupportedCommand, [FProgram[FProgramIndex].Command]));
    553546    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);
    559550    Inc(FProgramIndex);
    560     if not NoNewCode then Inc(NewProgram.Index);
    561551  end;
    562552
     
    581571var
    582572  I: Integer;
     573  LastIndex: Integer;
    583574begin
    584575  inherited;
    585576  DebugSteps.Clear;
    586577  FProgram.Count := Length(FSourceCode);
    587   FProgramIndex := 0;
     578  FProgram.Index := 0;
     579  LastIndex := 0;
    588580  for I := 1 to Length(FSourceCode) do begin
    589581    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));
    623590    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;
    627597end;
    628598
  • trunk/UCore.pas

    r125 r128  
    3838    CellSize: Integer;
    3939    MemorySize: Integer;
     40    DebugEnabled: Boolean;
     41    OptionsFormTabIndex: Integer;
    4042    Optimizations: TOptimizations;
    4143    procedure Init;
     
    120122    MemorySize := ReadIntegerWithDefault('MemorySize', 30000);
    121123    CellSize := ReadIntegerWithDefault('CellSize', 256);
     124    DebugEnabled := ReadBoolWithDefault('DebugEnabled', True);
     125    OptionsFormTabIndex := ReadIntegerWithDefault('OptionsFormTabIndex', 0);
    122126    ThemeManager.Theme := ThemeManager.Themes.FindByName(ReadStringWithDefault('Theme', 'System'));
    123127  finally
     
    143147    WriteInteger('MemorySize', MemorySize);
    144148    WriteInteger('CellSize', CellSize);
     149    WriteBool('DebugEnabled', DebugEnabled);
     150    WriteInteger('OptionsFormTabIndex', OptionsFormTabIndex);
    145151    if Assigned(Translator.Language) and (Translator.Language.Code <> '') then
    146152      WriteString('LanguageCode', Translator.Language.Code)
  • trunk/UTarget.pas

    r126 r128  
    3535    function SearchIndexByProgramPos(Pos: Integer): Integer;
    3636    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);
    3839  end;
    3940
     
    108109    BreakPoints: TBreakPointList;
    109110    DebugSteps: TDebugStepList;
     111    DebugEnabled: Boolean;
    110112    Messages: TMessageList;
    111113    constructor Create; virtual;
     
    280282end;
    281283
    282 procedure TDebugStepList.UpdateTargetPos(OldProgramFrom, OldProgramTo, NewProgram, NewTarget: Integer);
     284procedure TDebugStepList.UpdateTargetPos(OldProgramFrom, OldProgramTo, NewProgramFrom,
     285    NewProgramTo: Integer; NewTarget: Integer = 0);
    283286var
    284287  I: Integer;
     
    288291  First := SearchIndexByProgramPos(OldProgramFrom);
    289292  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;
    296307      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');
    300310  end;
    301311end;
Note: See TracChangeset for help on using the changeset viewer.